Получилась ерунда, значения не достоверные.
PHP код:
#include <TimerOne.h>
volatile uint16_t timerCount0, timerCount1;
#define BTNPIN 2 //Входной сигнал PPM
int ppmImpuls[9]; // Массив импульсов для паузы и 8 каналов
int chImpuls[9] = {1000, 100, 100, 100, 100, 100, 100, 100, 100}; // Массив средних значений для паузы и 8 каналов
int chanel = 0 ; // Номер канала
int minImpuls = 45 ; // Минимальный импульс (450 us)
int maxImpuls = 155; // Максимальный импульс (1550 us)
int minPausa = 500; // Минимальная пауза (5000 us)
int maxPausa = 1300; // Максимальная пауза (13000 us)
int ppm1 = 0 ;
void setup()
{
Serial.begin(115200);
pinMode (BTNPIN, INPUT);
Timer1.initialize(10);
Timer1.attachInterrupt(callback);
attachInterrupt(0, impDown0, RISING);
attachInterrupt(1, impUp1, FALLING);
}
void loop()
{
for (int i=1; i <= 8; i++)
{
chImpuls[i] = (4 * chImpuls[i] + ppmImpuls[i]) / 5 ; // усреднение 3 импульсов
Serial.print(i); Serial.print("=");
Serial.print(chImpuls[i]); Serial.print(" p=");
Serial.print(ppm1); Serial.print(" ");
delay (100);
}
Serial.println("");
}
void callback() //--------- Счетчик------------
{
timerCount0++;
timerCount1++;
}
void impUp0() //---------- Функция обработки положительного импульса по таймеру 0
{
detachInterrupt(0);
timerCount0=0;
attachInterrupt(0, impDown0, RISING);
}
void impDown0() // Функция обработки отрицательного импульса по таймеру 0
{
int ppm0 = timerCount0;
detachInterrupt(0);
if( ppm0 > minPausa ) { chanel=0 ; } else { chanel ++ ; }
ppmImpuls[chanel] = ppm0 ;
attachInterrupt(0, impUp0, FALLING);
}
void impUp1() //---------- Функция обработки положительного импульса по таймеру 1
{
ppm1 = timerCount1;
detachInterrupt(1);
attachInterrupt(1, impDown0, RISING);
}
void impDown1() // Функция обработки отрицательного импульса по таймеру 1
{
detachInterrupt(1);
timerCount1=0;
attachInterrupt(1, impUp0, FALLING);
}