This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How do I control servo simultaneosly in the interrupt_hadler?

FormerMember
FormerMember

Hi,

I'm using SD110, SDK 10.0.0, nRF51822

In my own application, I control 4 servo by pwm with Timer1 and Timer2,

and I have 2 buttons, each button is a flag for moving servo1,2 and servo3,4.

When button1 occur button_interrupt, a flag which I declared refer move_servo1_or_servo2.

This is example code :

button_handler()
{
  switch(pin)
  {
    case button1:
     flag = move_servo1_or_servo2;
     break;
    case button2:
     flag = move_servo3_or_servo4;
     break;
  }
}

int main()
{
  while()
  {
    if(flag != null)
    {
      move_servo(flag);
    }
  }
}

Until now, This is not a problem, but I need to control servo within interrupt.

For example :

button_handler()
{
  switch(pin)
  {
    case button1:
      move_servo1();
      break;
    case button2:
      move_servo2();
      break;
  }
}

Like above,

The problem is when I deal with controling servo in interrupt, application is stopped every activity, or something unpredictable result.

How do I solve it?

Thaks,

Parents
  • What do move_servo1() and move_servo2() do? After the pwm value is updated with app_pwm_channel_duty_set(..) it will be busy until it receives a timer interrupt. This interrupt is run at APP_IRQ_PRIORITY_LOW. If you are waiting for the pwm to be ready in another interrupt you will wait forever since the pwm will stay busy forever (timer interrupt will never happen).

    For example, don't do this in the button interrupt:

    while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
    
Reply
  • What do move_servo1() and move_servo2() do? After the pwm value is updated with app_pwm_channel_duty_set(..) it will be busy until it receives a timer interrupt. This interrupt is run at APP_IRQ_PRIORITY_LOW. If you are waiting for the pwm to be ready in another interrupt you will wait forever since the pwm will stay busy forever (timer interrupt will never happen).

    For example, don't do this in the button interrupt:

    while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY);
    
Children
No Data
Related