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

Bug in the 16-bit PWM implementation in dimming examples

Hi,

Experimental dimming examples contain a 16 bit PWM implementation. I added the Enocean switch functionality to the dimming server example to control the LED on the board with the app as well as with the switch. I was using the 16-bit PWM function to dim the lights by Enocean switch. 

I found a weird bug when I was displaying the light levels while dimming as you can see below:

As you can see, while looping through all the values for light levels, the debugger shows the jump in the values frequently. 

When I tried adding a delay close to 1ms between each value, it is looping through all the values.

Because of these jumps, limits of dimming can't be properly defined. 

Do you guys have any idea on this weird behavior and any solution because adding delay of 1ms while looping through 32000 values I like a lot?

Thank you.

Parents
  • Hi.

    Where and how did you add these logs to output the "Current Dimming"?

    The three highlighted outputs (Current dimming: 19402/19410/19491) that stands out from the rest is always where the jump in value happens.
    Are these values collected the same way as the rest?
    Why does the output look different?

    Maybe you could upload the code where this is implemented?

    Best regards,
    Joakim

Reply
  • Hi.

    Where and how did you add these logs to output the "Current Dimming"?

    The three highlighted outputs (Current dimming: 19402/19410/19491) that stands out from the rest is always where the jump in value happens.
    Are these values collected the same way as the rest?
    Why does the output look different?

    Maybe you could upload the code where this is implemented?

    Best regards,
    Joakim

Children
  • Hi,

    Below is the code where I am recording the "Current Dimming" values:

    while (m_dim && On_OFF)
    {
        if(m_dim_state == 0)
        {
    		CURRENT_LIGHT_INTENSITY++;
    		if(CURRENT_LIGHT_INTENSITY > (UINT16_MAX/2))
            {
    			m_dim_state = 1;
                m_dim = false;
                break;
    		}
    	}
        else if(m_dim_state == 1)
        {
    		CURRENT_LIGHT_INTENSITY--;
            if(CURRENT_LIGHT_INTENSITY < 0)
            {
    			nrf_delay_ms(10);
                while (app_pwm_channel_duty_set2(&PWM0, 0, 0) == NRF_ERROR_BUSY);
                CURRENT_LIGHT_INTENSITY = 0;
                m_dim_state = 0;
                m_dim = false;
                break;
    	    }
        }
        while ( app_pwm_channel_duty_set2(&PWM0, 0, CURRENT_LIGHT_INTENSITY) == NRF_ERROR_BUSY);
        
        __LOG(LOG_SRC_APP, LOG_LEVEL_ERROR, "Current dimming: %d\n", CURRENT_LIGHT_INTENSITY);
    }
    

    The code for the function that sets the duty cycle for PWM is:

    ret_code_t app_pwm_channel_duty_set2(app_pwm_t const * const p_instance,
                                      uint8_t channel, app_pwm_duty_t duty)
    {
        uint16_t ticks = ((uint32_t)(duty) * m_pwm0_max) / UINT16_MAX;
        return app_pwm_channel_duty_ticks_set(&PWM0, 0, ticks);
    }

    As I said, I added EnOcean functionality, the "m_dim" indicates switch press; 'On_OFF' indicates LED On/Off; "m_dim_state" indicates increase/ decrease of intensity and CURRENT_LIGHT_INTENSITY indicates the level.

    The image that was posted in the question was taken when I was trying to increase the intensity of the LED. The jumps are also vague as the jump will not be at the same value next time and also the amount of jump is always different. 

    More or less, it can be said that, when I loop through the values from 0 to 32767, I observe numerous jumps and rarely catch the exact limits(0,32767)

    Thank you.

  • Hi Joakim,

    Were you able to reproduce this issue and check what the exact reason might be?

    Thank you.

Related