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

PWM Driver

Hello,

I want to use the PWM driver to change the output voltage with respect to analog input voltage. If I call the simple_playback_sequence from the SAADC event handler, the voltage only raises for that time but if I call the same function from the while(); loop in main, it remains constant. I am giving LOOPS, no repeats and no end delay. Is there any specific reason that I can't call PWM from the event handlers and have to do it only from the infinite while loop?

Parents
  • Hi,

    This does not immediately make sense to me. Can you explain in more detail, and show with code what you do?

  • Sorry for the late reply, consider timer_handler as a function I call using app_timer library and pwm_change as a function I want to change the PWM value. count is a global variable

    Code that Works :

    void timer_handler()

    {

    count+= 1;

    }

    void pwm_change()

    {

    nrf_pwm_values_common_t seq_values[] = {count};
    nrf_pwm_sequence_t const seq =
    {
    .values.p_common = seq_values,
    .length = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats = 0,
    .end_delay = 0
    };

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

    }

    int main()

    {

    // Initialise peripherals...

    while(1)

    {

    idle_state_handle();

    pwm_change();

    }

    }

    Code that does not Work :

    void timer_handler()

    {

    count+= 1;

    pwm_change();

    }

    void pwm_change()

    {

    nrf_pwm_values_common_t seq_values[] = {count};
    nrf_pwm_sequence_t const seq =
    {
    .values.p_common = seq_values,
    .length = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats = 0,
    .end_delay = 0
    };

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

    }

    int main()

    {

    // Initialise peripherals...

    while(1)

    {

    idle_state_handle();     

     }

    }

    The place where I call pwm_change is what's changed between the codes. If i call from main(), it functions well but if I call from any event handler, the PWM breaks continuously.

Reply
  • Sorry for the late reply, consider timer_handler as a function I call using app_timer library and pwm_change as a function I want to change the PWM value. count is a global variable

    Code that Works :

    void timer_handler()

    {

    count+= 1;

    }

    void pwm_change()

    {

    nrf_pwm_values_common_t seq_values[] = {count};
    nrf_pwm_sequence_t const seq =
    {
    .values.p_common = seq_values,
    .length = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats = 0,
    .end_delay = 0
    };

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

    }

    int main()

    {

    // Initialise peripherals...

    while(1)

    {

    idle_state_handle();

    pwm_change();

    }

    }

    Code that does not Work :

    void timer_handler()

    {

    count+= 1;

    pwm_change();

    }

    void pwm_change()

    {

    nrf_pwm_values_common_t seq_values[] = {count};
    nrf_pwm_sequence_t const seq =
    {
    .values.p_common = seq_values,
    .length = NRF_PWM_VALUES_LENGTH(seq_values),
    .repeats = 0,
    .end_delay = 0
    };

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

    }

    int main()

    {

    // Initialise peripherals...

    while(1)

    {

    idle_state_handle();     

     }

    }

    The place where I call pwm_change is what's changed between the codes. If i call from main(), it functions well but if I call from any event handler, the PWM breaks continuously.

Children
Related