Thread Tools
Jan 13, 2013, 03:42 PM
Registered User
Hasi's Avatar
Thread OP
Discussion

Arduino ppm signal reader and generator


Hy, I just wanted to share my latest project with you. I wrote two codes in arduino:

The first one generates a fully customizable ppm signal. You can change the number of channels, the polarity, the ppm frame length and the pulse length.
Download: http://code.google.com/p/generate-ppm-signal

The second one reads any kind of ppm signal. It doesn't matter which polarity, which frame length, which pulse length it has. It will still read the signal and put the servo values in an array called ppm.
Download: http://code.google.com/p/read-any-ppm

Please only use this code if you know what you are doing. Donations are kindly accepted (look for the link on google code).
Last edited by Hasi; Oct 25, 2014 at 02:37 PM.
Sign up now
to remove ads between posts
Jan 17, 2013, 03:59 AM
Registered User
So the first one reads for example all the channels from the receiver and then generates a ppm stream?
Jan 17, 2013, 04:05 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by msev
So the first one reads for example all the channels from the receiver and then generates a ppm stream?
You have to write the part, where it reads the channels, but yes.
Jan 17, 2013, 04:22 AM
Registered User
So you have to know how the signal stream that comes from the rx to the arduino looks like?
Jan 17, 2013, 04:29 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by msev
So you have to know how the signal stream that comes from the rx to the arduino looks like?
Thatīs just a simple pwm signal. It will be high for about 1000-2000us. 1500us is the middle position and so on...
Jan 17, 2013, 04:33 AM
Registered User
It would be interesting for turnigy 9x receiver users (there must be thousands of them), if you could write some sort of failsafe detection system...Since on some channels it goes blank and on others the signal stays...So on a particular channel bound to some autopilot the arduino would emulate a certain position of a switch (so that it would trigger RTH for example)...Hope you get what I mean
Jan 18, 2013, 07:35 AM
Registered User
rimshotcopter's Avatar
Thank you, Greatly appreciated.
Jan 18, 2013, 11:57 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by msev
It would be interesting for turnigy 9x receiver users (there must be thousands of them), if you could write some sort of failsafe detection system...Since on some channels it goes blank and on others the signal stays...So on a particular channel bound to some autopilot the arduino would emulate a certain position of a switch (so that it would trigger RTH for example)...Hope you get what I mean
It doesn't sound complicated. If there is anyone else, who would need this, I might write the code for it.

Quote:
Originally Posted by rimshotcopter
Thank you, Greatly appreciated.
You welcome!
Jun 28, 2013, 09:29 AM
Registered User
cool
Last edited by IMATs; Jun 29, 2013 at 12:18 PM.
Jun 28, 2013, 01:52 PM
Registered User
midelic's Avatar
Hasi,
I uploaded the FlySky TX module code here:
https://www.rcgroups.com/forums/show....php?t=1921870
Thanks!
Jun 28, 2013, 03:05 PM
Registered User
Hasi's Avatar
Thread OP
That's the "magic" of open source.
Jun 28, 2013, 03:06 PM
Registered User
rimshotcopter's Avatar
Quote:
Originally Posted by Hasi
That's the "magic" of open source.
+1 to that!
Jul 18, 2013, 03:29 PM
Registered User
HaxK's Avatar
HI, I need to read a PPM stream, add one channel (clone the channel 3 actually) and output a new PPM stream. I've read and tried to mod several PPM reading/writing sketches but yours seems more clear and the PPM reading sketch works fair better than others.

I've mixed both sketches in one and I'm able to read the PPM in but the PPM out doesn't work. I've seen that the
Code:
attachInterrupt(ppm_in_Pin - 2, read_ppm_in, CHANGE);
line is the one who prevents the PPM out to work but without this the PPM IN will not work.

Could you help me with this issue? I'm a newbie with interrupts.
Jul 18, 2013, 10:46 PM
Registered User
Nice code! Can I borrow it for my transmitter project?
Jul 19, 2013, 03:32 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by HaxK
HI, I need to read a PPM stream, add one channel (clone the channel 3 actually) and output a new PPM stream. I've read and tried to mod several PPM reading/writing sketches but yours seems more clear and the PPM reading sketch works fair better than others.

I've mixed both sketches in one and I'm able to read the PPM in but the PPM out doesn't work. I've seen that the
Code:
attachInterrupt(ppm_in_Pin - 2, read_ppm_in, CHANGE);
line is the one who prevents the PPM out to work but without this the PPM IN will not work.

Could you help me with this issue? I'm a newbie with interrupts.
Both codes will not work together, because both use timer1, but in a different way. You'll have to write your own for that.



