This commit is contained in:
Stefan Kögl 2012-10-20 15:02:25 +02:00
parent 7eb67d88e7
commit 85126113e8
2 changed files with 55 additions and 34 deletions

View File

@ -15,6 +15,8 @@ project(ReflowCtl C CXX)
set(ARDUINO_DEFAULT_BOARD diecimila) # Default Board ID, when not specified set(ARDUINO_DEFAULT_BOARD diecimila) # Default Board ID, when not specified
set(ARDUINO_DEFAULT_PORT /dev/ttyUSB0) # Default Port, when not specified set(ARDUINO_DEFAULT_PORT /dev/ttyUSB0) # Default Port, when not specified
link_directories(/usr/share/arduino/libraries)
generate_arduino_firmware(reflowctl generate_arduino_firmware(reflowctl
SKETCH reflowctl SKETCH reflowctl
PORT /dev/ttyUSB0 PORT /dev/ttyUSB0

View File

@ -1,3 +1,6 @@
// include the library code:
#include <LiquidCrystal.h>
#include <DFR_Key.h>
// states // states
#define START_STATE 0 #define START_STATE 0
@ -22,10 +25,10 @@
#define E_TP_TOO_LONG 256 // Tp duration too long #define E_TP_TOO_LONG 256 // Tp duration too long
// system time, timestamps and temperatures from sensors // system time, timestamps and temperatures from sensors
static unsigned int time = 0; // profile seconds unsigned int time = 0; // profile seconds
static unsigned int temperature = 25; // actual oven temp unsigned int temperature = 25; // actual oven temp
static unsigned int last_temperature = 25; // last oven temp unsigned int last_temperature = 25; // last oven temp
static int actual_dt = 0; // actual difference from last to actual temperatur int actual_dt = 0; // actual difference from last to actual temperatur
// profile temperatures // profile temperatures
@ -77,14 +80,25 @@ boolean is_oven_heating = false;
boolean led_on = false; boolean led_on = false;
boolean disable_checks = true; boolean disable_checks = true;
//Pin assignments for SainSmart LCD Keypad Shield
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DFR_Key keypad;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
set_start_state(); set_start_state();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("hello, world!");
keypad.setRate(10);
Serial.println("init done");
} }
static void control_oven() { void control_oven() {
if (temperature < set_min && !is_oven_heating) { if (temperature < set_min && !is_oven_heating) {
is_oven_heating = true; is_oven_heating = true;
Serial.println("Oven turned on"); Serial.println("Oven turned on");
@ -96,7 +110,7 @@ static void control_oven() {
} }
static void set_temp(int min, int max, int dt_min, int dt_max) { 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;
@ -104,14 +118,14 @@ static void set_temp(int min, int max, int dt_min, int dt_max) {
} }
static void get_temp() { void get_temp() {
last_temperature = temperature; last_temperature = temperature;
temperature = int(float(analogRead(2)) * 0.2929); temperature = int(float(analogRead(2)) * 0.2929);
actual_dt = temperature - last_temperature; actual_dt = temperature - last_temperature;
} }
static void check_dt() { void check_dt() {
if (disable_checks) if (disable_checks)
return; return;
if (actual_dt > set_dt_max) { if (actual_dt > set_dt_max) {
@ -122,7 +136,7 @@ static void check_dt() {
} }
} }
static void print_debug() { void print_debug() {
Serial.print("Time: "); Serial.print("Time: ");
Serial.print(time); Serial.print(time);
Serial.print(", temperatur: "); Serial.print(", temperatur: ");
@ -135,7 +149,8 @@ static void print_debug() {
Serial.println(error_condition); Serial.println(error_condition);
} }
static void check_max_duration() {
void check_max_duration() {
if (disable_checks) if (disable_checks)
return; return;
Serial.println(time); Serial.println(time);
@ -145,7 +160,7 @@ static void check_max_duration() {
Serial.println(time); Serial.println(time);
} }
static void check_Ts_duration_min() { void check_Ts_duration_min() {
if (disable_checks) if (disable_checks)
return; return;
Tl_time_end = time; Tl_time_end = time;
@ -154,7 +169,7 @@ static void check_Ts_duration_min() {
} }
} }
static void check_Ts_duration_max() { void check_Ts_duration_max() {
if (disable_checks) if (disable_checks)
return; return;
if (time - Ts_time_start > Tl_duration_max) { if (time - Ts_time_start > Tl_duration_max) {
@ -163,7 +178,7 @@ static void check_Ts_duration_max() {
} }
static void check_Tl_duration_min() { void check_Tl_duration_min() {
if (disable_checks) if (disable_checks)
return; return;
Tl_time_end = time; Tl_time_end = time;
@ -172,7 +187,7 @@ static void check_Tl_duration_min() {
} }
} }
static void check_Tl_duration_max() { void check_Tl_duration_max() {
if (disable_checks) if (disable_checks)
return; return;
if (time - Tl_time_start > Tl_duration_max) { if (time - Tl_time_start > Tl_duration_max) {
@ -180,14 +195,14 @@ static void check_Tl_duration_max() {
} }
} }
static void check_Tp_duration_min() { void check_Tp_duration_min() {
Tp_time_end = time; Tp_time_end = time;
if (time - Tp_time_start < Tp_duration_min) { if (time - Tp_time_start < Tp_duration_min) {
error_condition |= E_TP_TOO_SHORT; error_condition |= E_TP_TOO_SHORT;
} }
} }
static void check_Tp_duration_max() { void check_Tp_duration_max() {
if (disable_checks) if (disable_checks)
return; return;
if (time - Tp_time_start > Tp_duration_max) { if (time - Tp_time_start > Tp_duration_max) {
@ -195,7 +210,7 @@ static void check_Tp_duration_max() {
} }
} }
static void set_start_state() { void set_start_state() {
led_on = false; led_on = false;
digitalWrite(13, LOW); digitalWrite(13, LOW);
error_condition = 0; error_condition = 0;
@ -207,50 +222,50 @@ static void set_start_state() {
} }
static void set_preheat_state() { void set_preheat_state() {
Serial.println("Changing state to PREHEAT_STATE"); Serial.println("Changing state to PREHEAT_STATE");
state++; state++;
} }
static void set_ramp_up_state() { void set_ramp_up_state() {
Serial.println("Changed state to RAMP_UP_STATE"); Serial.println("Changed state to RAMP_UP_STATE");
state++; state++;
} }
static void set_tal_first_state() { void set_tal_first_state() {
Serial.println("Changed state to TAL_FIRST_STATE"); Serial.println("Changed state to TAL_FIRST_STATE");
state++; state++;
} }
static void set_peak_state() { void set_peak_state() {
Serial.println("Changed state to PEAK_STATE"); Serial.println("Changed state to PEAK_STATE");
state++; state++;
} }
static void set_tal_second_state() { 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++;
} }
static void set_ramp_down_state() { void set_ramp_down_state() {
Serial.println("Changed state to RAMP_DOWN_STATE"); Serial.println("Changed state to RAMP_DOWN_STATE");
state++; state++;
} }
static void set_end_state() { void set_end_state() {
Serial.println("Changed state to END_STATE"); Serial.println("Changed state to END_STATE");
state++; state++;
} }
static void set_error_state() { void set_error_state() {
if (state != ERROR_STATE) { if (state != ERROR_STATE) {
Serial.println("Changed state to ERROR_STATE"); Serial.println("Changed state to ERROR_STATE");
set_temp(0, 0, 0, 0); set_temp(0, 0, 0, 0);
@ -259,7 +274,7 @@ static void set_error_state() {
} }
static void handle_start_state() { void handle_start_state() {
check_max_duration(); check_max_duration();
Serial.println(time); Serial.println(time);
if (temperature > Ts_min) { if (temperature > Ts_min) {
@ -269,7 +284,7 @@ static void handle_start_state() {
} }
static void handle_preheat_state() { void handle_preheat_state() {
check_Ts_duration_max(); check_Ts_duration_max();
check_max_duration(); check_max_duration();
if (temperature > Ts_max) { if (temperature > Ts_max) {
@ -279,7 +294,7 @@ static void handle_preheat_state() {
} }
static void handle_ramp_up_state() { void handle_ramp_up_state() {
check_max_duration(); check_max_duration();
if (temperature > Tl) { if (temperature > Tl) {
Tl_time_start = time; Tl_time_start = time;
@ -288,7 +303,7 @@ static void handle_ramp_up_state() {
} }
static void handle_tal_first_state() { void handle_tal_first_state() {
check_max_duration(); check_max_duration();
check_Tl_duration_max(); check_Tl_duration_max();
if (temperature > Tp - 5) { if (temperature > Tp - 5) {
@ -298,7 +313,7 @@ static void handle_tal_first_state() {
} }
static void handle_peak_state() { void handle_peak_state() {
check_Tl_duration_max(); check_Tl_duration_max();
check_Tp_duration_max(); check_Tp_duration_max();
if (time - Tp_time_start > Tp_duration_max) { if (time - Tp_time_start > Tp_duration_max) {
@ -308,7 +323,7 @@ static void handle_peak_state() {
} }
static void handle_tal_second_state() { void handle_tal_second_state() {
check_Tl_duration_max(); check_Tl_duration_max();
if (temperature < Tl) { if (temperature < Tl) {
check_Tl_duration_min(); check_Tl_duration_min();
@ -316,21 +331,22 @@ static void handle_tal_second_state() {
} }
} }
static void handle_ramp_down_state() { void handle_ramp_down_state() {
if (temperature < Ts_min) { if (temperature < Ts_min) {
set_end_state(); set_end_state();
} }
} }
static void handle_end_state() { void handle_end_state() {
// while(true) { // while(true) {
// continue; // continue;
// } // }
} }
static void handle_error_state() {
void handle_error_state() {
if (led_on) { if (led_on) {
digitalWrite(13, LOW); digitalWrite(13, LOW);
led_on = false; led_on = false;
@ -406,6 +422,9 @@ void loop() {
} }
control_oven(); control_oven();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(time);
delay(1000); delay(1000);
} }