PPM (RC) to PWM converter

3,000 views
Skip to first unread message

jgeidl

unread,
Mar 6, 2012, 8:17:46 PM3/6/12
to HomeBrew Robotics Club
Anybody run across a device to do this?

I have a motor controller that only accepts PWM. I want to be able to
switch from PWM control from a MCU to R/C control. Some controllers
do this within themselves but not this one.

Tahnsk,

Jim, K6JMG

Alan

unread,
Mar 6, 2012, 8:43:01 PM3/6/12
to hbrob...@googlegroups.com
Jim,

This board will do it.

http://paparazzi.enac.fr/wiki/ATmega168_PPM_Encoder_Board

Use ServoDecode library in Arduino

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230065255

Alan KM6VV

> -----Original Message-----
> On Behalf Of jgeidl

Ytai Ben-Tsvi

unread,
Mar 6, 2012, 9:26:37 PM3/6/12
to hbrob...@googlegroups.com

Should be easy to do with a small MCU that has input capture and a bunch of pwm outputs. Probably order of 100-200 lines of code at most.

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To post to this group, send email to hbrob...@googlegroups.com.
To unsubscribe from this group, send email to hbrobotics+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hbrobotics?hl=en.

Steven Nelson

unread,
Mar 10, 2012, 3:48:07 AM3/10/12
to hbrob...@googlegroups.com
So you are trying to send a PWM signal from either a R/C receiver or a Micro controller to what a speed controller? Is that right?

--
You received this message because you are subscribed to the Google Groups "HomeBrew Robotics Club" group.
To post to this group, send email to hbrob...@googlegroups.com.
To unsubscribe from this group, send email to hbrobotics+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hbrobotics?hl=en.




--
Inspection time: The period of time required to inspect a recently welded piece of metal using your bare hand.
The hotter the metal the shorter the period of inspection time

James M. Geidl

unread,
Mar 10, 2012, 9:02:46 PM3/10/12
to hbrob...@googlegroups.com
Steven,
 
I have a Sabertooth 2x25 controller.  It works perfectly if I feed it a signal from a RC receiver.  If I try and feed it from an Arduino using the Servo library the operation is erratic at best. 
 
My goal is to be able to switch between the Arduino and the RC transmitter pretty much on the fly.  I can put in a small relay to switch 2 signal lines between the two devices.  I can trip the relay from the RC transmitter by putting a small circuit I have that responds (on/off) to a RC signal on a 3rd channel.
 
The only real issue I have if trying to get the motor controller to properly respond to the Arduino signals.
 
Any help will be greatly (did I say GREATLY?) appreciated.
 
Here is the code I am using for testing:
 
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
 

#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
Servo myservo2; // second servo               
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(2);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(4);
  Serial.begin(9600);
}
 
 
void loop()
{
  for(pos = 1; pos < 180; 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'
    myservo2.write(180 - pos);
    Serial.print(180 - pos, DEC);
    Serial.print(" ");
    Serial.println(pos, DEC);
   
    delay(200);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    myservo2.write(180 - pos);
    Serial.println(pos, DEC);
    Serial.print(180 - pos, DEC);
    Serial.print(" ");
 
    delay(200);                       // waits 15ms for the servo to reach the position
   }
}
 

James M. Geidl, K6JMG
D.B. Cooper, you have a message.
 



From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On Behalf Of Steven Nelson
Sent: Saturday, March 10, 2012 12:48 AM
To: hbrob...@googlegroups.com
Subject: Re: [HBRobotics] PPM (RC) to PWM converter

Steven Nelson

unread,
Mar 10, 2012, 10:21:50 PM3/10/12
to hbrob...@googlegroups.com
Huh that should work, I'm sure you also connected a common ground from the Arduino boards ground and the speed controllers (PWM input ground). 

Steven Nelson