Quote:
Originally Posted by patolin
Nice code! Can I borrow it for my transmitter project?
Shure! Feel free to use it!
Jul 19, 2013, 12:29 PM
Registered User
HaxK's Avatar
I've tried to recode the sketches using the timer2 from the AVR but wont read. Maybe the 8bit resolution of that timer is not enough?

Ive started with the PPM reader but can't read the PPM stream.

Ive included the line "Serial.println(counter);" to see the values stored on tat vaiable and with timer1 they are near 800 but with timer 2 the are very lower.

I've played with the prescaling (in the code atached the prescaling is deactivated) but cant even get closer to timer1

What approach you suggest?


Code:
/*This program puts the servo values into an array,
 reagrdless of channel number, polarity, ppm frame length, etc...
 You can even change these while scanning!*/

#define ppm_in_Pin 3  //this must be 2 or 3
int ppm_in[16];  //array for storing up to 16 servo signals

void setup()
{
  Serial.begin(115200);
  Serial.println("ready");

  pinMode(ppm_in_Pin, INPUT);
  attachInterrupt(ppm_in_Pin - 2, read_ppm_in, CHANGE);
  
  TCCR2A = 0;  //reset timer1
  TCCR2B = 0;
  TCCR2B = (0<<CS22) | (0<<CS21) | (1<<CS20);  // pre-scaler.
}

void loop()
{
  //You can delete everithing inside loop() and put your own code here
  int count;

  while(ppm_in[count] != 0){  //print out the servo values
    Serial.print(ppm_in[count]);
    Serial.print("  ");
    count++;
  }
  Serial.println("");
  delay(100);  //you can even use delays!!!
}



void read_ppm_in(){  //leave this alone
  static unsigned int pulse;
  static unsigned long counter;
  static byte channel;

  counter = TCNT2;
  TCNT2 = 0;
  Serial.println(counter);
  if(counter < 1020){  //must be a pulse if less than 510us
    pulse = counter;
  }
  else if(counter > 3820){  //sync pulses over 1910us
    channel = 0;
  }
  else{  //servo values between 510us and 2420us will end up here
    ppm_in[channel] = (counter + pulse)/2;
    channel++;
  }
}
Jul 21, 2013, 03:22 PM
Registered User
Hasi's Avatar
Thread OP
I also don't know. That's why they are not compatible.
Jul 21, 2013, 03:36 PM
Registered User
midelic's Avatar
If you use 8 bits timer counts from 0 to 255....so it cannot count more than 8 bits values like....... 1000-2000 us normal servo timing.For that you need to use a 16 bits timer which is not posible atm or a 8 bits timer a suitable prescaller and range conversion algorithm code from 0 - 255 range to 1000-2000 normal range for servo data....and a lot of testing.Better use viceversa...... timer 1 for decoding and timer0 for encoding.
This is a general explanation of why it is not working your code.
Jul 23, 2013, 09:07 AM
Registered User
HaxK's Avatar
But timer 0 is a 8bit timer same as timer2, also, timer1 and timer0 share the same prescaler... I'm giving up on this issue.

The PPM link from RX1 to the Wookong works nice and only the PPM link from RX2 to Zenmuse gimbal fails. Can't understand why DJI is so stupid to program the GCU to ignore the PPM ch3, and want a PPM ch9 to set the camera orientation on FPV mode. This nonsense makes impossible to use an 8CH receiver to control it.

At the end it's easier to wire all channels old way and forget this issue.

Thanks to everyone for your help, at least I've learnt to read and write PPM signals which will be useful for other projects.
Last edited by HaxK; Jul 23, 2013 at 09:13 AM.
Jul 23, 2013, 11:48 PM
Registered User
Hasi, thanks for your code, you rock!. I need to improve my avr coding

Im using it in a custom Arduino based transmitter. Check it out in this post

https://www.rcgroups.com/forums/show...1817699&page=8
Oct 14, 2013, 06:16 AM
Registered User
Hi Hasi

Great project. Just a couple of questions;
  1. Is the 5V logic level generated by Arduino suitable for the Turnigy 9X and 9XR?
  2. When using your code with my Turnigy 9X transmitter I find that it works for 1-2s out of every 10s. Any thoughts as to why this would occur?

Cheers

Jase
Oct 22, 2013, 07:51 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by ilovetoflyfpv
Hi Hasi

Great project. Just a couple of questions;
  1. Is the 5V logic level generated by Arduino suitable for the Turnigy 9X and 9XR?
  2. When using your code with my Turnigy 9X transmitter I find that it works for 1-2s out of every 10s. Any thoughts as to why this would occur?

Cheers

Jase
1) Yes
2) I donīt really understand your question, could you please clarify?
Nov 14, 2013, 06:51 PM
Registered User

great code


thanks for sharing. it's just a pity that both the ppm reader and generator cannot work on the same arduino.

