PWM on ports other than 9 and 10

I have read in several places that servos can only be controlled from an Arduino on ports 9 and 10. However, I know there are several other ports that can send PWM signals. Is it true that only 9 and 10 will work for servos, and if so, why?

I think a significant percentage of my posts have been made answering this question. ;)

You can information about PWM and servos here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1232572239

And you can find the MegaServo library here that can be used on any pin: http://www.arduino.cc/playground/Code/MegaServo

However, I know there are several other ports that can send PWM signals

Be careful not to confuse PWM signals with the PPM signals used by servos - they're not the same at all.

Thanks! In that case, would you happen to know if the Sabertooth 2x25 motor controller will work with the PWM that the MegaServo library would put out? The documentation says that it can handle analog inputs including PWM as long as it is filtered. Here is the manual:

http://www.robotmarketplace.com/products/images/Sabertooth2x25.pdf

Specifically, page 11.

I want to make sure that when I try to write to it, I don’t damage it by using PPM rather than PWM or vice versa.

According to the manual you linked, you can drive that with PWM (using analogWrite on any of the Arduino analog output ports) or using RC input with servo PPM signals using Servo on pins 9 or 10 or MegaServo on any pin. Read through the manual to make sure you set the board up correctly.

Great, thanks a lot!

Were you able to get this setup with PWM? I have this board (Sabertooth 2x25) and am having some trouble interfacing it with the Arduino board. I tried using PPM with the ServoTimer library and I get erratic movement from my DC Motor (i.e. spins one way than the other all of a sudden).

I tried using PPM with the ServoTimer library

Did you try it with either the standard Servo Library (the one distributed with Arduino) or MegaServo (available from the playground)

Your using the term 'port' where you should be using the term 'pin', as port is something else, a grouping of 8 pins belonging to the same I/O port register.

Lefty

I will try both the standard servo library and the MegaServo library. This may be dumb but do I need to connect a ground wire in addition to the signal wire to the sabertooth? I didn't see anything in the manual about it http://www.dimensionengineering.com/datasheets/Sabertooth2x25.pdf

Yes you will need to wire a ground between the Arduino and the controller.

Lefty

Ok that definitely solved a lot of problems. PPM still was not very stable, so I switched over to PWM. I'm writing some code to control a DC motor inside of an old RC car. For the Sabertooth, 0V PWM sets the motor full forward throttle and 5V PWM to full throttle the other way. My concern is this: if I set PWM to 2.5V it should stop which it mostly does (my voltmeter reads 0V for the motor output) but there is a little fluctuation. I would like to the car to stop completely, so is there a way to disconnect the pin through software to I can get a 0V readout? I've notice I get no fluctuation if I connect the signal pin to a pin on the Arduino that I didn't set when using " pinMode(analogPin, OUTPUT);". Here is what I'm using, keep in mind I'm pretty green with this.

/* Test program for Sabertooth 2x25 PWM
Modified Code from various other code snippets found on forum */

int analogPin = 9;   //  analog pin 9
int val = 0;         // variable to store the write value

const char FORWARD_THRUST_KEY = 'F';
const char REVERSE_THRUST_KEY = 'R';
const char STOP_KEY = 'S';

char lastCommand;     //Data received from the serial port


void setup()
{
 Serial.begin(9600);
 delay(2000);
 pinMode(analogPin, OUTPUT);   // sets the pin as output
 val = 211;
}


void loop()
 {
 //set lastCommand if applicable
 if (Serial.available())
   {  //If data is available to read,
   lastCommand = Serial.read();    //read it and store it as lastCommand
   
   switch (lastCommand)
     {
       case FORWARD_THRUST_KEY:
       {
         val = val--;
         analogWrite(analogPin, val); 
         delayMicroseconds(5);
         Serial.println(val);
         Serial.println(lastCommand);
       }
      
       break;
   
       case REVERSE_THRUST_KEY:   //If R is recieved (Reverse Thrust Key)
        {
        val = val++;
        analogWrite(analogPin, val);
        delayMicroseconds(5); 
        Serial.println(val);
        Serial.println(lastCommand);
        }
       
       break;
   
   case STOP_KEY:  //If S is recieved (Stop)
       {
       val = 211;
       analogWrite(analogPin, val); 
       delayMicroseconds(5);
       Serial.println(val);
       Serial.println(lastCommand);
        pinMode(analogPin, OUTPUT);
       }
       break;
     }
  }
 }