unread,
Mar 10, 2012, 10:41:40 PM3/10/12
to hbrob...@googlegroups.com
Hey I just found some interesting information on using the controller with RC or a Micro controller. That controller has a auto calibrate function that senses the R/C PWM signal range it may be causing you some issues when switching to the micro-controller if it is in a different range check out this book if you haven't already done so.. 

James M. Geidl

unread,
Mar 11, 2012, 3:18:01 PM3/11/12
to hbrob...@googlegroups.com
Yeah, I did but I am going to go one step further and power the Arduino from the Sabretooth then there shouldn't be any power questions. 
 

James M. Geidl, K6JMG
D.B. Cooper, you have a message.
 


From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On Behalf Of Steven Nelson
Sent: Saturday, March 10, 2012 7:22 PM

KM6VV

unread,
Mar 11, 2012, 10:59:32 PM3/11/12
to hbrob...@googlegroups.com
James,

I have similar goals.  You might take a lesson from the quadcopter guys, use PPM signal from RCVR, and use a fail shift or a command on the TX to switch back and forth.  Getting PPM from is easier with one of the little modules.  You can even program your own from supplied code (DIYdrones).  I intend to send I2C to my motor controllers.   You could send motor PWM to your controller. 

The DIYdrones channel to PPM module also does a fail safe (important for drones!).

Alan  KM6VV

James M. Geidl

unread,
Mar 12, 2012, 9:43:04 AM3/12/12
to hbrob...@googlegroups.com
Alan,
 
The switching back and forth is the easy part, I have some switching circuits that take a PPM signal and switch.  My problem is getting the motor controller to play nice with the Arduino.
 

James M. Geidl, K6JMG
D.B. Cooper, you have a message.
 



From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On Behalf Of KM6VV
Sent: Sunday, March 11, 2012 8:00 PM

Alex Sy

unread,
Mar 12, 2012, 2:28:48 PM3/12/12
to hbrob...@googlegroups.com
I had to deal with this on the quadrotor.  Several other things to consider assuming all the wiring is correct.
1.  The transmitters can generate anywhere from 2 to 8 or more PPM channels.  Although the spec is 1 to 2 msecs, with 1.5 msec being idle, every transmitter is different and the low range, high range and idle may not be the same, even on different channels of the same transmitter.  The idle can usually be trimmed on any decent remote control, while the range can only be trimmed on the higher end units.  On the higher end transmitters, even the linearity of the pulses can be adjusted to allow users to have a better control at both low and high speeds.
2.  Make sure the PPM you are getting from the receiver is the correct one.  Servos usually take an active high PPM pulse of 1 to 2 msecs at 20 msec period.  Most RC receviers just send out what they receive from the transmitter but some add logic that forces the pulse (usually for failsafe purposes).  You need to look at it with an oscilloscope or logic analyzer.
3.  When you use an Ardiuino or other program to generate the pulses, they must have the same polarity, min, idle and max and period (and possibly linearity).  This usually means that you had to calibrate your program, otherwise when you switch, it will act abnormally.
The method I use is for the program on the switcher, to monitor the levels of the pulses while the remote is using it, then record the min, max and idle, then when the CPU takes over, it makes sure that it follows those limits.  In reality, the CPU is always in the path, and it just either takes the remote control receiver pulses or generates its own.  Other people use a hardware multiplexer so that the CPU is not in the path in case the software is not working right.
In the end debugging this requires an oscilloscope or logic analyzer so you can compare the signals.

Alan

unread,
Mar 12, 2012, 1:24:56 PM3/12/12
to hbrob...@googlegroups.com

James,

 

Your motor controller doesn’t like the Arduino PWM?  And it doesn’t take RS-232 (TTL)?

The RoboClaw DOES, however you’d probably want the Arduino Mega with its 2nd serial port to talk to it. 

 

Alan  KM6VV

 

Behalf Of James M. Geidl

James M. Geidl

