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

PWM implementation for dimming.

Hi,

I tried adding PWM for turning on/off the LED's on the DK for the Enocean switch example. It worked well.

I tried to perform dimming on the switch example by restricting the increasing or decreasing brightness using the RELEASE_ACTION as follows.

       if (p_status->b0 && timer_diff(timestamp, m_switch_state[index].b0_ts) > SWITCH_DEBOUNCE_INTERVAL_US)
        {
            m_switch_state[index].b0_ts = timestamp;
            set_params.on_off = APP_STATE_ON;
            app_pwm_enable(&PWM1);	
            for (uint32_t i=90; i > 50; i--)
                     {
			while ( app_pwm_channel_duty_set(&PWM1, 0, i) == NRF_ERROR_BUSY);
                        nrf_delay_ms(100); 
if(p_status->action == RELEASE_ACTION)
{
break;
} } status = generic_onoff_client_set_unack(&m_clients[1], &set_params, &transition_params, APP_UNACK_MSG_REPEAT_COUNT);
}

But when I release the button to stop the dimming, the release action is not getting recorded immediately. I can see the release action after the PWM is implemented completely(till duty cycle of 50). How can I solve the issue to stop the dimming once I release the switch. I know that the experimental_dimming example contains generic level model but I would like to know why this code isn't functioning properly.



Thank you.
Related