MCU Ardiuno: библиотека PPMint

Потребовалось с тренерского разъема Futaba T7C получить сигнал PPM и обработать его с помощью Arduino. Принял, обработал – за основу подсмотрел идеи из AeroQuad. В результате имею готовую библиотеку для работы с суммированным PWM – то, что я называю PPM.
Как это работает:
- ко входу D2 Arduino Uno подключаем сигнал с аппаратуры (проверено с Futaba T7C 2.4, Futaba 8FG)
- закачиваем файл PPMint.zip(внизу поста ссылка)
- распаковываем в “libraries
- в рабочем скетче делаем #include “PPMint.h”;, инициализируем объект PPMint ppm;
- используем по тексту программы конструкцию realRaw[номер канала]
Проще вроде некуда. Далее немного кода и ссылка на загрузку.
Same in english here…
It took a trainer connector Futaba T7C get PPM signal and process it using the Arduino. Received, processed – the basis of ideas spied AeroQuad . As a result, I have finished the library to work with the summarized PWM – what I call the PPM.
How it works:
- to the input D2 Arduino Uno connect the signal from the equipment (tested with Futaba T7C 2.4, Futaba 8FG)
- upload files PPMint.zip (at the bottom of the post link)
- unpack in “libraries
- in working sketch do # include “PPMint.h”; , initialize the object PPMint ppm;
- use the text of the program structure realRaw [channel number]
Simply like nowhere else. Next, some code and download link .
PPMint.h
#ifndef PPMint_h
#define PPMint_h
#include "Arduino.h"
#define _CHA_NUM 10
#define _PPM_PIN 2
#define _PPM_INT 0
class PPMint
{
public:
PPMint();
int realRaw[10];
void PPMinterrupt(void);
void setup();
private:
uint8_t prevRealRaw[10];
uint8_t currentChannel;
unsigned long lastms,diffms;
boolean sync;
};
#endif
PPMint.cpp
#include
//BEGIN
// only one instance allowed - some hack here
static PPMint *pclass = 0;
void ppmInterrupt() {// dummy function
if (pclass)
pclass->PPMinterrupt();
}
//END
PPMint::PPMint() {
} //PPMint
void PPMint::setup() {
realRaw[10]=0,0,0,0,0,0,0,0,0,0;
prevRealRaw[10]=0,0,0,0,0,0,0,0,0,0;
currentChannel=0;
lastms = 0;
sync = false;
pinMode(_PPM_PIN,INPUT);
pclass=this; //create an pointer to func
attachInterrupt(_PPM_INT,ppmInterrupt,RISING);
while(!sync) {
delay(100);
}
}
void PPMint::PPMinterrupt() { //here real work to come ;)
long nowms = micros();
diffms = nowms - lastms;
if(lastms>0) {
if(diffms>5000) {
sync = true;
currentChannel = 0;
}
else {
if(sync) {
if(diffms<=2000 && diffms>=1000) {
realRaw[currentChannel] = diffms;
}
currentChannel++;
}
}
}
lastms = nowms;
}//PPMinterrupt
Пример использования:
#include
PPMint ppm;
void setup() {
Serial.begin(9600);
ppm.setup();
}
void loop() {
delay(30);
Serial.print("Channel 0: ");
Serial.println(ppm.realRaw[0]);
}
Все – в деталях 🙂 В конструкторе не получается зацепить прерывания (есть предположения – почему – блок BEGIN / END внутри конструктора не канает).
All – in detail:) In the constructor fails to catch interrupts (the assumption is – why – block BEGIN / END inside the constructor is not the channel).
Обещанная ссылка PPMint.zip.
The promised link PPMint.zip.
Спс/Tnx 😉
PS (a bit late): https://github.com/ilyxa/ArduinoPPMint