cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with frequency counter

Raahul Jagannathan
Associate II
Posted on June 20, 2018 at 06:42

The original post was too long to process during our migration. Please click on the attachment to read the original post.
2 REPLIES 2
S.Ma
Principal
Posted on June 20, 2018 at 07:25

It would be good before sharing a large source code to express how the timer is being configured, the source code main bluprints would help tuning to the specific issue.

If here the timer is overflowing and the measured period between two falling edge (for example) is less than a timer period, just directly substract the 2 input captures regardless of their value. However the values shall be typed to be the same as the timer input captures. If the timer is 16 bit unsigned, so shall be the global variables tied to them.

Example: first capture is 0xF000, second is 0x1000, then period is (u16) 0x1000 - (u16) 0xF000 = 0x2000

Can't tell if this is the exact issue, just quick browsing the code. My two quick cents...

Posted on June 20, 2018 at 07:30

Thank you for replying. Tim 2 has been set in input capture mode. It has no prescaler and counts to 0xFFFF. I am taking inputs from Channel 2,3 and 4 of TIM2. TIM21 has been configured in basic mode, has a prescaler of 32000, and it counts upto 999. It is used to give us a an interrupt every second so that we can periodically print the display. Both timers have a 32MHz Clock source and both are 16-bit counters.