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

How to control the number of pulses using app_pwm library?

Hi, I would like to generate PWM waves with on/off period as low as 10usec.

  1. How to stop the PWM and restart it? I tried this but does not stop the PWM:

    void pwm_start( void ) { nrf_drv_gpiote_out_task_enable(GPIO_YELLOW_LED_PIN_WII); app_pwm_enable(&PWM1); } void pwm_stop( void ) { app_pwm_disable(&PWM1); nrf_drv_gpiote_out_task_disable(GPIO_YELLOW_LED_PIN_WII); uint32_t err_code = app_pwm_uninit(&PWM1); APP_ERROR_CHECK(err_code);
    nrf_gpio_cfg_output(GPIO_YELLOW_LED_PIN_WII); nrf_gpio_pin_set(GPIO_YELLOW_LED_PIN_WII); }

  2. How to control the number of PWM pulses? I want to output 1 PWM pulse upon button press. Thanks.

Parents
  • I want to output 1-60 (depends upon the input from the BLE app) PWM pulses of on time 42usec and off time 14usec and then send 1 PWM pulse of on time 260usec and off time=0usec. Then wait for 10msec.

    Is it necessary to use PWM for the above? Why not set/unset the GPIO pin directly? Won't that give you more control?

  • Hi Ole, thanks for your reply. I have used PWM library(app_pwm) to run the pwm waves and to set the number of cycles, I use another timer(timer2 using HF clock - I configured so that I get TMR2 irq interrupts every 5 usec (prescalar = 4, cc[0] = 5). Inside the isr of tmr2, I check if count2 is = or > the desired period in usec/5 (where, count2= number of times tmr2 isr was entered ). If yes then I stop the PWM pulses. But in this method too, there is a risk of missing one/several TMR2 interrupts because of a higher priority interrupt from BLE, so I would not get the desired amount of cycles if BLE has interrupted at that time. Also after reading the spec of softdevice s110, I found that the softdevice needs in the order of milliseconds to finish running its ISR. Does it mean that I wont be getting TMR2 interrupts till the softdevice interrupt has finished servicing? If so, by that time, several (undesired)cycles of pwm would have occurred and this would cause serious trouble with our project. How to handle this?

Reply
  • Hi Ole, thanks for your reply. I have used PWM library(app_pwm) to run the pwm waves and to set the number of cycles, I use another timer(timer2 using HF clock - I configured so that I get TMR2 irq interrupts every 5 usec (prescalar = 4, cc[0] = 5). Inside the isr of tmr2, I check if count2 is = or > the desired period in usec/5 (where, count2= number of times tmr2 isr was entered ). If yes then I stop the PWM pulses. But in this method too, there is a risk of missing one/several TMR2 interrupts because of a higher priority interrupt from BLE, so I would not get the desired amount of cycles if BLE has interrupted at that time. Also after reading the spec of softdevice s110, I found that the softdevice needs in the order of milliseconds to finish running its ISR. Does it mean that I wont be getting TMR2 interrupts till the softdevice interrupt has finished servicing? If so, by that time, several (undesired)cycles of pwm would have occurred and this would cause serious trouble with our project. How to handle this?

Children
No Data
Related