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 <mchaparro@paltatech.com>
This commit is contained in:
Marcos Chaparro 2019-01-24 13:16:28 -03:00
parent 17f97763c0
commit 12fcffb629
3 changed files with 13 additions and 16 deletions

View File

@ -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();

View File

@ -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];

View File

@ -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
{