dd
Dependencies: BufferedSerial FastAnalogIn FastPWM mbed SHT75
Revision 10:c751a0e8b7f9, committed 2016-07-11
- Comitter:
- sbh9428
- Date:
- Mon Jul 11 01:05:52 2016 +0000
- Parent:
- 9:6ef12ac2ddc3
- Commit message:
- fff;
Changed in this revision
diff -r 6ef12ac2ddc3 -r c751a0e8b7f9 commandt.cpp --- a/commandt.cpp Thu Mar 31 14:01:49 2016 +0000 +++ b/commandt.cpp Mon Jul 11 01:05:52 2016 +0000 @@ -67,6 +67,26 @@ case 'e': control->set_period((int)asci_to_bin(data+2)); printf("set period %d\n", (int)asci_to_bin(data+2)); + break; + case 'h': + control->highTemp=asci_to_bin(data+2); + printf("set high temp %2.2f\n", asci_to_bin(data+2)); + break; + case 'l': + control->lowTemp=asci_to_bin(data+2); + printf("set low temp %2.2f\n", asci_to_bin(data+2)); + break; + case 'a': + control->highTempTime=(int)asci_to_bin(data+2); + printf("set high temp time%d\n", (int)asci_to_bin(data+2)); + break; + case 'b': + control->lowTempTime=(int)asci_to_bin(data+2); + printf("set low temp %d\n", (int)asci_to_bin(data+2)); + break; + case 'o': + control->periodNumber=(int)asci_to_bin(data+2); + printf("set period repeat number %d \n", (int)asci_to_bin(data+2)); break; default: pc->printf("command error");
diff -r 6ef12ac2ddc3 -r c751a0e8b7f9 controlt.cpp --- a/controlt.cpp Thu Mar 31 14:01:49 2016 +0000 +++ b/controlt.cpp Mon Jul 11 01:05:52 2016 +0000 @@ -28,6 +28,10 @@ table_count=0; table_mode=0; + + repeatTime=0; + repeatCount=0; + repeatSide=0; } control_t::~control_t() { @@ -111,8 +115,8 @@ void control_t::refresh_PWM() { write_log(); - time+=3; - printf("\n%1.4f, %1.4f, %1.4f, %1.4f, %2.2f, %d, %d, %d, %2.2f, %2.2f", P_value, I_value, D_value, PWM_value, start_temp, period, time, mode, target_temp, temp_sensor->get_temp()); + time+=10; + printf("\n%1.4f, %d, %d, %d, %d, %d, %d, %d, %2.2f, %2.2f, %2.2f, %2.2f", P_value, time, mode, repeatTime, repeatCount, repeatSide, highTempTime, lowTempTime, highTemp, lowTemp, target_temp, temp_sensor->get_temp()); if(mode==0) { PWM_value=0; @@ -133,6 +137,10 @@ { follow_table(); } + else if(mode==5) + { + repeatPeriod(); + } } int control_t::get_mode() @@ -283,4 +291,38 @@ printf(",remain step: %d",period-step); step++; } -} \ No newline at end of file +} + +void control_t::repeatPeriod() +{ + repeatTime+=10; + if(repeatSide==0) + { + target_temp=lowTemp; + if(repeatTime>lowTempTime) + { + repeatSide=1; + repeatTime=0; + } + } + else + { + target_temp=highTemp; + if(repeatTime>highTempTime) + { + repeatSide=0; + repeatTime=0; + repeatCount++; + if(repeatCount>=periodNumber) + { + repeatSide=0; + repeatTime=0; + repeatCount=0; + mode=0; + } + } + + } + control_temp(); + +} \ No newline at end of file
diff -r 6ef12ac2ddc3 -r c751a0e8b7f9 controlt.h --- a/controlt.h Thu Mar 31 14:01:49 2016 +0000 +++ b/controlt.h Mon Jul 11 01:05:52 2016 +0000 @@ -48,6 +48,19 @@ void print_table(); void follow_table(); + float highTemp; + float lowTemp; + + int highTempTime; + int lowTempTime; + int periodNumber; + + void repeatPeriod(); + + int repeatTime; + int repeatCount; + int repeatSide; + control_t(); control_t(temp_sensor_t* _temp_sensor, peltier_t* _peltier,BufferedSerial* _pc); virtual ~control_t();
diff -r 6ef12ac2ddc3 -r c751a0e8b7f9 main.cpp --- a/main.cpp Thu Mar 31 14:01:49 2016 +0000 +++ b/main.cpp Mon Jul 11 01:05:52 2016 +0000 @@ -11,7 +11,7 @@ Ticker controltick; -AnalogIn temp_sensor_pin(p19); +AnalogIn temp_sensor_pin(p20); temp_sensor_t temp_sensor(&temp_sensor_pin); @@ -45,7 +45,7 @@ pc.printf("temperature start \n"); - controltick.attach(&peltier_control, 3);// sampling time + controltick.attach(&peltier_control, 10);// sampling time wait(10);
diff -r 6ef12ac2ddc3 -r c751a0e8b7f9 peltiert.cpp --- a/peltiert.cpp Thu Mar 31 14:01:49 2016 +0000 +++ b/peltiert.cpp Mon Jul 11 01:05:52 2016 +0000 @@ -26,8 +26,8 @@ void peltier_t::set_PWM(float duty_ratio) { if(duty_ratio>0) - *direction_pin=1; + *direction_pin=0; else - *direction_pin=0; + *direction_pin=1; peltier_pin->pulsewidth_us(1000*abs(duty_ratio)); } \ No newline at end of file
diff -r 6ef12ac2ddc3 -r c751a0e8b7f9 tempsensort.cpp --- a/tempsensort.cpp Thu Mar 31 14:01:49 2016 +0000 +++ b/tempsensort.cpp Mon Jul 11 01:05:52 2016 +0000 @@ -24,5 +24,5 @@ float temp_sensor_t::get_temp() { - return (double)temperature_sensor->read_u16()/1024/64*165-40; + return (float)temperature_sensor->read_u16()/1024/64*165-40; }