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

PWM library limitations?

Hi everyone,

somebody recently told me that the PWM library as part of the current nRF51/5 SDK (v10 or v11) is more like a hack?

Since the docs fail to mention specifics, what are the limitations of the PWM library?

What is the max PWM frequency it can do?

What is the max resolution it can do? (E.g. 16-bit?)

  • Hi Raphael,

    Due to the implementation of the PWM that should ensure that it is not reversed, only one duty cycle for the same timer/PWM instance can be updated at the time. Updating to a new duty cycle on any of the channels on the same PWM instance can not be done before one to two periods have elapsed since the last duty cycle update (can be more if interrupted by higher priority tasks like the SoftDevice). During this time the app_pwm_channel_duty_set(..) will return NRF_ERROR_BUSY. The pwm instance going from busy to allowing the user to set a new duty cycle will happen in interrupt context APP_PRIORITY_LOW, so care must be taken if the duty cycle is to be updated from another interrupt. The best way is to update the duty cycle always from main context (use for example app_scheduler).

    The maximum PWM frequency is 1MHz. The period is specified in microseconds (period_us) and the library will configure the timer for a prescaler of 16 resulting in a base frequency of 1MHz on the timer.

    The maximum resolution is 16 bit. This is the maximum resolution of TIMER1 and TIMER2, see the Product Sepcification part 4.2. 16 bits is also applied if TIMER0 is used even though this timer has hardware limitation of 32 bits. The resolution will of course be limited if the frequency is high (e.g. frequency of 100KHz will only give a resolution of 10).

    Hope I've not confused you,
    Ole

Related