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)

Parents
  • Hi,

    Yes, you can do this with GPIOTE, PPI, and two timers - for example, TIMER1 is a pulse counter, TIMER2 is a 16-MHz timer.
    - configure TIMER1->CC[0] for a number of pulses to measure plus 1 (in your case, 1000 pulses is about 0.08 sec that meets your requirements)
    - configure first PPI channel to start TIMER2 and increment TIMER1 by GPIOTE rise event
    - configure second PPI channel to capture TIMER2 value into CC[0] by counter's TIMER1->COMPARE[0] event (after 1000 pulses)
    - to start measurement, clear TIMER1 and TIMER2, then enable both PPI channels
    - after TIMER1->COMPARE[0] event, TIMER2->CC[0] will contain total time for 1000 pulses in 1/16 usec units.

    1Hz resoultion is a challenge. A difference between 149999 and 150000 Hz is about 0.04 usec at 1000 periods, resolution of nRF52 timer is 1/16 usec - I believe you can get about 2-3 Hz resolution if everything is done carefully.

  • Thanks for the input Dimitry. That's the issue: The different between say 150000Hz and 150001Hz is not 0.04 usec. It's 0.04 nsec - that's about 40 picoseconds (0.00000666662 vs 0.00000666666). I think the fundamental issue is detecting changes accurately down to the 10's of ps level - probably unlikely with a 52832. Thoughts?

    Not only that but I want to use an S132 SoftDevice and as I understand it, the SoftDevice uses Timers 0 and 1. So I think I would need Timers 2 and 3, right? Aren't there limitations to timers above 2?

Reply
  • Thanks for the input Dimitry. That's the issue: The different between say 150000Hz and 150001Hz is not 0.04 usec. It's 0.04 nsec - that's about 40 picoseconds (0.00000666662 vs 0.00000666666). I think the fundamental issue is detecting changes accurately down to the 10's of ps level - probably unlikely with a 52832. Thoughts?

    Not only that but I want to use an S132 SoftDevice and as I understand it, the SoftDevice uses Timers 0 and 1. So I think I would need Timers 2 and 3, right? Aren't there limitations to timers above 2?

Children
Related