How do I use timer 7 on an STM32L433 to time an event?
I am trying to use timer7 to give me the number of counts when an event occurs. I could not get this to work, and wrote some test code to show the issue.
This test code should set the initial count to zero, then fill an array with 10 timer values as the firmware run through the "for" loop. The problem is every time through the while(1) loop, I get an array with each element about 20 counts more than the last value, as expected, but the first value shows that the count is never set to zero.
I expect something like 10, 30, 50, 70 in the array every time through while loop, but instead I get 1010, 1030, 1050 on the first run, 3610, 3630, 3650 on the second run etc.
I have a really simple question,. how do I reset the count to zero?
Note that I am not looking for alternate methods.
/* set counter pre-scale to 1 (16MHz) */
TIM7->PSC = 0;
TIM7->ARR = MAX_COUNT; /* set the reload value */
TIM7->CNT = 0;
TIM7->SR &= ~TIM_SR_UIF; /* clear the update flag */
TIM7->CR1 |= TIM_CR1_CEN; /* Start the Timer */
while(1)
{
TIM7->CNT = 0;
for(i = 0; i < 10; i++)
{
CountArray[i] = TIM7->CNT;
}
}