dd
Dependencies: BufferedSerial FastAnalogIn FastPWM mbed SHT75
Revision 0:9bfc4aea91e2, committed 2016-02-19
- Comitter:
- sbh9428
- Date:
- Fri Feb 19 07:07:26 2016 +0000
- Child:
- 1:5c42ec7f1aeb
- Commit message:
- temp;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BufferedSerial.lib Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/sam_grove/code/BufferedSerial/#779304f9c5d2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastAnalogIn.lib Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/Sissors/code/FastAnalogIn/#afc3b84dbbd6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FastPWM.lib Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/Sissors/code/FastPWM/#7f484dd7323d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commandt.cpp Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,116 @@ +/* + * commandt.cpp + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#include "commandt.h" + +command_t::command_t() { + // TODO Auto-generated constructor stub + +} + +command_t::command_t(BufferedSerial* _pc, control_t* _control) +{ + count=0; + control=_control; + pc=_pc; + pc->baud(115200); +} + +command_t::~command_t() { + // TODO Auto-generated destructor stub +} + +void command_t::clear_data() +{ + for(int i=0;i<10;i++) + { + data[i]=0; + } +} +void command_t::parse() +{ + switch(data[0]) + { + case 's': + switch(data[1]) + { + case 'm': + control->set_mode(data[2]-'0'); + break; + case 'p': + control->control_PWM(asci_to_bin(data+2)); + printf("set WPM duty ratio %f\n", asci_to_bin(data+2)); + break; + case 't': + + break; + } + break; + case 'g': + + break; + dafault: + pc->printf("command error"); + } + pc->printf("\n"); +} + +void command_t::get_data() +{ + data [count]=pc->getc(); + + if(data [count]=='f') + parse(); + else + count++; + + if(count>9) + { + count=0; + pc->printf("command error\n"); + } +} + +void command_t::refreshPWM() +{ + printf("temperature is %f\n", control->get_temp()); + +} + +double command_t::asci_to_bin(int *start) +{ + double _data=0; + int current=0; + + double nth=1; //�ڸ��� + int mode=0; + int sign=1; + + if(*start=='-') + { + current++; + sign=-1; + } + while(*(start+current)!='f'&&*(start+current)!='.') + { + _data*=10; + _data+=*(start+current)-'0'; + + current++; + } + if(*(start+current)=='.') + { + current++; + while(*(start+current)!='f') + { + nth/=10; + _data+=nth*(*(start+current)-'0'); + current++; + } + } + return sign*_data; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commandt.h Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,35 @@ +/* + * commandt.h + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#ifndef COMMANDT_H_ +#define COMMANDT_H_ + +#include "BufferedSerial.h" +#include "controlt.h" + +class command_t { +public: + void clear_data(); + void parse(); + void get_data(); + void refreshPWM(); + double asci_to_bin(int *start); + + command_t(); + command_t(BufferedSerial* _pc, control_t* _control); + virtual ~command_t(); +private: + int count; + int data[10]; + + BufferedSerial* pc; + control_t *control; +}; + + +#endif /* COMMANDT_H_ */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/controlt.cpp Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,44 @@ +/* + * controlt.cpp + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#include "controlt.h" + +control_t::control_t() { + // TODO Auto-generated constructor stub + +} + +control_t::control_t(temp_sensor_t* _temp_sensor, peltier_t* _peltier) +{ + temp_sensor=_temp_sensor; + peltier=_peltier; +} + +control_t::~control_t() { + // TODO Auto-generated destructor stub +} + +float control_t::get_temp() +{ + return temp_sensor->get_temp(); +} + +void control_t::control_PWM(float PWM) +{ + peltier->set_PWM(PWM); +} + +void control_t::control_temp() +{ + + +} + +void control_t::set_mode(int _mode) +{ + mode=_mode; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/controlt.h Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,32 @@ +/* + * controlt.h + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#ifndef CONTROLT_H_ +#define CONTROLT_H_ + +#include "tempsensort.h" +#include "peltiert.h" + +class control_t { +public: + float get_temp(); + void control_PWM(float PWM); + void control_temp(); + void set_mode(int _mode); + + control_t(); + control_t(temp_sensor_t* _temp_sensor, peltier_t* _peltier); + virtual ~control_t(); +private: + temp_sensor_t* temp_sensor; + peltier_t* peltier; + + int mode;//0: stop 1: set pwm 2: set temp +}; + +#endif /* CONTROLT_H_ */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" + +#include "BufferedSerial.h" +#include "FastAnalogIn.h" +#include "FastPWM.h" + +#include "commandt.h" +#include "controlt.h" +#include "peltiert.h" +#include "tempsensort.h" + +Ticker controltick; + +FastAnalogIn temp_sensor_pin(p20); + +temp_sensor_t temp_sensor(&temp_sensor_pin); + + + +FastPWM PWM_pin(p21); +DigitalOut PWM_dir(p22); + +peltier_t peltier(&PWM_pin, &PWM_dir); + + + +control_t control(&temp_sensor, &peltier); + + + + +BufferedSerial pc(USBTX, USBRX); + + + +command_t command(&pc, &control); + + + +void peltier_control(); + +int main() { + pc.printf("temperature start \n"); + + controltick.attach(&peltier_control, 1); + + + + while(1) + { + while(pc.readable()) + { + command.get_data(); + } + } + +} + +void peltier_control() +{ + command.refreshPWM(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/252557024ec3 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/peltiert.cpp Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,33 @@ +/* + * peltiert.cpp + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#include "peltiert.h" + +peltier_t::peltier_t() { + // TODO Auto-generated constructor stub + +} + +peltier_t::peltier_t(FastPWM* _peltier_pin, DigitalOut* _direction_pin) { + peltier_pin=_peltier_pin; + direction_pin=_direction_pin; + + peltier_pin->period_ms(1); +} + +peltier_t::~peltier_t() { + // TODO Auto-generated destructor stub +} + +void peltier_t::set_PWM(float duty_ratio) +{ + if(duty_ratio>0) + *direction_pin=1; + else + *direction_pin=0; + peltier_pin->pulsewidth_us(1000*abs(duty_ratio)); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/peltiert.h Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,25 @@ +/* + * peltiert.h + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#ifndef PELTIERT_H_ +#define PELTIERT_H_ + +#include "FastPWM.h" + +class peltier_t { +public: + void set_PWM(float duty_ratio); + + peltier_t(); + peltier_t(FastPWM* _peltier_pin, DigitalOut* _direction_pin); + virtual ~peltier_t(); +private: + FastPWM* peltier_pin; + DigitalOut* direction_pin; +}; + +#endif /* PELTIERT_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tempsensort.cpp Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,29 @@ +/* + * tempsensott.cpp + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#include "tempsensort.h" + +temp_sensor_t::temp_sensor_t() { + // TODO Auto-generated constructor stub + +} + +temp_sensor_t::temp_sensor_t(FastAnalogIn* _temperature_sensor) +{ + temperature_sensor=_temperature_sensor; + temperature_sensor->enable(1); +} + + +temp_sensor_t::~temp_sensor_t() { + // TODO Auto-generated destructor stub +} + +float temp_sensor_t::get_temp() +{ + return temperature_sensor->read()*165-40; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tempsensort.h Fri Feb 19 07:07:26 2016 +0000 @@ -0,0 +1,24 @@ +/* + * tempsensott.h + * + * Created on: 2016. 2. 19. + * Author: sbh9428 + */ + +#ifndef TEMPSENSORT_H_ +#define TEMPSENSORT_H_ + +#include "FastAnalogIn.h" + +class temp_sensor_t { +public: + float get_temp(); + + temp_sensor_t(); + temp_sensor_t(FastAnalogIn* _temperature_sensor); + virtual ~temp_sensor_t(); +private: + FastAnalogIn* temperature_sensor; +}; + +#endif /* TEMPSENSOTT_H_ */