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

pwm clock accuracy

I am running the example under peripheral\pwm_driver on PCA10040, and SDK 12.2.0. Using a scope, I measured the period (from rising edge to rising edge) on one of the LEDs, instead of 10.000 msec, I got 9.860 msec to 10.240 msec, and appears varying. What contributes to this discrepancy?

I also used the example under pwm_library, I didn't get the exact 200 Hz either, I get 198.7Hz.

Thanks.

  • Hi,

    The PWM frequency accuracy is simply the same as the accuracy of the clock source you are using. The PWM will either run on the internal HF RC Oscillator (HFINT) or the external HF crystal (HFXO). It will always run on HFINT unless you explicitly start HFXO. The accuracy of the HFINT is given in the product specification as TYP: <±1.5%, and MAX<±6%. For custom boards, the accuracy of HFXO is naturally up to the the designer to decide (Note that you need max ± 40ppm accuracy for BLE). On the nRF52832-DK(PCA10040) we have a 10ppm external HF crystal( 0.001 %). So if you use HFXO, you should see exact 200 Hz on the nRF52832-DK.


    The HFXO is started by triggering the HFCLKSTART task and stopped using the HFCLKSTOP task. A HFCLKSTARTED event will be generated when the HFXO has started and its frequency is stable. So run this code before you initialize the PWM in order to start HFXO:

    // Start clock for accurate frequencies
    NRF_CLOCK->TASKS_HFCLKSTART = 1; 
    // Wait for clock to start
    while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) ;
    
Related