cancel
Showing results for 
Search instead for 
Did you mean: 

Using TIM1 To Count External Pulses On STM32H563

mccabehm
Associate III

I am playing with the TIM_InputCapture example (calculates frequency of external pulse) for the NUCLEO-H563ZI dev board. The example works OK except:

  • Frequency is not updated for no edges (signal generator off)
  • Minimum frequency is about 3KHz. I need to measure 0 - 2KHz

There should be a way to trigger the latching of the count reg in SW rather than the timer. The pulse frequency is low enough that I can look at the pulse count in non-ISR code. 

How do I (a) trigger the latching of the count reg, and (b) disable the timer event?

1 ACCEPTED SOLUTION

Accepted Solutions

 

 

> There should be a way to trigger the latching of the count reg in SW rather than the timer. 

Why? Just read out TIMx_CNT.

JW

View solution in original post

4 REPLIES 4

 

 

> There should be a way to trigger the latching of the count reg in SW rather than the timer. 

Why? Just read out TIMx_CNT.

JW

mccabehm
Associate III

The CNT reg would continue to increment while I read the time. I would like to (a) disable interrupts, (b) latch the CNT reg, (c) read the time, (d) re-enable interrupts, (e) read the latched count.

Also, my attempts at reading the CNT reg yield unexpected results. The differences in the count compared to the input frequency and the time interval -- don't correlate at all.

TDK
Guru

The input capture function does this. It stores the value of CNT at the time of the trigger. You can't get more accurate than that. Your method would be subject to IRQ and software delays.

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

Any software method is subject to IRQ and software delays, regardless of whether you disable/enable interrupts around it.

Reading out TIMx_CNT is a simple and short operation, you can't force capture in software any more effectively.

While you did not tell us any relevant details - which STM32, which timer, what clocks - your problems probably stem from timer having a limited overall period, probably you are using a 16-bit timer. Calculate how fast will it oferflow; try 32-bit timer, try using appropriate prescalers. Alternatively, you could count timer overflows in interrupt and factor them into your frequency calculation, but this is tricky and I recommend to avoid it.

You should also have some sort of timeout. That establishes a minimum input signal frequency. There is no such thing as measuring 0Hz input; to measure it precisely you would have to wait infinite time.

JW