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

How to set 2 PWM channel with different frequence on 52810

I'm using 52810 with s112 stack.

And I need two PWM channel with different frequence. one channel set to 4KHz to cotroller BEEP,  the other one set  to 15Khz to control motor.

For now I use APP_Pwm.c set two channel with same frequence. I don't know how to set them to different frequence.

Parents
  • Hi,

    you cannot set different frequency for channels within one PWM instance. Either create a second instance (if you have TIMER1 and TIMER2 free), or use nrfx_pwm module for second channel (app_pwm.c is an old way based on timer and GPIOTE, whereas nrfx_pwm uses hardware PWM generator).

  • Thanks for your reply.

    Seems that 52810 only has one PWM generator. am I right?

    and i have no idea how to check which Timers are free.

    I use the demo project ble_app_uart from SDK and I set a 1ms timer bia below code:

    ----------------------------------------------------

    app_timer_create(&m_app_1ms_tmr,APP_TIMER_MODE_REPEATED,app_1ms_timer_handler); //BRN
    app_timer_start(m_app_1ms_tmr, APP_TIMER_TICKS(1), NULL);

    -----------------------------------------------------

    So, which timers are free?

    or could you please tell me the stack used which timers.

  • Yes, 52810 has one hadware PWM generator, plus two timers that can generate PWM through GPIOTE (I don't count TIMER0 as it's usually reserved by the stack).

    app_timer uses RTC, so I think both timers are available in your case. But I would recommend to use nrfx_pwm, maybe second timer will come in handy for some other task.

  • Hi 

    I agree with Dmitry. 

    You can use the nrfx_pwm library for your 15kHz PWM, and then handle the 4kHz beep using the TIMER, PPI and GPIOTE modules. 

    The PWM module is the best choice when you want to seamlessly update the PWM duty cycle from a RAM buffer, and allows you to control up to 4 pins from the same controller (the frequency is shared between all 4 pins though). 

    The TIMER/PPI/GPIOTE approach requires a little more manual setup, and doesn't allow you to read updates directly from RAM, but you are able to set the PWM frequency and duty cycle in a more flexible way. In other words I think this is a good option for the BEEP pulse. 

    Best regards
    Torbjørn

Reply
  • Hi 

    I agree with Dmitry. 

    You can use the nrfx_pwm library for your 15kHz PWM, and then handle the 4kHz beep using the TIMER, PPI and GPIOTE modules. 

    The PWM module is the best choice when you want to seamlessly update the PWM duty cycle from a RAM buffer, and allows you to control up to 4 pins from the same controller (the frequency is shared between all 4 pins though). 

    The TIMER/PPI/GPIOTE approach requires a little more manual setup, and doesn't allow you to read updates directly from RAM, but you are able to set the PWM frequency and duty cycle in a more flexible way. In other words I think this is a good option for the BEEP pulse. 

    Best regards
    Torbjørn

Children
No Data
Related