[solved] strange phenomenons on DC motor driver

Hi all,

I’m experiencing some problems (and strange phenomenons…) with a DC motor driver (sabertooth 2x5, for more detaills see : http://www.robotshop.com/eu/Sabertooth-2x5-fr.html). The schematics are attached.

I’ve successfully runned a motor using a potentiometer. However, things get tricky when I try to use the PWM instead.

I’m using the motor driver in analog command mode and would like to use my arduino’s PWM (arduino : Uno/ATMEGA328P).
Note that the arduino uses the 5V power supply provided by the motor driver to make sure that both integrated circuits share the same ground (which evoids ground reference problems).

The driver’s user manual advised to use a (R=10kOhm, C = 0.1uF) RC filter but that was for a greater PWM frequency than the arduino’s 500Hz.
In consequence, I chose the components of the RC filter myself using “qucs” circuit simulator so that the output voltage keeps quite constant. I chose (R=100kOhm, C=0.47uF). However, i don’t know if there can be another criteria to choose the components except the fact of having a signal as flat as possible.

Things get weird when I power the motor : it acts crazy, firstly running very quickly then stopping then running in the opposite direction quicker and quicker. You could think that this is because the capacitor is getting empty and that output voltage equal to 0 means full speed for the driver. But the voltage is actually increasing as if it was fed by the driver. In such a situation, the mesured voltage for the resistance given by a voltmeter is 0 as if there was no current from the arduino.

Another strange stuff : if I unplug the power supply of the whole circuit then plug it again after 1 second or so things work as they should be. If I wait longer or less things get crazy again. If I unplug the arduino only for one second or so, things get working again. Actually, whenever the led at pin #13 blinks twice at startup, things work properly. If it doesn’t blink at all, the motor goes crazy. When things work properly, current mesured with the help of a voltmeter through the resistance show 17E-4 A if things do not work, then current is equal to 0. So from a certain point of view it seems that it is as if the arduino wasn’t powering it’s PWM all the time.

Strange isn’t it ?

Oh forgot to mention : this motor driver is regenerative meaning that when braking, the motor is supposed to give power to the battery… except that I don’t use a battery but a normal 9W power supply in an electric socket. Could that explain why things turn out like this ?

Also, it is likely that the motor can hold more than 9W which is the max power supply that can be delivered, could that envolve a lack of electric power available on the circuit and force a “shutdown” of the arduino circuit preventing it from sending any PWM signal ?

Thanks in advance for your help

From a datasheet for the controller:

The output impedance of the signals fed into the inputs should be less than 10k ohms for best results. If you are using a potentiometer to generate the input signals, a 1k, 5k or 10k linear taper pot is recommended.

You are driving a signal through a 100,000 ohm resistor (part of your low-pass filtering of the PWM) signal from the arduino pwm digital output pin. You are therefore way out of specification of the motor controllers analog input requirements.

I would suspect you would be better off configuring the motor controller to except 'R/C control' which means the motor controller will emulate being a servo, then you can simply utilize the arduino servo library to send your desired commands to the motor controller, rather then you using PWM > low-pass filter > analog DC voltage >> controller. Keep it all digital control by using arduino servo output to motor controller, life will be simpler for you.

Oh forgot to mention : this motor driver is regenerative meaning that when braking, the motor is supposed to give power to the battery... except that I don't use a battery but a normal 9W power supply in an electric socket. Could that explain why things turn out like this ?

Regenerative 'breaking' will only work if using battery power as batterys will accept current being driven 'backwards' into them, that's what charging a battery is all about. AC powered DC power supplies will not accept current to be driven backwards and return power back to the AC source.

Lefty

ok I'll try that !

I don’t get it why does this code work :

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  for(pos = 90; pos < 95; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(10);                       // waits 15ms for the servo to reach the position 
  }
}

void loop() { 
}

when this code doesn’t :

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{
  pos = 90;
  myservo.attach(9);
  delay(15);
  myservo.write(pos);
  delay(15);
  pos++;
  myservo.write(pos);
  delay(15);
  pos++;
  myservo.write(pos);
  delay(15);
  pos++;
}

