Hi All,
I am attempting to use 6 PWM channels with the app_pwm library on the nRF52 and am only able to successfully get 4 pwm outputs. Upon changing the 6th channel (PWM2 below ch 0) the softdevice would disconnect. I was able to stop the disconnection adding enable and disable calls before the PWM2 app_pwm_channel_duty_set call but this results in the PWM not being set correctly.
Any suggestions on what to do? I'm going to dig into the raw nrf_drv_pwm driver tomorrow to see if I can get that to perform as intended since I only need fixed pwm cycles for now.
All help is appreciated!!!
Please find the code below:
Globals:
APP_PWM_INSTANCE(PWM0,3); // Create the instance "PWM0" using TIMER3.
APP_PWM_INSTANCE(PWM1,1); // Create the instance "PWM1" using TIMER1.
APP_PWM_INSTANCE(PWM2,4); // Create the instance "PWM2" using TIMER4.
Initialization:
nrf_gpio_cfg_output(RED1_PIN);
nrf_gpio_cfg_output(RED2_PIN);
nrf_gpio_cfg_output(RED3_PIN);
nrf_gpio_cfg_output(BLUE1_PIN);
nrf_gpio_cfg_output(BLUE2_PIN);
nrf_gpio_cfg_output(BLUE3_PIN);
nrf_gpio_pin_clear(RED1_PIN);
nrf_gpio_pin_clear(RED2_PIN);
nrf_gpio_pin_clear(RED3_PIN);
nrf_gpio_pin_clear(BLUE1_PIN);
nrf_gpio_pin_clear(BLUE2_PIN);
nrf_gpio_pin_clear(BLUE3_PIN);
/* 2-channel PWM, 200Hz, output on DK LED pins. */
app_pwm_config_t pwm0_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, RED1_PIN, BLUE1_PIN);
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, RED2_PIN, BLUE2_PIN);
app_pwm_config_t pwm2_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, RED3_PIN, BLUE3_PIN);
/* Initialize and enable PWM. */
uint32_t err_code;
err_code = app_pwm_init(&PWM0,&pwm0_cfg,pwm_ready_callback);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&PWM0);
err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&PWM1);
err_code = app_pwm_init(&PWM2,&pwm2_cfg,pwm_ready_callback);
APP_ERROR_CHECK(err_code);
app_pwm_enable(&PWM2);
Softdevice events trigger:
void TurnItOff(void)
{
ready_flag = false;
app_pwm_channel_duty_set(&PWM0, 0, OFF_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM1, 0, OFF_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM2, 0, OFF_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM0, 1, OFF_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM1, 1, OFF_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM2, 1, OFF_DUTYCYCLE);
while(!ready_flag);
}
void MakeItHot()
{
ready_flag = false;
app_pwm_channel_duty_set(&PWM0, 0, RED_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM1, 0, RED_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM2, 0, RED_DUTYCYCLE);
while(!ready_flag);
}
void MakeItBlue(void)
{
ready_flag = false;
app_pwm_channel_duty_set(&PWM0, 1, BLUE_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM1, 1, BLUE_DUTYCYCLE);
while(!ready_flag);
ready_flag = false;
app_pwm_channel_duty_set(&PWM2, 1, BLUE_DUTYCYCLE);
while(!ready_flag);
}