Many of us are trying to modify certain channels in the ppm stream and output the modified ppm signal.

for rearranging the channels or applying some mixes.

is the limitation only the timer1? can we have say timer1 read the ppm then a new timer2 handle the ppmout part?
Last edited by AeroM'ck'y; Nov 19, 2013 at 07:14 PM.
Nov 24, 2013, 12:23 PM
Registered User
Fist of all you don't need the timer to read PPM. There is easy alternative way - catch faling(or raising) edge of ext1 pin and use micros() call to measure time difference. And after this - use timer1 for generating PPM.

Or, if you don't want to use micros() - alternative way: use as time source timer 0 with 8 prescaler and timer 2 with 1024 prescaler, and combine them as

TCNT0 | (TCNT2 & 0xFE << 7) - in this case you will have 0.5ms resosution instead of 1ms in micro() function using case.
Nov 27, 2013, 06:24 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by Tahorg
Fist of all you don't need the timer to read PPM. There is easy alternative way - catch faling(or raising) edge of ext1 pin and use micros() call to measure time difference. And after this - use timer1 for generating PPM.

Or, if you don't want to use micros() - alternative way: use as time source timer 0 with 8 prescaler and timer 2 with 1024 prescaler, and combine them as

TCNT0 | (TCNT2 & 0xFE << 7) - in this case you will have 0.5ms resosution instead of 1ms in micro() function using case.
Thanks for the input, I might try that. Btw, as far as I know the resolution of micros() is 4 and thatīs why I didnīt use it. (Itīs fine for eg. controlling leds, but not really for flying.)
Dec 02, 2013, 01:00 PM
Registered User
https://code.google.com/p/rcjoy/sour...%2Fppm_decoder

I've uploaded there my PPM->PWM converter and there you can find how I do measure the pulse width with .5ms precision using 8bit Timer2. It's my working code, and idea is very simple - on timer event increment additional variable. In this case I always can easy calcualte current "time" ticks as

TCNT2 | (Counter << 8)
Dec 02, 2013, 02:07 PM
Registered User
midelic's Avatar
Nice job...I can think of several aplications on small SOIC8 avr chips.
How about a ppm encoder using a 8 bits timer(good resolution).?.that is one I want to see.
Dec 02, 2013, 02:52 PM
Registered User
I'm afraid that PPM generator is much harder to make on 8 bit timer. On STM32 I've built PPM gen using PWM mode of timer, I can give you the code of it, but there I can specify not only OCR but also the TOP value of timer counter, this is impossible in avr.
Dec 02, 2013, 03:06 PM
Registered User
midelic's Avatar
I know that....trying to make one myself...I don't think is imposible in avr.,,maybe one day.
Dec 04, 2013, 12:06 PM
Registered User
Hasi's Avatar
Thread OP
As I don't have 2 trainer cables, I can't test it, so I will not be able to write the code. But if anyone manages to write and test the code, I'll include it in my code and probably make a library out of it.
Dec 11, 2013, 01:23 PM
Registered User
Hi

hasi ..can adapt arduino code software for PIC microcontroller encoder-decoder?
Dec 11, 2013, 02:02 PM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by bubulinu
Hi

hasi ..can adapt arduino code software for PIC microcontroller encoder-decoder?
What?
Dec 11, 2013, 02:54 PM
Registered User
You can modify the code to work with pic microcontroller ex 16F630,676? encoder - decoder

ppm generator for eencoder - tx
ppm reader for decoder - rx

it is posible?
Last edited by bubulinu; Dec 11, 2013 at 03:00 PM.
Dec 12, 2013, 04:42 AM
Registered User
Hasi's Avatar
Thread OP
Sure it is possible, but I wonīt do it.
Feb 01, 2014, 04:50 PM
Hello, I have a project (using multiwii code as base) that requires reading a PPMsum signal from the Rx and passing it through when a failsafe isn't detected. The idea is that it will create a new PPM sum signal for RTH when the failsafe is triggered. Can you provide some advice/tips on how to setup the passthru? i.e., could you show me how to use your examples to create a simple PPM sum passthru routine (input on one pin, output the same signal on another)???
Apr 19, 2014, 01:34 PM
Can't fly, can't live.
Failsafe! Pretty please...
Oct 25, 2014, 05:43 AM
Registered User

Arduino ppm signal reader


Hi all

for Hasi
I would like to build the diagram below.
What should I change in the code "Arduino ppm signal reader" to work?
Arduino nano v3.
Please help me..
Best regards!
Oct 25, 2014, 09:56 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by bubulinu
Hi all

for Hasi
I would like to build the diagram below.
What should I change in the code "Arduino ppm signal reader" to work?
Arduino nano v3.
Please help me..
Best regards!
Take a look at the Servo library in Arduino.
Oct 25, 2014, 12:10 PM
Registered User

