7 years, 7 months ago.

period of PWM is disturbed

Hi

I would like to make roughly 25kHz PWM and I added the following code to the latest HRM example with the latest mbed library. PwmOut pwm0(p16); pwm0.period_us(32); pwm0.pulsewidth_us(15);

This works periodically unless I establish BLE connection. Once my smartphone connects my board with LightBlue app, a unexpected long pulse is generated about every 30ms like this image /media/uploads/gell/img_7749.jpg . Because this pulse affects the behavior of my board, I can't neglect this.

Is it possible to solve this problem? I read this thread, but this problem was not solved. https://developer.mbed.org/questions/3733/When-I-use-the-BLE-functionPWM-is-not-su/

Please tell me how to solve this problem.

I'm using my custom board with nRF51822. Then, I found this problem that the period of PWM is disturbed while BLE connection is established.

Best regards, Ishikawa

1 Answer

7 years, 6 months ago.

Hi Yu,

Sorry for the issues :)

It seems that the PWM is blocked during every BLE connection event (Lightbue is an iOS app and on iOS devices send a connection event every 30ms; it match with user symptoms).

Unfortunately this is not an issue related to BLE but rather related to the PWM driver: The PWM driver for the NRF51822 use a timer interrupt to toggle the PWM GPIO at a specific rate. The softdevice (Nordic BLE stack) will cause perturbation because it has the higher IRQ priority and there is no way to change that.

This should be fixed for NRF51_DK, NRF51_DONGLE and NRF52 targets. Those targets use completely new drivers which takes advantage of some facilities of the chip.

The best thing you can do is look at the new drivers and pick what you can backport: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_NORDIC/TARGET_NRF5/TARGET_MCU_NRF51822_UNIFIED/pwmout_api.c It may also be worth looking at: https://github.com/NordicSemiconductor/nrf51-pwm-library

Regards,

Andrea, team mbed

Hi Andrea,

I am running into a related problem. 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. 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.

Please help!

posted by Shruti Koparkar 17 Feb 2017