unread,
Mar 12, 2012, 4:39:27 PM3/12/12
to hbrob...@googlegroups.com
Alan,
 
The motor controller will either handle analog signals (PWM) from a mcu like the Arduino or PPM from a RC receiver.  The problem is that the controller requires resetting dip switches to change from one to the other.  This wipes my desire to be able to switch on the fly.  The Arduino drives a servo perfectly when connected directly to it and using the Servo library.  Something goes haywire when the Arduino is talking to the motor controller.  Steven might have hit is on the head and, also, Alex Sy pointed out some potential issues.  I am going to have to fiddle more.  Worse case, I can use PWM when using the Arduino and manually switch to RC when I want to after resetting the Sabertooth's dip switches.  It frustrates me because the Arduino is obviously putting out the correct signals or directly connected servo would not work.
 
I have a Mega 2560 R3 but going to serial doesn't' solve my remote switching desires.  Seems like I ALWAYS want something I can't have.  :-)
 

James M. Geidl, K6JMG
D.B. Cooper, you have a message.
 

 
 


From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On Behalf Of Alan
Sent: Monday, March 12, 2012 10:25 AM
To: hbrob...@googlegroups.com
Subject: RE: [HBRobotics] PPM (RC) to PWM converter

Steven Nelson

unread,
Mar 12, 2012, 10:26:34 PM3/12/12
to hbrob...@googlegroups.com
There may be a third solution you could just read the signals directly from the receiver with the Arduino and the PulseIn command and then output those values to the speed controller using the Arduino . I did the same thing a long time ago with a BASIC Stamp2 on my robot Eva. So you read the two channels one for speed and one for steering and a third channel to select radio or computer control. This way you wouldn't have to change the dip sw's when you wanted to change modes. I haven't done this with the Arduino yet but it should work very similar. 



This example should do the job just Serial.print(duration,DEC); the duration variable and wiggle your transmitter's joystick on whatever channel your testing to see the changes... 


Also I never owned a scope or a logic analyzer. But I have looked at receiver signals with the Stamp using PulseIn and printing the decimal values to my computer screen using the debug terminal which is similar to using the serial monitor in Arduino speak. You can do a test by connecting only the Ground and the Signal wires from the receiver to an Arduino input pin and  then serial print the value to the serial monitor.

Foot note:  You probably don't want to connect the receiver's +5 vdc to the Arduino unless they are both powered from the Arduino's regulator and that might not be enough to run both depending on the receiver's current needs. If you use different + 5vdc sources just make sure the grounds are common. I do this all the time because i don't like to power too many things especially servo's or even radio receiver's with a micro controllers board's (typically tiny voltage regulator). FYI even small servos can draw 2 amps at stall so I always power them directly from a battery to prevent regulator brownouts or other nasty and weird things.

Randy M. Dumse

unread,
Mar 14, 2012, 1:05:47 PM3/14/12
to hbrob...@googlegroups.com
> Steven Nelson said: Monday, March 12, 2012 9:27 PM

> read the signals directly from the receiver with
> the Arduino and the PulseIn command and then
> output those values to the speed controller using
> the Arduino .

Dr. Huff at UTA did a similar thing with our 'Pods in his UAV.
Basically, system generated inputs to their system. But as a
failsafe, they had an RC receiver also. They ran both sets of
signals into a 'Pod, which read them both, but under normal
circumstances repeated the autonomous system signals out. As
long as the joystick on the RC transmitter was left centered,
the generated controls passed through. But if the joystick was
moved off center, the RC signals took over and were passed. Once
left to settle to the center again, the 'Pod would kick back to
system control. That way, they were able to operate autonomously
on the system, but in case of anything going wrong, the operator
could take over control to fly the UAV out of trouble, then go
back to the system seemlessly.

