This code is intended to be used as an Arduino library. Create a new directory called ServoDecode in the directory with the other libraries ( ? hardware\libraries\ServoDecode)
Copy ServoDecode.h and ServoDecode.cpp into this directory.
The ServoDecode.pde code should be pasted into the IDE to create a new sketch. This example sketch includes <ServoDecode.h> but if you create your own sketch, you can use the 'Sketch/Import Library' function from the IDE menu.
There is some information in the playground on Arduino Libraries that goes into more detail.
thanks for the great libraries. New life for the old receiver - I used your code with GWS R-4PII/H receiver with only 3 channels working - accidentally burned one channel long time ago. The beauty is I get all 6 channels on arduino. Now I'm wondering if the library could be used to decode Futaba PCM signal? Have you heard if anyone tried that? I found arduino helicopter autopilot thread (another great project) mentions PCM in several places, but looking at the code samples in the thread it seems its just PPM.
The technique used in this library is completely different from that needed to decode a signal encoded using the Futaba PCM protocol. That protocol uses proprietary serial encoding and would required much more processing than the PPM decoding used here.
In my opinion it would not be worth the effort to do this – of course you are welcome to take it on if you are up for the challenge. But I would think in most situations there would be no benefit and for those cases with strong interference you would be better of using 2.4ghz technology.
I just thought it would be fun to get PCM out or PPM receiver. But PPM works great and I don't want to spend time working on PCM if will eat up too much arduino processing power, though your interrupt method could probably be adopted to read the bits of PCM transmission too?
By the way the library works with inverted signals too. For some reason my GWS receiver had it inverted and the only problem i noticed first channel had very high numbers (around 10,000 or so) but the rest of the channels were fine.
In my opinion, PCM would be a lot of work for no benefit. There are many more productive and fun things to do with your time.
BTW, if you want to use the library with a receiver with an inverted output, in ServorDecode.cpp change:
volatile byte pulseEnd = PULSE_START_ON_RISING_EDGE ; // default value
to
volatile byte pulseEnd = PULSE_START_ON_FALLING_EDGE; // inverted pulses
then recompile the library (by deleting ServoDecode.o and rebuilding your sketch)
Bummer, should have asked earlier about the inverted. I already soldered a simple amplifier/inverter right on to GWS R4PII/H
Well, it needed amplifier though - only had 2.5V impulses without it and was getting very noisy feedback from arduino controller back into the receiver. But with this code change i could have gotten away with just one transistor...
Thanks for the info!
I would have thought that the transistor and resistor would have been enough to invert the signal with the 2.5 volt pulses and drive the Arduino input. But no worries if you now have something that works.
Hi, I have a suggestion for the code, instead of using "TCNT1 = 0;", why not remember the previous value of ICR1 and keep track of overflows, this way you can get an unlimited value for the pulse width, also it's more accurate since it takes a few clock cycles to clear TCNT1
Hi Frank, resetting TCNT to 0 takes 250 nanoseconds on a 16Mhz Arduino. Because the timer is counting in 500 nanosecond ticks I don't think this delay makes any difference. Indeed I would be surprised to hear if any of the radio control equipment that would be used with this kind of application would notice differences in timing of less than a microsecond.
I am not clear if the ability to detect unlimited values for the pulse width are something one would would use in radio control or if you have another application for the code.
Many thanks for taking the time to share your comments, its always interesting to see the different ways people approach things.
oh i totally agree that it's overkill, the RC radio would need a 16 bit ADC for the joystick if it wants to make the accuracy worthwhile, i'm not dividing my timer so i'm getting 0.05 microsecond resolution if i run my chip at 20 MHz
Hi all, mem.... could you tell me what would be the designation for the pin 8, i´m using an Arduino Duemilinove board with an atmega 328 and i think pin 8 is not the indicated one for this board . :
Hi again, i think you mean pin 8 at the top board, i haven´t tried yet...i ment IC pin 8(atmega), so i understand now,...i´ve loaded the code and i could visualize the data stream on the arduino serial monitor.
One more dumb question, what are the pin´s used for the outputs ?
I have the ServoDecode_pde sketch working with my chepo VEX transmitter. When I attach my scope probe to the ppm pin to view the pulses while it's going to the arduino it switches to Failsafe mode the moment I touch the pin.
Any ideas what would cause this? The scopes input impedance is 1M ohm. Not sure why this would effect anything. I can see the pulses fine on the scope but the arduino goes immediately into failsafe.
Edit:
I just noticed that if I touch the pull-up resistor with my finger it also goes into failsafe mode.... I'm confused!