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

Pulsewidth modulation with app_pwm results in NRF_ERROR_INVALID_STATE

I have a nrf51-DK. I am trying to get a PWM signal on one pin. Here is my code:

static volatile bool ready_flag;
void pwm_ready_callback(uint32_t pwm_id){ ready_flag = true; }      // PWM callback function

void test_pwm(){
    APP_PWM_INSTANCE(PWM1,2);                   // Create the instance "PWM1" using TIMER2.
    ret_code_t err_code;
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, 17);
    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);
    app_pwm_enable(&PWM1);
    app_pwm_channel_duty_set(&PWM1, 0, 50);
}

The error code returned by init is 8 NRF_ERROR_INVALID_STATE. It happens with whatever TimerX (0,1,2) I use. I am not using a SoftDevice, nor am I using the Timers in another part of the code (except one SPI part, which is commented out atm).

What can I do to further debug the issue?

Parents Reply Children
No Data
Related