loop() {
}

What do you expect for your version to do?

As written it appears to me to position the servo to midrange (90 degrees, if not already at that position) and then makes three quick steps of 1 degree each and stops. You might not even be able see such a small total travel (3 degrees) in just 45 millisec. pos++ increments pos but just 1 degree, is that what you wanted?

Lefty

Well, for me, both version are identical on a programming point of view, but it does not seem to be actually the case since when I run both programs the motor behave very differently : - version one makes the motor rotate a certain speed (meaning the motor never stops) - that is what I want to obtain - version two has no visible effect : either nothing happened or the motor turned from a few degrees only. I agree a 1 degree rotation is invisible. But then, why should the motor keep on rotating with version 1 : after all : it should stop turning once it reached 95 degrees ? Why is that so ?

What I want to achieve is to have the motor rotate at a usr-chosen speed. That's why, for me, the effects brought by version 1 are great, especialy because the uC is not permanently requested to make updates (e.g. updating an angle). However, I would like to achieve the same result with a cleaner code (I mean using a "for" loop just to choose a speed is not cool).

Oh yeah, and I also tryed to increment the angle until it reaches 360 and then reset it to zero and so on... but didn't work out well (nothing happened).

I've been working on the motor driver for a while now.

Sunday, I managed to get it working using the Servo library but I didn't understand how and why it was working. Also, the code which made the circuit work was not very convenient and forced the use of a "for" loop, although I still don't understand why I needed it. In a result I had a program which was dirty and that I didn't understand myself, and this is uncool... and "dangerous" since I couldn't foresee and/or solve the problems I could have in the future.

That's why, today I decided to give another shot using PWM... and surprisingly it worked perfectly... using exactly the same electronic circuit that I first tried (and didn't work). On the other hand, a lot has been going on since Saturday and perhaps I made a change on something somewhere in my circuit which made the difference. The only thing I can come up with is the change of power supply : I swapped my 9W power supply with a 430W PC power supply. This might explain the reason why the circuit suddently worked : in the old circuit, the DC motor I was using might consume more than 9W of electric power and since the arduino was powered by the motor driver, there might have been not enough electric power left to power the ATMEGA, which couldn't generate the PWM signal, which would explain why the DC motor was going crazy.

So the working circuit is the following :

        -----------
input---| 100kOhm |----------------------- output
        -----------       |
                          |
                        -----
                        ----- C=0.47uF
                          |
                          |
                         GND

I chose the 0.47uF simply because that was the highest value capacitor I had in ceramic technology (I don't know how long electrolytic capacitor last at 500Hz frequencies). And I chose the 100kOhm resistor by progressively changing resistor value from 68Ohm to 100kOhm. Actually 10kOhm is fine too, 100kOhm is kind of max value (by mesuring voltage at output and input, It seems that the motor driver's impedence is about 10MOhm).

I imporved the circuit so that default voltage at output is 2.5V, meaning that the DC motor must not rotate. The final circuit is as follow :

    5V                  input (0V to 5V)
     |                    |
   -----                -----
   |   |                |   |
   |   | R=100kOhm      |   | R = 10kOhm
   |   |                |   |
   -----                -----
     |                    |
     ----------------------------- output
     |                    |
   -----                  |
   |   |                ----- 
   |   | R=100kOhm      ----- C = 0.47uF
   |   |                  |
   -----                  |
     |                    |
     |                    |
    GND                  GND

@ retrolefty Thanks for your help

I chose the 0.47uF simply because that was the highest value capacitor I had in ceramic technology (I don't know how long electrolytic capacitor last at 500Hz frequencies).

About the same as if you leave it on the shelf - feeding an electrolytic via 100k resistor is not going to stress it - its high currents that cause issues really.

Of course aluminium electrolytics do deteriorate with time, tantalum ones are used when this matters.

tantalum ones are used when this matters.

Except that when a tantalum capacitor fails it almost always fails short circuit and can start fires. I one place I worked the technical director banned any one from using tantalum capacitors in any circuit produced by the company.