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

pwm library continuous change with softdevice not working

Hi Guys,

once again, I have strange behavior of my code.

In my code I try in loop after ble_event received change PWM from 0 to 255 for my motor device. In debug logs, I can see continuous change value with 100ms delay (I tried also 500ms), but instead of slowly speed-up I can not see any motor movement. Here comes weird things. Then I change value back from 255 -> 0 (on logs everything looks good) but motor start working at maximum. Based on observations, it seems, PWM react only on 1st change at the time because when I set only one value, it works like charm.

This is my setup:

  • nrf51822 rev. 3
  • Softdevice 8.0.0
  • SDK 9.0.0
  • pwm library (latest version), nrf_pwm_noglitch
  • PWM working in general

Do you have any idea what is going on, or how should fix this issue?

  • actually, I tried app_pwm from SDK 9 and issue remains. In forum I find out, that pwm was not able apply changes, because I did it all in ble event handling which has higher priority. So current version I have (still not working like I want) is following:

    • based on ble event (after parsing) i set some parameters for pwm.
    • separate timer (initialized in main.c) check if this parameters was changed, and if yes, change pwm accordingly. Unfortunately with this approach I get ble disconnect event due general timeout. So far I don't found/implement any solution. Maybe scheduler will do the trick, but I have no experience with this stuff.
  • There was a lot of bugfixes and improvements, so I would recommend using app_pwm from SDK 10 anyway. Note that app_pwm requires some time to change the duty cycle (up to 2 periods). To make a change when PWM is busy, you have to wait until the previous operation is complete. Waiting in interrupt (BLE event handler or timer handler) blocks the execution of lower/equal priority tasks. App_scheduler is a good option here - task can be queued in interrupt and executed in app_sched_execute() from main context.

  • @Paweł Zadrożniak, Finally, I incorporate scheduler into my application. Unfortunately, problem with Disconnect after some period of time remains. Updated workflow is following:

    1. scheduler and my core functionality is initialized in main.
    2. When ble_event is received it's dispatched to my service.
    3. Service checks send message (few bytes) it is propagated to HW.
    4. When PWM function is required, I start timer 1 (timer was already initialized)
    5. When timer IRQ happened, it schedules setting PWM value.
    6. In while loop (main), scheduler is executed.

    In general program works, but when I set continuous changing PWM from duty cycle 0 to 255 with step 4, it takes about 20 iterations till BLE is disconnected. Do you have any idea how to solve this issue?

Related