PPM decoder

Arduino projects on the go
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

PPM decoder

Post by MaxZ »

Hi all,
Due to a silly mistake at ordering a small Tx and belonging Rx, I am now in need of a PPM decoder. The Tx/Rx combo is primarily aimed at drone flight controllers, and comes without channel trim buttons or mixing facilities.

As I bought it from HK's EU warehouse, I could send it back and get my money reimbursed. But for some reason that means I should send it to an adress in Leeds/UK, which will cost me something like a third of the purchase price, so I'd rather put it to use.

I want to put it to use for a boat or car, but the Rx only delivers PPM and S.Bus/I.Bus, hence the need for a decoder to drive the servo's.
Preferably PPM, because then I can make use of it for a different project as well, providing an external throttle timer on another transmitter which does not have one, by making use of the ppm output for the buddy lead.
And preferably for an ATtiny85, as it is nice and small.
A lot of wishes, I know :roll:

I did some searching, on this forum and elsewhere, and I found viewtopic.php?f=41&t=612, Martin's exquisit little S.Bus decoder. Unfortunately the code is way beyond my capabilities, so I cannot bend it to serve my purpose.

On the other end of the scale I found this: https://create.arduino.cc/projecthub/ab ... ino-c42929, which looks a bit simplistic (but I can understand it :D ). Or is it genius-simple?

Any help would be appreciated.

Cheers,
Max.
bluejets
Posts: 316
Joined: 19 Jun 2019, 04:09

Re: PPM decoder

Post by bluejets »

What is the unit you bought.?
It might be simpler to add a different receiver depending on the transmit type.


https://www.banggood.com/S_BUS-Turn-PWM ... ehouse=CN

https://au.banggood.com/PPM-to-PWM-Adap ... LXLfD_BwE

https://www.ebay.com.au/itm/22422224018 ... KY2_D_BwE
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: PPM decoder

Post by MaxZ »

Hi Bluejets,

This is the unit I bought https://hobbyking.com/nl_nl/turnigy-evolution ... _analytics

I did find some commercial units, but they were all either too big ( I only need 2 or 3 PWM outputs) or too expensive. But the ebay one (Feichao) you linked to fits the bill, so I ordered a few straight away. Thanks!

Just as a project, and not having to wait for their arrival, I would still be interested in a DIY Arduino version though.

Thanks again, cheers,
Max.

(p.s. is there a way to hide these long url's behind some text?)
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

What type of Arduino board do you intend to use?
bluejets
Posts: 316
Joined: 19 Jun 2019, 04:09

Re: PPM decoder

Post by bluejets »

That system is very common with the Flysky radios, I have a couple of the 6 channel Tx's.(Flysky FS-i6)
AFHDS 2A ......there are pwm receivers that suit and are realitively cheap at Bangood etc.
I usually use the iA6B which has pwm out as well as iBus and ppm.
Actually the link you provided has the compatibility listed down lower in the link.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: PPM decoder

Post by MaxZ »

Martin wrote: 14 Jun 2021, 12:34 What type of Arduino board do you intend to use?
Hi Martin,
Preferably the ATtiny85, because of its small size. But if that is too complicated, I could go for the ProMini 5V.

Cheers,
Max.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: PPM decoder

Post by MaxZ »

bluejets wrote: 14 Jun 2021, 13:13 That system is very common with the Flysky radios, I have a couple of the 6 channel Tx's.(Flysky FS-i6)
AFHDS 2A ......there are pwm receivers that suit and are realitively cheap at Bangood etc.
I usually use the iA6B which has pwm out as well as iBus and ppm.
Actually the link you provided has the compatibility listed down lower in the link.
I do have a Turnigy i6 (same as the Flysky), and various Rx's, iA6A and iA6B, a number of the very small Rx from Banggood, AFHDS 2A protocol (but no telemetry), and another one with telemetry, all with PWM which I am happy to use.

But as I outlined in my OP, I do have at least one AFHDS 2A Rx with just the serial outputs, so I am in need of a decoder. As said, I have them on order now, but still would like to continue the arduino project.....

Cheers,
Max.
Last edited by MaxZ on 14 Jun 2021, 14:51, edited 1 time in total.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: PPM decoder

Post by MaxZ »

I did have a closer look at the code presented here:https://create.arduino.cc/projecthub/ab ... ino-c42929.
I arranged it slightly to get a better overview, with proper indents and (with exceptions) one command per line. I also got rid of the "read_RC" routine, by placing it directly in the loop (had to change one of the "i" counters, and changed the name of the temporary array which was not to my liking).

It does not seem very efficient, but it might suffice for my secondary project. Basically, what he does is use the interrupt to register the pulses. The code is specific for a 7 channel Rx, so he captures 15 intervals to ensure the long reset interval is caught with at least a further 7 channels. Then all are transferred to the loop with a temporary array, and rearranged into the final channel array by picking the next 6 channels after the long interval.

Here is my version of the code:

Code: Select all

/*Created by Abhilash Patel
  Comments by MZ:
  The ISR registers 15 time intervals between ppm pulses, with a random start time
  (15 intervals need to be registered to catch the long interval on a 7 channel ppm stream with a random start time)
  After 15 intervals, the values are transferred to a temporary array.
  In the loop, the array is sorted to set the first interval after the long (> 10 ms) interval as channel 1
  6 Channels are registered in the final array (ch[0] remains empty?)
*/

unsigned long int a,b=0,c;
int x[15],tempch[15],ch[7],count;
//specifing arrays and variables to store values 

void setup() {
  
  Serial.begin(9600);
  
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING); // enabling interrupt at pin 2
}

