Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PWM disable doesn't work. Can't turn off PWM.

Hi! I am using an nRF51 DK board and the app_pwm library. I am using SDK 12.3.0.

Why doesn't

app_pwm_disable(&PWM1);

stop the PWM? I call it right after initialization:

// initialization in main.c
static int pwm_value = 50;

void pwm_complete_callback(uint32_t pwm_instance_index) {
}
APP_PWM_INSTANCE(PWM1,1); 
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH	(3822L, 25);

// in main() function:
    NRF_LOG_INFO("Initializing PWM For Buzzer...\r\n");
	
		err_code = app_pwm_init(&PWM1, &pwm1_cfg, pwm_complete_callback); 
		APP_ERROR_CHECK(err_code);
		while (app_pwm_channel_duty_set(&PWM1, 0, pwm_value) == NRF_ERROR_BUSY);
		
		// !!! Why doesn't this stop PWM?
		app_pwm_disable(&PWM1);
		
    // Start execution.
    NRF_LOG_INFO("Blinky Start!\r\n");
    advertising_start();

    // Enter main loop.
    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }

... as well as in a button handler, and neither stop PWM from happening.

I am using it to control a buzzer, so it doesn't matter whether it stops high or low. It just needs to stop.

None of the solutions on other threads worked, and they were all for older versions of the SDK <10.

Related