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

BLE_UART example and UART Driver

Hi good evening,

i am working on a project that requires ble transmission between 2NRF52dks and one of them is connected to a PC and apart from receiving data from another nrf52 and outputting the data serially, I require PWM and UART (using drivers) in order to control a motor RPM speed depending on user inputs, is it possible to combine them all together. I have already coded the pwm and Uart and they work well but i did not integrate this to the ble_app_uart_c and before i do so i wanted to see if it is possible and if so maybe i get some help on how to properly do it.

thanks

best regards

nikolai dimech

also happy holidays to all Slight smile

Parents Reply Children
  • Hi Nikolai

    You mentioned you were using the ble_app_uart_c example as reference?

    This example already has the UART enabled, so adding this should not be necessary. 

    I modified the example to also include PWM, so you can see how this is done. 

    The example here (just unzip to \nRF5_SDK_17.0.2_d674dde\examples\ble_central):

    ble_app_uart_c_pwm.zip

    Patch file here, if you just want to see what I changed:

    change.patch

    Best regards
    Torbjørn

  • Thank you for your reply it is very helpful, my only concern is that I constantly need to update the frequency rather than the dutycycle. In my application the user will need to enter some value like RPM300 (300 rpms for a motor) where the 300 is extracted and depending on the value I change the frequency of the PWM for example RPM300 means PWM of period 5us and the duty cycle Is always on 50% etc.... where the RPM ranges from 0-300 RPM.

    In my case where i had the uarte and pwm i was using the pwm library and i had a lookup table (array with all periods) and depending on the value of RPM it will get the period from that array.

    can this be done n the same manner

    or can the pwm part be changed to using the library rather than driver?

    what do you think please?

  • Hi Nikolai

    Approximately how often do you need to change the PWM frequency?

    Do you only need a single output, or multiple?

    The PWM peripheral is not very well suited for applications where you want to change the frequency rather than the duty cycle, since by default the frequency is fixed and only the duty cycle changes. 

    In this case it might be better to setup a timer module to generate events at your desired frequency, and connect these events to a pin through the PPI and GPIOTE peripherals. 

    Then you simply need to change the compare value of the timer in order to change the frequency of the pin. 

    Best regards
    Torbjørn

  • i need to change the PWM around every 1-2min as I am measuring rotational accelaeation and gyro results from an inertial sensor and the point of the project is to ensure that the measured data is equal to the input RPM 

  • But why do you need to change the PWM frequency ?

    As the name suggests, PWM is normally just about changing (ie, Modulating) the Pulse Width - not changing the frequency.

Related