HI,dialog
After i set a pin as PWM0 and inited time0 ,I can get stable output at the pin.
Then, I add some code to do sth in CALLBACK. Now,I can see stable wave at the
pin and enter CallBACK periodically.It seems that erverything is well.
But, if I set_tmr_enable(CLK_PER_REG_TMR_DISABLED) in CALLBACK,and reenable
(CLK_PER_REG_TMR_ENABLED)it,then the wave disappeared and the pin
always keep low.although I can enter CallBACK periodically. WHY?
I just want to ctrl PWM output at the pin,sometime I turn on , sometime I turn off
But I can turn on and turn off,but I cann't turn on again.
The code as bellow:
1> In void set_pad_functions(void)
GPIO_ConfigurePin(PWM0_PORT,PWM0_PIN, OUTPUT, PID_PWM0, false);
2> void pwm0_init(void)
{
set_tmr_enable(CLK_PER_REG_TMR_ENABLED);//Enables TIMER0,TIMER2 clock
static uint8_t init=0;
#if 0 /* no different for result with or without GPIO_ConfigurePin*/
GPIO_ConfigurePin(PWM0_PORT,PWM0_PIN, OUTPUT, PID_PWM0, false);
#endif
#if 0 /* no different for result with or without init ctrl*/
if(init==0)
#endif
{
set_tmr_div(CLK_PER_REG_TMR_DIV_8);
timer0_init(TIM0_CLK_FAST, PWM_MODE_ONE, TIM0_CLK_NO_DIV);
timer0_set(1000, 500, 200);
timer0_register_callback(pwm0_callback);
init++;
}
timer0_enable_irq();
timer0_start();
}
3>void pwm0_callback(void)
{
timer0_disable_irq();
static uint8_t sw=0;
//if(sw>0) //if comment this line I will never see wave at the specical pin
//if uncomment ,I can get wave after enter callback at the first time
// and the wave disappear at second time enter
// and I will never get wave at the pin after third,fourth,fifth............ WHY???
{
dosth();
set_tmr_enable(CLK_PER_REG_TMR_DISABLED);
timer0_stop();
sw=0;
}
sw++;
}
4> my main program
......
if (express) ///other trig condiction
{
pwm0_init();
}
.......
PS:我有undef EXT_SLEEP DEEP_SLEEPin da14580_config.h

Did you get any idea about this ?
My issue is the callback function is not run at all.
U should patch set_tmr_enable as below,then every thing is OK.
good lucky!
inline void set_tmr_enable(CLK_PER_REG_TMR_ENABLE_t clk_per_reg_tmr_enable)
{
clk_per_reg.BITFLD_TMR_ENABLE = clk_per_reg_tmr_enable; // Enable/Disable TIMER0/TIMER2 clock
if (clk_per_reg_tmr_enable)
{
while (app_get_sleep_mode()) app_force_active_mode();
} else
{
while (!app_get_sleep_mode()) app_restore_sleep_mode();
}
}