PPM decoder

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

Re: PPM decoder

Post by MaxZ »

bluejets wrote: 15 Jun 2021, 11:16 Point was, a complete new receiver is more than likely cheaper than any decoder.
Yeah, you're probably right.....I am getting in the habit of impulse purchases :shock:

Anyway, I am proceeding with the code development. Since Martin has offered to get this clock thing worked out for the ATtiny, I am now working on the development of a throttle-timer based on the simple code presented earlier.
I have streamlined it, omitting those unnecessary array transfers, and updating the channels straight from the ISR. The latter now waits for the sync pulse to occur, then starts to update ch[1], ch[2], etc with the next pulses.
The pulse duration is not very stable, varying by about 4 microseconds both ways (as I expected), but it is good enough for the throttle timer project, as it requires just seconds and minutes to be shown on the screen.

Here is the code:

Code: Select all

// Ch[0] remains at 0.

unsigned long int mark,oldmark=0,space;
volatile int ch[7];
int count=1;
bool start = false; 

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

void loop() {

  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.

  mark=micros(); // store time value when PPM pin status rises.
  space=mark-oldmark; // calculating time between two peaks
  oldmark=mark;
  if (start) {
    ch[count]=space;
    count+=1;
    if (count>6) { // restrict channel value recording to 6 channels
      count = 1;
      start = false;
    }
  }
  
// detect sync space and set start flag for channel recording from next spaces.
  if ((space>10000) && (space<20000)) start = true; // sync space detected.
  
}
I will cover the throttle timer project in a separate topic later , I think I have it working, but I am awaiting the arrival of a couple of small Oled screens (128x32) to complete testing.

Cheers,
Max.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

I've done the ATtiny85 (digispark) decoder, and it works great. Here's the YouTube video demonstrating and explaining it.

Attachments
ATtiny85CPPMdecode.zip
Sketch for ATtiny85 (Digispark).
(1.26 KiB) Downloaded 160 times
Last edited by Martin on 18 Jun 2021, 16:57, edited 1 time in total.
MaxZ
Posts: 330
Joined: 31 Jan 2019, 11:48
Location: Boskoop, Netherlands

Re: PPM decoder

Post by MaxZ »

Wow, great stuff Martin!
When my hobby shed (actually attic of sorts....) cools down a bit I'll have a go at hooking one up to test.
Question: " Set the ATtiny to use the internal 16MHz (or 16.5MHz) clock.", does that mean I will have to do the "burn bootloader" trick? (ATtiny85)?

Thanks, and cheers,
Max.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

Yes Max, that's right. "Burn bootloader" to set the clock speed if you're programming with a USBasp or similar. I mention it in the YouTube video, which I've now edited into the post a couple up from this one.
bluejets
Posts: 316
Joined: 19 Jun 2019, 04:09

Re: PPM decoder

Post by bluejets »

Was there a link to this Martin..?
I did notice on the forum pages there is no actual post number in each section.
Don't know whether or not that is in my settings but makes it diffficult I would imagine to refer exactly to any particular post.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

bluejets wrote: 19 Jun 2021, 00:49 Was there a link to this Martin..?
I did notice on the forum pages there is no actual post number in each section.
Don't know whether or not that is in my settings but makes it diffficult I would imagine to refer exactly to any particular post.
Link from where? You can link to an individual post if you want to: click the button with the quote marks to quote a post and you'll see the post_id inside the square brackets of the reply. Make a note of the number and then cancel / back out of replying in the thread, unless you actually want to "reply with quote".

If you do actually "reply with quote" as I've done here, then the forum software puts a little up-arrow next to the word "wrote:". That up-arrow is a link to the quoted post. You can right-click and copy the link to see how it uses the post_id to link to an individual post - then use that same format to link to any post, including the ones that have never been quoted.
Spike S
Posts: 181
Joined: 16 Feb 2018, 14:59
Location: Salisbury UK

Re: PPM decoder

Post by Spike S »

"Every day, a Classroom"
That little arrow not previously noticed but useful admin data. Thanks Martin
Spike S
(Tune for maximum smoke)
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

I did an eight channel version that runs on any Uno / Pro Mini / Nano / whatever. It works without alteration on both 16 MHz and 8 MHz types.

Attachments
UnoNanoMini_CPPMdecode.zip
(1.4 KiB) Downloaded 154 times
bluejets
Posts: 316
Joined: 19 Jun 2019, 04:09

Re: PPM decoder

Post by bluejets »

Martin wrote: 18 Jun 2021, 16:58 I mention it in the YouTube video, which I've now edited into the post a couple up from this one.
Link to this....

As for the rest, if one wants to provide a link to your good work, say in an email, and quote a particular post number, none exists and what is then required is for the recipient to read though a complete post.
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: PPM decoder

Post by Martin »

If you want to send a link to a specific post in email, the format to use is:

Code: Select all

https://mode-zero.uk/viewtopic.php?p=11320#p11320
Here's the same thing as a link: Link to a super post on Mode Zero!

That shows the thread (topic) but starting with the specific post rather than the first post in the thread. To find the 'magic number' press the quote button on the post that you want to link to, note the number, and then back away without actually replying.
Post Reply