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
  • Hi,

    Where in you code are you running this? Are you running this inside a handler?

    I suspect that p_status won't be updated, so it won't stop until the for-loop is done. Maybe an easier way of doing this, will be to check the button value instead. You can have "1" for pressed and "0" for released, then stop the dimming if the button value is "0".

    Best Regards,

    Martin

Reply
  • Hi,

    Where in you code are you running this? Are you running this inside a handler?

    I suspect that p_status won't be updated, so it won't stop until the for-loop is done. Maybe an easier way of doing this, will be to check the button value instead. You can have "1" for pressed and "0" for released, then stop the dimming if the button value is "0".

    Best Regards,

    Martin

Children
No Data
Related