Hi!
I've quite wired problem with PWM based on NRF_TIMER.
When I modify CC value to adjust current value to desired value slowly (function is fired from outside event) sometimes output signal get inverted, eg. if 35% of period output should be HI state, at 34 % (decreasing brightness) it goes to LO state for 34%, 33%, .... And at the end it switches off normally.
Have you got any idea what can be the reason?
void adjust_brightness(brightness_t * channel) {
if(channel->currentBrightness < channel->desiredBrightness) // it's to dark, increase brightness
{
if(channel->currentBrightness == 0 && channel->desiredBrightness != 0)
{
nrf_gpiote_task_config(pwm_gpiote_channel[channel->pwmChannel], pwm_io_ch[channel->pwmChannel], NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);
}
channel->currentBrightness++;
PWM_TIMER->CC[channel->pwmChannel] = channel->currentBrightness;
if(channel->currentBrightness == pwm_max_value)
{
nrf_gpiote_unconfig(pwm_gpiote_channel[channel->pwmChannel]);
nrf_gpio_pin_write(pwm_io_ch[channel->pwmChannel], 1);
}
}
else if(channel->currentBrightness > channel->desiredBrightness) // to bright, decrease
{
if(channel->currentBrightness == pwm_max_value && channel->desiredBrightness != pwm_max_value)
{
nrf_gpiote_task_config(pwm_gpiote_channel[channel->pwmChannel], pwm_io_ch[channel->pwmChannel], NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_HIGH);
}
channel->currentBrightness--;
if(channel->currentBrightness == 0)
{
nrf_gpiote_unconfig(pwm_gpiote_channel[channel->pwmChannel]);
nrf_gpio_pin_write(pwm_io_ch[channel->pwmChannel], 0);
}
PWM_TIMER->CC[channel->pwmChannel] = channel->currentBrightness;
}
}
Thanks, Patriko