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

Nordic SDK: PWM duty cycle of 0 on LED

I am using PWM on a BLE Nano using Nordic SDK. I was having problems with the PWM and decided I would set the duty cycle to 0 to see if the program was working right:

#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.

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

int main(void)
{
ret_code_t err_code;

app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, BSP_LED_0);
int dutyCycle = 0;
app_pwm_channel_duty_set(&PWM1, 0, dutyCycle);

pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;

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

}```   

After doing this I hooked an LED up to BSP_LED_0 and was surprised to find that it lit up. What could cause an LED to light up when the duty cycle is 0? Am I doing something wrong?

Parents
  • Hi,

    Looks like there is a bug in SDK 8.1 with the pwm/ppi library when you have the SOFTDEVICE_PRESENT flag, the bug causes the program to run into a hardfault. Ideally, you should upgrade to a newer SDK, but you could also fix this by downloading SDK 10 from here, and replace the following libraries in SDK 8.1 with the SDK 10 libraries.

    Replace the following files:

    The 2 files located in SDK_folder\components\libraries\pwm

    The 2 files located in SDK_folder\components\drivers_nrf\ppi

    The file called nrf_ppi in SDK_folder\components\drivers_nrf\hal

Reply
  • Hi,

    Looks like there is a bug in SDK 8.1 with the pwm/ppi library when you have the SOFTDEVICE_PRESENT flag, the bug causes the program to run into a hardfault. Ideally, you should upgrade to a newer SDK, but you could also fix this by downloading SDK 10 from here, and replace the following libraries in SDK 8.1 with the SDK 10 libraries.

    Replace the following files:

    The 2 files located in SDK_folder\components\libraries\pwm

    The 2 files located in SDK_folder\components\drivers_nrf\ppi

    The file called nrf_ppi in SDK_folder\components\drivers_nrf\hal

Children
No Data
Related