Hi Hasi


I looked, what do you mean?
Oct 25, 2014, 12:19 PM
Registered User
Hasi's Avatar
Thread OP
I meant use it!
Oct 25, 2014, 12:33 PM
Registered User
sorry, do not understand what you mean ,I hope you do not mind
the code you posted goes without any modification for 3ch??



I sent you a pm
Last edited by bubulinu; Oct 25, 2014 at 01:12 PM. Reason: no reason
Oct 25, 2014, 02:14 PM
Registered User
Hasi please tell me what steps you have to follow, give me an example or something.
I understand I need to introduce servo code in your code?
Oct 25, 2014, 02:23 PM
Registered User
midelic's Avatar
These things not working like that.....explaining in words only(anyway it takes a book to explain all because coming problems one after another).You need an entire course of arduino...or C++,and also knowledge about RC stuff like PPM signal and servo PWM signals..how they are generated.And need start working with small code and test a lot,understand what you test ........ takes a lot of time..
Last edited by midelic; Oct 25, 2014 at 02:31 PM.
Oct 25, 2014, 02:33 PM
Registered User
Hasi's Avatar
Thread OP
I made an update to immediately output servo value on predefined pins. Have not tested it though...
Oct 26, 2014, 03:18 AM
http://3roomlab.blogspot.sg/
3roomlab's Avatar
Quote:
Originally Posted by midelic
These things not working like that.....explaining in words only(anyway it takes a book to explain all because coming problems one after another).You need an entire course of arduino...or C++,and also knowledge about RC stuff like PPM signal and servo PWM signals..how they are generated.And need start working with small code and test a lot,understand what you test ........ takes a lot of time..
well im not doing anything arduino-ish, im trying to first understand the actual PPM stream protocol. as i understood ... (or not?)

1) many websites describe the PPM as 20ms frames, this 1 says its 22.5ms, and that it is maxed at 8channels. http://www.mftech.de/ppm_en.htm. i saw a frame capture plot from futaba (another thread in this forum), and it is actually 27ms. so in actual, there isnt really a max channels is there? and by the 27ms futaba frame, there is no such 50Hz standard too right?
2) so there are 2 major camps of PPM stream format, a positive mark type, and a spaced type (inverted futaba style). i am assuming that the norm is actually the positive style? is there even more formats out there (PPM based)?
3) some sites denote the header of each channel is 0.3ms, some 0.7ms in either a mark/space. there are some diagrams which denotes it as 1ms and active data is between 1.25-1.75ms. so an actual "bit" with neutral data is 1.5ms. with this i assume that every "bit" of channel data actually has only a 1ms data, the other approx 0.3-1.0ms is only used as a "header", in decoding, a servo subtracts the "head" to get the actual PWM width of the 2nd 1ms, am i right? due to this variances of the "head" bit, is that why most TX only work with its own RX? or there is actually a universal TX/RX?
4) is there a standard minimum length for blanking? 2 "bits" long (4ms)? 3?
Oct 26, 2014, 07:38 AM
Registered User
midelic's Avatar
Your answered yourself.Nothing is fixed in RC business it depends on what is the destination.


Quote:
Originally Posted by 3roomlab
well im not doing anything arduino-ish, im trying to first understand the actual PPM stream protocol. as i understood ... (or not?)

1) many websites describe the PPM as 20ms frames, this 1 says its 22.5ms, and that it is maxed at 8channels. http://www.mftech.de/ppm_en.htm. i saw a frame capture plot from futaba (another thread in this forum), and it is actually 27ms. so in actual, there isnt really a max channels is there? and by the 27ms futaba frame, there is no such 50Hz standard too right?
2) so there are 2 major camps of PPM stream format, a positive mark type, and a spaced type (inverted futaba style). i am assuming that the norm is actually the positive style? is there even more formats out there (PPM based)?
3) some sites denote the header of each channel is 0.3ms, some 0.7ms in either a mark/space. there are some diagrams which denotes it as 1ms and active data is between 1.25-1.75ms. so an actual "bit" with neutral data is 1.5ms. with this i assume that every "bit" of channel data actually has only a 1ms data, the other approx 0.3-1.0ms is only used as a "header", in decoding, a servo subtracts the "head" to get the actual PWM width of the 2nd 1ms, am i right? due to this variances of the "head" bit, is that why most TX only work with its own RX? or there is actually a universal TX/RX?
4) is there a standard minimum length for blanking? 2 "bits" long (4ms)? 3?
Oct 26, 2014, 07:54 AM
Registered User
midelic's Avatar
Hasi,

Nice piece of code you made ,I like it and used myself
I see you introduced a constant "multiplyer".
One observation though,The way you used doens't make much sense.Probably you introduced it for different frequency other than 16 Mhz.
To make sense the code should be like this.

