This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Turn off PWM LED

I have a BLE device that is using Nordic SDK 8.1 and uses PWM to control an LED. Now I want to turn the led off with PWM. To do this I set the duty cycle to 0 and printed to the led. Yet when I do this the led stays on. What could cause this? Here is my code (it is in main.c in the example/ble-central/app-hrs dir from the sdk): ` /* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. * * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. * * Licensees are granted free, non-transferable use of the information. NO * WARRANTY of ANY KIND is provided. This heading must NOT be removed from * the file. * */

/** @file
 * @defgroup pwm_example_main main.c
 * @{
 * @ingroup pwm_example
 * 
 * @brief  PWM Example Application main file.
 *
 * This file contains the source code for a sample application using PWM.
 *
 *
 */

#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "app_error.h"
#include "bsp.h"
#include "nrf_delay.h"
#include "app_pwm.h"

#define TIMER1_INSTANCE_INDEX      (TIMER0_ENABLED)


APP_PWM_INSTANCE(PWM1,1);                   // Create the instance "PWM1" using TIMER1.

static volatile bool ready_flag;            // A flag indicating PWM status.


int main(void)
{
    ret_code_t err_code;

    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(2000L, 28);

    pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW;



    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&PWM1,&pwm1_cfg,NULL);

    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&PWM1);


    while(true)
    {
        int dutyCycle = 0;
        /* Set the duty cycle - keep trying until PWM is ready... */
        while(app_pwm_channel_duty_set(&PWM1, 0, dutyCycle) == NRF_ERROR_BUSY);

        // enter into sleep mode
        __SEV();
        __WFE();
        __WFE();
    }

}


/** @} */

`

Related