Best PWM implementation for an RGB led on a low power device?

  • SDK: 15.2
  • SoftDevice: s140_nrf52_6.1.0
  • FreeRTOS
  • Hardware:
    • nRF52840 (Custom board running on a 240 mAh battery)
    • RGB LED (ARGB1313HS)

Hello,

I am implementing PWM for a single RGB LED. I see that there are a large number of different PWM implementation examples in the SDK. Those being:

  • nRF5_SDK_15.2.0_9412b96\examples\peripheral\pwm_driver
  • nRF5_SDK_15.2.0_9412b96\examples\peripheral\pwm_library
  • nRF5_SDK_15.2.0_9412b96\examples\peripheral\low_power_pwm
  • nRF5_SDK_15.2.0_9412b96\examples\peripheral\led_softblink     (It seems this is based on 'low_power_pwm' example above)

I have spent quite a bit of time testing the 'pwm_driver' example which uses the PWM hardware peripheral, but I have read on the DevZone that using this consumes a quite a bit of power since it requires the HFCLK to generate the PWM signals. Ideally, it would be nice to use the PWM peripheral since it essentially does what I need it to do.

Question 1: Is the PWM peripheral (pwm_driver example) really that power hungry? If the PWM peripheral is running using DMA while the CPU is sleeping, only the HFCLK and PWM will be consuming power. So, what is the power consumption of A: The HFCLK, and B: The PWM hardware peripheral? I couldn't find these in the nRF52840 product spec v1.7 PDF.

Question 2: The 'pwm_library' uses a hardware timer for the nRF52 which also requires the HFCLK, so is it any more power efficient than using the PWM peripheral (pwm_driver)?

Question 3: 'led_softblink' (also 'low_power_pwm') uses an RTC and application timers to wake the CPU. How does the power consumption of this compare to 'pwm_driver' and 'pwm_library'?

Question 4: For a battery operated device, which PWM implementation (SDK example) above would you recommend for an RGB led that requires blinking, on/off, and fade in/out (aka "Breathing") functionalities?

Thanks,

Derek

  • Hello drobertson,

    My apology for the late reply. I have checked the documentations and quickly go over the implementation of each of the three options you are asking about, being the PWM Driver, PWM Library, and the Low-power PWM Library.

    Here are my conclusions based on such information alone.

    Question 1: Is the PWM peripheral (pwm_driver example) really that power hungry? If the PWM peripheral is running using DMA while the CPU is sleeping, only the HFCLK and PWM will be consuming power. So, what is the power consumption of A: The HFCLK, and B: The PWM hardware peripheral? I couldn't find these in the nRF52840 product spec v1.7 PDF.

    The HFCLK power consumption for the nRF52 series doesn't seem to be specified.

    The PWM power consumption is specified for the nRF52832, which should be similar for the nRF52840.

    However, please note that the above specs do not take into account EasyDMA current consumption. EasyDMA can take 1.2mA or more (Update 22.01.10: This includes current drawn by the DMA bus and the HFCLK). Though I expect that it does not run while you are not updating duty cycle, I am not sure. You could setup a simple PWM test case where the duty cycle is never updated to check this.

    Question 2: The 'pwm_library' uses a hardware timer for the nRF52 which also requires the HFCLK, so is it any more power efficient than using the PWM peripheral (pwm_driver)?

    The PWM Library could be more power efficient than the PWM Peripheral thanks to its not using EasyDMA.

    Question 3: 'led_softblink' (also 'low_power_pwm') uses an RTC and application timers to wake the CPU. How does the power consumption of this compare to 'pwm_driver' and 'pwm_library'?

    The RTC uses LFCLK and is even lower power than the TIMER peripheral used in the pwm_library and the PWM peripheral.

    As stated in its documentation, a disadvantage of this solution is its lower accuracy, which is further affected when used with a SoftDevice.

    Question 4: For a battery operated device, which PWM implementation (SDK example) above would you recommend for an RGB led that requires blinking, on/off, and fade in/out (aka "Breathing") functionalities?

    The PWM Driver's advantage is its accuracy. However, for your human machine interface use case, that level of accuracy is likely not necessary.

    I would recommend you try the PWM Library and the Low-power PWM Library and compare the power consumption using an external power supply, or using Nordic's Power Profiling Kit.

    Asides from power consumption, you might want to also judge the comfort of the visual effects of the two solutions.


    My apology that I cannot perform the actual testing and give you more concrete information on some of the details. That would take time, and I likely cannot do that before the end of Thu Jan 12. Therefore, I opted to provide support with just the above information instead.

    If you encountered difficulty doing the tests I recommended, please let me know and we can figure out some new actions.


    By the way, if you don't mind, how far along is your project?

    If you are starting, I would recommend you check out the nRF Connect SDK (NCS), which is newer and is in active development.
    If a move to NCS is too drastic (it could be), I would recommend at least using the latest version of nRF5 SDK instead. That would be v17.1.0.

    Hieu

  • Hey Hieu,

    Thanks for the detailed response! I will discuss internally, do some testing, and report back. As for your question, this project is quite far along and nearing end of development. It started with SDK 15.2 and upgrading to SDK 17.1.0 seems like a stability risk at this point. I am aware of nRF Connect SDK (Zephyr), and moving to this is not feasible for this project.

    Thanks!

    Derek

  • Hieu,

    I do have one other question. You stated EasyDMA consumes 1.2 mA. Is this per peripheral, or for all peripherals? In other words, if I am using EasyDMA for SPI and EasyDMA for PWM, is this 1.2 mA for both combined, or 2.4 mA for both combined?

    Thanks,

    Derek

  • Hey Derek,

    I got in touch with someone more knowledgeable on the topic, and there were some inaccurate implications in my previous post. Sorry about that. Below are more details, and I will also update my previous post to correct those implications.

    The 1.2mA is the consumption of both the DMA bus and the HFCLK combined, when anything is using the EasyDMA.

    So, when you are using EasyDMA for both SPI and PWM, the consumption of EasyDMA is still 1.2mA, not 2.4.

    Please also note that this 1.2mA is including the HFCLK. That means, for peripheral like PWM, where the HFCLK is already requested, you won't see a whole 1.2mA increase when EasyDMA is involved. You can expect less.

    The exact number is unfortunately not available. I hope you could find out in your tests.

    Finally, these are assuming HFINT is used as HFCLK source. With HFXO, the consumption will be a little higher.

    Hieu

Related