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
  • How do I know if the code will work without a Softdevice? I'm confused on how I could run a program without the softdevice. I am unable to compile the peripheral/pwm because when I try to run the srec_cat $SOFTDEVICE -intel $INPUT -intel -o $OUTPUT -intel --line-length=44 command I get the following error: "srec_cat: _build/nrf51422_xxac_s120.hex: open: No such file or directory". I tried switching the INPUT to _build/nrf51422_xxac.hex because that file existed, but when I run the srec command I get the following error: "srec_cat: _build/nrf51422_xxac.hex: 1: contradictory 0x00000000 value (previous = 0xC0, this one = 0x00)"

Reply
  • How do I know if the code will work without a Softdevice? I'm confused on how I could run a program without the softdevice. I am unable to compile the peripheral/pwm because when I try to run the srec_cat $SOFTDEVICE -intel $INPUT -intel -o $OUTPUT -intel --line-length=44 command I get the following error: "srec_cat: _build/nrf51422_xxac_s120.hex: open: No such file or directory". I tried switching the INPUT to _build/nrf51422_xxac.hex because that file existed, but when I run the srec command I get the following error: "srec_cat: _build/nrf51422_xxac.hex: 1: contradictory 0x00000000 value (previous = 0xC0, this one = 0x00)"

Children
No Data
Related