cancel
Showing results for 
Search instead for 
Did you mean: 

Timers in Input capture mode (STM32G0) occassionally ticks more counts incorrectly

karnag
Associate

On a STM32G030 MCU, i have Timer-1 (Channel 2) configured in "Input Capture Mode" and is running at 4 Mhz (64 prescaled by 16), So effectively the TIM1 counter increments at every 0.25uS. This is used to measure "On time" of a LED strobe-Light on a GPIO line(which can be as wide as 20 microsec multiple times in a span of 16 millisec window slot).

The approach : Set timer-1 trigger for rising edge,on rising edge interrupt start the timer-counter and reset trigger for falling edge, and on falling edge, stop the counter and read the counter difference and set back to rising edge again. div the difference by 4 gives you the pulse ON time in micro sec.

The measurement happens correctly for most of the time .. but often(every 20 sec or so) i noticed that the timer counter adds a value of 1000 incorrectly. I arrived at this number by repeated captures on this error and its always been 1000 more. 1000 implies its 250 microsec more. The strobe pulses are very regular in the system and i confrmed via scope. I break on error and hooked this condition to scope and look back the aquired train of pulses and confirmed that system was sending a constant pulse train of 20uS with a ~1.2ms gap between them.

I have disabled all other MCU activities but this timer1, hoping there is a culprit within... but still this happens. 

this being exactly 1000 counts or 250uS makes me think this is a MCU issue. if it was any other rogue thread or watch dog.. or something else stuck doing some house keeping, it would be a random number and counts should have been different.  composed below table, where edge column can be Rising(R) or Falling(F) or X=error

 

 EdgeTimer CounterDiffDiff (uS)Strobe Count
[0]'F' 99080202
[1]'R' 911   
[2]'F' 99180203
[3]'R' 910   
[4]'F' 99080204
[5]'R' 909   
[6]'F' 98980205
[7]'R' 909   
[8]'F' 19911082270.56
[9]'X'     

 

Any thoughts?  if you disagree, please share your thoughts on this.

@st Micro : If you have any Errata on this, please point out and save me some time

Thanks in advance

Nag

 

 

 

 

3 REPLIES 3
STM_Thirty2
ST Employee

Can you provide a minimal project that reproduces the behavior. 

If you feel a post has answered your question, please click "Accept as Solution"

I can try making a project for Nucleo board (STM32G031K8) which is not the same chip we have it on our custom board(STM32G030K8T6). but also you might need a function generator that makes a 20uS pulse every 1200uS and input that line to one of the Nucleo pin(PB3) and observe if it can fault as often as i say. 

> On a STM32G030 MCU, i have Timer-1 (Channel 2) configured in "Input Capture Mode"

And when evaluating the pulse, do you read the TIM1_CCR2 register, or TIM1_CNT?

I see "FreeRTOS" in the tags, that's essentially a timer interrupt. Make sure it has a lower interrupt priority than your interrupt. Make your interrupt the highest priority of all other interrupts you have.

JW