/CPPM

CPPM Library for Arduino

Primary LanguageC++MIT LicenseMIT

CPPM Library for Arduino

2016-05-17 No change.

2015-08-06 Revision.

Added CPPM Output Frame.
Expand Sync/Pulse/Frame timings.
Correct Sync Pulse to falling edge.

This library provides an interface for reading a CPPM signal delivered by a RC receiver like Orange R615X. Commonly, the 22ms frame limits the maximum number of servos/channels to 9.

NEW: The library also generates a CPPM Output Frame.

CHANGED: The synchronization pulse starts on falling edge.

Example

#include <CPPM.h>

// your code...

void setup(void)
{
  CPPM.begin();
}

void loop(void)
{
  CPPM.cycle(); // update some variables and check timeouts...

  if (CPPM.synchronized())
  {
    int throttle = CPPM.read_us(CPPM.THRO);
  
    // do something funny...
  }
}

22ms CPPM Frame

The timings of plotted signals are all generated by an Orange R920X receiver.
The signal transmitter is a Spektrum DX8 in DSMX mode.

22ms CPPM Frame

Note 1: The CPPM frame is formed of 9 concatenated servo pulses and 1 gap pulse.
Note 2: The T trig is set on the falling edge following the gap pulse.

CPPM Frame Length

Note 1: Cursor A is set on falling edge of start CPPM frame.
Note 2: Cursor B is set on falling edge of next CPPM frame.
Note 3: CPPM frame length is more precisely 21980us.
Note 4: Unsynchronized CPPM frame length is about 22120us.
Note 5: Unsynchronized CPPM frame length can largely vary 
from one model/manufacter to another.

1520us CPPM Servo Pulse

1520us CPPM Servo Pulse

Note 1: Cursor A is set on falling edge of sync pulse.
Note 2: Cursor B is set on falling edge of next sync pulse.
Note 3: CPPM servo pulse starts and ends on a sync pulse.
Note 4: Middle CPPM pulse width is more precisely 1510us.
Note 5: Middle CPPM pulse width can largely vary 
from one model/manufacter to another.
Note 6: +/-100% CPPM range pulse width is about +/-455us.
Note 7: CPPM range pulse width can largely vary 
from one model/manufacter to another.

300us CPPM Sync Pulse

Warning: FrSky standard sync pulse width is 300us. Orange R920X differs largely.

300us CPPM Sync Pulse

Note 1: Cursor A is set on falling edge of sync pulse.
Note 2: Cursor B is set on rising edge of sync pulse.
Note 3: CPPM sync pulse width is more precisely 136us.
Note 4: CPPM sync pulse width can largely vary 
from one model/manufacter to another.

Implementation

This library works only on ATmega328 implementation of Arduino UNO, Duemillanove and similar, also Leonardo. It uses the 16bit Timer1. So PWM analogWrite() on pin 9 and 10 are unavailable. The library Servo is not compatible because it also uses Timer1.

The CPPM input signal is connected to the Arduino pin 8 named ICP1. A CPPM output signal is generated on pin 9 OC1A. At moment, pin 10 OC1B has no dedicated usage.

This implementation differs from https://github.com/claymation/CPPM in one significant point: Edges of pulses are exactly catched by hardware counter ICR1 with a precision of 0.5 microsecond. TCNT1 counter is a true running counter and is never resetted by software.

Implementation has been extensively tested with Orange R920X (9 channels) and Orange R615X (6 channels) receiver and a Spektrum DX8 transmitter.

Protect the CPPM input signal from glitches that can catch ICP1. Add a 1nF capacitor between ICP1 and GND and insert a 330ohms resistor in the CPPM signal. This is particulary necessary when high currents are switched (dc motors, etc...).

The main page is http://jean-marc.paratte.ch/articles/arduino-cppm/ (French language).

Installation

  1. Download the ZIP file.
  2. Use the Arduino menu Sketch / Import Library / Add Library...
  3. Verify the expanded content in the folder Documents/Arduino/libraries/CPPM.
  4. Restart the Arduino environment.
  5. Connect a receiver and try the Monitor example.