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

Is it possible to detect the frequency of a clock signal?

There is an input clock signal with frequency of 3MHz-5MHz, but the exact frequency is unknown. I want to use nRF51822 to detect the clock signal's frequency, the accuracy requirement is about 0.1MHz, is this possibles? Thanks a lot.

Parents
  • That's a fairly high frequency. You could try applying the signal to a GPIO pin, then setting up the GPIOTE for that pin to generate an event on a rising edge, then also set up a PPI between that event and the COUNT task of the timer. So every pulse generates an event which makes the counter count. You then use another timer, probably the RTC, to measure a time interval and see how many pulses you counted. That gives you the frequency.

    I can't find in the manual the maximum frequency at which the nrf51822 will detect pulses and generate events, 3-5MHz is fairly high on a chip with a clock of 16MHz so I'm really not sure it's going to work. Another option is to use an external frequency divider chip, they're very cheap and simple, to divide the frequency down to something easier to measure, and then measure that.

  • I think you can have the event trigger an interrupt and also connect via PPI to trigger another event, yes. Have to try it out. At the kind of frequency you're talking about that interrupt is going to be constantly triggered right, you have a max of about 5 clock cycles / instructions between pulses, that's less than the overhead to enter and exit the interrupt handler. That's fine if you're just interrupting to detect the first pulse but you're not going to get one interrupt per pulse after that, nothing like that much.

Reply
  • I think you can have the event trigger an interrupt and also connect via PPI to trigger another event, yes. Have to try it out. At the kind of frequency you're talking about that interrupt is going to be constantly triggered right, you have a max of about 5 clock cycles / instructions between pulses, that's less than the overhead to enter and exit the interrupt handler. That's fine if you're just interrupting to detect the first pulse but you're not going to get one interrupt per pulse after that, nothing like that much.

Children
No Data
Related