2012-10-01 19:03:30 +00:00
|
|
|
|
2012-10-02 20:00:49 +00:00
|
|
|
#define START_STATE 0
|
|
|
|
#define PREHEAT_STATE 1
|
|
|
|
#define RAMP_UP_STATE 2
|
|
|
|
#define TAL_FIRST_STATE 3
|
|
|
|
#define PEAK_STATE 4
|
|
|
|
#define TAL_SECOND_STATE 5
|
2012-10-03 15:58:34 +00:00
|
|
|
#define RAMP_DOWN_STATE 6
|
2012-10-02 20:00:49 +00:00
|
|
|
#define END_STATE 7
|
|
|
|
#define ERROR_STATE 8
|
|
|
|
|
|
|
|
// error conditions
|
2012-10-03 18:09:27 +00:00
|
|
|
#define E_DT_MIN 1 // temperatur dt too small
|
|
|
|
#define E_DT_MAX 2 // temperatur dt too big
|
2012-10-02 20:00:49 +00:00
|
|
|
#define E_TIME_MAX 4 // reflow process does take too long
|
2012-10-03 18:09:27 +00:00
|
|
|
#define E_PEAK_TOO_LONG 8 // package was roasted
|
2012-10-02 20:00:49 +00:00
|
|
|
|
2012-10-01 19:03:30 +00:00
|
|
|
unsigned int time = 0; // profile seconds
|
2012-10-02 13:03:02 +00:00
|
|
|
unsigned int temperatur = 25; // actual oven temp
|
|
|
|
unsigned int last_temperatur = 25;
|
2012-10-03 18:09:27 +00:00
|
|
|
unsigned int actual_dt = 0;
|
2012-10-01 19:03:30 +00:00
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
|
|
|
|
// profile stuff
|
2012-10-01 19:03:30 +00:00
|
|
|
unsigned int Ts_min = 150; // °C
|
2012-10-03 18:09:27 +00:00
|
|
|
unsigned int Ts_max = 200; // °C
|
2012-10-01 19:03:30 +00:00
|
|
|
unsigned int Tp = 260; // 245-260°C
|
2012-10-03 18:09:27 +00:00
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
unsigned int rampup_rate = 50; // 3°C/s
|
2012-10-01 19:03:30 +00:00
|
|
|
unsigned int preheat_duration = 100; // 60-180s
|
2012-10-03 18:09:27 +00:00
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
unsigned int Tl = 217; // 217°C
|
|
|
|
unsigned int Tl_duration = 100; // 60-150s
|
2012-10-01 19:03:30 +00:00
|
|
|
unsigned int peak_duration = 30; // 20-40s
|
|
|
|
unsigned int rampdown_max = 6; // 6°C/s max
|
2012-10-02 20:00:49 +00:00
|
|
|
unsigned int rampdown_min = 2; // 2°C/s max
|
2012-10-01 19:03:30 +00:00
|
|
|
unsigned int time_max = 480; // 8*60s max
|
|
|
|
|
2012-10-02 13:03:02 +00:00
|
|
|
unsigned int Ts_min_time = 0;
|
|
|
|
unsigned int Ts_max_time = 0;
|
2012-10-03 15:58:34 +00:00
|
|
|
unsigned int Tl_time_start = 0;
|
2012-10-02 20:00:49 +00:00
|
|
|
unsigned int Tl_time_end = 0;
|
2012-10-03 15:58:34 +00:00
|
|
|
unsigned int Tp_time_start = 0;
|
2012-10-03 00:29:05 +00:00
|
|
|
unsigned int Tp_time_end = 0;
|
2012-10-02 13:03:02 +00:00
|
|
|
unsigned int error_condition = 0;
|
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
boolean is_oven_heating = false;
|
2012-10-03 18:09:27 +00:00
|
|
|
boolean led_on = false;
|
2012-10-03 15:58:34 +00:00
|
|
|
|
2012-10-02 20:00:49 +00:00
|
|
|
byte state = START_STATE;
|
2012-10-01 19:03:30 +00:00
|
|
|
|
2012-10-03 00:29:05 +00:00
|
|
|
int analogPin = 2;
|
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
int hysteresis = 0;
|
|
|
|
|
|
|
|
int set_min = 0;
|
|
|
|
int set_max = 0;
|
2012-10-03 18:09:27 +00:00
|
|
|
int set_dt_min = 0;
|
|
|
|
int set_dt_max = 0;
|
2012-10-03 15:58:34 +00:00
|
|
|
|
2012-10-01 19:03:30 +00:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
2012-10-03 18:09:27 +00:00
|
|
|
delay(2000);
|
|
|
|
set_start_state();
|
2012-10-03 15:58:34 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
void control_oven() {
|
2012-10-03 18:09:27 +00:00
|
|
|
if (temperatur < set_min && (!is_oven_heating)) {
|
2012-10-03 15:58:34 +00:00
|
|
|
is_oven_heating = true;
|
|
|
|
Serial.println("Oven turned on");
|
|
|
|
}
|
2012-10-03 18:09:27 +00:00
|
|
|
else if (temperatur > set_max && is_oven_heating) {
|
2012-10-03 15:58:34 +00:00
|
|
|
is_oven_heating = false;
|
|
|
|
Serial.println("Oven turned off");
|
|
|
|
}
|
2012-10-01 19:03:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
void set_temp(int min, int max, int dt_min, int dt_max) {
|
|
|
|
set_min = min;
|
|
|
|
set_max = max;
|
|
|
|
set_dt_min = dt_min;
|
|
|
|
set_dt_max = dt_max;
|
|
|
|
}
|
|
|
|
|
2012-10-01 19:03:30 +00:00
|
|
|
void get_temp() {
|
2012-10-03 15:58:34 +00:00
|
|
|
last_temperatur = temperatur;
|
|
|
|
temperatur = int(float(analogRead(analogPin)) * 0.2929);
|
2012-10-03 18:09:27 +00:00
|
|
|
actual_dt = temperatur - last_temperatur;
|
2012-10-02 13:03:02 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
void check_dt() {
|
|
|
|
if (actual_dt > set_dt_max) {
|
|
|
|
error_condition |= E_DT_MAX;
|
2012-10-02 20:00:49 +00:00
|
|
|
}
|
2012-10-03 18:09:27 +00:00
|
|
|
if (actual_dt < set_dt_min) {
|
|
|
|
error_condition |= E_DT_MIN;
|
2012-10-02 20:00:49 +00:00
|
|
|
}
|
2012-10-01 19:03:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
void print_debug() {
|
|
|
|
Serial.print("Time: ");
|
|
|
|
Serial.print(time);
|
|
|
|
Serial.print(", temperatur: ");
|
|
|
|
Serial.print(temperatur);
|
|
|
|
Serial.print(", last_temperatur: ");
|
|
|
|
Serial.print(last_temperatur);
|
|
|
|
Serial.print(", state: ");
|
|
|
|
Serial.print(state);
|
|
|
|
Serial.print(", Error: ");
|
|
|
|
Serial.println(error_condition);
|
2012-10-02 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
// boolean check_max_duration() {
|
|
|
|
// if (time > time_max) {
|
|
|
|
// error_condition = E_TIME_MAX;
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
/*
|
2012-10-03 15:58:34 +00:00
|
|
|
boolean check_Tl_duration() {
|
2012-10-02 20:00:49 +00:00
|
|
|
if (time > time_max) {
|
|
|
|
error_condition = E_TIME_MAX;
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-03 18:09:27 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
void set_start_state() {
|
|
|
|
get_temp();
|
|
|
|
last_temperatur = temperatur;
|
|
|
|
set_temp(Tp-5, Tp, 0, rampup_rate);
|
2012-10-02 20:00:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
void set_preheat_state() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_ramp_up_state() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_tal_first_state() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_peak_state() {
|
|
|
|
Serial.println("Changed state to PEAK_STATE");
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_tal_second_state() {
|
|
|
|
Serial.println("Changed state to TAL_SECOND_STATE");
|
|
|
|
set_temp(25, 25, -3, -6);
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_ramp_down_state() {
|
|
|
|
Serial.println("Changed state to RAMP_DOWN_STATE");
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_end_state() {
|
|
|
|
state = END_STATE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_error_state() {
|
|
|
|
if (state != ERROR_STATE) {
|
|
|
|
set_temp(0, 0, 0, 0);
|
|
|
|
state = ERROR_STATE;
|
|
|
|
}
|
|
|
|
}
|
2012-10-01 19:03:30 +00:00
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
void handle_start_state() {
|
2012-10-03 18:09:27 +00:00
|
|
|
Serial.println("START_STATE");
|
2012-10-03 15:58:34 +00:00
|
|
|
if (temperatur > Ts_min) {
|
|
|
|
Serial.println("Changing state to PREHEAT_STATE");
|
|
|
|
Ts_min_time = time;
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
void handle_preheat_state() {
|
|
|
|
Serial.println("PREHEAT_STATE");
|
|
|
|
if (temperatur > Ts_max) {
|
|
|
|
Serial.println("Changed state to RAMP_UP_STATE");
|
|
|
|
Ts_max_time = time;
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_rampup_state() {
|
|
|
|
Serial.println("RAMP_UP_STATE");
|
|
|
|
if (temperatur > Tl) {
|
|
|
|
Serial.println("Changed state to TAL_FIRST_STATE");
|
|
|
|
Tl_time_start = time;
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tal_first_state() {
|
|
|
|
Serial.println("TAL_FIRST_STATE");
|
|
|
|
if (temperatur > Tp - 5) {
|
|
|
|
Serial.println("Changed state to PEAK_STATE");
|
|
|
|
Tp_time_start = time;
|
|
|
|
state++;
|
|
|
|
set_peak_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
void handle_peak_state() {
|
|
|
|
Serial.println("PEAK_STATE");
|
|
|
|
|
|
|
|
if (time - Tp_time_start > peak_duration) {
|
|
|
|
Tp_time_end = time;
|
2012-10-03 18:09:27 +00:00
|
|
|
set_tal_second_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handle_tal_second_state() {
|
|
|
|
if (temperatur < Tl) {
|
|
|
|
set_ramp_down_state();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_ramp_down_state() {
|
|
|
|
if (temperatur < Ts_min) {
|
|
|
|
Serial.println("Changed state to END_STATE");
|
2012-10-03 15:58:34 +00:00
|
|
|
state++;
|
2012-10-03 00:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-02 20:00:49 +00:00
|
|
|
|
2012-10-02 15:46:12 +00:00
|
|
|
|
2012-10-03 18:09:27 +00:00
|
|
|
void handle_error_state() {
|
|
|
|
if (led_on) {
|
|
|
|
digitalWrite(13, LOW);
|
|
|
|
led_on = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
digitalWrite(13, HIGH);
|
|
|
|
led_on = true;
|
|
|
|
}
|
|
|
|
if (error_condition & E_DT_MIN)
|
|
|
|
Serial.print("Error: delta °K/second too low");
|
|
|
|
if (error_condition & E_DT_MAX)
|
|
|
|
Serial.print("Error: delta °K/second too big");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-03 00:29:05 +00:00
|
|
|
void loop() {
|
2012-10-03 15:58:34 +00:00
|
|
|
time = millis() / 1000;
|
|
|
|
get_temp();
|
2012-10-03 18:09:27 +00:00
|
|
|
check_dt();
|
|
|
|
|
|
|
|
if (error_condition) {
|
|
|
|
set_error_state();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print_debug();
|
|
|
|
}
|
|
|
|
|
2012-10-03 15:58:34 +00:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case START_STATE:
|
|
|
|
handle_start_state();
|
|
|
|
break;
|
|
|
|
case PREHEAT_STATE:
|
2012-10-03 18:09:27 +00:00
|
|
|
handle_preheat_state();
|
2012-10-03 15:58:34 +00:00
|
|
|
break;
|
|
|
|
case RAMP_UP_STATE:
|
2012-10-03 18:09:27 +00:00
|
|
|
handle_rampup_state();
|
2012-10-03 15:58:34 +00:00
|
|
|
break;
|
|
|
|
case TAL_FIRST_STATE:
|
2012-10-03 18:09:27 +00:00
|
|
|
handle_tal_first_state();
|
2012-10-03 15:58:34 +00:00
|
|
|
break;
|
|
|
|
case PEAK_STATE:
|
|
|
|
handle_peak_state();
|
|
|
|
break;
|
|
|
|
case TAL_SECOND_STATE:
|
2012-10-03 18:09:27 +00:00
|
|
|
Tl_time_end = time;
|
|
|
|
handle_tal_second_state();
|
2012-10-03 15:58:34 +00:00
|
|
|
break;
|
|
|
|
case RAMP_DOWN_STATE:
|
2012-10-03 18:09:27 +00:00
|
|
|
handle_ramp_down_state();
|
2012-10-03 15:58:34 +00:00
|
|
|
break;
|
|
|
|
case END_STATE:
|
|
|
|
Serial.println("END_STATE");
|
2012-10-03 18:09:27 +00:00
|
|
|
break;
|
|
|
|
case ERROR_STATE:
|
|
|
|
handle_error_state();
|
|
|
|
break;
|
2012-10-03 15:58:34 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
control_oven();
|
2012-10-03 00:29:05 +00:00
|
|
|
delay(1000);
|
2012-10-01 19:03:30 +00:00
|
|
|
}
|
2012-10-03 15:58:34 +00:00
|
|
|
|