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

PWM skipping

Hello, this is my PWM wrapper around nrf sdk pwm implementation:

#include "Pwm.h"
#include "app_pwm.h"

#define PIN    7

APP_PWM_INSTANCE(PWM1, 2);

static volatile TYesNo Ready = NO;

//-----------------------------------------------------------------------------

static void pwm_ready_callback(uint32_t pwm_id)    // PWM callback function
{
   Ready = YES;
}

void PwmInit( void)
// Initialisation
{
   app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(5000L, PIN);
   pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
   app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
   app_pwm_enable(&PWM1);
}

void PwmStart( byte Channel)
// Start PWM
{
}

void PwmDutySet( byte Channel, word Duty)
// Set PWM <Duty> cycle
{
   Ready = NO;
   while(app_pwm_channel_duty_set(&PWM1, Channel, Duty) == NRF_ERROR_BUSY);
   while(!Ready);
}

void PwmStop( byte Channel)
// Stop PWM
{
}

In main function I call:

PwmInit();
PwmDutySet(0, 50); // 50% duty on channel 0

It generates this:

PWM skipping

The duty is OK, but the problem is that PWM is generated for 200 ms, then shuts off for another 200 ms. Why and how to fix it? Is anything bad with my PWM wrapper? I use softdevice S110. The MCU is not resetting as I'm able to connect to the application via BLE.

Related