There's a little bit of a trick to programming such a system to
work in realtime without getting trapped by blocking calls. The
hardware timers in the 'Pod make this easy, because you can set
them to capture a pulse width, then check each input to see if
the pulse was captured, and if it was, change the PWM outputs,
also hardware based, to the new desired PPM or PWM. I'm not sure
if Arduino has that capability.

I'd be very curious to hear, from someone who knows, if the
Arduino does multitasking so several PulseIn and PulseOut words
can run concurrently.

Randy


Chris Palmer

unread,
Mar 14, 2012, 1:54:05 PM3/14/12
to hbrob...@googlegroups.com
One thing to keep in mind, that can make this easier on you, is that you don't need to send (or intercept) signals to multiple servos in parallel. The multi-channel RC radios will send the pulses sequentially (servo1 pulse, followed by servo2 pulse, and so on, then repeat). This works because the servos will operate if they keep getting a pulse every 20ms (worth verifying, but I believe that's the standard). Besides simplicity, I believe this is also done to spread out the power usage of servos, so they don't all spike simultaneousy. You can easily manage 6 or 8 servo signals sequentially in the 20ms window.

This doesn't answer your Arduino question, but might let you continue without worrying about it, unless you needed multiple radios or more servo pulses to generate in parallel.

-Chris

"Randy M. Dumse" <r...@newmicros.com> wrote:

..snip..

James M. Geidl

unread,
Mar 14, 2012, 11:36:40 PM3/14/12
to hbrob...@googlegroups.com
Steve,
 
I'm not ignoring your suggestion, I am thinking about it. 
 
I am testing the output from the Arduino as well as the voltage output from the controller to the motors.   I am actually getting close but don't understand some things.  The range of servo values is very very limited.  I can get reasonable control if I use a range of output values from the Arduino like 45 - 130 or 68 - 107.  These should be 0 - 180 but there is a whole chunk of those values that don't do anything.  I am testing the output from the Arduino right now to see what those values look like.  I can watch them climb and descend in frequency on the scope but that doesn't really tell me much about them. I can watch the values form the RC receive climbing and descend the same way.  I just don't get why the RC receiver input to the controller works OK and the output from the Arduino doesn't.   I am thinking about running the output from a pin to another analog input pin and printing the results in the serial monitor window. 
 

James M. Geidl, K6JMG
D.B. Cooper, you have a message.
 


From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On Behalf Of Steven Nelson
Sent: Monday, March 12, 2012 7:27 PM

James M. Geidl

unread,
Mar 16, 2012, 2:54:37 PM3/16/12
to hbrob...@googlegroups.com
Chris,

The 20ms is what I read everywhere, so you are correct. I'm not feeding
servos so that part really doesn't matter but any information is good
information when you are trying to work out a problem.

James M. Geidl, K6JMG
D.B. Cooper, you have a message.


-----Original Message-----
From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On
Behalf Of Chris Palmer
Sent: Wednesday, March 14, 2012 10:54 AM
To: hbrob...@googlegroups.com
Subject: RE: [HBRobotics] PPM (RC) to PWM converter

-Chris

Steven Nelson

unread,
Mar 17, 2012, 2:49:39 AM3/17/12
to hbrob...@googlegroups.com
Reading a receiver signal without using PulseIn statement.. This is supposed to be much faster..  http://arduino.cc/playground/Code/ReadReceiver 

James M. Geidl

unread,
Mar 17, 2012, 12:53:47 PM3/17/12
to hbrob...@googlegroups.com
Steven,
 
Thanks, I will look into this. 
 
I am making some headway but I'm afraid my original idea just ain't gonna work.
 

James M. Geidl, K6JMG
D.B. Cooper, you have a message.
 



From: hbrob...@googlegroups.com [mailto:hbrob...@googlegroups.com] On Behalf Of Steven Nelson
Sent: Friday, March 16, 2012 11:50 PM
To: hbrob...@googlegroups.com
Subject: Re: [HBRobotics] PPM (RC) to PWM converter

Reply all
Reply to author
Forward
0 new messages