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.
Parents
  • That code mentioned was running inside the app_switch_debounce() function.

    I realized that the delay function is keeping the processor busy and it isn't allowing the processor to check for the press action of the enocean switch. 

    How can I perform dimming without using a nrf_delay_ms() function so that the process can be interrupted in between with the release action?

    Thank you.

Reply
  • That code mentioned was running inside the app_switch_debounce() function.

    I realized that the delay function is keeping the processor busy and it isn't allowing the processor to check for the press action of the enocean switch. 

    How can I perform dimming without using a nrf_delay_ms() function so that the process can be interrupted in between with the release action?

    Thank you.

Children
No Data
Related