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

Using 2 PWM instances

Hello,

I want to control 2 PWM with different frequencies and hence I am using two separate instances. I want to use only the hardware and not the PWM library. Initializing and everything works fine but when I call the PWM in main loop, the second PWM's duty cycle is fed into the first one as well.  

Code's as below :

pwm1()

{

nrf_pwm_values_common_t seq_values[] = {100 - x};
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);

}

pwm2()

{

nrf_pwm_values_common_t seq_values_2[] = {100 - count};
nrf_pwm_sequence_t const seq_2 =
{
.values.p_common = seq_values_2,
.length = NRF_PWM_VALUES_LENGTH(seq_values_2),
.repeats = 0,
.end_delay = 0
};

nrf_drv_pwm_simple_playback(&m_pwm1, &seq_2, 1, NRF_DRV_PWM_FLAG_LOOP);
}

void main()

{

// Initialise...

  for (;;)

{

idle_state_handle();

pwm1();

pwm2();

}

}

Parents
  • Hello,

    The code looks to be correct, except I'm not sure what will happen when you call pwm1() and pwm2() this frequently (looks to me like they will end up being called repeatedly before the play sequence is even complete).

    As a test, could you try to add a 'busy wait' between the calls to see if that helps?

    e.g.

    #include "nrf_delay.h"

    int main(void)

    {

    ...

    // Initialise...

      for (;;)

    {

    idle_state_handle();

    pwm1();

    pwm2();

    nrf_delay_ms(10);

    }

Reply
  • Hello,

    The code looks to be correct, except I'm not sure what will happen when you call pwm1() and pwm2() this frequently (looks to me like they will end up being called repeatedly before the play sequence is even complete).

    As a test, could you try to add a 'busy wait' between the calls to see if that helps?

    e.g.

    #include "nrf_delay.h"

    int main(void)

    {

    ...

    // Initialise...

      for (;;)

    {

    idle_state_handle();

    pwm1();

    pwm2();

    nrf_delay_ms(10);

    }

Children
No Data
Related