mirror of https://github.com/rusefi/bldc.git
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:
parent
17f97763c0
commit
12fcffb629
7
mcpwm.c
7
mcpwm.c
|
@ -465,12 +465,6 @@ void mcpwm_init(volatile mc_configuration *configuration) {
|
||||||
if (timeout_had_IWDG_reset())
|
if (timeout_had_IWDG_reset())
|
||||||
mc_interface_fault_stop(FAULT_CODE_BOOTING_FROM_WATCHDOG_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
|
// Reset tachometers again
|
||||||
tachometer = 0;
|
tachometer = 0;
|
||||||
tachometer_abs = 0;
|
tachometer_abs = 0;
|
||||||
|
@ -1725,7 +1719,6 @@ void mcpwm_adc_int_handler(void *p, uint32_t flags) {
|
||||||
update_timer_attempt();
|
update_timer_attempt();
|
||||||
|
|
||||||
// Reset the watchdog
|
// Reset the watchdog
|
||||||
WWDG_SetCounter(100);
|
|
||||||
timeout_feed_WDT(THREAD_MCPWM);
|
timeout_feed_WDT(THREAD_MCPWM);
|
||||||
|
|
||||||
const float input_voltage = GET_INPUT_VOLTAGE();
|
const float input_voltage = GET_INPUT_VOLTAGE();
|
||||||
|
|
|
@ -449,12 +449,6 @@ void mcpwm_foc_init(volatile mc_configuration *configuration) {
|
||||||
if (timeout_had_IWDG_reset())
|
if (timeout_had_IWDG_reset())
|
||||||
mc_interface_fault_stop(FAULT_CODE_BOOTING_FROM_WATCHDOG_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;
|
m_init_done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1490,7 +1484,6 @@ void mcpwm_foc_adc_int_handler(void *p, uint32_t flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the watchdog
|
// Reset the watchdog
|
||||||
WWDG_SetCounter(100);
|
|
||||||
timeout_feed_WDT(THREAD_MCPWM);
|
timeout_feed_WDT(THREAD_MCPWM);
|
||||||
|
|
||||||
int curr0 = ADC_Value[ADC_IND_CURR1];
|
int curr0 = ADC_Value[ADC_IND_CURR1];
|
||||||
|
|
15
timeout.c
15
timeout.c
|
@ -40,6 +40,16 @@ void timeout_init(void) {
|
||||||
timeout_brake_current = 0.0;
|
timeout_brake_current = 0.0;
|
||||||
has_timeout = false;
|
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();
|
timeout_init_IWDT();
|
||||||
|
|
||||||
chThdSleepMilliseconds(10);
|
chThdSleepMilliseconds(10);
|
||||||
|
@ -194,8 +204,9 @@ static THD_FUNCTION(timeout_thread, arg) {
|
||||||
feed_counter[i] = 0;
|
feed_counter[i] = 0;
|
||||||
|
|
||||||
if (threads_ok == true) {
|
if (threads_ok == true) {
|
||||||
// Feed WDT
|
// Feed WDT's
|
||||||
IWDG_ReloadCounter();
|
WWDG_SetCounter(127); // must reload in >6.24ms and <12.48ms
|
||||||
|
IWDG_ReloadCounter(); // must reload in <12ms
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue