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.

  • Well, as I stated earlier the PWM frequency changes between 100Hz and 1000Hz. The frequency can go from 100Hz to 1000Hz in 5, 6, 7, or even 10 seconds; so there is a slow ramp up for frequency. If I try to measure the PWM frequency within 5 seconds it won't be accurate and I will see an average value of 500Hz. Whereas if I try to measure the frequency as the state of GPIO pin changes I can measure frequency within 1 to 10 milliseconds.

    I used to measure frequencies with 8-bit ATmega328p processor and accuracy was never an issue for me, and it was always accurate. Why would I encounter lower accuracy if I try to measure frequency in a window of faster than 5 seconds?

Reply
  • Well, as I stated earlier the PWM frequency changes between 100Hz and 1000Hz. The frequency can go from 100Hz to 1000Hz in 5, 6, 7, or even 10 seconds; so there is a slow ramp up for frequency. If I try to measure the PWM frequency within 5 seconds it won't be accurate and I will see an average value of 500Hz. Whereas if I try to measure the frequency as the state of GPIO pin changes I can measure frequency within 1 to 10 milliseconds.

    I used to measure frequencies with 8-bit ATmega328p processor and accuracy was never an issue for me, and it was always accurate. Why would I encounter lower accuracy if I try to measure frequency in a window of faster than 5 seconds?

Children
No Data
Related