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

nRF51 BLE and PWM doesn't work simultaneously

Hi

I'm using a custom board with nRF51822 and mbed. Then, I would like to generate 25kHz PWM and use BLE simultaneously. So, I read this thread, write like the attachment code and could generate 25kHz PWM. devzone.nordicsemi.com/.../ source code.txt

However, I couldn't use BLE while my board generates PWM. Although I changed the frequency of PWM, I couldn't detect BLE. Are there anyone who face the same problem? If there are, please tell me how to solve this problem.

Best regards Ishikawa

  • I don't know how it works in mbed but app_pwm from Nordic SDK 9.0 and later worked well for me. My boards were able to beep and dim LEDs while exchanging large amounts of data with smartphone without any additional work.

  • Creating PWM with variable duty cycle on nRF51 is hard, which is why the pwm library in the SDK was not stable until SDK 10 and later. If you only want a square wave signal with fixed frequency and duty cycle (like 50%) it is not that hard and you can do it as you purposed/as done in the linked post.

    Some things that might cause problems:

    • You are using SDK function nrf_gpiote_task_config(..). I do not know if you can use this in mbed.
    • You are using PPI channel 0. This might be used by other modules. Try using channel something else like channel 10. You should also use NRF_PPI->CHENSET instead of NRF_PPI->CHEN to avoid clearing all the other channels.

    You are not enabling timer 2 interrupt in the peripheral and you don't need the interrupt, so you don't have to enable it in the cortex (NVIC_EnableIRQ(TIMER2_IRQn)).

  • Thank you for your quick responses, Keton and Bauck and I'm sorry for late.

    I achieved generating 25kHz PWM and communicating with BLE simultaneously!

    I added NVIC_SetPriority(TIMER2_IRQn, 3);
    before, NVIC_EnableIRQ(TIMER2_IRQn);.

    The other parts are almost the same as proposed in the linked post. Then, finally, I was able to generate 3 PWMs with the same more than 25kHz frequency and 50% duty cycle.

    Thank you for your help!

    You are not enabling timer 2 interrupt in the peripheral and you don't need the interrupt, so you don't have to enable it in the cortex (NVIC_EnableIRQ(TIMER2_IRQn)).

    Bauck, I would like to ask you a question about this. Don't I need to use the interrupt, because the behavior of PPIs doesn't need the help of CPU?

    Best regards

  • Setting the priority is a good idea. If you don't set the priority, it will default to the highest (0) which is used by the SoftDevice and not permitted to be used by the application.

    The reason I said that you don't need the interrupt is because the signal will run by itself because of the use of PPI.

  • i don't find NVIC_SetPriority(TIMER2_IRQn, 3); or NVIC_EnableIRQ(TIMER2_IRQn);. Where can I add commands?

    best regards

Related