main features are done
This commit is contained in:
parent
f6bdb987f0
commit
7eb67d88e7
|
@ -482,25 +482,35 @@ endfunction()
|
|||
function(get_arduino_flags COMPILE_FLAGS_VAR LINK_FLAGS_VAR BOARD_ID)
|
||||
set(BOARD_CORE ${${BOARD_ID}.build.core})
|
||||
if(BOARD_CORE)
|
||||
if(ARDUINO_SDK_VERSION MATCHES "([0-9]+)[.]([0-9]+)")
|
||||
if(ARDUINO_SDK_VERSION MATCHES "([0-9]+)[.]([0-9]+)[.]([0-9]+)")
|
||||
string(REPLACE "." "" ARDUINO_VERSION_DEFINE "${ARDUINO_SDK_VERSION}") # Normalize version (remove all periods)
|
||||
set(ARDUINO_VERSION_DEFINE "")
|
||||
if(CMAKE_MATCH_1 GREATER 0)
|
||||
set(ARDUINO_VERSION_DEFINE "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
if(CMAKE_MATCH_2 GREATER 10)
|
||||
set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}${CMAKE_MATCH_2}")
|
||||
else()
|
||||
set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}0${CMAKE_MATCH_2}")
|
||||
endif()
|
||||
# message("1 ARDUINO_VERSION_DEFINE = ${ARDUINO_VERSION_DEFINE}")
|
||||
# set(ARDUINO_VERSION_DEFINE "")
|
||||
# if(CMAKE_MATCH_1 GREATER 0)
|
||||
# set(ARDUINO_VERSION_DEFINE "${CMAKE_MATCH_1}")
|
||||
# message("foo = ${ARDUINO_VERSION_DEFINE}")
|
||||
# endif()
|
||||
# if(CMAKE_MATCH_2 GREATER 10)
|
||||
# set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}${CMAKE_MATCH_2}")
|
||||
# message("bar = ${ARDUINO_VERSION_DEFINE}")
|
||||
# else()
|
||||
# set(ARDUINO_VERSION_DEFINE "${ARDUINO_VERSION_DEFINE}0${CMAKE_MATCH_2}")
|
||||
# message("baz = ${ARDUINO_VERSION_DEFINE}")
|
||||
# endif()
|
||||
else()
|
||||
message("Invalid Arduino SDK Version (${ARDUINO_SDK_VERSION})")
|
||||
endif()
|
||||
|
||||
|
||||
# message("CMAKE_MATCH_1 = ${CMAKE_MATCH_1}")
|
||||
# message("CMAKE_MATCH_2 = ${CMAKE_MATCH_2}")
|
||||
# message("CMAKE_MATCH_3 = ${CMAKE_MATCH_3}")
|
||||
message("2 ARDUINO_VERSION_DEFINE = ${ARDUINO_VERSION_DEFINE}")
|
||||
|
||||
# output
|
||||
set(COMPILE_FLAGS "-DF_CPU=${${BOARD_ID}.build.f_cpu} -DARDUINO=${ARDUINO_VERSION_DEFINE} -mmcu=${${BOARD_ID}.build.mcu} -I${ARDUINO_CORES_PATH}/${BOARD_CORE} -I${ARDUINO_LIBRARIES_PATH}")
|
||||
set(LINK_FLAGS "-mmcu=${${BOARD_ID}.build.mcu}")
|
||||
if(ARDUINO_SDK_VERSION VERSION_GREATER 1.0 OR ARDUINO_SDK_VERSION VERSION_EQUAL 1.0)
|
||||
if(ARDUINO_SDK_VERSION VERSION_GREATER 1.0.0 OR ARDUINO_SDK_VERSION VERSION_EQUAL 1.0.0)
|
||||
set(PIN_HEADER ${${BOARD_ID}.build.variant})
|
||||
set(COMPILE_FLAGS "${COMPILE_FLAGS} -I${ARDUINO_VARIANTS_PATH}/${PIN_HEADER}")
|
||||
endif()
|
||||
|
@ -809,6 +819,8 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS
|
|||
|
||||
list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_NAME}.hex")
|
||||
|
||||
message("${AVRDUDE_ARGS}")
|
||||
|
||||
add_custom_target(${UPLOAD_TARGET}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${AVRDUDE_ARGS}
|
||||
|
@ -1079,9 +1091,10 @@ endfunction()
|
|||
function(detect_arduino_version VAR_NAME)
|
||||
if(ARDUINO_VERSION_PATH)
|
||||
file(READ ${ARDUINO_VERSION_PATH} ARD_VERSION)
|
||||
message(${ARD_VERSION})
|
||||
if("${ARD_VERSION}" MATCHES " *[0]+([0-9]+)")
|
||||
set(${VAR_NAME} 0.${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
elseif("${ARD_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+)")
|
||||
elseif("${ARD_VERSION}" MATCHES "[ ]*([0-9]+[.][0-9]+[.][0-9]+)")
|
||||
set(${VAR_NAME} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -1589,9 +1602,9 @@ endfunction()
|
|||
#=============================================================================#
|
||||
# C Flags
|
||||
#=============================================================================#
|
||||
set(ARDUINO_C_FLAGS "-Wall -Wunused -ffunction-sections -fdata-sections")
|
||||
set(ARDUINO_C_FLAGS "-g -Wall -ffunction-sections -fdata-sections")
|
||||
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 "-Os ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG -w ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -w ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
||||
|
@ -1601,7 +1614,7 @@ set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -w ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
|||
#=============================================================================#
|
||||
set(ARDUINO_CXX_FLAGS "${ARDUINO_C_FLAGS} -fno-exceptions")
|
||||
set(CMAKE_CXX_FLAGS "-Os ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Os ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-Os -DNDEBUG ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
|
@ -1609,7 +1622,7 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
|||
#=============================================================================#
|
||||
# Executable Linker Flags #
|
||||
#=============================================================================#
|
||||
set(ARDUINO_LINKER_FLAGS "-Wl,--gc-sections -lm -dead_strip")
|
||||
set(ARDUINO_LINKER_FLAGS "-Wl,--gc-sections -lm")
|
||||
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_MINSIZEREL "${ARDUINO_LINKER_FLAGS}" CACHE STRING "")
|
||||
|
@ -1724,8 +1737,11 @@ if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
|
|||
AVRSIZE_PROGRAM
|
||||
MSG "Invalid Arduino SDK path (${ARDUINO_SDK_PATH}).\n")
|
||||
|
||||
message(${ARDUINO_VERSION_PATH})
|
||||
detect_arduino_version(ARDUINO_SDK_VERSION)
|
||||
message(${ARDUINO_SDK_VERSION})
|
||||
set(ARDUINO_SDK_VERSION ${ARDUINO_SDK_VERSION} CACHE STRING "Arduino SDK Version")
|
||||
message(${ARDUINO_SDK_VERSION})
|
||||
|
||||
if(ARDUINO_SDK_VERSION VERSION_LESS 0.19)
|
||||
message(FATAL_ERROR "Unsupported Arduino SDK (require verion 0.19 or higher)")
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
// states
|
||||
#define START_STATE 0
|
||||
#define PREHEAT_STATE 1
|
||||
#define RAMP_UP_STATE 2
|
||||
|
@ -13,75 +14,82 @@
|
|||
#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
|
||||
#define E_TS_TOO_SHORT 8 // Ts duration too short
|
||||
#define E_TS_TOO_LONG 16 // Ts duration too long
|
||||
#define E_TL_TOO_SHORT 32 // Tl duration too short
|
||||
#define E_TL_TOO_LONG 64 // Tl duration too long
|
||||
#define E_TP_TOO_SHORT 128 // Tp duration too short
|
||||
#define E_TP_TOO_LONG 256 // Tp duration too long
|
||||
|
||||
// system time, timestamps and temperatures from sensors
|
||||
__attribute__((__unused__)) static unsigned int time = 0; // profile seconds
|
||||
__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
|
||||
static unsigned int time = 0; // profile seconds
|
||||
static unsigned int temperature = 25; // actual oven temp
|
||||
static unsigned int last_temperature = 25; // last oven temp
|
||||
static int actual_dt = 0; // actual difference from last to actual temperatur
|
||||
|
||||
|
||||
// profile temperatures
|
||||
__attribute__((__unused__)) static unsigned int Ts_min = 150; // °C
|
||||
__attribute__((__unused__)) static unsigned int Ts_max = 200; // °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 Ts_min = 150; // °C
|
||||
unsigned int Ts_max = 200; // °C
|
||||
unsigned int Tl = 217; // 217°C
|
||||
unsigned int Tp = 260; // 245-260°C
|
||||
unsigned int time_max = 480; // 8*60s max
|
||||
|
||||
|
||||
// profile temp per second rates
|
||||
__attribute__((__unused__)) static unsigned int ramp_up_rate_min = 0; // not used yet
|
||||
__attribute__((__unused__)) static unsigned int ramp_up_rate_max = 50; // 3°C/s
|
||||
__attribute__((__unused__)) static unsigned int ramp_down_max = 6; // 6°C/s max
|
||||
__attribute__((__unused__)) static unsigned int ramp_down_min = 2; // 2°C/s max
|
||||
unsigned int ramp_up_rate_min = 0; // not used yet
|
||||
unsigned int ramp_up_rate_max = 50; // 3°C/s
|
||||
unsigned int ramp_down_max = 6; // 6°C/s max
|
||||
unsigned int ramp_down_min = 2; // 2°C/s max
|
||||
|
||||
|
||||
// profile temp durations
|
||||
__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
|
||||
unsigned int Ts_duration_min = 60; // s
|
||||
unsigned int Ts_duration_max = 180; // s
|
||||
unsigned int Tl_duration_min = 60; // 60-150s
|
||||
unsigned int Tl_duration_max = 150; // 60-150s
|
||||
unsigned int Tp_duration_min = 20; // 20-40s
|
||||
unsigned int Tp_duration_max = 40; // 20-40s
|
||||
|
||||
|
||||
// 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;
|
||||
unsigned int Ts_time_start = 0;
|
||||
unsigned int Ts_time_end = 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;
|
||||
|
||||
|
||||
// thermostat
|
||||
__attribute__((__unused__)) static unsigned int set_min = 0;
|
||||
__attribute__((__unused__)) static unsigned int set_max = 0;
|
||||
__attribute__((__unused__)) static int set_dt_min = 0;
|
||||
__attribute__((__unused__)) static int set_dt_max = 0;
|
||||
unsigned int set_min = 0;
|
||||
unsigned int set_max = 0;
|
||||
int set_dt_min = 0;
|
||||
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;
|
||||
unsigned int error_condition = 0;
|
||||
byte state = 0;
|
||||
boolean is_oven_heating = false;
|
||||
|
||||
// ui stuff
|
||||
__attribute__((__unused__)) static boolean led_on = false;
|
||||
boolean led_on = false;
|
||||
boolean disable_checks = true;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
delay(2000);
|
||||
pinMode(13, OUTPUT);
|
||||
set_start_state();
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void control_oven() {
|
||||
if (temperature < set_min && (!is_oven_heating)) {
|
||||
if (temperature < set_min && !is_oven_heating) {
|
||||
is_oven_heating = true;
|
||||
Serial.println("Oven turned on");
|
||||
}
|
||||
else if (temperature > set_max && is_oven_heating) {
|
||||
else if (temperature > set_min && is_oven_heating) {
|
||||
is_oven_heating = false;
|
||||
Serial.println("Oven turned off");
|
||||
}
|
||||
|
@ -104,6 +112,8 @@ static void get_temp() {
|
|||
|
||||
|
||||
static void check_dt() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
if (actual_dt > set_dt_max) {
|
||||
error_condition |= E_DT_MAX;
|
||||
}
|
||||
|
@ -126,19 +136,61 @@ static void print_debug() {
|
|||
}
|
||||
|
||||
static void check_max_duration() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
Serial.println(time);
|
||||
if (time > time_max) {
|
||||
error_condition |= E_TIME_MAX;
|
||||
}
|
||||
Serial.println(time);
|
||||
}
|
||||
|
||||
static void check_Tl_duration() {
|
||||
if (time - Tl_time_start > Tp_duration) {
|
||||
static void check_Ts_duration_min() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
Tl_time_end = time;
|
||||
if (time - Tl_time_start < Tl_duration_min) {
|
||||
error_condition |= E_TL_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
static void check_Ts_duration_max() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
if (time - Ts_time_start > Tl_duration_max) {
|
||||
error_condition |= E_TS_TOO_LONG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void check_Tl_duration_min() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
Tl_time_end = time;
|
||||
if (time - Tl_time_start < Tl_duration_min) {
|
||||
error_condition |= E_TL_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
static void check_Tl_duration_max() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
if (time - Tl_time_start > Tl_duration_max) {
|
||||
error_condition |= E_TL_TOO_LONG;
|
||||
}
|
||||
}
|
||||
|
||||
static void check_Tp_duration() {
|
||||
if (time - Tp_time_start > Tp_duration) {
|
||||
static void check_Tp_duration_min() {
|
||||
Tp_time_end = time;
|
||||
if (time - Tp_time_start < Tp_duration_min) {
|
||||
error_condition |= E_TP_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
static void check_Tp_duration_max() {
|
||||
if (disable_checks)
|
||||
return;
|
||||
if (time - Tp_time_start > Tp_duration_max) {
|
||||
error_condition |= E_TP_TOO_LONG;
|
||||
}
|
||||
}
|
||||
|
@ -208,22 +260,27 @@ static void set_error_state() {
|
|||
|
||||
|
||||
static void handle_start_state() {
|
||||
if (temperature > Ts_min) {
|
||||
Ts_min_time = time;
|
||||
check_max_duration();
|
||||
Serial.println(time);
|
||||
if (temperature > Ts_min) {
|
||||
Ts_time_start = time;
|
||||
set_preheat_state();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void handle_preheat_state() {
|
||||
check_Ts_duration_max();
|
||||
check_max_duration();
|
||||
if (temperature > Ts_max) {
|
||||
Ts_max_time = time;
|
||||
check_Ts_duration_min();
|
||||
set_ramp_up_state();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void handle_ramp_up_state() {
|
||||
check_max_duration();
|
||||
if (temperature > Tl) {
|
||||
Tl_time_start = time;
|
||||
set_tal_first_state();
|
||||
|
@ -232,7 +289,8 @@ static void handle_ramp_up_state() {
|
|||
|
||||
|
||||
static void handle_tal_first_state() {
|
||||
check_Tl_duration();
|
||||
check_max_duration();
|
||||
check_Tl_duration_max();
|
||||
if (temperature > Tp - 5) {
|
||||
Tp_time_start = time;
|
||||
set_peak_state();
|
||||
|
@ -241,18 +299,19 @@ static void handle_tal_first_state() {
|
|||
|
||||
|
||||
static void handle_peak_state() {
|
||||
check_Tl_duration();
|
||||
check_Tp_duration();
|
||||
if (time - Tp_time_start > Tp_duration) {
|
||||
Tp_time_end = time;
|
||||
check_Tl_duration_max();
|
||||
check_Tp_duration_max();
|
||||
if (time - Tp_time_start > Tp_duration_max) {
|
||||
check_Tp_duration_min();
|
||||
set_tal_second_state();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void handle_tal_second_state() {
|
||||
check_Tl_duration();
|
||||
check_Tl_duration_max();
|
||||
if (temperature < Tl) {
|
||||
check_Tl_duration_min();
|
||||
set_ramp_down_state();
|
||||
}
|
||||
}
|
||||
|
@ -265,9 +324,9 @@ static void handle_ramp_down_state() {
|
|||
|
||||
|
||||
static void handle_end_state() {
|
||||
while(true) {
|
||||
continue;
|
||||
}
|
||||
// while(true) {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -286,9 +345,17 @@ static void handle_error_state() {
|
|||
Serial.println("Error: delta °K/second too big");
|
||||
if (error_condition & E_TIME_MAX)
|
||||
Serial.println("Error: reflow process does take too long");
|
||||
if (error_condition & E_TS_TOO_SHORT)
|
||||
Serial.println("Error: heatup duration was too short");
|
||||
if (error_condition & E_TS_TOO_LONG)
|
||||
Serial.println("Error: heatup duration was too long");
|
||||
if (error_condition & E_TL_TOO_SHORT)
|
||||
Serial.println("Error: temperature above liquidus duration was too short");
|
||||
if (error_condition & E_TL_TOO_LONG)
|
||||
Serial.println("Error: temperature above liquidus was too long");
|
||||
Serial.println("Error: temperature above liquidus duration was too long");
|
||||
if (error_condition & E_TP_TOO_LONG)
|
||||
Serial.println("Error: peak temperature duration was too short");
|
||||
if (error_condition & E_TP_TOO_SHORT)
|
||||
Serial.println("Error: peak temperature duration was too long");
|
||||
}
|
||||
|
||||
|
@ -297,15 +364,13 @@ void loop() {
|
|||
time = millis() / 1000;
|
||||
get_temp();
|
||||
check_dt();
|
||||
check_max_duration();
|
||||
|
||||
if (error_condition) {
|
||||
set_error_state();
|
||||
}
|
||||
else {
|
||||
if (!error_condition) {
|
||||
print_debug();
|
||||
}
|
||||
|
||||
else {
|
||||
set_error_state();
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case START_STATE:
|
||||
|
|
Loading…
Reference in New Issue