void loop() {
  
  int i,j,k=0;
  for(k=14;k>-1;k--) {
    if(tempch[k]>10000) j=k; //detecting separation space 10000us in the temporary array  
  }                     
  for(i=1;i<=6;i++){
    ch[i]=(tempch[i+j]); //assign 6 channel values after separation space
  }

  Serial.print(ch[1]); Serial.print("\t");
  Serial.print(ch[2]); Serial.print("\t");
  Serial.print(ch[3]); Serial.print("\t");
  Serial.print(ch[4]); Serial.print("\t");
  Serial.print(ch[5]); Serial.print("\t");
  Serial.print(ch[6]); Serial.print("\n");

  delay(100);
}


void read_me() { // ISR, this code reads value from RC reciever from PPM pin (Pin 2 or 3)

  a=micros(); //store time value a when pin value falling
  c=a-b;      //calculating time inbetween two peaks
  b=a;
  x[count]=c;
  count=count+1;
  if(count==15) { //storing 15 value in array (MZQ: why 15?)
    for(int j=0;j<15;j++) { //refresh all values in the (unsorted) temporary array after 15 readings
      tempch[j]=x[j];
    }
    count=0;
  }
}
Cheers,
Max.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

To keep it simple on the ATtiny85, you could disable all interrupts, and do the edge detection and output switching in a tight loop. Use a free-running hardware timer to time the intervals between pulses - the ATtiny85 only has 8-bit timers, but you don't need great resolution because you're not actually measuring each channel - only detecting the difference between the sync pulse and normal pulses. The sync pulse would reset the channel number to zero, and any other pulse would increment it. You'd toggle, the servo output pins based on the channel number for the first two or three channels: for example on receiving the first pulse after the sync pulse, you'd toggle the first servo output off, and the second one on.

The absence of any interrupts would help eliminate jitter, but you'd want a really tight loop for the 'wait for next edge' part. Probably best to use a tiny bit of inline assembler for that - with a 16MHz internal clock you could get it down to less than half a microsecond. The channel counter and output drive could be in normal C++: it doesn't have to be specially fast providing that the delays it introduces are consistent delays.

Whole thing, including the timer set-up, should be less than twenty lines of code. I'm away on a job for the next few days, but I'll see if I can get it working once I'm back, assuming no one has already done it by then.
bluejets
Posts: 316
Joined: 19 Jun 2019, 04:09

Re: PPM decoder

Post by bluejets »

MaxZ wrote: 14 Jun 2021, 13:28
bluejets wrote: 14 Jun 2021, 13:13 That system is very common with the Flysky radios, I have a couple of the 6 channel Tx's.(Flysky FS-i6)
AFHDS 2A ......there are pwm receivers that suit and are realitively cheap at Bangood etc.
I usually use the iA6B which has pwm out as well as iBus and ppm.
Actually the link you provided has the compatibility listed down lower in the link.
I do have a Turnigy i6 (same as the Flysky), and various Rx's, iA6A and iA6B, a number of the very small Rx from Banggood, AFHDS 2A protocol (but no telemetry), and another one with telemetry, all with PWM which I am happy to use.

But as I outlined in my OP, I do have at least one AFHDS 2A Rx with just the serial outputs, so I am in need of a decoder. As said, I have them on order now, but still would like to continue the arduino project.....

Cheers,
Max.
Point was, a complete new receiver is more than likely cheaper than any decoder.
Post Reply