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

PWM Frequency Measurement on nRF52 with SDK 11

Hi,

I need to measure the frequency of a PWM signal with 50% duty cycle through one of the GPIO pins. The frequency of input PWM signal ranges between 100Hz to 1000Hz.

I am hoping to measure the PWM frequency in the following way: I'll wait for the signal to go HIGH, start timing, then wait for the signal to go LOW and stop timing. Then I'll repeat the same process but this time from LOW to HIGH, and then find the average of the two half periods measured.

I know the above process gives me half of a full period, but since the duty cycle of my PWM signal is 50% I can calculate the PWM frequency based on the averaged value.

How can I implement the above process?

Is there a better way for measuring PWM signals?

Thanks

Parents
  • It will be a lot more accurate to let the PWM transitions cause an interrupt and have the ISR increment a counter. Then let the whole works run for, say, 5 seconds. Divide the number of counts by 5 and you will have Hz.

  • I don't care how fast the frequency varies, but I need to measure it every millisecond, and within 1% accuracy.

    I don't think I need to know about FM demodulation. If I could use a timer to measure how fast the GPIO pin goes from 0V to 3.3V and vice versa in the next cycle, that should be accurate enough for me.

    I don't know how familiar you are with Arduino IDE, but there's a PulseIn() function that measures PWM frequency pretty good. At least it was pretty accurate for me when I was measuring PWM frequencies from 100Hz to 500Hz.

    I just want to accomplish the same goal with nRF52, and it seems to be pretty complicated!

Reply
  • I don't care how fast the frequency varies, but I need to measure it every millisecond, and within 1% accuracy.

    I don't think I need to know about FM demodulation. If I could use a timer to measure how fast the GPIO pin goes from 0V to 3.3V and vice versa in the next cycle, that should be accurate enough for me.

    I don't know how familiar you are with Arduino IDE, but there's a PulseIn() function that measures PWM frequency pretty good. At least it was pretty accurate for me when I was measuring PWM frequencies from 100Hz to 500Hz.

    I just want to accomplish the same goal with nRF52, and it seems to be pretty complicated!

Children
No Data
Related