Question on PWM input mode - STM32

Thread Starter

Xavier Pacheco Paulino

Joined Oct 21, 2015
728
I want to use PWM input mode to measure inputs signals up to let's say 1 kHz. My question is about the selection of the prescaler and the counter period that supports the inputs frequencies. My timer clock is 2 MHz. So, if I say

[Timer Frequency ] / [(Prescaler+1)*(Period+1)] <= 1KHz

Is this the right way to choose the prescaler and counter period?
I'm using Timer 2, which is 32 bit, so I expect a good resolution.

I read that if I'm not sure about my input range frequencies, I can set the timer like this:
[Timer Frequency ] / [(MaxPrescaler)*(MaxCounterPeriod)]

But, in my case, I think I will measure frequencies under 1 kHz.

Can I say for example [2 MHz ] / [(1+1)*(999+1)] = 1 kHz?
 

MrChips

Joined Oct 2, 2009
34,807
I am not sure about the relationship between PWM and measuring input frequencies.

For best resolution, you want the fastest counter clock frequency.
There is no limitation on the slowest input frequency you can measure. Any limitation imposed by the limited number of bits in the counter can be overcome.
 

MaxHeadRoom

Joined Jul 18, 2013
30,654
I also am not sure where PWM comes in?
Why not use a timer in the capture mode and record a input cycle (pulse) value over a given time?
I have a small library of routines for Timing and counting using a PIC that maybe could be adapted.
Max.
 

Thread Starter

Xavier Pacheco Paulino

Joined Oct 21, 2015
728
I could use Input Capture Mode or PWM Input Mode. The difference is not so relevant. PWM input mode uses 2 timer channels as compared to input capture that only uses one channel. By using two channels I detect the rising and falling edges, and I get the period of the signal automatically. Nothing that input capture can't do. At the end of the day my question is basically about the configuration of the timer that will receive the input signals, that is, I have to set a prescaler (if needed) and a counter period based on the frequencies I intend to measure.
 
Top