reduced code size, added comments and more features, cleaned up code

This commit is contained in:
Stefan Kögl 2012-10-03 23:17:50 +02:00
parent b1060ab9f4
commit eeb154f88a
2 changed files with 85 additions and 68 deletions

View File

@ -1589,7 +1589,7 @@ endfunction()
#=============================================================================# #=============================================================================#
# C Flags # C Flags
#=============================================================================# #=============================================================================#
set(ARDUINO_C_FLAGS "-ffunction-sections -fdata-sections") set(ARDUINO_C_FLAGS "-Wall -Wunused -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "-Os ${ARDUINO_C_FLAGS}" CACHE STRING "") set(CMAKE_C_FLAGS "-Os ${ARDUINO_C_FLAGS}" CACHE STRING "")
set(CMAKE_C_FLAGS_DEBUG "${ARDUINO_C_FLAGS}" CACHE STRING "") set(CMAKE_C_FLAGS_DEBUG "${ARDUINO_C_FLAGS}" CACHE STRING "")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG ${ARDUINO_C_FLAGS}" CACHE STRING "") set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG ${ARDUINO_C_FLAGS}" CACHE STRING "")
@ -1609,7 +1609,7 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
#=============================================================================# #=============================================================================#
# Executable Linker Flags # # Executable Linker Flags #
#=============================================================================# #=============================================================================#
set(ARDUINO_LINKER_FLAGS "-Wl,--gc-sections -lm") set(ARDUINO_LINKER_FLAGS "-Wl,--gc-sections -lm -dead_strip")
set(CMAKE_EXE_LINKER_FLAGS "${ARDUINO_LINKER_FLAGS}" CACHE STRING "") set(CMAKE_EXE_LINKER_FLAGS "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${ARDUINO_LINKER_FLAGS}" CACHE STRING "") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${ARDUINO_LINKER_FLAGS}" CACHE STRING "") set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")

View File

