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

Controling a PWM signal (duty cycle (0 to 100%) , frequency (0 to 1hz )), using ble over a phone application . Guidance Needed

hi all,

we're developping an application to control the frequency and the duty cycle of a pwm signal throuth ble .

firstly we have built both the functionalities separatly , the ble control and the pwm control (we're using the pwm library as it can gets to low frequencies ) .

but when merging both firmwares , a buch of issues where trigered .first starting with building . we have enabled the the pwm related defines in the config_sdk.h file , including the App_pwm_enabe  the build output pointing to . even that we still get these errors .

we don't know , if we should use the pwm driver instead as we're using the softdevice . cause we're able to control the pwm signal using ble for the pwm driver .but seems we can't get to low frequencies (low then 1hz) !

Any help/guidance would be very apreciated .

*we're using the lastest SDK 15.3.0

best regards,

 

Parents
  • Hi

    How low do you need to go in frequency, while still being above 0?

    How high accuracy do you need? 

    Do you need multiple output channels, or just a single one?

    If you need really low frequencies it is possible that it would be better to use a dedicated RTC timer, rather than one of the standard libraries.If you have the app_timer library in your project you should also be able to use this when the frequency is low. 

    Best regards
    Torbjørn

  • hi ,

    thanks for your reply.

    well, a 0.25hz would be the minimum we need to go for .

    for the accuracy , it should be good . 

    just one channel , need to output the pwm signal to 4 gpio pins .

    for the RTC timer, we're new to the nrf52 developement .and we apreciate any axamples or guidance on how to use the dedicated RTC timer here, also keep in mind that we also need to control the duty cycle .

    best regards,

  • Hi

    I cooked up a quick example showing how you can set up an RTC timer to control a pin. 

    Please note that the pin is set directly from the interrupt handler, which means the pin update can be delayed by higher priority interrupts in the system. 

    I would suggest doing some testing to see if the accuracy is good enough. 

    Also, the example requires you to set the on and off time of the PWM, so you need to do some arithmetics to calculate this based on the frequency and the duty cycle. 

    Best regards
    Torbjørn

  • Hi,

    thanks again , for your help .

    will test that for sure . 

    but, haven't found any links in your reply to the example ? 

    best regards,

    Abdelali

  • Hi Abdelali

    My apologies, I forgot to attach the files ...

    You will find them below, embedded in a small test project based on ble_app_uart

    238215_ble_app_uart_rtc_pwm.zip

    Best regards
    Torbjørn

  • thanks alot ,

    will give it a try .

    Best regards,

    Abdelali

  • You welcome Abdelali. If you have any questions to the example just let me know. 

    Best regards
    Torbjørn

Reply Children
  • HI Torbjorn,

    I'm looking for an example that I can control a simple PWM pin (about 1Khz, 0-100duty cycle) by sending Values through NUS example.

    I used the attached project and put it under the SDK15.3 ble_peripherial library and compiled it Succesful. But not sure what this project is doing? Will be happy to get something to start with.

    Tnx,

    Eran.

  • Hi Eran

    If you need to run a PWM aroun 1KHz I don't think that example is a good choice, I would recommend using the regular PWM module instead. 

    If you have a look a this case I share an example written by a colleague showing how to setup and use the PWM driver:
    https://devzone.nordicsemi.com/f/nordic-q-a/28081/is-there-a-simple-example-how-to-set-a-pwm-driver

    Best regards
    Torbjørn

  • Hi Torbjorn,

    This example is fine , I flashed it and changed the duty cycle and delay time 

    for(int i = 0; i <= 90; i++)
    {
    nrf_delay_ms(20);
    pwm_update_duty_cycle(i);

    Now I need to integrate it with ble_app_uart to change these values from the nrf connect/toolbox.

    I've found this thread that I can start with https://devzone.nordicsemi.com/f/nordic-q-a/33110/beginner-needing-help-with-basic-structure-and-pwm/156850#156850

    I just need to add on-off button.

    Tnx,

    Eran.

  • Hi Eran

    All incoming data from the mobile app is handled by the nus_data_handler(ble_nus_evt_t * p_evt) ballback. The standard example simply forwards this data to the physical UART, but you can change this any way you like by modifying the code inside the if (p_evt->type == BLE_NUS_EVT_RX_DATA) { } section. 

    The simplest way would be to send an integer value from the app, and convert that from a string to an integer in the nus_data_handler and then set the PWM. 

    If you need to send many different commands you can use the first byte of the package as a command byte, and include a check on this byte in the nus_data_handler to figure out which action to take. 

    Best regards
    Torbjørn