Orangutan SVP high motor speed conflicts with delay

I’m using the Orangutan SVP 1284 controller and I was trying to write a simple program which lets me specify the motor speed with a potentiometer and then run the motors for 5 seconds at that speed. However, I found that whenever I set the speed above 113 or so, the “delay” function returns immediately and my motors are turned off immediately.

Now, I did read in the documentation that the OrangutanMotor library uses Timer2 and so does the OrangutanTime library, so it is possible that they are conflicting with each other. My question is how do I fix this? Should I edit OrangutanTime.[h,cpp] and change it to use timer1 and reinstall the library? Or is there a simpler way out.

Here is my code:

#include <pololu/orangutan.h>

int main()
{
  int pot;
  int speed;
  
  int secsleft;

  while (1)
  {
    /* read the potentiometer for the desired speed until the user presses
     * a button
     */

    do {
      pot = read_trimpot();

      lcd_goto_xy(0, 0);        // avoid clearing the LCD to reduce flicker  
      print("pot   = ");  
      print_long(pot);          // print the trim pot position (0 - 1023)  
      print("    ");            // overwrite any left over digits
      
      speed = pot - 512;
      if (speed > 255)
        speed = 255;
      else if (speed < -255)
        speed = -255;
      
      lcd_goto_xy(0, 1);
      print("spd=");
      print_long(speed);
      print("  ");

      delay_ms(100);
    } while (!button_is_pressed(ANY_BUTTON));

    set_motors(speed, speed);

    /* wait for 5 seconds and display the count-down timer */
    for (secsleft = 5; secsleft > 0; secsleft --)
    {
      lcd_goto_xy(15, 0);
      print_long(secsleft);
      delay(1000);
    }
    lcd_goto_xy(15, 0);
    print(" ");
    set_motors(0, 0); // stop the motors
  }
}

Hello.

The delay is achieved using a loop delay and cannot be conflicting with the motor code. It sounds to me like you’re experiencing a power issue that’s causing the controller to brown-out and reset as the motor power draw increases. You could easily test this by adding a start-up sequence to your program (e.g. blink the red LED five times before entering the main loop).

How are you powering your system and what are the specs of the motor you’re using?

- Ben

You were right, the controller is resetting.

The chassis and motor are this one: http://letsmakerobots.com/node/8250. It has 4 motors (2 attached in parallel to each of the Orangutan’s motor controllers). The motor specs are
• No-load current(3V):60mA
• No-load current(6V):71mA
• Stall current(3V):260mA
• Stall current(6V):470mA
I’m powering it with 5 NiMH AA batteries. However, these batteries are quite old. I’m waiting for new batteries to arrive and I can let you know if it works with them.

You can easily see if your batteries are running low by adding this to your program:

clear();
print_long(read_battery_millivolts_svp());
print(" mV");
wait_for_button_press(ANY_BUTTON);

That’s what we do at the beginning of the program in some of our 3pi Robot sample code and its a good practice.

-David

Note that using five NiMH cells means that your nominal voltage is 6V, which is the minimum recommended operating voltage for the SVP. Your problems are probably a combination of this and the age of your batteries. If you continue to have issues, you should consider adding one or two more cells.

- Ben

Well, I have just received 8 brand new NiMH rechargeable batteries. With all 8 (fully-charged) batteries the maximum speed that I can get is about 208. The controller still resets when I try to set the speed to 255. With only 6 batteries I can get a speed of about 150 before it will reset.

Also, I changed my program to display the voltage as suggested above. The voltage is as expected. For example, with 6 batteries the voltage reads 7.8V and when I run the motors at 150 it is around 7.4V.

I don’t really want to try 10 batteries because I’m afraid that will burn out the motors which are rated for 6V. So what should I look at next to get the motors running at full speed?

Hello,

Another thing that can cause problems is motor noise. See this page for a few techniques for reducing it. If you could post a picture of your setup, we could also take a look at it; we might notice something obvious.

Are you saying that the battery voltage reads around 7.4V while the motors are running at 150? Are you holding them stalled somehow?