@ -15,48 +15,57 @@
#define E_TIME_MAX 4 // reflow process does take too long #define E_TIME_MAX 4 // reflow process does take too long
#define E_PEAK_TOO_LONG 8 // package was roasted #define E_PEAK_TOO_LONG 8 // package was roasted
unsigned int time = 0; // profile seconds // system time, timestamps and temperatures from sensors
unsigned int temperatur = 25; // actual oven temp __attribute__((__unused__)) static unsigned int time = 0; // profile seconds
unsigned int last_temperatur = 25; __attribute__((__unused__)) static unsigned int temperatur = 25; // actual oven temp
unsigned int actual_dt = 0; __attribute__((__unused__)) static unsigned int last_temperatur = 25; // last oven temp
__attribute__((__unused__)) static unsigned int actual_dt = 0; // actual difference from last to actual temperatur
// profile stuff // profile temperatures
unsigned int Ts_min = 150; // °C __attribute__((__unused__)) static unsigned int Ts_min = 150; // °C
unsigned int Ts_max = 200; // °C __attribute__((__unused__)) static unsigned int Ts_max = 200; // °C
unsigned int Tp = 260; // 245-260°C __attribute__((__unused__)) static unsigned int Tl = 217; // 217°C
__attribute__((__unused__)) static unsigned int Tp = 260; // 245-260°C
__attribute__((__unused__)) static unsigned int time_max = 480; // 8*60s max
unsigned int rampup_rate = 50; // 3°C/s
unsigned int preheat_duration = 100; // 60-180s
unsigned int Tl = 217; // 217°C // profile temp per second rates
unsigned int Tl_duration = 100; // 60-150s __attribute__((__unused__)) static unsigned int ramp_up_rate_min = 0; // not used yet
unsigned int peak_duration = 30; // 20-40s __attribute__((__unused__)) static unsigned int ramp_up_rate_max = 50; // 3°C/s
unsigned int rampdown_max = 6; // 6°C/s max __attribute__((__unused__)) static unsigned int ramp_down_max = 6; // 6°C/s max
unsigned int rampdown_min = 2; // 2°C/s max __attribute__((__unused__)) static unsigned int ramp_down_min = 2; // 2°C/s max
unsigned int time_max = 480; // 8*60s max
unsigned int Ts_min_time = 0;
unsigned int Ts_max_time = 0;
unsigned int Tl_time_start = 0;
unsigned int Tl_time_end = 0;
unsigned int Tp_time_start = 0;
unsigned int Tp_time_end = 0;
unsigned int error_condition = 0;
boolean is_oven_heating = false; // profile temp durations
boolean led_on = false; __attribute__((__unused__)) static unsigned int Ts_duration = 100; // 60-180s
__attribute__((__unused__)) static unsigned int Tl_duration = 100; // 60-150s
__attribute__((__unused__)) static unsigned int Tp_duration = 30; // 20-40s
byte state = START_STATE;
int analogPin = 2; // timestamps of event beginnings/ends
__attribute__((__unused__)) static unsigned int Ts_min_time = 0;
__attribute__((__unused__)) static unsigned int Ts_max_time = 0;
__attribute__((__unused__)) static unsigned int Tl_time_start = 0;
__attribute__((__unused__)) static unsigned int Tl_time_end = 0;
__attribute__((__unused__)) static unsigned int Tp_time_start = 0;
__attribute__((__unused__)) static unsigned int Tp_time_end = 0;
int hysteresis = 0;
int set_min = 0; // thermostat
int set_max = 0; __attribute__((__unused__)) static unsigned int set_min = 0;
int set_dt_min = 0; __attribute__((__unused__)) static unsigned int set_max = 0;
int set_dt_max = 0; __attribute__((__unused__)) static int set_dt_min = 0;
__attribute__((__unused__)) static int set_dt_max = 0;
// state machine
__attribute__((__unused__)) static byte state;
__attribute__((__unused__)) static boolean is_oven_heating = false;
__attribute__((__unused__)) static byte error_condition = 0;
// ui stuff
__attribute__((__unused__)) static boolean led_on = false;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
@ -66,7 +75,7 @@ void setup() {
} }
void control_oven() { static void control_oven() {
if (temperatur < set_min && (!is_oven_heating)) { if (temperatur < set_min && (!is_oven_heating)) {
is_oven_heating = true; is_oven_heating = true;
Serial.println("Oven turned on"); Serial.println("Oven turned on");
@ -77,20 +86,20 @@ void control_oven() {
} }
} }
void set_temp(int min, int max, int dt_min, int dt_max) { static void set_temp(int min, int max, int dt_min, int dt_max) {
set_min = min; set_min = min;
set_max = max; set_max = max;
set_dt_min = dt_min; set_dt_min = dt_min;
set_dt_max = dt_max; set_dt_max = dt_max;
} }
void get_temp() { static void get_temp() {
last_temperatur = temperatur; last_temperatur = temperatur;
temperatur = int(float(analogRead(analogPin)) * 0.2929); temperatur = int(float(analogRead(2)) * 0.2929);
actual_dt = temperatur - last_temperatur; actual_dt = temperatur - last_temperatur;
} }
void check_dt() { static void check_dt() {
if (actual_dt > set_dt_max) { if (actual_dt > set_dt_max) {
error_condition |= E_DT_MAX; error_condition |= E_DT_MAX;
} }
@ -99,7 +108,7 @@ void check_dt() {
} }
} }
void print_debug() { static void print_debug() {
Serial.print("Time: "); Serial.print("Time: ");
Serial.print(time); Serial.print(time);
Serial.print(", temperatur: "); Serial.print(", temperatur: ");
@ -126,112 +135,117 @@ boolean check_Tl_duration() {
} }
}*/ }*/
void set_start_state() { static void set_start_state() {
state = START_STATE;
get_temp(); get_temp();
last_temperatur = temperatur; last_temperatur = temperatur;
set_temp(Tp-5, Tp, 0, rampup_rate); set_temp(Tp-5, Tp, 0, ramp_up_rate_max);
} }
void set_preheat_state() { static void set_preheat_state() {
Serial.println("Changing state to PREHEAT_STATE");
state++;
} }
void set_ramp_up_state() { static void set_ramp_up_state() {
Serial.println("Changed state to RAMP_UP_STATE");
state++;
} }
void set_tal_first_state() { static void set_tal_first_state() {
Serial.println("Changed state to TAL_FIRST_STATE");
state++;
} }
void set_peak_state() { static void set_peak_state() {
Serial.println("Changed state to PEAK_STATE"); Serial.println("Changed state to PEAK_STATE");
state++;
} }
void set_tal_second_state() { static void set_tal_second_state() {
Serial.println("Changed state to TAL_SECOND_STATE"); Serial.println("Changed state to TAL_SECOND_STATE");
set_temp(25, 25, -3, -6); set_temp(25, 25, -3, -6);
state++; state++;
} }
void set_ramp_down_state() { static void set_ramp_down_state() {
Serial.println("Changed state to RAMP_DOWN_STATE"); Serial.println("Changed state to RAMP_DOWN_STATE");
state++; state++;
} }
void set_end_state() { static void set_end_state() {
state = END_STATE; Serial.println("Changed state to END_STATE");
state++;
} }
void set_error_state() { void set_error_state() {
if (state != ERROR_STATE) { if (state != ERROR_STATE) {
Serial.println("Changed state to ERROR_STATE");
set_temp(0, 0, 0, 0); set_temp(0, 0, 0, 0);
state = ERROR_STATE; state = ERROR_STATE;
} }
} }
void handle_start_state() { static void handle_start_state() {
Serial.println("START_STATE"); Serial.println("START_STATE");
if (temperatur > Ts_min) { if (temperatur > Ts_min) {
Serial.println("Changing state to PREHEAT_STATE");
Ts_min_time = time; Ts_min_time = time;
state++; set_preheat_state();
} }
} }
void handle_preheat_state() { static void handle_preheat_state() {
Serial.println("PREHEAT_STATE"); Serial.println("PREHEAT_STATE");
if (temperatur > Ts_max) { if (temperatur > Ts_max) {
Serial.println("Changed state to RAMP_UP_STATE");
Ts_max_time = time; Ts_max_time = time;
state++; set_ramp_up_state();
} }
} }
void handle_rampup_state() { static void handle_ramp_up_state() {
Serial.println("RAMP_UP_STATE"); Serial.println("RAMP_UP_STATE");
if (temperatur > Tl) { if (temperatur > Tl) {
Serial.println("Changed state to TAL_FIRST_STATE");
Tl_time_start = time; Tl_time_start = time;
state++; state++;
} }
} }
void handle_tal_first_state() { static void handle_tal_first_state() {
Serial.println("TAL_FIRST_STATE"); Serial.println("TAL_FIRST_STATE");
if (temperatur > Tp - 5) { if (temperatur > Tp - 5) {
Serial.println("Changed state to PEAK_STATE"); Serial.println("Changed state to PEAK_STATE");
Tp_time_start = time; Tp_time_start = time;
state++;
set_peak_state(); set_peak_state();
} }
} }
void handle_peak_state() { static void handle_peak_state() {
Serial.println("PEAK_STATE"); Serial.println("PEAK_STATE");
if (time - Tp_time_start > peak_duration) { if (time - Tp_time_start > Tp_duration) {
Tp_time_end = time; Tp_time_end = time;
set_tal_second_state(); set_tal_second_state();
} }
} }
void handle_tal_second_state() { static void handle_tal_second_state() {
if (temperatur < Tl) { if (temperatur < Tl) {
set_ramp_down_state(); set_ramp_down_state();
} }
} }
void handle_ramp_down_state() { static void handle_ramp_down_state() {
if (temperatur < Ts_min) { if (temperatur < Ts_min) {
Serial.println("Changed state to END_STATE"); Serial.println("Changed state to END_STATE");
state++; set_end_state();
} }
} }
void handle_error_state() { static void handle_error_state() {
if (led_on) { if (led_on) {
digitalWrite(13, LOW); digitalWrite(13, LOW);
led_on = false; led_on = false;
@ -268,7 +282,7 @@ void loop() {
handle_preheat_state(); handle_preheat_state();
break; break;
case RAMP_UP_STATE: case RAMP_UP_STATE:
handle_rampup_state(); handle_ramp_up_state();
break; break;
case TAL_FIRST_STATE: case TAL_FIRST_STATE:
handle_tal_first_state(); handle_tal_first_state();
@ -285,6 +299,9 @@ void loop() {
break; break;
case END_STATE: case END_STATE:
Serial.println("END_STATE"); Serial.println("END_STATE");
while(true) {
continue;
}
break; break;
case ERROR_STATE: case ERROR_STATE:
handle_error_state(); handle_error_state();