Digital signal frequency counter

Show off your projects to others!
Posts: 14
Joined: Tue Aug 26, 2014 9:42 am

Re: Digital signal frequency counter

Post by citizen3942 » Mon Jun 15, 2015 2:47 pm

I believe I figured out the reason.

Code: Select all

uint32_t Timer::getAndResetCount() {
    uint32_t t = *_tmr;
    *_tmr = 0;
    return t;
As you can see the code above the counter starts counting from zero, hence the zero is actually also a pulse, which in the end result is not accounted for. Thus when the timer frame is 5Hz, every time the counter value is requested and resetted, one pulse is actually the 0-th pulse. So every time the counter value is represented it is represented as in COUNTS-1*[timeframe frequency] whereas it should be outputted as COUNT+1*[timeframe frequency].
The *_tmr value should start counting from 1 not 0.
I believe this is a good explanation for that behaviour. And the explanation is understood mutually.

User avatar
Site Admin
Posts: 2188
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK

Re: Digital signal frequency counter

Post by majenko » Mon Jun 15, 2015 3:54 pm

But count value "0" isn't a pulse count, it's an initial value before it gets a pulse. The first pulse to come in will increment that to 1, so one pulse in = a count of 1 in _tmr.
Why not visit my shop?
Universal IDE:
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

Post Reply