-Paul

OK, I will work on adding the capacitors and report back. But I’m puzzled as to why there would be any electronic noise when the motors are not even moving. There is nothing causing them to stall, as you can see in the picture below I have even removed the wheels.

Yes, the voltate is around 7.4 V while the motor is running at a speed of 150. (I have changed my code to display the voltage continuously. Here is the new code.

#include <pololu/orangutan.h>

int main()
{
  int pot;
  int speed;
  int secsleft;
  int i;

  /* flash the green LED to indicate reset or power-up */
  for (i=0; i<2; i++)
  {
    green_led(HIGH);
    delay(250);
    green_led(LOW);
    delay(250);
  }

  /* display the battery voltage */
  clear();
  lcd_goto_xy(0, 0);
  print_long(read_battery_millivolts_svp());
  print(" mV");
  lcd_goto_xy(0, 1);
  print("press button");
  wait_for_button(ANY_BUTTON);

  while (1)
  {
    clear();

    /* read the potentiometer for the desired speed until the user presses
     * a button
     */

    do {
      /* print battery voltage */
      lcd_goto_xy(0, 0);
      print_long(read_battery_millivolts_svp());
      print(" mV  ");

      /* print the user trim pot */
      pot = read_trimpot();
      lcd_goto_xy(0, 1);  
      print("pot=");  
      print_long(pot);
      
      /* calculate speed */
      speed = pot - 512;
      if (speed > 255)
        speed = 255;
      else if (speed < -255)
        speed = -255;
      
      /* print speed */
      print(" spd=");
      print_long(speed);
      print("  "); // clear trailing digits

      delay_ms(100);
    } while (!button_is_pressed(ANY_BUTTON));

    set_motors(speed, speed);

    /* wait for 5 seconds and display the count-down timer */
    for (secsleft = 5; secsleft > 0; secsleft --)
    {
      /* print battery voltage */
      lcd_goto_xy(0, 0);
      print_long(read_battery_millivolts_svp());
      print(" mV  ");

      lcd_goto_xy(15, 0);
      print_long(secsleft);
      delay(1000);
    }
    lcd_goto_xy(15, 0);
    print(" "); // clear the count-down timer

    set_motors(0, 0); // stop the motors

    /* blink the red LED to indicate previous round is over */
    for (i=0; i<2; i++)
    {
      red_led(HIGH);
      delay(250);
      red_led(LOW);
      delay(250);
    }
  }
}

Here are some pictures of my setup:




So does the board still reset with the wheel removed? I am also confused about why you say the motors are not moving. In the picture you posted, either they are moving or they are stalled - which is it?

-Paul

I’m sorry if I was not clear.

With 6 batteries I can get the motors to run at a speed of 150 (one of the pictures above shows this). If I increase the speed above 150, say 200, the motors don’t move (with or without wheels on them) and the board immediately resets.

So, my question was this. When I set speed to 200 and try to start the motors, how could noise from stationary motors cause the board to reset?

Hello,

When you have a motor at rest that you instantly change to a speed of 200, it will remain at rest for a moment before it starts moving. Until it starts turning, the motor is stalled, which means it will be drawing its maximum current. That sudden burst of current (2 or 3A?) might itself be enough for your battery voltage to drop under the SVP’s minimum of 6V, or the surge of current could cause noise that would interfere with electronics.

If the motors run fine at 150, can you try holding them stalled at that speed, and watch what happens to the battery voltage?

-Paul

What happens if you start at 150 and ramp the speed up to 200 (turn the pot while the motor is running)? How does the voltage change as the speed increases?

I am using the SVP 1284 with two 100:1 Micro Metal Gearmotor HP and 6 AAA batteries (850mA) and have had the board reset if I tried to start at a high speed. If I ramp the speed, I can reach the maximum. As Paul said the CPU is probably browning out because of the sudden current rush.

Mike

OK, I understand now. Sudden increases in speed draw too much current causing brown out.

I have changed my code to ramp up the speed from 0 to 100 percent of desired speed in steps of 1 percent every 2ms. In other words it takes .2 seconds to reach the desired speed. This seems to work quite well. In fact, I can get the motors running at their max speed even with 5 NiMH batteries!

Here is the full code.

#include <pololu/orangutan.h>

int main()
{
  int pot;
  int speed;
  int speed_pct;
  int secsleft;
  int i;

  /* flash the green LED to indicate reset or power-up */
  for (i=0; i<2; i++)
  {
    green_led(HIGH);
    delay(250);
    green_led(LOW);
    delay(250);
  }

  clear();
  
  /* display the battery voltage */
  lcd_goto_xy(0, 0);
  print_long(read_battery_millivolts_svp());
  print(" mV  ");

  /* wait till the user presses a button */
  lcd_goto_xy(0, 1);
  print("press button    ");
  wait_for_button(ANY_BUTTON);

  while (1)
  {
    clear();

    /* read the potentiometer for the desired speed until the user presses
     * a button
     */

    do {
      /* print battery voltage */
      lcd_goto_xy(0, 0);
      print_long(read_battery_millivolts_svp());
      print(" mV  ");

      /* print the user trim pot */
      pot = read_trimpot();
      lcd_goto_xy(0, 1);  
      print("pot=");  
      print_long(pot);
      
      /* calculate speed */
      speed = pot - 512;
      if (speed > 255)
        speed = 255;
      else if (speed < -255)
        speed = -255;
      
      /* print speed */
      print(" spd=");
      print_long(speed);
      print("  "); // clear trailing digits

      delay_ms(100);
    } while (!button_is_pressed(ANY_BUTTON));

    /* gradually ramp up the speed from 0 to 100 percent */
    for (speed_pct=0; speed_pct<100; speed_pct++)
    {
      set_motors(speed * speed_pct / 100, speed * speed_pct / 100);

      delay_ms(2);
    }

    /* run the motors for 5 seconds and also display a count-down timer */
    for (secsleft = 5; secsleft > 0; secsleft --)
    {
      /* print battery voltage */
      lcd_goto_xy(0, 0);
      print_long(read_battery_millivolts_svp());
      print(" mV  ");

      lcd_goto_xy(15, 0);
      print_long(secsleft);

      delay(1000);
    }
    lcd_goto_xy(15, 0);
    print(" "); // clear the count-down timer

    set_motors(0, 0); // stop the motors

    /* blink the red LED to indicate previous round is over */
    for (i=0; i<2; i++)
    {
      red_led(HIGH);
      delay(250);
      red_led(LOW);
      delay(250);
    }
  }
}

I think it would help some other beginner if the provided example code has the ramp up in it.

    /* gradually ramp up the speed from 0 to 100 percent */
    for (speed_pct=0; speed_pct<100; speed_pct++)
    {
      set_motors(speed * speed_pct / 100, speed * speed_pct / 100);

      delay_ms(2);
    }

I will work next on using the current sense to more intelligently ramp up and detect stalls.

Thanks for all the help.

Have you tried stalling your motors and looking at the battery voltage yet? If your power system cannot handle the stall current of your motors, you are going to have many more headaches in the future.

Once you start using the current sense, it would also be interesting to find out whether the stall current is actually as advertised.

-Paul

Yes, when I forcibly stall one of the motors the battery voltage drops and the board resets. For example, with 5 NiMH AA batteries (2800mAH) the battery voltage starts out at 6.4V, when I run the motors at 255 the voltage drops to 5.5V and then picks up to 5.9V and stabilizes at 6.1V. However, if I hold one of the motor’s shaft then the voltage drops to 5.4V and the next instant the board resets.

I’m hoping that the stall issue will not bother me since I’ll be monitoring the current in a background job (controlled by a timer) and I’ll stop the motors if the current starts to shoot up.

I’ll let you know what the stall current really is.

If you can measure the current, that would be great. It would also be good to test voltage and current with the motor directly connected to your batteries - no SVP in the circuit at all.

-Paul