//************************************
#define multiplyer (F_CPU/8000000) //leave this alone

void read_ppm(){ //leave this alone
if(counter < 510*multiplyer){ //must be a pulse if less than 510us
pulse = counter;
//blah blah
}else if(counter > 1910*multiplyer){
//blah
} else{ //servo values between 510us and 2420us will end up here
ppm[channel] = (counter + pulse)/multiplyer;
//blah
}
}
//*********************

I use it like that for my Atmega8/8mhz projects.
Oct 26, 2014, 01:03 PM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by midelic
Hasi,

Nice piece of code you made ,I like it and used myself
I see you introduced a constant "multiplyer".
One observation though,The way you used doens't make much sense.Probably you introduced it for different frequency other than 16 Mhz.
To make sense the code should be like this.

//************************************
#define multiplyer (F_CPU/8000000) //leave this alone

void read_ppm(){ //leave this alone
if(counter < 510*multiplyer){ //must be a pulse if less than 510us
pulse = counter;
//blah blah
}else if(counter > 1910*multiplyer){
//blah
} else{ //servo values between 510us and 2420us will end up here
ppm[channel] = (counter + pulse)/multiplyer;
//blah
}
}
//*********************

I use it like that for my Atmega8/8mhz projects.
I tried to make the code compatible with 16 and 8Mhz projects. Yeah, you're right. I corrected it in the next version (V0.5).
Jan 21, 2015, 10:51 AM
Registered User
Hi,
very good job !
i arrived to read my PPM signals with your code
however i would like to send the read PPM signals on another pin of arduino, but i don't know if it's possible and how i can make it
If somebody can help me
best regards
Jan 21, 2015, 02:46 PM
Registered User
Hasi's Avatar
Thread OP
You cannot use both of my codes at the same time.
Jan 21, 2015, 03:01 PM
Registered User
it is possible to make one code who decode all signals and after encode all the signals on another pin please ?
best regards
Jan 22, 2015, 01:42 AM
Registered User
Quote:
Originally Posted by midelic
One observation though,The way you used doens't make much sense.Probably you introduced it for different frequency other than 16 Mhz.
Doesn't make much sense to constantly be doing multiply and divide operations on longs with an 8-bit processor.
Jan 22, 2015, 04:22 AM
Registered User
I need to encode the signals to PPM sum because i want to send it on PPM Sum input's KK2
Jan 22, 2015, 12:18 PM
Registered User
pierrotm777's Avatar
Quote:
Originally Posted by sv650s
I need to encode the signals to PPM sum because i want to send it on PPM Sum input's KK2
I think that this link can help you

You have also this solution that use le Asynchronous libraries : http://p.loussouarn.free.fr/arduino/...cPpmFrame.html
Jan 22, 2015, 02:20 PM
Registered User
Hi
For the first link, itīs impossible to mixe the 2 codes....
And i already use the second code in this think to decode the signal

For the second link, i will read this as soon as possible

Somebody have already make this ? I'm not the first ?
Thanks for your help
Jan 22, 2015, 06:19 PM
Quote:
Originally Posted by sv650s
Hi
For the first link, itīs impossible to mixe the 2 codes....
And i already use the second code in this think to decode the signal

For the second link, i will read this as soon as possible

Somebody have already make this ? I'm not the first ?
Thanks for your help
search google for "arduino PWM to PPM encoder" and you will find more info.

Also, FYI, you can purchase one of these modules for that specific purpose:
http://www.ebay.com/itm/8-Channel-Re...item3cef951837
Jan 23, 2015, 02:24 AM
Registered User
Your link doesn't work ....
i have already search on google for "arduino PWM to PPM encoder", but each time i don't arrive to mixe the find code avec my first part...
Jan 23, 2015, 02:35 AM
Quote:
Originally Posted by sv650s
Your link doesn't work ....
i have already search on google for "arduino PWM to PPM encoder", but each time i don't arrive to mixe the find code avec my first part...
google "8 Channel Receiver PWM to PPM Encoder"
try this:
http://www.google.com/search?q=8+Cha...to+PPM+Encoder
Jan 23, 2015, 03:01 AM
Registered User
ok i see... but i don't want to use an external module
i want decode an encode are make by the arduino
i always arrived to decode the signal and send it on 5 pins of arduino mega
i've just tried to transfer the program on an arduino NANO V3 but this doesn't work ...
Why ? the program maybe not compatible with arduino NANO ? it's possible ?
Jan 23, 2015, 03:10 AM
If you don't want to buy an external module, then you'll need to go read & study how PWM and timers work on AVR processors. There are many tutorials on the web. You need to understand how this process works if you insist on trying to setup a non-standard configuration.
Jan 23, 2015, 04:37 AM
Registered User
This thread has been going on for quite some time...
There's lots of PPM examples out there. I suggest looking at APM code. They've been dealing with PPM for a long time now. They were even foolish enough to use it for interprocessor communication.

