From 12fcffb629004cead30272bb77cc641743c736d5 Mon Sep 17 00:00:00 2001 From: Marcos Chaparro Date: Thu, 24 Jan 2019 13:16:28 -0300 Subject: [PATCH] Window Watchdog feed moved outside ADC ISR. Now it has the same coverage as the IWDG, with the extra capability of detecting that the timeout thread is running faster than expected. Signed-off-by: Marcos Chaparro --- mcpwm.c | 7 ------- mcpwm_foc.c | 7 ------- timeout.c | 15 +++++++++++++-- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/mcpwm.c b/mcpwm.c index 91105384..8a36728c 100644 --- a/mcpwm.c +++ b/mcpwm.c @@ -465,12 +465,6 @@ void mcpwm_init(volatile mc_configuration *configuration) { if (timeout_had_IWDG_reset()) mc_interface_fault_stop(FAULT_CODE_BOOTING_FROM_WATCHDOG_RESET); - // WWDG configuration - RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); - WWDG_SetPrescaler(WWDG_Prescaler_1); - WWDG_SetWindowValue(255); - WWDG_Enable(100); - // Reset tachometers again tachometer = 0; tachometer_abs = 0; @@ -1725,7 +1719,6 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) { update_timer_attempt(); // Reset the watchdog - WWDG_SetCounter(100); timeout_feed_WDT(THREAD_MCPWM); const float input_voltage = GET_INPUT_VOLTAGE(); diff --git a/mcpwm_foc.c b/mcpwm_foc.c index 8e7b8cce..aac75174 100644 --- a/mcpwm_foc.c +++ b/mcpwm_foc.c @@ -449,12 +449,6 @@ void mcpwm_foc_init(volatile mc_configuration *configuration) { if (timeout_had_IWDG_reset()) mc_interface_fault_stop(FAULT_CODE_BOOTING_FROM_WATCHDOG_RESET); - // WWDG configuration - RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); - WWDG_SetPrescaler(WWDG_Prescaler_1); - WWDG_SetWindowValue(255); - WWDG_Enable(100); - m_init_done = true; } @@ -1490,7 +1484,6 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) { } // Reset the watchdog - WWDG_SetCounter(100); timeout_feed_WDT(THREAD_MCPWM); int curr0 = ADC_Value[ADC_IND_CURR1]; diff --git a/timeout.c b/timeout.c index 703d36ac..ea411247 100644 --- a/timeout.c +++ b/timeout.c @@ -40,6 +40,16 @@ void timeout_init(void) { timeout_brake_current = 0.0; has_timeout = false; + // WWDG configuration + RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); + // Timeout = t_PCLK1 (ms) * 4096 * 2^(WDGTB [1:0]) * (T[5:0] + 1) + // CLK1 = 42MHz + + // Window set between 6.24ms and 12.48ms. Mcu will reset if watchdog is fed outside the window + WWDG_SetPrescaler(WWDG_Prescaler_2); + WWDG_SetWindowValue(127); + WWDG_Enable(127); //0x7F + timeout_init_IWDT(); chThdSleepMilliseconds(10); @@ -194,8 +204,9 @@ static THD_FUNCTION(timeout_thread, arg) { feed_counter[i] = 0; if (threads_ok == true) { - // Feed WDT - IWDG_ReloadCounter(); + // Feed WDT's + WWDG_SetCounter(127); // must reload in >6.24ms and <12.48ms + IWDG_ReloadCounter(); // must reload in <12ms } else {