(re)-initialize more stuff for start state

This commit is contained in:
Stefan Kögl 2012-10-04 00:04:28 +02:00
parent affb9b64d1
commit f6bdb987f0
1 changed files with 26 additions and 25 deletions

View File

@ -10,16 +10,16 @@
#define ERROR_STATE 8
// error conditions
#define E_DT_MIN 1 // temperatur dt too small
#define E_DT_MAX 2 // temperatur dt too big
#define E_DT_MIN 1 // temperature dt too small
#define E_DT_MAX 2 // temperature dt too big
#define E_TIME_MAX 4 // reflow process does take too long
#define E_TL_TOO_LONG 8 // package was roasted
#define E_TP_TOO_LONG 16 // package was roasted
// system time, timestamps and temperatures from sensors
__attribute__((__unused__)) static unsigned int time = 0; // profile seconds
__attribute__((__unused__)) static unsigned int temperatur = 25; // actual oven temp
__attribute__((__unused__)) static unsigned int last_temperatur = 25; // last oven temp
__attribute__((__unused__)) static unsigned int temperature = 25; // actual oven temp
__attribute__((__unused__)) static unsigned int last_temperature = 25; // last oven temp
__attribute__((__unused__)) static int actual_dt = 0; // actual difference from last to actual temperatur
@ -77,11 +77,11 @@ void setup() {
static void control_oven() {
if (temperatur < set_min && (!is_oven_heating)) {
if (temperature < set_min && (!is_oven_heating)) {
is_oven_heating = true;
Serial.println("Oven turned on");
}
else if (temperatur > set_max && is_oven_heating) {
else if (temperature > set_max && is_oven_heating) {
is_oven_heating = false;
Serial.println("Oven turned off");
}
@ -97,9 +97,9 @@ static void set_temp(int min, int max, int dt_min, int dt_max) {
static void get_temp() {
last_temperatur = temperatur;
temperatur = int(float(analogRead(2)) * 0.2929);
actual_dt = temperatur - last_temperatur;
last_temperature = temperature;
temperature = int(float(analogRead(2)) * 0.2929);
actual_dt = temperature - last_temperature;
}
@ -116,40 +116,41 @@ static void print_debug() {
Serial.print("Time: ");
Serial.print(time);
Serial.print(", temperatur: ");
Serial.print(temperatur);
Serial.print(temperature);
Serial.print(", last_temperatur: ");
Serial.print(last_temperatur);
Serial.print(last_temperature);
Serial.print(", state: ");
Serial.print(state);
Serial.print(", Error: ");
Serial.println(error_condition);
}
static boolean check_max_duration() {
static void check_max_duration() {
if (time > time_max) {
error_condition |= E_TIME_MAX;
return false;
}
}
static boolean check_Tl_duration() {
static void check_Tl_duration() {
if (time - Tl_time_start > Tp_duration) {
error_condition |= E_TL_TOO_LONG;
return false;
}
}
static boolean check_Tp_duration() {
static void check_Tp_duration() {
if (time - Tp_time_start > Tp_duration) {
error_condition |= E_TP_TOO_LONG;
return false;
}
}
static void set_start_state() {
led_on = false;
digitalWrite(13, LOW);
error_condition = 0;
state = START_STATE;
get_temp();
last_temperatur = temperatur;
last_temperature = temperature;
actual_dt = temperature - last_temperature;
set_temp(Tp-5, Tp, 0, ramp_up_rate_max);
}
@ -207,7 +208,7 @@ static void set_error_state() {
static void handle_start_state() {
if (temperatur > Ts_min) {
if (temperature > Ts_min) {
Ts_min_time = time;
set_preheat_state();
}
@ -215,7 +216,7 @@ static void handle_start_state() {
static void handle_preheat_state() {
if (temperatur > Ts_max) {
if (temperature > Ts_max) {
Ts_max_time = time;
set_ramp_up_state();
}
@ -223,7 +224,7 @@ static void handle_preheat_state() {
static void handle_ramp_up_state() {
if (temperatur > Tl) {
if (temperature > Tl) {
Tl_time_start = time;
set_tal_first_state();
}
@ -232,7 +233,7 @@ static void handle_ramp_up_state() {
static void handle_tal_first_state() {
check_Tl_duration();
if (temperatur > Tp - 5) {
if (temperature > Tp - 5) {
Tp_time_start = time;
set_peak_state();
}
@ -251,13 +252,13 @@ static void handle_peak_state() {
static void handle_tal_second_state() {
check_Tl_duration();
if (temperatur < Tl) {
if (temperature < Tl) {
set_ramp_down_state();
}
}
static void handle_ramp_down_state() {
if (temperatur < Ts_min) {
if (temperature < Ts_min) {
set_end_state();
}
}
@ -286,7 +287,7 @@ static void handle_error_state() {
if (error_condition & E_TIME_MAX)
Serial.println("Error: reflow process does take too long");
if (error_condition & E_TL_TOO_LONG)
Serial.println("Error: temperatur above liquidus was too long");
Serial.println("Error: temperature above liquidus was too long");
if (error_condition & E_TP_TOO_LONG)
Serial.println("Error: peak temperature duration was too long");
}