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

Why is my PWM is modulated ?

When I set the PWM driver for very low frequency i can see how it blinks, the thing is that it always blinks where it's more or less 70% of the time ON and 30% OFF .

When I change the duty cycle say for 10%, it will not change the duration of the time that the led is on, but the intensity of the light when it's on, and it will keep blinking the same way (70% on and 30% off). I would expect that in such a low frequency I will see a change in the "on" time and not intensity. (intensity effect happens on high frequencies)

This means that changes to the duty cycle will affect the intensity of the light when it's on, and NOT the time that it's on

Thats some kind of modulation, so when it's on, its a pwm signal.

Here is how I init the pwm to a very low frequency :

 nrf_drv_pwm_config_t const config0 =
        {
            .output_pins =
            {
                pin1, 
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
                NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
            },
            .irq_priority = APP_IRQ_PRIORITY_LOWEST,
            .base_clock   = NRF_PWM_CLK_125kHz,
            .count_mode   = NRF_PWM_MODE_UP,
            .top_value    = 32700, //3 to 32767k
            .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
            .step_mode    = NRF_PWM_STEP_AUTO
        };
        // Init PWM without error handler
        APP_ERROR_CHECK(nrf_drv_pwm_init(&m_pwm0, &config0, NULL));

and how I set the duty cycle :

nrf_pwm_values_individual_t seq_values[] = {0, 0, 0, 0}; 


nrf_pwm_sequence_t const seq =
{
    .values.p_individual = seq_values,
    .length          = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats         = 0,
    .end_delay       = 0
};

void pwm_update_duty_cycle(uint8_t duty_cycle)
{
    

    if(duty_cycle > 100)
        seq_values->channel_0 = 100;
    
    else
        seq_values->channel_0 = duty_cycle;

    
    nrf_drv_pwm_simple_playback(&m_pwm0, &seq, 1, NRF_DRV_PWM_FLAG_LOOP);
}

So for example pwm_update_duty_cycle(10); , will set a low intensity with the same duty cycle, and pwm_update_duty_cycle(100); will set high intensity with the same duty cycle.

Related