7 years, 1 month ago.

PwmOuts grab 3 unique instances supported by nRF52, when I don't want it to.

I need four PWM channels - all with the same period. I have a nRF52 DK which should support 3 unique instances, with 2 channels for each instance. I want to control the duty cycle on the PwmOuts with a app via BLE. I got everything working if I limit number of channels to 3. But when I add the fourth PwmOut things stop working. I suspect the first three PwmOuts exhaust the three instances and that is why things go south for the fourth one, because this is the assertion fail I get via Tera Term mbed assertation failed: i != PWM_INSTANCE_COUNT, file: /extras/mbed-os.lib/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/pwmout_api.c, line 158

However, looking at the driver (https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF51822_UNIFIED/pwmout_api.c ) it looks like that shouldn't be happening. This driver seems to have the cognizance of two channels per instance. So when I declare 4 PwmOuts, it should allocate first two as two channels of a single instance and the next two as two channels of another instance.

I don't know if I am doing anything wrong, or I need to do something different when I declare my PwmOuts to ensure that all the instances don't get exhausted on the first three of them. I am using the online compiler so technically it should be using the updated driver from Nordic. How do I look at the pwmout_api.c being used and ensure that it is the same as the updated one on github.

Please help!

1 Answer

7 years, 1 month ago.

Ah you got the NRF52, I thought the NRF51, my bad, that has a different driver. The NRF51 can do 3 PWM per timer, and uses 1 timer. No idea why it doesn't use two timers, since I don't think the second timer is used for anything else.

Back to your question, your PWM driver is here: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF52832/pwmout_api.c

Which seems to be able to do one PWM per timer, and it has 3 timers available. Now while the NRF51 PWM code was confusing (and questionable imo), at least it had all code contained in one file. Here it seems to run (partially) on their own driver code, so I really wouldn't know if that is a limitation from hardware (which would mean different timers than the NRF51), or a driver limitation from just looking at the code.

Accepted Answer

Thank you for such a quick response. I don't know why their driver code doesn't do two channels per timer as the hardware surely supports it according to http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk51.v10.0.0%2Flib_pwm.html

The nRF51 driver code was much better, as it first exhausted two channels on each instance before using the next instance!

Anyway, I'll see what I can do with this. Thank you for your feedback!

posted by Shruti Koparkar 22 Feb 2017