mirror of
https://github.com/ArduinoHannover/Maiskolben.git
synced 2025-09-03 10:03:07 +02:00
Refactoring, higher temperature bar, correct EEPROM update
- EEPROM autoboot/auto shutdown was set to auto shutdown when updating temperature - Indentation for definition.h altered - More constants - Better constant names - Individual temperature bar height - Starting bar at TEMP_COLD - Higher "cold" temperature
This commit is contained in:
@@ -331,7 +331,7 @@ void updateEEPROM(void) {
|
|||||||
}
|
}
|
||||||
EEPROM.update(8, set_t >> 8);
|
EEPROM.update(8, set_t >> 8);
|
||||||
EEPROM.update(9, set_t & 0xFF);
|
EEPROM.update(9, set_t & 0xFF);
|
||||||
EEPROM.update(EEPROM_OPTIONS, 1); //Defaults to auto power down
|
EEPROM.update(EEPROM_OPTIONS, (bootheat << 1) | autopower);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getTemperature(void) {
|
int getTemperature(void) {
|
||||||
@@ -348,9 +348,8 @@ int getTemperature(void) {
|
|||||||
} else {
|
} else {
|
||||||
analogWrite(HEATER_PWM, pwm); //switch heater back to last value
|
analogWrite(HEATER_PWM, pwm); //switch heater back to last value
|
||||||
}
|
}
|
||||||
return round(adc*0.574503+43.5); //nasty resistors...
|
|
||||||
//return round(adc < 210 ? (((float)adc) * 0.530805 + 38.9298) : (((float)adc) * 0.415375 + 64.6123)); //old conversion
|
//return round(adc < 210 ? (((float)adc) * 0.530805 + 38.9298) : (((float)adc) * 0.415375 + 64.6123)); //old conversion
|
||||||
//return round(((float) adc)*ADC_TO_TEMP_GAIN+ADC_TO_TEMP_OFFSET); //even older conversion
|
return round(((float) adc) * ADC_TO_TEMP_GAIN + ADC_TO_TEMP_OFFSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void measureVoltage(void) {
|
void measureVoltage(void) {
|
||||||
@@ -461,8 +460,8 @@ void timer_sw_poll(void) {
|
|||||||
cnt_but_press++;
|
cnt_but_press++;
|
||||||
if((cnt_but_press >= 100) || sw_changed) {
|
if((cnt_but_press >= 100) || sw_changed) {
|
||||||
setStandby(false);
|
setStandby(false);
|
||||||
if(sw_up && set_t < MAX_TEMP) set_t++;
|
if(sw_up && set_t < TEMP_MAX) set_t++;
|
||||||
else if (sw_down && set_t > MIN_TEMP) set_t--;
|
else if (sw_down && set_t > TEMP_MIN) set_t--;
|
||||||
if(!sw_changed) cnt_but_press = 97;
|
if(!sw_changed) cnt_but_press = 97;
|
||||||
updateEEPROM();
|
updateEEPROM();
|
||||||
}
|
}
|
||||||
@@ -569,8 +568,8 @@ void display(void) {
|
|||||||
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
|
tft.setTextColor(ST7735_WHITE, ST7735_BLACK);
|
||||||
tft.write(' ');
|
tft.write(' ');
|
||||||
tft.print(set_t);
|
tft.print(set_t);
|
||||||
tft.fillTriangle(149, 50, 159, 50, 154, 38, (set_t < MAX_TEMP) ? ST7735_WHITE : ST7735_GRAY);
|
tft.fillTriangle(149, 50, 159, 50, 154, 38, (set_t < TEMP_MAX) ? ST7735_WHITE : ST7735_GRAY);
|
||||||
tft.fillTriangle(149, 77, 159, 77, 154, 90, (set_t > MIN_TEMP) ? ST7735_WHITE : ST7735_GRAY);
|
tft.fillTriangle(149, 77, 159, 77, 154, 90, (set_t > TEMP_MIN) ? ST7735_WHITE : ST7735_GRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!off) {
|
if (!off) {
|
||||||
@@ -609,8 +608,8 @@ void display(void) {
|
|||||||
if (cur_t_old == 999) {
|
if (cur_t_old == 999) {
|
||||||
tft.fillRect(44,76,72,16,ST7735_BLACK);
|
tft.fillRect(44,76,72,16,ST7735_BLACK);
|
||||||
}
|
}
|
||||||
tft.setTextColor(off ? temperature < 50 ? ST7735_CYAN : ST7735_RED : tft.Color565(min(10,abs(temperature-target_t))*25, 250 - min(10,max(0,(abs(temperature-target_t)-10)))*25, 0), ST7735_BLACK);
|
tft.setTextColor(off ? temperature < TEMP_COLD ? ST7735_CYAN : ST7735_RED : tft.Color565(min(10,abs(temperature-target_t))*25, 250 - min(10,max(0,(abs(temperature-target_t)-10)))*25, 0), ST7735_BLACK);
|
||||||
if (temperature < 60) {
|
if (temperature < TEMP_COLD) {
|
||||||
tft.print("COLD");
|
tft.print("COLD");
|
||||||
} else {
|
} else {
|
||||||
tft.write(' ');
|
tft.write(' ');
|
||||||
@@ -619,10 +618,10 @@ void display(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (temperature < cur_t_old)
|
if (temperature < cur_t_old)
|
||||||
tft.drawFastHLine((int)(temperature/2.6), 0, 160-(int)(temperature/2.6), ST7735_BLACK);
|
tft.fillRect(max(0, (temperature - TEMP_COLD)/2.4), 0, 160-max(0, (temperature - TEMP_COLD)/2.4), BAR_HEIGHT, ST7735_BLACK);
|
||||||
else if (cur_t != 999) {
|
else if (cur_t != 999) {
|
||||||
for (int16_t i = 0; i < temperature/2.6; i++) {
|
for (int16_t i = max(0, (cur_t_old - TEMP_COLD)/2.4); i < max(0, (temperature - TEMP_COLD)/2.4); i++) {
|
||||||
tft.drawPixel(i, 0, tft.Color565(min(255, max(0, i*5)), min(255, max(0, 400-i*2.5)), 0));
|
tft.drawFastVLine(i, 0, BAR_HEIGHT, tft.Color565(min(255, max(0, i*5)), min(255, max(0, 450-i*2.5)), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur_t_old = temperature;
|
cur_t_old = temperature;
|
||||||
@@ -730,7 +729,7 @@ void compute(void) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (stby_layoff || stby) {
|
if (stby_layoff || stby) {
|
||||||
target_t = STBY_TEMP;
|
target_t = TEMP_STBY;
|
||||||
} else {
|
} else {
|
||||||
target_t = set_t;
|
target_t = set_t;
|
||||||
}
|
}
|
||||||
@@ -834,7 +833,7 @@ void loop(void) {
|
|||||||
if (Serial.available() >= 3) {
|
if (Serial.available() >= 3) {
|
||||||
t = serialReadTemp();
|
t = serialReadTemp();
|
||||||
//Serial.println(t);
|
//Serial.println(t);
|
||||||
if (t <= MAX_TEMP && t >= MIN_TEMP) {
|
if (t <= TEMP_MAX && t >= TEMP_MIN) {
|
||||||
set_t = t;
|
set_t = t;
|
||||||
updateEEPROM();
|
updateEEPROM();
|
||||||
}
|
}
|
||||||
@@ -846,7 +845,7 @@ void loop(void) {
|
|||||||
uint8_t slot = Serial.read()-'1';
|
uint8_t slot = Serial.read()-'1';
|
||||||
if (slot < 3) {
|
if (slot < 3) {
|
||||||
t = serialReadTemp();
|
t = serialReadTemp();
|
||||||
if (t <= MAX_TEMP && t >= MIN_TEMP) {
|
if (t <= TEMP_MAX && t >= TEMP_MIN) {
|
||||||
stored[slot] = t;
|
stored[slot] = t;
|
||||||
updateEEPROM();
|
updateEEPROM();
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,16 @@
|
|||||||
#define VERSION "2.7"
|
#define VERSION "2.8"
|
||||||
#define EE_VERSION 27
|
#define EE_VERSION 27
|
||||||
#define EEPROM_CHECK 42
|
#define EEPROM_CHECK 42
|
||||||
|
|
||||||
#define STBY_TEMP 150
|
#define BAR_HEIGHT 4 //Should be no bigger than 5
|
||||||
/*
|
/*
|
||||||
* TIPS ARE SPECIFIED FOR 450 DEGREE MAX
|
* TIPS ARE SPECIFIED FOR 450 DEGREE MAX
|
||||||
* If read 1023 on Analog in, the tip is turned off
|
* If read 1023 on Analog in, the tip is turned off automatically
|
||||||
*/
|
*/
|
||||||
#define MAX_TEMP 450
|
#define TEMP_MAX 450
|
||||||
#define MIN_TEMP 100
|
#define TEMP_MIN 100
|
||||||
|
#define TEMP_STBY 150
|
||||||
|
#define TEMP_COLD 70
|
||||||
|
|
||||||
#define SHUTOFF_ACTIVE
|
#define SHUTOFF_ACTIVE
|
||||||
#define BOOTHEAT_ACTIVE
|
#define BOOTHEAT_ACTIVE
|
||||||
@@ -16,55 +18,54 @@
|
|||||||
#define STANDBY_TIMEOUT 240 // seconds without any significant temperature drop, if exceeded it will standby
|
#define STANDBY_TIMEOUT 240 // seconds without any significant temperature drop, if exceeded it will standby
|
||||||
#define OFF_TIMEOUT 900 // seconds in standby before turning off
|
#define OFF_TIMEOUT 900 // seconds in standby before turning off
|
||||||
|
|
||||||
#define TEMP_THRESHOLD 50 //threshold voltage, that must be exceeded in given time:
|
#define TEMP_THRESHOLD 50 //threshold voltage, that must be exceeded in given time:
|
||||||
#define TEMP_UNDER_THRESHOLD 150 //*10ms
|
#define TEMP_UNDER_THRESHOLD 150 //*10ms
|
||||||
#define THRES_MAX_DECEED 2 //max times the threshold temperature may be undercut by the current temperature
|
#define THRES_MAX_DECEED 2 //max times the threshold temperature may be undercut by the current temperature
|
||||||
|
|
||||||
//Temperature in degree to rise at least in given time
|
//Temperature in degree to rise at least in given time
|
||||||
#define TEMP_MIN_RISE 10
|
#define TEMP_MIN_RISE 10
|
||||||
//Time in that the temperature must rise by the set temperature
|
//Time in that the temperature must rise by the set temperature
|
||||||
#define TEMP_RISE_TIME 1000
|
#define TEMP_RISE_TIME 1000
|
||||||
|
|
||||||
//#define OLD_PWM
|
//#define OLD_PWM
|
||||||
|
|
||||||
// RX 0
|
// RX 0
|
||||||
// TX 1
|
// TX 1
|
||||||
#define SW_STBY 2
|
#define SW_STBY 2
|
||||||
#define HEATER_PWM 3
|
#define HEATER_PWM 3
|
||||||
#define SW_DOWN 4
|
#define SW_DOWN 4
|
||||||
#define HEAT_LED 5
|
#define HEAT_LED 5
|
||||||
#define SW_UP 6
|
#define SW_UP 6
|
||||||
#define SW_T3 7
|
#define SW_T3 7
|
||||||
#define SW_T2 8
|
#define SW_T2 8
|
||||||
#define SW_T1 9
|
#define SW_T1 9
|
||||||
#define TFT_CS 10
|
#define TFT_CS 10
|
||||||
// MOSI 11
|
// MOSI 11
|
||||||
#define TFT_BL 12 //use MISO PULLUP as switch
|
#define TFT_BL 12 //use MISO PULLUP as switch
|
||||||
// SCK 13
|
// SCK 13
|
||||||
#define TEMP_SENSE A0
|
#define TEMP_SENSE A0
|
||||||
#define STBY_NO A1
|
#define STBY_NO A1
|
||||||
#define BAT_C3 A2
|
#define BAT_C3 A2
|
||||||
#define BAT_C2 A3
|
#define BAT_C2 A3
|
||||||
#define BAT_C1 A4
|
#define BAT_C1 A4
|
||||||
#define TFT_DC A5
|
#define TFT_DC A5
|
||||||
#ifdef PIN_A7
|
#ifdef PIN_A7
|
||||||
#define VIN A7
|
#define VIN A7
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define kp 0.03
|
#define kp 0.03
|
||||||
#define ki 0.00001
|
#define ki 0.00001
|
||||||
#define kd 0.0
|
#define kd 0.0
|
||||||
|
|
||||||
#define TIME_COMPUTE_IN_MS 10
|
#define TIME_COMPUTE_IN_MS 10
|
||||||
#define TIME_MEASURE_VOLTAGE_IN_MS 200
|
#define TIME_MEASURE_VOLTAGE_IN_MS 200
|
||||||
#define TIME_SW_POLL_IN_MS 10
|
#define TIME_SW_POLL_IN_MS 10
|
||||||
#define DELAY_BEFORE_MEASURE 10
|
#define DELAY_BEFORE_MEASURE 10
|
||||||
#define DELAY_MAIN_LOOP 10
|
#define DELAY_MAIN_LOOP 10
|
||||||
#define PID_SAMPLE_TIME 10
|
#define PID_SAMPLE_TIME 10
|
||||||
|
|
||||||
#define ADC_TO_TEMP_GAIN 0.39
|
#define ADC_TO_TEMP_GAIN 0.574503
|
||||||
#define ADC_TO_TEMP_OFFSET 23.9
|
#define ADC_TO_TEMP_OFFSET 43.5
|
||||||
#define CTRL_GAIN 10
|
|
||||||
|
|
||||||
#define EEPROM_SET_T 8
|
#define EEPROM_SET_T 8
|
||||||
#define EEPROM_VERSION 10
|
#define EEPROM_VERSION 10
|
||||||
|
Reference in New Issue
Block a user