2020-11-30 10:33 PM
Hi,
We are using STM32F746ZET6.
we have to calculate input frequency on 5 pins from 40khz to 0.01hz.
currently we are using 50 micro seconds timer and at every timer interrupt we are processing frequency calculation based on the polling of the pin status(high or low), with this approach currently we are able to capture the frequency bellow 1hz with good accuracy but for frequency higher then 500hz or more we are not getting proper results, currently for 20000hz(20khz) we are getting 20014hz.
we can not use GPIO interrupt other wise we will get frequent interrupts as there are total 5 pins.
currently we are capturing the input raising edge using timer capture mode but in this we are not able to detect frequency decimals points, as it only calculates raising edges then we read it at every one second so number of counts in 1 second will be our frequency.
but this is not giving us frequency in decimals, e.g 5.5hz, 18.9hz.
can we use timer input capture for calculating frequency without more interrupts?
Solved! Go to Solution.
2020-12-02 01:37 PM
Use 5 timers as counters in "external clock mode" on ETR pin. Read and reset those once per second. Probably can even make those 5 slave timers capture the value once per second on internal trigger from some 6th master timer. The interconnection between the peripherals can be seen in AN4676.
2020-12-01 12:00 AM
I think your request is too excessive. Mesurement of 0.01hz at least needs 100 seconds.
If the range is 40khz to 1hz I have a idea about it. You have to use GPIO interrupt I don't think these interrupts are things.
Start a timer with autoload counting from 0-50000 every 5 us. when the counter to 50000 inc the counter times . This counter should counter 65535*50000*5us.
When a Gpio interrupt triggered test if it is the first time record the counter as start time if it is the second time record the counter as end time. Mius end time by start time you can calc the frequency.
2020-12-01 06:03 AM
Hi DDong.2,
Thanks for the response,
for below 1hz frequency I am able to calculate, and I don't have issue with that, but my only worry is for high frequency.
if I enable interrupts on all 5 pins, and if all are at 40khz than I think my code will always gets stuck in interrupts only.
that's why I don't want to use interrupts, please correct me if my understanding regarding interrupt is wrong.
2020-12-01 06:19 AM
Sure. You have to make the interrupt code as simple as possible. With my idea I think the interrupt code can be done in about 2us. 5*2us=10us. The period of 40KHz is 25us. There is about 15us to deal the other things. I'm not sure if it can fufill your requirment.
2020-12-01 06:27 AM
By the way I don't think you need to test the frequency every 25us, Maybe you can enable the interrupt 10ms every second if the frequency is over 1kHZ otherwise you can enable the interrupt all time.
2020-12-02 01:37 PM
Use 5 timers as counters in "external clock mode" on ETR pin. Read and reset those once per second. Probably can even make those 5 slave timers capture the value once per second on internal trigger from some 6th master timer. The interconnection between the peripherals can be seen in AN4676.