2017-11-19 07:30 PM
Can you reset a counter from another timer? I'm using TIM2 as a PWM input and in the callback() I'd like to reset the counter for TIM22 to stop it from triggering its interrupt. Is this possible?
This is what I've tried but the TIM22 counter doesn't change:
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
{ if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) { TIM22->CNT = 0; // <-- This doesn't change the count. HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin); // gives me something to look at with the oscope }}
Any help is greatly appreciated.
Richard
#timer-interrupts2017-11-19 09:58 PM
TIM22->CNT = 0; // <-- This doesn't change the count.
How do you know?
JW
2017-11-19 11:09 PM
How about disabling the interrupt enable for the corresponding source? To me, playing with CNT is a bit crude. The less the HW gets discontinuities by SW, the easier it is to debug.
2017-11-20 12:33 AM
The OP neglected to tell us the mcu model he's using, but f there's a master-slave internal link between the timers, it could be used to reset the CNT. It exactly the same as writing zero to CNT so I fail to see why wouldn't that work.
JW
2017-11-20 10:10 AM
Hi Jan,
Sorry about not explaining my setup better. I'm using the Nucleo32L031K6 board with Tim2 setup as a PWM input on Ch1 &Ch2. I'm outputting a PWM using Tim21 and using Tim22 as a simple timer not tied to any pins or other timers.
I did finally get it working and I'm a bit embarrassed that I made such a rookie mistake but when I realized that I needed to make the period of Tim22 longer than the PWM input everything is working as planned. When the PWM detects an input on PA0 the callback resets the counter for Tim22 so that never fires its interrupt. As soon as the PWM input goes to zero the Tim22 timer times out and I get the HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) interrupt where I can clear my variable.
Thanks again,
Richard