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
  • Again you are doing the update inside an interrupt (button_handler). The first app_pwm_channel_duty_set(..) will probably work, but the next will not because it will not be ready before the timer interrupt has happen, which will at earliest happen after the button_handler is finished. If you check the return value of the second call to app_pwm_channel_duty_set(..) it should be NRF_ERROR_BUSY. Use app scheduler to run the function in main context instead.

Reply
  • Again you are doing the update inside an interrupt (button_handler). The first app_pwm_channel_duty_set(..) will probably work, but the next will not because it will not be ready before the timer interrupt has happen, which will at earliest happen after the button_handler is finished. If you check the return value of the second call to app_pwm_channel_duty_set(..) it should be NRF_ERROR_BUSY. Use app scheduler to run the function in main context instead.

Children
No Data
Related