TIMER0_ON-REG settling conditions

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.xmece.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
4 posts / 0 new
Last post
nhan.ngodinh
Offline
Last seen:1 year 4 months ago
加入:2017-03-21 20
TIMER0_ON-REG settling conditions

When setting a new value in the TIMER0_ON_REG register, we've seen that Timer0 is not applying the setting immediately. In some circumstances, Timer0 applies the settings after some ON-counter reload interrupts have been generated according to the old TIMER0_ON_REG value.

A workaround has been set up by waiting some ON-counter reload interrupts to occur before considering the new value settled. But the number of interrupts to wait for is uncertain as it seems to vary with some interrupt load conditions.

Could anyone clarify what is the procedure to follow in order to be sure that the new TIMER0_ON_REG value is in force?

Regards,
Nhan

Device:
MT_dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2015-06-08 11:34
Hi nhan.ngodinh,

Hi nhan.ngodinh,

Do you stop the timer from counting before changing the value in the TIMER_ON_REG ? since as far as i can tell if you dont do that, the device will use the previous value loaded on the TIMER0_ON_REG and when the interrupt hits it will then use the new value loaded for the TIMER_ON_REG. Please invoke the hw_timer0_disable(); before changing the value of the register.

Thanks MT_dialog

nhan.ngodinh
Offline
Last seen:1 year 4 months ago
加入:2017-03-21 20
Hi MT_dialog,

Hi MT_dialog,

In the application context we are working on it is not possible to do that: disabling timer0 would halt the PWM and the connected device would be affected by this.

Moreover, we tested that changing the ON-reload-counter online is possible, but the amount of time it is then in force is slightly unpredictable. Usually it goes in force in about 2 ON-reload cycles. In some rare circumstances we detected that it took 3, and even 4 cycles.

Here follows the initialization:


hw_timer0_set_clock_source(HW_TIMER0_CLK_SRC_FAST);
hw_timer0_set_pwm_mode(HW_TIMER0_MODE_PWM);
hw_timer0_set_fast_clock_div(HW_TIMER0_FAST_CLK_DIV_2);
hw_timer0_set_t0_reload(0, 0);
hw_timer0_set_on_clock_div(false);
hw_timer0_enable();

Then an ON-reload counter and an interrupt is registered:


hw_timer0_set_on_reload(10);
hw_timer0_register_int(cb1);

At first invocation, cb1 is called every 10 reloads. If we switch to a different reload counter, cb1 still get called at 10 reloads interval for 2-4 more cycles, then the interrupt interval switches to the new value.

Any idea on how to make it more predictable?

Regards,
Nhan

MT_dialog
Offline
Last seen:2 months 1 week ago
工作人员
加入:2015-06-08 11:34
Hi nhan.ngodinh,

Hi nhan.ngodinh,

Regarding timer0, it doesn't generate the interrupt only depending on the ON register value, there is a condition between the two counters that the timer implements in order for the interrupt to be triggered (please check the datasheet for that). Also i dont quite get the fact that the callback is invoked in 10 reloads, the hw_timer_set_on_reload(10) means that the callback will be invoked after 10 cycles of the chosen clock and not that it will be called after the ON counter reloads after 10 times, not sure if i got this correctly. Also, its recommended to change the reload values of the timer while the timer is disabled, although i ve tried the followinh scenario in order to replicate what you are experiencing.

So i ve created a timer where the t0_reload value is set to zero and the ON value set to 10, after a few times the callback has occured i changed the reload value, from the time the interrupt occured and change the reload value of the ON timer the interrupt occured twice with the old value and after that the next interrupt occured according to the new value reloaded in the ON timer. So to sum up, i haven't encountered a case where more than 2 interrupts with the old value after loading the new values is triggered, and i can assume that if that is occuring is because of the frequency of the interrupt generation, so if you have a large interrupt timer frequency, that is possible. In any case in order to change the values of the timers you should stop the timer change the settings and start it over.

Thanks MT_dialog