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 Reply
  • Hi!, So we have tried many things, adding additional variables to store ACTION_CHANGE for example, or moving the PWM loops to app_enocean_cb... nothing seems to work, as soon as I many a loop the action parameter doesn't get updated... do you have an EnOcean switch to run this example and replicate the issue? can you make any loop and break it with the release_action? and start it with the press_action?

Children
No Data
Related