In any case, robust code is a must. APM used to have MANY flyaways related to poor PPM code. They were finally forced by users to upgrade the code to properly handle things like failsafe behaviors.

https://github.com/diydrones/ardupil.../Tools/ArduPPM

You probably won't find any better source than this.
Jan 23, 2015, 04:48 AM
Registered User
Not sure if i understand what your trying to do.
I think you want to decode a ppm stream then re-encode it to output on a different pin.
This is ez to do with a Teensy and the Pulse position library.
I did a project similar to mix 2 head tracker inputs and combine them onto 1 output to go to the TX. Also added some local switches and a 6 button input for mode control with ardupilot.

https://forum.pjrc.com/threads/25265-Arduino-RC-library
Jan 23, 2015, 05:36 AM
Registered User
I want to decode PPM Sum signal from receiver, after i will modify this values and finally i want to encode all these news values in PPM Sum and output the new signal on another pin of arduino
Actually i enter the PPM sum from receiver on pin 2 of my arduino NANO and i arrived to decode the signal and i arrive to modified these values for each channel
But now my problem is to encode this new values of each channel and output this new PPM Sum signal on another pin...
Jan 23, 2015, 05:43 AM
Registered User
midelic's Avatar
Put the new values in new buffer array 16 bits variable.and use hasi PPM encoder with the new variable name. add new pin for PPM out ....code is on first post..where is the problem?
Jan 23, 2015, 05:58 AM
Registered User
I think there is a conflict with timer when i mixe the 2 code in star of this thread
Midelic, i'm curious to see how you write the code for that because it doesn't work for me
Jan 23, 2015, 06:21 AM
Registered User
Hasi's Avatar
Thread OP
You cannot use both of my codes, because they both use Timer1 and they are configured differently.
Jan 23, 2015, 06:59 AM
Registered User
midelic's Avatar
Use PPM decoder on timer0 ,prescaller 256 or 1024 .....and encoder on timer1...where is the problem?
Jan 23, 2015, 07:05 AM
Registered User
I don't know how to use 2 timers ....
Can you make me an exemple please ?
Thanks very much
Jan 23, 2015, 07:37 AM
Registered User
midelic's Avatar
Ask our host here...I'm only a guest ..just passing by.
Jan 23, 2015, 07:53 AM
Registered User
Use the Teensy, it is a very trivial task to do what you want and the ppm signals are extremely accurate and stable. The Pulse Position library allows up to 6 streams either in or output in any combination.
When i was looking for a way to do my project i kept finding people had timing issues when trying to have both a decode and an encode on the one arduino.
Jan 23, 2015, 07:59 AM
Registered User
Ok, i'm just looking for Teensy
But i have never used Teensy.....
Jan 23, 2015, 08:03 AM
Registered User
its just an arduino on steroids really. you ad an extension to the aduino environment and compile as usual.
https://www.pjrc.com/teensy/teensy31.html
Jan 23, 2015, 08:13 AM
Registered User
Have you got some examples of what i want to do on a teensy ?
Witch board i will must use ?
Jan 23, 2015, 08:18 AM
Registered User
midelic's Avatar
Ask "kindly" Hasi and he will make the code for you in 5 minutes on promini .
Jan 23, 2015, 08:25 AM
Registered User
I did the head tracker mixer at the first link. use the Teensy 3.1
https://forum.pjrc.com/threads/25265-Arduino-RC-library
I did document it here as well https://www.rcgroups.com/forums/show...ghlight=teensy
There is a project on the ardupilot site that reads mavlink and translates them to frsky protocol
There is an sbus library , but i can't remember where at the moment
Jan 23, 2015, 08:42 AM
Registered User
Hasi has answer me it's not possible to use the 2 code
So maybe it's not possible to have solution at my problem

Whimsical, i will look your link as soon as possible
Thanks
Jan 23, 2015, 09:23 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by midelic
Use PPM decoder on timer0 ,prescaller 256 or 1024 .....and encoder on timer1...where is the problem?
The problem is, that timer0 only has a resolution of 256. I guess I could add a routine that counts how many times the times has overflown and multiply that by 256 and add it to the interrupt value.
The main problem is testing, since I don't have an oscilloscope, I cannot test the generating code.
Jan 23, 2015, 09:31 AM
Registered User
midelic's Avatar
There is already PPM decoder on micros() timer0 used in multiwii...so no need too much thinking.
Another option you can make a PPM decoder using your code on timer zero without using overflow interrupt. .....with prescaller 256
256*0.0625*255=4080us...enough for max servo data(around 2000us).No need to be very accurate you can calculate the offset and adjust the output on PPM signal generated afterwards.
For testing no need you have sv650 ..as "guinea pig" helper.
Last edited by midelic; Jan 23, 2015 at 09:41 AM.
Jan 23, 2015, 11:10 AM
Registered User
Sorry, but i'm lost .....
Is it possible than arduino nano is overflow in less than one seconde of decode PPM Sum signal ?
Because i use the decode code from Hasi i have put it in my arduino nano
With serial monitor i see all values itīs good, actually i not recode the signal and i send them directly to my flight control board KK2, but this one doesn't see nothing....
And the same thing on arduino mega works very well
So, what is the problem ?

