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

PWM driver library does not work well with SoftDevice 8.1.0, What I neet to do ?

I use nrf51822 by example ble_peripheral/ble_app_uart with with SoftDevice 8.1.0, at the same time, I use pwm driver library, But it does not work well, What I need to do? or How to fix it?

I add

"#define USE_WITH_SOFTDEVICE 1"

as here said, it does not work well too.

Below is the outp capture by logic analyze image description

Below is the code:

 APP_PWM_INSTANCE(PWM1,1);                   

static volatile bool ready_flag;            

void pwm_ready_callback(uint32_t pwm_id)    
{
    ready_flag = true;
}

void pwm_led_init(){
	uint32_t err_code;
	app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, PWM_LED_WORK);
    
	pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH ; 
    
  err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
  APP_ERROR_CHECK(err_code);
}
void pwm_led_start(){
	 app_pwm_enable(&PWM1);
    
    uint32_t value;
    while(true)
    {
        for (uint8_t i = 0; i < 40; ++i)
        {
            value = (i < 20) ? (i * 5) : (100 - (i - 20) * 5);
            
            ready_flag = false;
            /* Set the duty cycle - keep trying until PWM is ready... */
            while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
            
            /* ... or wait for callback. */
            while(!ready_flag);
            nrf_delay_ms(25);
        }
    }

}
void pwm_led_stop(){

}
Related