I would like to use 3 PWM for controling RGBs. I use a softdevice because I want to control the pwm trough the MCP. But for now I just want to get it work to initialize these 3 pwms.
If I init one PWM everything works. When I try to init a second PWM, the first pwm will also not work.
Here the Init for the 2 PWMs:
static volatile bool ready_flag0;
static volatile bool ready_flag1;
APP_PWM_INSTANCE(PWM0,0);
APP_PWM_INSTANCE(PWM1,1);
static void pwm0_ready_callback(uint32_t pwm0_id)
{
ready_flag0 = true;
}
static void pwm1_ready_callback(uint32_t pwm1_id)
{
ready_flag1 = true;
}
static void PWMinit(void)
{
app_pwm_config_t pwm0_cfg = APP_PWM_DEFAULT_CONFIG_1CH(2000000,22);
pwm0_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
app_pwm_init(&PWM0,&pwm0_cfg,pwm0_ready_callback);
app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000000, 23);
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
app_pwm_init(&PWM1,&pwm1_cfg,pwm1_ready_callback);
}
static void PWMstart(uint8_t pwm_number)
{
switch(pwm_number)
{
case 0: nrf_drv_gpiote_out_task_enable(22);
app_pwm_enable(&PWM0);
while (app_pwm_channel_duty_set(&PWM0, 0, 50) == NRF_ERROR_BUSY);
break;
case 1: nrf_drv_gpiote_out_task_enable(23);
app_pwm_enable(&PWM1);
while (app_pwm_channel_duty_set(&PWM1, 0, 50) == NRF_ERROR_BUSY);
break;
}
}
And in the main:
PWMinit();
PWMstart(0);
PWMstart(1);
What is wrong with the initialization for the second pwm?