I want to measure the frequency of a PWM signal. To do that, I'm using STM-F401RE and its Timer_Input_Capture function.
The problem is:
- the input signal has a quite high frequency (approx. 2MHz) and,
- the STM-F401RE controller has only a 80MHz clock
Therefore when using an interrupt routine for counting the number of rising edge of the input signal, it misses many rising edges (depending on the frequency of the input signal). When using an Oscilloscope and toggling an I/O-pin, I saw that it can only capture all the rising edge when the frequency is lower than 400kHz.
Question is: How to overcome this problem? or is there another way to measure an input pwm signal with high frequency ?
Thanks
You need to setup your timer as PWM input and not capture input (TIM1 for example can do it). This way, 2 channels are used (but you have only one physical connection). Basically, the first channel will give you the period and the second channel will give you the pulse. The counters are automatically reset.
The init function:
And the interrupt handler