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
  • FormerMember
    0 FormerMember

    Okay, let me explain you another example.

    I have two servo motors and two buttons, and each servo's pwm is matched with timer1 and timer2.

    And I can active servo1 by button1, servo2 by button2.

    When I push button1 and button2 in the same time, I wanna active two servo motors in the same time.

    For now, I've programmed it like below(I tried, but failed, It wasn't actived in the same time) :

    void button_handler()
    {
      switch(pin)
      {
        case button1:
          active_servo(1);
          break;
        case button2:
          active_servo(2);
          break;
      }
    }
    
    inline void active_servo(i)
    {
      app_pwm_channel_duty_set(pwm[i], 0, value1);
      nrf_delay_ms(550);
      app_pwm_channel_duty_set(pwm[i], 0, value2);
      nrf_delay_ms(450);
    }
    

    How do I program it?

Reply
  • FormerMember
    0 FormerMember

    Okay, let me explain you another example.

    I have two servo motors and two buttons, and each servo's pwm is matched with timer1 and timer2.

    And I can active servo1 by button1, servo2 by button2.

    When I push button1 and button2 in the same time, I wanna active two servo motors in the same time.

    For now, I've programmed it like below(I tried, but failed, It wasn't actived in the same time) :

    void button_handler()
    {
      switch(pin)
      {
        case button1:
          active_servo(1);
          break;
        case button2:
          active_servo(2);
          break;
      }
    }
    
    inline void active_servo(i)
    {
      app_pwm_channel_duty_set(pwm[i], 0, value1);
      nrf_delay_ms(550);
      app_pwm_channel_duty_set(pwm[i], 0, value2);
      nrf_delay_ms(450);
    }
    

    How do I program it?

Children
No Data
Related