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
    1. I am able to stop and restart the PWM pulses using the following code:

      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_clear(GPIO_YELLOW_LED_PIN_WII); } void pwm_start( void ) { app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(56L, GPIO_YELLOW_LED_PIN_WII, GPIO_GREEN_LED_PIN_WII); nrf_drv_gpiote_out_task_enable(GPIO_YELLOW_LED_PIN_WII); uint32_t err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); app_pwm_enable(&PWM1); }

    Now the only question remaining is how to control the number of PWM pulses? 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. I want to repeat the above forever.

Reply
    1. I am able to stop and restart the PWM pulses using the following code:

      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_clear(GPIO_YELLOW_LED_PIN_WII); } void pwm_start( void ) { app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(56L, GPIO_YELLOW_LED_PIN_WII, GPIO_GREEN_LED_PIN_WII); nrf_drv_gpiote_out_task_enable(GPIO_YELLOW_LED_PIN_WII); uint32_t err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); app_pwm_enable(&PWM1); }

    Now the only question remaining is how to control the number of PWM pulses? 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. I want to repeat the above forever.

Children
No Data
Related