From 84b3b53f68a358c48878992660519e4a81892656 Mon Sep 17 00:00:00 2001 From: Gustavo Casanova Date: Mon, 7 Oct 2019 20:49:07 -0300 Subject: [PATCH] Update hardware and software to v0.6 --- .../victoria-control/.vscode/settings.json | 2 +- software/victoria-control/include/delays.h | 16 +- software/victoria-control/include/errors.h | 6 +- .../include/victoria-control.h | 50 ++++- software/victoria-control/platformio.ini | 18 +- .../victoria-control/src/victoria-control.c | 188 ++++++++++++------ .../victoria-control/test/non-bloking-timer.c | 96 +++++++++ 7 files changed, 294 insertions(+), 82 deletions(-) create mode 100644 software/victoria-control/test/non-bloking-timer.c diff --git a/software/victoria-control/.vscode/settings.json b/software/victoria-control/.vscode/settings.json index fa77e2f..e4eca10 100644 --- a/software/victoria-control/.vscode/settings.json +++ b/software/victoria-control/.vscode/settings.json @@ -1,6 +1,6 @@ { "terminal.integrated.env.windows": { - "PATH": "C:\\Users\\casanovg\\.platformio\\penv\\Scripts;C:\\Users\\casanovg\\.platformio\\penv;C:\\Python27\\;C:\\Python27\\Scripts;C:\\ProgramData\\Boxstarter;C:\\WinAVR-20100110\\bin;C:\\WinAVR-20100110\\utils\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\MinGW\\bin;C:\\Program Files\\PuTTY\\;C:\\Program Files\\LLVM\\bin;C:\\Program Files\\nodejs\\;C:\\ProgramData\\chocolatey\\bin;C:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin\\;C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Bin\\;C:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;%SYSTEMROOT%\\System32\\OpenSSH\\;C:\\Ruby25-x64\\bin;C:\\Users\\casanovg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\casanovg\\AppData\\Local\\atom\\bin;C:\\Users\\casanovg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\casanovg\\AppData\\Roaming\\npm;C:\\Users\\casanovg\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\casanovg\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\Python27\\;C:\\Python27\\Scripts;C:\\ProgramData\\Boxstarter;C:\\WinAVR-20100110\\bin;C:\\WinAVR-20100110\\utils\\bin;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\MinGW\\bin;C:\\Program Files\\PuTTY\\;C:\\Program Files\\LLVM\\bin;C:\\Program Files\\nodejs\\;C:\\ProgramData\\chocolatey\\bin;C:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin\\;C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Bin\\;C:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\Bin;%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;%SYSTEMROOT%\\System32\\OpenSSH\\;C:\\Ruby25-x64\\bin;C:\\Users\\casanovg\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\casanovg\\AppData\\Local\\atom\\bin;C:\\Users\\casanovg\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\casanovg\\AppData\\Roaming\\npm;C:\\Users\\casanovg\\AppData\\Local\\Programs\\Git\\cmd;C:\\Users\\casanovg\\AppData\\Local\\Microsoft\\WindowsApps;", + "PATH": "C:\\Users\\casanovg\\.platformio\\penv\\Scripts;C:\\Users\\casanovg\\.platformio\\penv;C:\\WinAVR-20100110\\bin;C:\\WinAVR-20100110\\utils\\bin;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\Git\\cmd;C:\\Users\\casanovg\\AppData\\Local\\Microsoft\\WindowsApps;;C:\\WinAVR-20100110\\bin;C:\\WinAVR-20100110\\utils\\bin;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Intel\\iCLS Client\\;C:\\Program Files\\Intel\\iCLS Client\\;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\DAL;C:\\Program Files (x86)\\Intel\\Intel(R) Management Engine Components\\IPT;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft VS Code\\bin;C:\\Program Files\\Git\\cmd;C:\\Users\\casanovg\\AppData\\Local\\Microsoft\\WindowsApps;", "PLATFORMIO_CALLER": "vscode" } } \ No newline at end of file diff --git a/software/victoria-control/include/delays.h b/software/victoria-control/include/delays.h index dd8410b..6cd0037 100644 --- a/software/victoria-control/include/delays.h +++ b/software/victoria-control/include/delays.h @@ -4,7 +4,7 @@ * ........................................................ * File: delays.h (non-blocking delays) for ATmega328 * ........................................................ - * Version: 0.5 "Juan" / 2019-08-19 + * Version: 0.6 "Juan" / 2019-09-22 * gustavo.casanova@nicebots.com * ........................................................ */ @@ -23,12 +23,18 @@ #define DLY_L_IGNITING_4 100 /* Igniting_4 step long delay */ #define DLY_L_IGNITING_5 300 /* Igniting_5 step long delay */ #define DLY_L_IGNITING_6 500 /* Igniting_6 step long delay */ -#define DLY_L_DHW_ON_DUTY_1 500 /* On_DHW_Duty_1 step long delay */ +#define DLY_L_DHW_ON_DUTY_1 100 /* On_DHW_Duty_1 step long delay */ #define DLY_L_DHW_ON_DUTY_LOOP 3000 /* On_DHW_Duty loop long delay */ #define DLY_L_CH_ON_DUTY_1 500 /* On_CH_Duty_1 step long delay */ #define DLY_L_CH_ON_DUTY_LOOP 3000 /* On_DHW_Duty loop long delay */ -#define DLY_WATER_PUMP_OFF 1800000 /* Delay until the water pump shuts down when there are no CH requests */ - /* Time: 900000 / 60 / 1000 = 15 min aprox, 1800000 = 30 min aprox */ -#define DLY_DEBOUNCE 1000 /* Debounce delay for electromechanical switches */ +#define DLY_L_FLAME_MODULATION 9000 /* Modulation cycle: used in 1/3 parts */ +#define DLY_WATER_PUMP_OFF 600000 /* Delay until the water pump shuts down when there are no CH requests */ + /* Time: 600000 / 60 / 1000 = 15 min aprox */ + /* Time: 900000 / 60 / 1000 = 15 min aprox */ + /* Time: 1800000 / 60 / 1000 = 30 min aprox */ +#define DLY_DEBOUNCE_CH_REQ 1000 /* Debounce delay for CH request thermostat switch */ +#define DLY_DEBOUNCE_AIRFLOW 10 /* Debounce delay for airflow sensor switch */ +#define DLY_FLAME_OFF 100 /* Delay before checking if the flame is off after closing gas */ +#define DLY_AIRFLOW_OFF 2000 /* Delay before checking if the airflow sensor switches off when the fan gets turned off */ #endif /* DELAYS_H_ */ \ No newline at end of file diff --git a/software/victoria-control/include/errors.h b/software/victoria-control/include/errors.h index 21390c6..dbedba5 100644 --- a/software/victoria-control/include/errors.h +++ b/software/victoria-control/include/errors.h @@ -4,7 +4,7 @@ * ........................................................ * File: errors.h (error codes header) for ATmega328 * ........................................................ - * Version: 0.5 "Juan" / 2019-08-19 + * Version: 0.6 "Juan" / 2019-09-22 * gustavo.casanova@nicebots.com * ........................................................ */ @@ -20,13 +20,13 @@ #define ERROR_002 2 // E003: Airflow sensor out of sequence #define ERROR_003 3 -// E004: Exhaust fan not producing enough airflow or airflow-sensor failure +// E004: Exhaust fan not producing enough airflow or airflow-sensor failure (before ignition) #define ERROR_004 4 // E005: Ignition timeout, flame not detected or unexpectedly extinguished #define ERROR_005 5 // E006: Airflow sensor didn't turn off on time #define ERROR_006 6 -// E007: No pressure detected in the flue-exhaust duct, there is a fan or airflow sensor problem +// E007: No pressure detected in the flue-exhaust duct, there is a fan or airflow sensor failure (when the flame is lit) #define ERROR_007 7 // E008: DHW sensor out of range: NTX thermistor failure or cable disconnected #define ERROR_008 8 diff --git a/software/victoria-control/include/victoria-control.h b/software/victoria-control/include/victoria-control.h index 5ac9f2d..340a91e 100644 --- a/software/victoria-control/include/victoria-control.h +++ b/software/victoria-control/include/victoria-control.h @@ -4,7 +4,7 @@ * ........................................................ * File: victoria-control.h (headers) for ATmega328 * ........................................................ - * Version: 0.5 "Juan" / 2019-08-19 + * Version: 0.6 "Juan" / 2019-09-22 * gustavo.casanova@nicebots.com * ........................................................ */ @@ -25,8 +25,8 @@ #define BAUDRATE 38400 #define BAUD_PRESCALER (((F_CPU / (BAUDRATE * 16UL))) - 1) -#define CH_SETPOINT_HIGH 730 /* ADC-NTC CH temperature ~ 52°C */ -#define CH_SETPOINT_LOW 830 /* ADC-NTC CH temperature ~ 42°C */ +#define CH_SETPOINT_HIGH 241 /* ADC-NTC CH temperature ~ 55°C */ +#define CH_SETPOINT_LOW 379 /* ADC-NTC CH temperature ~ 38°C */ #ifndef MAX_IGNITION_RETRIES #define MAX_IGNITION_RETRIES 3 /* Number of ignition retries when no flame is detected */ @@ -37,7 +37,7 @@ #endif /* OVERHEAT_OVERRIDE */ #ifndef AIRFLOW_OVERRIDE -#define AIRFLOW_OVERRIDE true /* True: Flue airflow sensor override */ +#define AIRFLOW_OVERRIDE false /* True: Flue airflow sensor override */ #endif /* AIRFLOW_OVERRIDE */ #ifndef FAST_FLAME_DETECTION @@ -129,7 +129,8 @@ //#define CH_TEMP ADC7 #define ADC_MIN 0 #define ADC_MAX 1023 -#define MAX_CH_TEMP_TOLERANCE 80 +#define MAX_CH_TEMP_TOLERANCE 65 + #define CH_TEMP_MASK 0x3FE // Types @@ -154,6 +155,8 @@ typedef enum inner_steps { IGNITING_5 = 25, IGNITING_6 = 26, DHW_ON_DUTY_1 = 31, + DHW_ON_DUTY_2 = 32, + DHW_ON_DUTY_3 = 33, CH_ON_DUTY_1 = 41, CH_ON_DUTY_2 = 42 } InnerStep; @@ -171,8 +174,6 @@ typedef enum input_flags { typedef enum analog_inputs { DHW_TEMPERATURE = 6, CH_TEMPERATURE = 7, - //DHW_TEMPERATURE = 4, // Just for testing -> SDA in production - //CH_TEMPERATURE = 5, // Just for testing -> SCL in production DHW_SETTING = 0, CH_SETTING = 1, SYSTEM_SETTING = 2 @@ -218,6 +219,11 @@ typedef struct sys_info { uint32_t pump_delay; /* CH water pump auto-shutdown timer */ InnerStep ch_on_duty_step; /* CH inner step before handing over control to DHW */ } SysInfo; +typedef struct heat_power { + bool valve_3_state; + bool valve_2_state; + bool valve_1_state; +} HeatPower; typedef struct debounce_sw { uint16_t ch_request_deb; /* CH request switch debouncing delay */ uint16_t airflow_deb; /* Airflow sensor switch debouncing delay*/ @@ -249,7 +255,7 @@ void GasOff(SysInfo *); void SystemRestart(void); // Globals -const char __flash str_header_01[] = {" OPEN-BOILER v0.5 "}; +const char __flash str_header_01[] = {" OPEN-BOILER v0.6 "}; const char __flash str_header_02[] = {"\"Juan, Sandra & Gustavo\" "}; const char __flash str_iflags[] = {"Inputs: "}; const char __flash str_oflags[] = {"Outputs: "}; @@ -291,4 +297,32 @@ const char __flash str_wptimer[] = {" CH water pump auto-shutdown timer: "}; #endif /* SHOW_PUMP_TIMER */ //const char __flash str_bug[] = {" FORCED BUG !!! "}; +const bool __flash heat_modes[5][3][3] = { + { + {0, 0, 1}, + {0, 0, 1}, + {0, 0, 1} + }, + { + {0, 1, 0}, + {0, 0, 1}, + {0, 0, 1} + }, + { + {0, 1, 0}, + {0, 1, 0}, + {0, 0, 1} + }, + { + {1, 0, 0}, + {0, 0, 1}, + {0, 0, 1} + }, + { + {0, 1, 0}, + {0, 1, 0}, + {0, 1, 0} + } +}; + #endif /* VICTORIA_CONTROL_H_ */ diff --git a/software/victoria-control/platformio.ini b/software/victoria-control/platformio.ini index de8e8fd..fff9873 100644 --- a/software/victoria-control/platformio.ini +++ b/software/victoria-control/platformio.ini @@ -11,14 +11,14 @@ [env:pro16MHzatmega328] platform = atmelavr framework = arduino -;board = pro16MHzatmega328 +board = pro16MHzatmega328 +; For Optiboot bootloader +;upload_speed = 115200 ; Without bootloader (Programmer USBasp) -board = ATmega328P -board_build.f_cpu = 16000000L -upload_protocol = usbasp -upload_flags = - -B3 - -Pusb - -;upload_speed = 57600 \ No newline at end of file +; board = ATmega328P +; board_build.f_cpu = 16000000L +; upload_protocol = usbasp +; upload_flags = +; -B3 +; -Pusb diff --git a/software/victoria-control/src/victoria-control.c b/software/victoria-control/src/victoria-control.c index 8c48ffe..6171795 100644 --- a/software/victoria-control/src/victoria-control.c +++ b/software/victoria-control/src/victoria-control.c @@ -4,7 +4,7 @@ * ........................................................ * File: victoria-control.c (main code) for ATmega328 * ........................................................ - * Version: 0.5 "Juan" / 2019-08-19 + * Version: 0.6 "Juan" / 2019-09-22 * gustavo.casanova@nicebots.com * ........................................................ */ @@ -39,8 +39,8 @@ int main(void) { // Electromechanical switches debouncing DebounceSw debounce_sw; DebounceSw *p_debounce = &debounce_sw; - debounce_sw.airflow_deb = DLY_DEBOUNCE; - debounce_sw.ch_request_deb = DLY_DEBOUNCE; + debounce_sw.airflow_deb = DLY_DEBOUNCE_CH_REQ; + debounce_sw.ch_request_deb = DLY_DEBOUNCE_AIRFLOW; // Delay variables uint16_t l_delay = 0; @@ -148,14 +148,18 @@ int main(void) { case OFF: { // Verify that the flame sensor is off at this point, otherwise, there's a failure if ((p_system->input_flags >> FLAME) & true) { + GasOff(p_system); p_system->error = ERROR_002; p_system->system_state = ERROR; /* >>>>> Next state -> ERROR */ + break; } #if !(AIRFLOW_OVERRIDE) // If there isn't a fan test in progress, verify that the airflow sensor is off, otherwise, there's a failure if ((p_system->inner_step < OFF_3) && ((p_system->input_flags >> AIRFLOW) & true)) { + ClearFlag(p_system, OUTPUT_FLAGS, EXHAUST_FAN); p_system->error = ERROR_003; p_system->system_state = ERROR; /* >>>>> Next state -> ERROR */ + break; } #endif /* AIRFLOW_OVERRIDE */ switch (p_system->inner_step) { @@ -191,14 +195,12 @@ int main(void) { #if !(AIRFLOW_OVERRIDE) // Airflow sensor activated -> fan test successful if ((p_system->input_flags >> AIRFLOW) & true) { - //-----ControlActuator(p_system, EXHAUST_FAN, TURN_OFF, false); ClearFlag(p_system, OUTPUT_FLAGS, EXHAUST_FAN); l_delay = DLY_L_OFF_4; p_system->inner_step = OFF_4; } // Timeout: Airflow sensor didn't activate on time -> fan test failed if (!(l_delay--)) { /* DLY_L_OFF_3 */ - //-----ControlActuator(p_system, EXHAUST_FAN, TURN_OFF, false); ClearFlag(p_system, OUTPUT_FLAGS, EXHAUST_FAN); p_system->error = ERROR_004; p_system->system_state = ERROR; @@ -240,8 +242,12 @@ int main(void) { // ................ // . OFF : Default . // ................ - default: + default: { + if (p_system->system_state == OFF) { + p_system->inner_step = OFF_1; + } break; + } } break; } @@ -252,10 +258,13 @@ int main(void) { |___________________________| */ case READY: { - // Verify that the flame sensor is off at this point, otherwise, there's a failure - if ((p_system->input_flags >> FLAME) & true) { - p_system->error = ERROR_002; - p_system->system_state = ERROR; /* >>>>> Next state -> ERROR */ + // Give the flame sensor time before checking if it is off when the gas is closed + if (l_delay < (DLY_L_READY_1 - DLY_FLAME_OFF)) { + // Verify that the flame sensor is off at this point, otherwise, there's a failure + if ((p_system->input_flags >> FLAME) & true) { + p_system->error = ERROR_002; + p_system->system_state = ERROR; /* >>>>> Next state -> ERROR */ + } } // If the water pump still has time to run before shutting // down, let it run until the delay counter reaches zero @@ -263,10 +272,13 @@ int main(void) { SetFlag(p_system, OUTPUT_FLAGS, WATER_PUMP); } #if !(AIRFLOW_OVERRIDE) - // Verify that the airflow sensor is off at this point, otherwise, there's a failure - if ((p_system->input_flags >> AIRFLOW) & true) { - p_system->error = ERROR_003; - p_system->system_state = ERROR; /* >>>>> Next state -> ERROR */ + // Give the airflow sensor time before checking if it switches off when the fan gets turned off + if (l_delay < (DLY_L_READY_1 - DLY_AIRFLOW_OFF)) { + // Verify that the airflow sensor is off at this point, otherwise, there's a failure + if ((p_system->input_flags >> AIRFLOW) & true) { + p_system->error = ERROR_003; + p_system->system_state = ERROR; /* >>>>> Next state -> ERROR */ + } } #endif /* AIRFLOW_OVERRIDE */ // Check if there a DHW or CH request. If both are requested, DHW will have higher priority after ignition @@ -295,6 +307,7 @@ int main(void) { // Request canceled, turn actuators off and return to "ready" state GasOff(p_system); p_system->last_displayed_iflags = 0xFF; /* Force a display dashboard refresh */ + l_delay = DLY_L_READY_1; p_system->inner_step = READY_1; p_system->system_state = READY; } @@ -403,17 +416,17 @@ int main(void) { p_system->ignition_retries = 0; // Hand over control to the requested service (DHW has higher priority) if ((p_system->input_flags >> DHW_REQUEST) & true) { - l_delay = DLY_L_DHW_ON_DUTY_LOOP; + l_delay = DLY_L_FLAME_MODULATION / 3; p_system->inner_step = DHW_ON_DUTY_1; p_system->system_state = DHW_ON_DUTY; } else if ((p_system->input_flags >> CH_REQUEST) & true) { l_delay = DLY_L_CH_ON_DUTY_LOOP; p_system->inner_step = CH_ON_DUTY_1; - //p_system->inner_step = p_system->ch_on_duty_step; p_system->system_state = CH_ON_DUTY; } else { // Request canceled, turn actuators off and return to "ready" state GasOff(p_system); + l_delay = DLY_L_READY_1; p_system->inner_step = READY_1; p_system->system_state = READY; } @@ -434,8 +447,14 @@ int main(void) { // ..................... // . IGNITING : Default . // ..................... - default: + default: { + if (p_system->system_state == IGNITING) { + l_delay = DLY_L_IGNITING_1; + p_system->inner_step = IGNITING_1; + } break; + } + } break; } @@ -475,10 +494,6 @@ int main(void) { // If there is a CH request active, modulate to valve 1 and // hand over control to CH service state if ((p_system->input_flags >> CH_REQUEST) & true) { - // Close valve 2 - //ClearFlag(p_system, OUTPUT_FLAGS, VALVE_2); - // Open valve 1 - //SetFlag(p_system, OUTPUT_FLAGS, VALVE_1); p_system->last_displayed_iflags = 0xFF; /* Force a display dashboard refresh */ l_delay = DLY_L_CH_ON_DUTY_LOOP; p_system->inner_step = p_system->ch_on_duty_step; @@ -486,9 +501,7 @@ int main(void) { } else { // DHW request canceled, turn gas off and return to "ready" state GasOff(p_system); - // if (p_system->pump_delay > 5000) { - // SetFlag(p_system, OUTPUT_FLAGS, WATER_PUMP); - // } + l_delay = DLY_L_READY_1; p_system->inner_step = READY_1; p_system->system_state = READY; } @@ -496,20 +509,69 @@ int main(void) { // // [ # # # ] DHW heat modulation code [ # # # ] // - if ((p_system->output_flags >> VALVE_1) & true) { - // Close valve 1 - ClearFlag(p_system, OUTPUT_FLAGS, VALVE_1); - // Open valve 2 - SetFlag(p_system, OUTPUT_FLAGS, VALVE_2); + switch (p_system->inner_step) { + // ....................................... + // . DHW_ON_DUTY_1 : Flame modulation 1/3 . + // ....................................... + case DHW_ON_DUTY_1: { + // Close valve 1 + ClearFlag(p_system, OUTPUT_FLAGS, VALVE_1); + // Close valve 3 + ClearFlag(p_system, OUTPUT_FLAGS, VALVE_3); + // Open valve 2 + SetFlag(p_system, OUTPUT_FLAGS, VALVE_2); + if (!(l_delay--)) { /* DLY_L_FLAME_MODULATION / 3 */ + l_delay = DLY_L_FLAME_MODULATION / 3; + p_system->inner_step = DHW_ON_DUTY_2; + } + break; + } + // ....................................... + // . DHW_ON_DUTY_2 : Flame modulation 2/3 . + // ....................................... + case DHW_ON_DUTY_2: { + // Close valve 2 + ClearFlag(p_system, OUTPUT_FLAGS, VALVE_2); + // Close valve 3 + ClearFlag(p_system, OUTPUT_FLAGS, VALVE_3); + // Open valve 1 + SetFlag(p_system, OUTPUT_FLAGS, VALVE_1); + if (!(l_delay--)) { /* DLY_L_FLAME_MODULATION / 3 */ + l_delay = DLY_L_FLAME_MODULATION / 3; + p_system->inner_step = DHW_ON_DUTY_3; + } + break; + } + // ....................................... + // . DHW_ON_DUTY_3 : Flame modulation 3/3 . + // ....................................... + case DHW_ON_DUTY_3: { + // Close valve 2 + ClearFlag(p_system, OUTPUT_FLAGS, VALVE_2); + // Close valve 3 + ClearFlag(p_system, OUTPUT_FLAGS, VALVE_3); + // Open valve 1 + SetFlag(p_system, OUTPUT_FLAGS, VALVE_1); + if (!(l_delay--)) { /* DLY_L_FLAME_MODULATION / 3 */ + l_delay = DLY_L_FLAME_MODULATION / 3; + p_system->inner_step = DHW_ON_DUTY_1; + } + break; + } + // ........................ + // . DHW_ON_DUTY : Default . + // ........................ + default: { + if (p_system->system_state == DHW_ON_DUTY) { + l_delay = DLY_L_FLAME_MODULATION / 3; + p_system->inner_step = DHW_ON_DUTY_1; + } + break; + } } // // [ # # # ] DHW heat modulation code end [ # # # ] // - if (!(l_delay--)) { /* DLY_L_DHW_ON_DUTY_1 */ - l_delay = DLY_L_DHW_ON_DUTY_LOOP; - p_system->last_displayed_iflags = 0xFF; /* Force a display dashboard refresh */ - } - break; } /* _______________________________ @@ -522,8 +584,7 @@ int main(void) { // ............................................ // . Step CH_ON_DUTY_1 : CH heating, burner on . // ............................................ - case CH_ON_DUTY_1: { - //p_system->ch_on_duty_step = CH_ON_DUTY_1; /* Preserve current CH service step */ + case CH_ON_DUTY_1: { // If the flame sensor is off, check that gas valves 3 and 2 are closed and retry ignition if (((p_system->input_flags >> FLAME) & true) == false) { if ((p_system->output_flags >> VALVE_3) & true) { @@ -559,7 +620,7 @@ int main(void) { // Open valve 1 //SetFlag(p_system, OUTPUT_FLAGS, VALVE_1); //p_system->last_displayed_iflags = 0xFF; /* Force a display dashboard refresh */ - l_delay = DLY_L_DHW_ON_DUTY_LOOP; + l_delay = DLY_L_FLAME_MODULATION / 3; p_system->inner_step = DHW_ON_DUTY_1; p_system->system_state = DHW_ON_DUTY; } else { @@ -567,6 +628,7 @@ int main(void) { if (((p_system->input_flags >> CH_REQUEST) & true) == false) { // CH request canceled, turn gas off and return to "ready" state GasOff(p_system); + l_delay = DLY_L_READY_1; p_system->inner_step = READY_1; p_system->system_state = READY; } @@ -600,7 +662,6 @@ int main(void) { // . Step CH_ON_DUTY_2 : CH recirculating water, burner off . // ......................................................... case CH_ON_DUTY_2: { - //p_system->ch_on_duty_step = CH_ON_DUTY_2; /* Preserve current CH service step */ // Close gas if ((p_system->input_flags >> FLAME) & true) { GasOff(p_system); @@ -631,6 +692,7 @@ int main(void) { if (((p_system->input_flags >> CH_REQUEST) & true) == false) { // CH request canceled, turn gas off and return to "ready" state GasOff(p_system); + l_delay = DLY_L_READY_1; p_system->inner_step = READY_1; p_system->system_state = READY; } @@ -640,10 +702,15 @@ int main(void) { // ....................... // . CH_ON_DUTY : Default . // ....................... - default: + default: { + if (p_system->system_state == CH_ON_DUTY) { + l_delay = DLY_L_CH_ON_DUTY_LOOP; + p_system->inner_step = p_system->ch_on_duty_step; + } break; + } } - if (!(l_delay--)) { /* DLY_L_DHW_ON_DUTY_1 */ + if (!(l_delay--)) { /* DLY_L_CH_ON_DUTY_1 */ l_delay = DLY_L_CH_ON_DUTY_LOOP; p_system->last_displayed_iflags = 0xFF; /* Force a display dashboard refresh */ } @@ -665,31 +732,38 @@ int main(void) { for (InputFlag digital_sensor = DHW_REQUEST; digital_sensor <= OVERHEAT; digital_sensor++) { CheckDigitalSensor(p_system, digital_sensor, p_debounce, false); } - ControlActuator(p_system, LED_UI, TURN_ON, false); /* true updates display on each pass */ + p_system->system_state = ERROR; + Dashboard(p_system, true); + SetFlag(p_system, OUTPUT_FLAGS, LED_UI); + //ControlActuator(p_system, LED_UI, TURN_ON, false); /* true updates display on each pass */ SerialTxStr(str_crlf); SerialTxStr(str_error_s); SerialTxNum(p_system->error, DIGITS_3); SerialTxStr(str_error_e); SerialTxStr(str_crlf); _delay_ms(500); - ControlActuator(p_system, LED_UI, TURN_OFF, false); + ClearFlag(p_system, OUTPUT_FLAGS, LED_UI); + //ControlActuator(p_system, LED_UI, TURN_OFF, false); _delay_ms(500); } // End of error loop // Next state -> OFF (reset error and try to resume service) p_system->last_displayed_iflags = 0xFF; /* Force a display dashboard refresh */ p_system->error = ERROR_000; - l_delay = DLY_L_OFF_2; p_system->inner_step = OFF_1; p_system->system_state = OFF; + break; } - /* ____________ - | | - | Default | - |_____________| + /* ____________________________ + | | + | System state -> Default | + |_____________________________| */ default: { + l_delay = DLY_L_OFF_2; + p_system->inner_step = OFF_1; + p_system->system_state = OFF; break; } @@ -731,6 +805,8 @@ void SystemRestart(void) { // Function InitAnalogSensor void InitAnalogSensor(SysInfo *p_sys, AnalogInput analog_sensor) { ADMUX |= (1 << REFS0); /* reference voltage on AVCC */ + ACSR &= ~(1 << ACIE); /* Clear analog comparator IRQ flag */ + ACSR = (1 << ACD); /* Stop analog comparator */ ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); /* ADC clock prescaler /128 */ //ADMUX |= (1 << ADLAR); /* left-adjust result, return only 8 bits */ ADCSRA |= (1 << ADEN); /* enable ADC */ @@ -764,7 +840,7 @@ void InitAnalogSensor(SysInfo *p_sys, AnalogInput analog_sensor) { // Function CheckAnalogSensor uint16_t CheckAnalogSensor(SysInfo *p_sys, AnalogInput analog_sensor, bool ShowDashboard) { - ADMUX = (0xf0 & ADMUX) | analog_sensor; + ADMUX = (0xF0 & ADMUX) | analog_sensor; ADCSRA |= (1 << ADSC); loop_until_bit_is_clear(ADCSRA, ADSC); switch (analog_sensor) { @@ -825,7 +901,7 @@ void SetFlag(SysInfo *p_sys, FlagsType flags_type, uint8_t flag_position) { case OUTPUT_FLAGS: { // WARNING !!! HARDWARE ACTIVATION !!! p_sys->output_flags |= (1 << flag_position); - ControlActuator(p_sys, flag_position, TURN_ON, true); + ControlActuator(p_sys, flag_position, TURN_ON, false); break; } default: { @@ -844,7 +920,7 @@ void ClearFlag(SysInfo *p_sys, FlagsType flags_type, uint8_t flag_position) { case OUTPUT_FLAGS: { // WARNING !!! HARDWARE DEACTIVATION !!! p_sys->output_flags &= ~(1 << flag_position); - ControlActuator(p_sys, flag_position, TURN_OFF, true); + ControlActuator(p_sys, flag_position, TURN_OFF, false); break; } default: { @@ -912,11 +988,11 @@ bool CheckDigitalSensor(SysInfo *p_sys, InputFlag digital_sensor, DebounceSw *p_ } return ((p_sys->input_flags >> DHW_REQUEST) & true); } - case CH_REQUEST: { /* CH request: Active = low, Inactive = high (electromechanical switch) */ + case CH_REQUEST: { /* CH request: Active = low, Inactive = high (bimetallic room thermostat) */ // CH request switch debouncing - if ( ((p_sys->input_flags >> CH_REQUEST) & true) == ((CH_RQ_PINP >> CH_RQ_PIN) & true) ) { + if (((p_sys->input_flags >> CH_REQUEST) & true) == ((CH_RQ_PINP >> CH_RQ_PIN) & true)) { if (!(p_deb->ch_request_deb--)) { - p_deb->ch_request_deb = DLY_DEBOUNCE; + p_deb->ch_request_deb = DLY_DEBOUNCE_CH_REQ; if ( ((p_sys->input_flags >> CH_REQUEST) & true) == ((CH_RQ_PINP >> CH_RQ_PIN) & true) ) { p_sys->input_flags ^= (1 << CH_REQUEST); } @@ -924,11 +1000,11 @@ bool CheckDigitalSensor(SysInfo *p_sys, InputFlag digital_sensor, DebounceSw *p_ } return ((p_sys->input_flags >> CH_REQUEST) & true); } - case AIRFLOW: { /* Flue air flow sensor: Active = low, Inactive = high (electromechanical switch) */ + case AIRFLOW: { /* Flue air flow sensor: Active = low, Inactive = high (flue air pressure switch) */ // Airflow switch debouncing - if ( ((p_sys->input_flags >> AIRFLOW) & true) == ((AIRFLOW_PINP >> AIRFLOW_PIN) & true) ) { + if (((p_sys->input_flags >> AIRFLOW) & true) == ((AIRFLOW_PINP >> AIRFLOW_PIN) & true)) { if (!(p_deb->airflow_deb--)) { - p_deb->airflow_deb = DLY_DEBOUNCE; + p_deb->airflow_deb = DLY_DEBOUNCE_AIRFLOW; if ( ((p_sys->input_flags >> AIRFLOW) & true) == ((AIRFLOW_PINP >> AIRFLOW_PIN) & true) ) { p_sys->input_flags ^= (1 << AIRFLOW); } diff --git a/software/victoria-control/test/non-bloking-timer.c b/software/victoria-control/test/non-bloking-timer.c new file mode 100644 index 0000000..2f930a7 --- /dev/null +++ b/software/victoria-control/test/non-bloking-timer.c @@ -0,0 +1,96 @@ + +/* set_timer function */ +void SetTimer(unsigned int duration, char type) { + char i; + // Disable timers... + //#asm(“cli”); + for (i = 0; i < TIMER_BUFFER_SIZE; i++) { // loop through and check for free spot, then place timer in there... + if (timer_queue[i].timer_id == TIMER_EMPTY) { // place new timer here... + timer_queue[i].timer_id = type; + timer_queue[i].end_time = duration + global_ms_timer; + return; + } + } + // Re-enable timers... + //#asm("sei"); +} + +/* The process_timers is shown below. */ + +void ProcessTimers() { + char i; + for (i=0;i