From: Nathael Pajani Date: Thu, 11 Jun 2020 19:05:16 +0000 (+0200) Subject: Changes to old v08 scialys version. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=a2b1e0c1be92be4b883301ff50f7eb0df985186a;p=soft%2Flpc122x%2Fscialys Changes to old v08 scialys version. --- diff --git a/v08/interface.c b/v08/interface.c index c937307..c1960a6 100644 --- a/v08/interface.c +++ b/v08/interface.c @@ -581,8 +581,8 @@ void config_interface_handle(void) /* usual menu and switch to config menu */ extern int water_centi_degrees; -extern uint32_t moyenne_solar; -extern uint32_t moyenne_home; +extern uint32_t solar_prod_value; +extern uint32_t home_conso_value; extern volatile uint8_t command_val; void interface_update(char heat_mode) @@ -631,22 +631,22 @@ void interface_update(char heat_mode) /* Display info */ snprintf(line, DISP_LLEN, "Water:% 2d.%03d %cC", (water_centi_degrees / 100), (abs_centi % 100), 0x1F); display_line(2, 0, line); - snprintf(line, DISP_LLEN, "Prod :% 2d,%03dA", (moyenne_solar / 1000), ((moyenne_solar % 1000) / 10)); + snprintf(line, DISP_LLEN, "Prod :% 2d,%03dA", (solar_prod_value / 1000), ((solar_prod_value % 1000) / 10)); display_line(3, 0, line); - snprintf(line, DISP_LLEN, "Conso:% 2d,%03dA", (moyenne_home / 1000), ((moyenne_home % 1000) / 10)); + snprintf(line, DISP_LLEN, "Conso:% 2d,%03dA", (home_conso_value / 1000), ((home_conso_value % 1000) / 10)); display_line(4, 0, line); snprintf(line, DISP_LLEN, "Command: %d%%", command_val); display_line(5, 0, line); snprintf(line, DISP_LLEN, "Mode: %c", heat_mode); display_line(6, 0, line); - snprintf(line, DISP_LLEN, "v0.8 - 0.3.2", heat_mode); + snprintf(line, DISP_LLEN, "v0.8 - 0.3.3"); display_line(7, 0, line); /* Update Oled display */ ssd130x_display_full_screen(&display); /* Update RGB leds */ /* FIXME : use for error signal */ - ws2812_set_pixel(0, (moyenne_home / 2000), (moyenne_solar / 2000), 0); + ws2812_set_pixel(0, (home_conso_value / 2000), (solar_prod_value / 2000), 0); ws2812_set_pixel(1, 0, 0, command_val); ws2812_send_frame(0); } diff --git a/v08/main.c b/v08/main.c index bcfacd8..c05ccee 100644 --- a/v08/main.c +++ b/v08/main.c @@ -89,14 +89,13 @@ uint32_t sunny_days_prod_value_config = 0; int external_disable = 0; enum modes { - heat = 'C', - ext_disable = 'E', - delayed_heat_prod = 'P', - forced = 'F', - temp_OK = 'T', + heat = 'C', /* Normal heating */ + ext_disable = 'E', /* Forced heating disabled by external input */ + forced = 'F', /* Forced heating */ manual = 'M', - idle_heat = 'L', - full_heat = 'F', + delayed_heat_prod = 'P', /* Pause */ + overprod = 'S', /* Over production, try to start other loads */ + temp_OK = 'T', /* Max temperature reached */ }; /* Water and internaltemperature */ @@ -156,19 +155,13 @@ void handle_dec_request(uint32_t curent_tick) { /* Track power production and usage */ /* Average value computed on last 10 ADC values */ -uint32_t moyenne_solar = 0; -uint32_t moyenne_home = 0; -/* Last ADC values (snapshot) */ -static uint16_t snapval_solar = 0; -static uint16_t snapval_home = 0; +uint32_t solar_prod_value = 0; +uint32_t home_conso_value = 0; -#define NB_VAL 5 static void track_isnail_values(void) { - static uint16_t isnail_solar_values[NB_VAL]; - static uint16_t isnail_home_values[NB_VAL]; - static uint8_t idx = 0; - + uint16_t snapval_solar = 0; + uint16_t snapval_home = 0; /* Get new values */ adc_get_value(&snapval_solar, LPC_ADC(1)); adc_get_value(&snapval_home, LPC_ADC(0)); @@ -178,28 +171,8 @@ static void track_isnail_values(void) * Coil convertion is 1000mA -> 50mV : multily mV value by 20 to get mA value * x * 3.2 * 20 == x * 32 * 2 == x << 6 * Increment is 64mA / ADC step */ - snapval_solar = snapval_solar << 6; - snapval_home = snapval_home << 6; - - /* Store value */ - isnail_solar_values[idx] = snapval_solar; - isnail_home_values[idx++] = snapval_home; - if (idx == NB_VAL) { - idx = 0; - } - - /* Compute average once we sampled enough values */ - if ((idx == 0) || (idx == (NB_VAL / 2))) { - int i = 0; - moyenne_solar = 0; - moyenne_home = 0; - for (i = 0; i < NB_VAL; i++) { - moyenne_solar += isnail_solar_values[i]; - moyenne_home += isnail_home_values[i]; - } - moyenne_solar = moyenne_solar / NB_VAL; - moyenne_home = moyenne_home / NB_VAL; - } + solar_prod_value = snapval_solar << 6; + home_conso_value = snapval_home << 6; } /***************************************************************************** */ @@ -300,16 +273,16 @@ void handle_cmd_update(uint32_t curent_tick) forced_heater_time = FORCED_HEATER_DELAY + FORCED_HEATER_DURATION; } } - if (moyenne_solar < (moyenne_home - 64)) { + if (solar_prod_value < (home_conso_value - 64)) { /* Low production mode */ if (cmd > 0) { cmd--; } - } else if (moyenne_solar > (moyenne_home + 1280)) { + } else if (solar_prod_value > (home_conso_value + 1280)) { if (cmd < 100) { cmd++; } - } else if (moyenne_solar > (moyenne_home + 192)) { + } else if (solar_prod_value > (home_conso_value + 256)) { /* High production mode */ if (cmd_up_delay > 0) { cmd_up_delay--; @@ -442,7 +415,7 @@ int main(void) track_isnail_values(); /* Feed the dog */ - if ((moyenne_solar != 0) && (moyenne_home != 0)) { + if ((solar_prod_value != 0) && (home_conso_value != 0)) { watchdog_feed(); } @@ -495,7 +468,7 @@ int main(void) } /* Do not force if there is a lot of sun, it may be enough to heat again soon */ - if (moyenne_solar > sunny_days_prod_value_config) { + if ((solar_prod_value > sunny_days_prod_value_config) && (forced_heater_mode == 1)) { mode = delayed_heat_prod; forced_heater_mode = 0; } @@ -527,18 +500,23 @@ int main(void) } } + /* Command at 100% and still more production than energy used ? */ + if ((command_val == 100) && (solar_prod_value > home_conso_value)) { + mode = overprod; + } + /* Display */ interface_update(mode); /* Debug */ if (1) { uprintf(UART0, "%c:%d - Is: %d,%04d - Ih: %d,%04d\n", mode, loop++, - (moyenne_solar / 1000), (moyenne_solar % 1000), - (moyenne_home / 1000), (moyenne_home % 1000)); + (solar_prod_value / 1000), (solar_prod_value % 1000), + (home_conso_value / 1000), (home_conso_value % 1000)); uprintf(UART0, "Water Temp : %d\n", water_centi_degrees); uprintf(UART0, "Internal Temp power : %d\n", deci_degrees_power); uprintf(UART0, "Internal Temp display : %d\n", deci_degrees_disp); - uprintf(UART0, "ADC: Sol: %dmA, Home: %dmA\n", snapval_solar, snapval_home); + uprintf(UART0, "ADC: Sol: %dmA, Home: %dmA\n", solar_prod_value, home_conso_value); uprintf(UART0, "Load: %d - %d\n", load_power_lowest, load_power_highest); uprintf(UART0, "Zc: %d\n", zc_cnt); uprintf(UART0, "CMD: %d/%d, Fan: %d/%d\n\n", command_val, (100 - act_cmd), fan_on, force_fan);