Hello Dialog,
void timer0_general_user_callback_function(void) { static uint8_t n = 0; // when pass 10 * 100ms if ( 10 == n ) { n = 0; timeout_expiration--; if (GPIO_GetPinStatus(GPIO_LED_PORT, GPIO_LED_PIN)) { GPIO_SetInactive(GPIO_LED_PORT, GPIO_LED_PIN); } else { GPIO_SetActive(GPIO_LED_PORT, GPIO_LED_PIN); } } n++; } static void button_timer_activtation(uint8_t delay_sec){ wdg_freeze(); // Stop timer for enter settings timer0_stop(); timeout_expiration = delay_sec; // register callback function for SWTIM_IRQn irq timer0_register_callback(timer0_general_user_callback_function); // Enable TIMER0 clock set_tmr_enable(CLK_PER_REG_TMR_ENABLED); // Sets TIMER0,TIMER2 clock division factor to 8, so TIM0 Fclk is F = 16MHz/8 = 2Mhz set_tmr_div(CLK_PER_REG_TMR_DIV_8); // clear PWM settings register to not generate PWM timer0_set_pwm_high_counter(0x0); timer0_set_pwm_low_counter(0x0); // Set timer with 2MHz source clock divided by 10 so Fclk = 2MHz/10 = 200kHz timer0_init(TIM0_CLK_FAST, PWM_MODE_ONE, TIM0_CLK_DIV_BY_10); // reload value for 100ms (T = 1/200kHz * RELOAD_100MS = 0,000005 * 20000 = 100ms) timer0_set_pwm_on_counter(20000); // Enable SWTIM_IRQn irq timer0_enable_irq(); // Start Timer0 timer0_start(); // Wait for desired number of seconds while (timeout_expiration); // Disable TIMER0, TIMER2 clocks set_tmr_enable(CLK_PER_REG_TMR_DISABLED); wdg_reload(WATCHDOG_DEFAULT_PERIOD); }
The above code is invoked after system_init( ) in main( ) before while(1){ schedule_while_ble_on() ;}.
The code does not run according to the logic desired.
The ISR callback is invoked even after timeout_expiration reaches 0.
Need Help ASAP.
Thanks
regards
Raju
HONEYWELL
Device:
Hello Dialog,
It was a design issue -
timeout_expiration should be "VOLATILE"
问候
Raju
Hi rajucoolsuraj,
高兴你找到你的问题ut and thanks for the indication,
Thanks, PM_Dialog