The arduino nano arrive to decode the PPM sum signal, i arrived to see values in serial monitor, but when i make a .writeMicroseconds for sending one signal (aileron for example) there is nothing on the KK2, but works very well with a MEGA........

For midelic, i'm sorry i don't understand your last sentence, i'm french....
Jan 23, 2015, 12:02 PM
Registered User
midelic's Avatar
It is an expression means you can help test the code from Hasi..is not offensive.
arduino nano is using Atmega328 chip and arduino mega is using Atmega 1280/2560 different chip, different timers ,different animal.
Last edited by midelic; Jan 23, 2015 at 12:10 PM.
Jan 23, 2015, 12:54 PM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by midelic
There is already PPM decoder on micros() timer0 used in multiwii...so no need too much thinking.
Another option you can make a PPM decoder using your code on timer zero without using overflow interrupt. .....with prescaller 256
256*0.0625*255=4080us...enough for max servo data(around 2000us).No need to be very accurate you can calculate the offset and adjust the output on PPM signal generated afterwards.
For testing no need you have sv650 ..as "guinea pig" helper.
Besides the accuracy, there is also another problem with using the 256 prescaler. You also have to measure the sync pulse, which can be much higher than 4080us.

I just tried to use timer2 and do what I described above, but there is a bug, that I cannot explain.
Jan 23, 2015, 01:15 PM
Registered User
midelic's Avatar
No need to measure sync pulse when decoding PPM signal you want only valid signals if TCNT0 more than 250 discard the data ....return.The interrupt is on PPM pin not on timer.The PPM signal drive your code not opposite.
And atmega328 have also 1024 prescaler max not 256.
Jan 23, 2015, 01:16 PM
Registered User
Thanks for your help men !
I just hope i will can have a code who work one day on my arduino nano
I will be very happy to have this work
I will continue to search a solution
Jan 23, 2015, 01:28 PM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by midelic
No need to measure sync pulse when decoding PPM signal you want only valid signals if TCNT0 more than 250 discard the data ....return.The interrupt is on PPM pin not on timer.The PPM signal drive your code not opposite.
And atmega328 have also 1024 prescaler max not 256.
Still, I really don't think that ~65 steps of resolution is enough. That's what you get with 256 prescaler.
Jan 23, 2015, 01:32 PM
Registered User
midelic's Avatar
Take the code on multiwii based on micros().,,or you can make one like that...
start a timer time =micros() in interrupt ; and any consequent interrupt you calculate the difference and found the timing.I would use micros resolution is 4us.
Jan 23, 2015, 01:36 PM
Registered User
Hasi's Avatar
Thread OP
Yeah, that is also a possibility. But the accuracy would still not be as high as with my code. micros() has an accuracy of 4us on 16MHz.
Jan 23, 2015, 01:39 PM
Registered User
midelic's Avatar
Yes but is not bad ,,, for what he needs the end result is encding again in PPM signal on 16 bits,,you can compensate.It is used very good and for many years in multiwii...I saw quads flying very good with that decoder.

Or he can use atmega 2560 he have already and those many timers on 16 bits.
Jan 23, 2015, 02:03 PM
Registered User
Hasi's Avatar
Thread OP
So sv650s, this should do it. Beware, that accuracy for reading ppm is 4us, which is not that bad (about 500 steps). I did not test the code, let me know if it works.
Jan 23, 2015, 02:10 PM
Registered User
midelic's Avatar
I remember some code with micros() on 0.5us using timer2.
http://electricrcaircraftguy.blogspo...-function.html
Jan 23, 2015, 02:32 PM
Registered User
Ok thanks very much Hasi
I will test that code on sunday, i hope it will work on my arduino nano
I will say you the result as soin as possible
Thanks again vey much
Jan 23, 2015, 04:44 PM
Registered User
i have just tried this code quickly on my arduino MEGA
but after 1 or 2 seconds, the serial monitor stop ...
with your code, now i can see something on the KK2 but it's not good, the result is strange...
For information, i use a RX receiver LemonRX PPM Sum

