This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Frequency detector possible?

Hi. Can anyone think of a way to use the nRF52832 (probably Timer) to detect approximately 125KHz-150KHz variable square wave down to about a 1Hz resolution? I'd like to detect frequency changes at about 100 times a second though. Ideally I'd like to do this without any external hardware (like a heterodyne mixer). Thoughts? Thanks!

(FINAL answer at very bottom. The answer is YES, the nRF52832 can be used even with a SoftDevice to accurately detect a few hundred KHz signal down to a few Hz resolution)

  • Thanks Hugh. I'll try that out! MUCH appreciated. Slight smile 

  • Hi Dmitry,

    So this freq detector has been working rather well. I can get down to about 1Hz resolution for a few hundred KHz signal. However I am seeing a strange anomaly that I'd like some help with. Every so often - maybe every 2 to 10 seconds, the frequency detector reports a slightly higher frequency (when sampling at about 10x/sec) of around 100hz. The raw count coming out of NRF_TIMER3->CC[0] just reports a slightly lower count making me think there is some kind of phase sampling error or something of that nature. Most of the times it is dead accurate, but sometimes like I said, it counts about 110 fewer pulses then immediately recovers on the next reading.

    I tried a bunch of things but can't figure out why, perhaps once every 100 or 1000 samples it misses about 100 pulses. My signal generator is dead on and verified with a scope so it is not the signal coming in. I am driving it with about a 3 foot coax so there is a little ringing due to inductance/capacitance but I don't think that is the cause. 

    Do you have any thoughts of what might be going on given the code sample above? FWIW, I'm detecting over 1500 pulses, counting the number of 16MHz pulses. I am also using the above ensureExternalClkRunning function to ensure an accurate CLK.

    Thoughts? Thanks!

  • Hi Kevin,

    really have no idea.. if the difference is one input pulse, I would guess some race condition because timers are not synchronized internally, but 100 pulses is too much to be a hardware issue.

  • One thought: If the sig gen is on high impedance output try switching to 50 Ohm output mode and double the source amplitude to compensate for the halved signal at the input - use a 'scope to be sure. Maybe even add a terminating 50R. 3 foot coax is very long ..

  • Thanks Hugh. I'll try that later today. But even on high impedance output, wouldn't the sig gen still be driving the signal hard into the input (which is also high impedance - an I/O pin on the µC?)

Related