|
|
@ -18,13 +18,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*===== Object =====*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ticker heater; |
|
|
|
|
|
|
|
Ticker serial_reporter; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*===== Variable =====*/ |
|
|
|
/*===== Variable =====*/ |
|
|
|
//-300: off
|
|
|
|
//-300: off
|
|
|
|
double temp1_current = 0; |
|
|
|
double temp1_current = 0; |
|
|
@ -37,66 +30,65 @@ boolean stringComplete = false; // whether the string is complete |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*===== Function =====*/ |
|
|
|
/*===== Function =====*/ |
|
|
|
|
|
|
|
|
|
|
|
double getTemperature(uint8_t thermistor_pin){ |
|
|
|
double getTemperature(uint8_t thermistor_pin){ |
|
|
|
// vin ---- Rs --(adc)-- Rtm ---- gnd
|
|
|
|
// vin ---- Rs --(adc)-- Rtm ---- gnd
|
|
|
|
const double Vin = 3.3; //3.3 for ESP/STM32 series
|
|
|
|
const double Vin = 3.3; //3.3 for ESP/STM32 series
|
|
|
|
const double Rs = 10000; //strip resistor resistance
|
|
|
|
const double Rs = 10000; //strip resistor resistance
|
|
|
|
const double Rtm_std = 100000; //thermistor resistance at 25C
|
|
|
|
const double Rtm_std = 100000; //thermistor resistance at 25C
|
|
|
|
const uint32_t adc_resolution = 1023; //10bit ADC
|
|
|
|
const uint32_t adc_resolution = 1023; //10bit ADC
|
|
|
|
const uint32_t B = 3950; |
|
|
|
const uint32_t B = 3950; |
|
|
|
|
|
|
|
|
|
|
|
const double C1 = 1/298.15; |
|
|
|
const double C1 = 1/298.15; |
|
|
|
|
|
|
|
|
|
|
|
// Vtm(Vadc) = Vin * Rtm/(Rs+Rtm)
|
|
|
|
// Vtm(Vadc) = Vin * Rtm/(Rs+Rtm)
|
|
|
|
// Rtm = Vtm * Rs / (Vin - Vtm)
|
|
|
|
// Rtm = Vtm * Rs / (Vin - Vtm)
|
|
|
|
|
|
|
|
|
|
|
|
// Rtm = Rtm_std * exp(B*(1/Tk - 1/298.15))
|
|
|
|
// Rtm = Rtm_std * exp(B*(1/Tk - 1/298.15))
|
|
|
|
// Rtm = Rtm_std * exp(B*(1/Tk - C1))
|
|
|
|
// Rtm = Rtm_std * exp(B*(1/Tk - C1))
|
|
|
|
|
|
|
|
|
|
|
|
// exp(B*(1/Tk - C1)) = Rtm / Rtm_std
|
|
|
|
// exp(B*(1/Tk - C1)) = Rtm / Rtm_std
|
|
|
|
// B*(1/Tk - C1) = log[Rtm / Rtm_std]
|
|
|
|
// B*(1/Tk - C1) = log[Rtm / Rtm_std]
|
|
|
|
// 1/Tk = log[Rtm / Rtm_std] / B + C1
|
|
|
|
// 1/Tk = log[Rtm / Rtm_std] / B + C1
|
|
|
|
// Tk = 1/( log[Rtm / Rtm_std] / B + C1 )
|
|
|
|
// Tk = 1/( log[Rtm / Rtm_std] / B + C1 )
|
|
|
|
|
|
|
|
|
|
|
|
// T = Tk -273.15;
|
|
|
|
// T = Tk -273.15;
|
|
|
|
|
|
|
|
|
|
|
|
double Vtm = (analogRead(thermistor_pin) * Vin) / adc_resolution; |
|
|
|
double Vtm = (analogRead(thermistor_pin) * Vin) / adc_resolution; |
|
|
|
double Rtm = Vtm * Rs / (Vin - Vtm); |
|
|
|
double Rtm = Vtm * Rs / (Vin - Vtm); |
|
|
|
double T = 1 / ( log(Rtm / Rtm_std) / B + C1) - 273.15; |
|
|
|
double T = 1 / ( log(Rtm / Rtm_std) / B + C1) - 273.15; |
|
|
|
|
|
|
|
|
|
|
|
return T; |
|
|
|
return T; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void heat_drive(uint8_t heater, bool heat_sw){ |
|
|
|
void heat_drive(uint8_t heater, bool heat_sw){ |
|
|
|
if(heater == 1){ |
|
|
|
if(heater == 1){ |
|
|
|
digitalWrite(HEATER1_PIN, heat_sw); |
|
|
|
digitalWrite(HEATER1_PIN, heat_sw); |
|
|
|
digitalWrite(HEATER1_LED_PIN, !heat_sw); //low: turn on
|
|
|
|
digitalWrite(HEATER1_LED_PIN, !heat_sw); //low: turn on
|
|
|
|
}else if(heater == 2){ |
|
|
|
}else if(heater == 2){ |
|
|
|
digitalWrite(HEATER2_PIN, heat_sw); |
|
|
|
digitalWrite(HEATER2_PIN, heat_sw); |
|
|
|
digitalWrite(HEATER2_LED_PIN, !heat_sw); //low: turn on
|
|
|
|
digitalWrite(HEATER2_LED_PIN, !heat_sw); //low: turn on
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void heat_handler(){ |
|
|
|
void heat_handler(){ |
|
|
|
temp1_current = getTemperature(HEATER1_THERMISTOR_PIN); |
|
|
|
temp1_current = getTemperature(HEATER1_THERMISTOR_PIN); |
|
|
|
temp2_current = getTemperature(HEATER2_THERMISTOR_PIN); |
|
|
|
temp2_current = getTemperature(HEATER2_THERMISTOR_PIN); |
|
|
|
|
|
|
|
|
|
|
|
if(temp1_target > MAX_TEMP || temp1_target < 0 || temp1_current > temp1_target){ |
|
|
|
if(temp1_target > MAX_TEMP || temp1_target < 0 || temp1_current > temp1_target){ |
|
|
|
heat_drive(1,0); |
|
|
|
heat_drive(1,0); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
heat_drive(1,1); |
|
|
|
heat_drive(1,1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(temp2_target > MAX_TEMP || temp2_target < 0 || temp2_current > temp2_target){ |
|
|
|
if(temp2_target > MAX_TEMP || temp2_target < 0 || temp2_current > temp2_target){ |
|
|
|
heat_drive(2,0); |
|
|
|
heat_drive(2,0); |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
heat_drive(2,1); |
|
|
|
heat_drive(2,1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -152,6 +144,18 @@ void heat_handler(){ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*===== Object =====*/ |
|
|
|
|
|
|
|
#ifdef WIRELESS_SUPPORT |
|
|
|
|
|
|
|
Ticker heater; |
|
|
|
|
|
|
|
Ticker serial_reporter; |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
Ticker heater(heat_handler, 100); |
|
|
|
|
|
|
|
Ticker serial_reporter(serial_report_handler, 500); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*===== Main =====*/ |
|
|
|
/*===== Main =====*/ |
|
|
|
|
|
|
|
|
|
|
|
void setup() { |
|
|
|
void setup() { |
|
|
@ -170,10 +174,18 @@ void setup() { |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
/*[Ticker Init]*/ |
|
|
|
/*[Ticker Init]*/ |
|
|
|
heater.attach(0.1, heat_handler); |
|
|
|
#ifdef WIRELESS_SUPPORT |
|
|
|
#ifndef SERIAL_DEBUG |
|
|
|
heater.attach(0.1, heat_handler); |
|
|
|
serial_reporter.attach(0.5, serial_report_handler); |
|
|
|
#ifndef SERIAL_DEBUG |
|
|
|
|
|
|
|
serial_reporter.attach(0.5, serial_report_handler); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
heater.start(); |
|
|
|
|
|
|
|
#ifndef SERIAL_DEBUG |
|
|
|
|
|
|
|
serial_reporter.start(); |
|
|
|
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -183,6 +195,9 @@ void loop() { |
|
|
|
//delay(100);
|
|
|
|
//delay(100);
|
|
|
|
#ifdef WIRELESS_SUPPORT |
|
|
|
#ifdef WIRELESS_SUPPORT |
|
|
|
wireless_handler(); |
|
|
|
wireless_handler(); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
heater.update(); |
|
|
|
|
|
|
|
serial_reporter.update(); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#ifndef SERIAL_DEBUG |
|
|
|
#ifndef SERIAL_DEBUG |
|
|
|