Lemon DSMX PPM (6-Channel ONLY) Receiver LM0006

Do i must change value in this
Quote:
#define chanel_number 8 //set the number of chanels
#define default_servo_value 1500 //set the default servo value
#define PPM_FrLen 22500 //set the PPM frame length in microseconds (1ms = 1000ĩs)
#define PPM_PulseLen 300 //set the pulse length
#define onState 1 //set polarity of the pulses: 1 is positive, 0 is negative
and here ?

Quote:
if(counter < 710){ //must be a pulse if less than 710us
pulse = counter;
}
else if(counter > 1910){ //sync pulses over 1910us
channel = 0;
Thanks for your help, it's better, now i have something on the screen of kk2 but it's not good at all
Jan 23, 2015, 05:34 PM
Registered User
Hasi's Avatar
Thread OP
How is it not good, what is the problem?
Jan 23, 2015, 05:48 PM
Registered User
The serial monitor stop working after one second approximatly
I have the framelen in serial monitor
And on kk2 , channels not'respond well...
How can i display values of each channel read on pin 3 in serial monitor ?
And display values send on pin 10 ?
With this i will can know more of what's go wrong
Thanks again Hasi
Jan 24, 2015, 01:36 AM
Registered User
midelic's Avatar
You cannot activate serial debugging and monitor on real time,,....that is only for debugging.
When you test on KK board serial must be stopped of course the channels not working well.On top of that the serial debug is on pin interrupt.
So or serial monitor or KK board not both at the same time.
Jan 24, 2015, 02:22 AM
Registered User
i have tried again with deactivate serial monitor, thanks for the information midelic
but this not work ... there are values on kk2's screen but there are fixe, when i move
the sticks of my radio RC the values doesn't change there are all (the 6) at 1230....

for Hasi :
why you have put values in this sketch
710us and 1910us and ppm[channel] = counter + pulse;

and in you first decode sketch you have put
1020us and 3820us and ppm[channel] = (counter + pulse)/2;
Last edited by sv650s; Jan 24, 2015 at 03:59 AM.
Jan 24, 2015, 05:58 AM
Registered User
Hasi's Avatar
Thread OP
Quote:
Originally Posted by sv650s
i have tried again with deactivate serial monitor, thanks for the information midelic
but this not work ... there are values on kk2's screen but there are fixe, when i move
the sticks of my radio RC the values doesn't change there are all (the 6) at 1230....

for Hasi :
why you have put values in this sketch
710us and 1910us and ppm[channel] = counter + pulse;

and in you first decode sketch you have put
1020us and 3820us and ppm[channel] = (counter + pulse)/2;
You have to assign the ppmWrite array something to transmit of course. See the loop part of the code. You have to do that for every channel.

I changed the values for compatibility with other systems.

edit. Try this code, it should directly output the ppm values, that it reads.
Last edited by Hasi; Jan 24, 2015 at 06:04 AM.
Jan 24, 2015, 06:35 AM
Registered User
For information i have contact lemonrx and they say me that
"It's standard PPM signal. 1 to 2 ms for full travel per channel (*depending on your transmitter setting, you may also get up to about 0.85ms to 2.15ms with maximum travel set of over 100% under your Spektrum transmitter)."

And what do you want to say by
"You have to assign the ppmWrite array something to transmit of course. See the loop part of the code. You have to do that for every channel."
Jan 24, 2015, 07:40 AM
Registered User
Hasi's Avatar
Thread OP
It's like digitalRead and digitalWrite. You can read the incoming ppm values with ppmRead[] and you can send new ppm values with ppmWrite[].
Jan 24, 2015, 08:30 AM
Registered User
Ok thanks for information
Hasi, can you post a .txt file of your last sketch please ? Because i'm not at my home (i will be back at home only tomorrow afternoon) and i'm on ipad so i can't view .ino files
These will give me the possibility to see and try to understand your code
Last edited by sv650s; Jan 24, 2015 at 08:39 AM.
Jan 24, 2015, 11:33 AM
Registered User
Hasi's Avatar
Thread OP
Just rename it to .txt


Quick Reply
Message:

Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Discussion DIY PPM generator PPM reader and PPM expander Dennis Frie FPV Talk 63 Sep 12, 2016 03:01 PM
Question PPM to TX problem with arduino generated PPM Nase DIY Electronics 65 Jul 22, 2016 06:42 PM
Discussion Help: arduino ppm values to th9x slave rcpilotp51 DIY Electronics 6 Mar 04, 2012 06:13 AM
Question generate PPM signal for "Nine Eagles" Transmitter Nase Radios 3 Aug 27, 2010 06:04 PM
Discussion Generate a PPM signal fkendoul UAV - Unmanned Aerial Vehicles 0 Dec 15, 2007 10:22 AM