Reading Problem from RC Receiver

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
brksnn
Posts: 4
Joined: Fri Oct 30, 2015 10:17 am

Reading Problem from RC Receiver

Post by brksnn »

Hi Guys,

I have a weird problem. Hope you guys help to solve my problem. Here is the code.

Code: Select all

#include <PinChangeInt.h>
// MultiWii SE v2.5 Pins (2-6-4-5)
// MultiWii Crius AIO Pro (A8-A11-A9-A12)
#define ch1 2 //A8 // 2 //Thro - R9D(3)
#define ch2 6 //A11 //6 //Rudd - R9D(4)
#define ch3 4 //A9 //4 //Aile - R9D(1)
#define ch4 5 //A10 //5 //Elev - R9D(2)
#define LiPo 7 //A12 //7 //Aux for Bigger LiPo of Motor
// External Interrupts
// Necessary to Read RC Receiver
volatile int Thro_value = 0; //ch1 - Thro
volatile int Rudd_value = 0; //ch2 - Rudd
volatile int Aile_value = 0; //ch3 - Aile
volatile int Elev_value = 0; //ch4 - Elev
volatile int AUX_value = 0; //LiPo - AUX
volatile int RPM_value = 0; //LiPo - AUX
volatile int Thro_prev_time = 0;
volatile int Rudd_prev_time = 0;
volatile int Aile_prev_time = 0;
volatile int Elev_prev_time = 0;
volatile int AUX_prev_time = 0;
volatile int RPM_prev_time = 0;
uint8_t Thro_pin; // for CRUIS AIO Pro
uint8_t AUX_pin;
uint8_t Rudd_pin;
uint8_t Elev_pin;
uint8_t Aile_pin;
uint8_t RPM_pin;

void setup() {
  Serial.begin(57600); // Pour a bowl of Serial
  // Input Pins
  // when pin D2 goes high, call the rising function
  // Thro pin
  attachInterrupt(0, Thro_rising, RISING); // for MultiWii SE v2.5
  //pinMode(ch1, INPUT); digitalWrite(ch1, HIGH); //Thro // for Crius AIO Pro
  pinMode(ch2, INPUT); digitalWrite(ch2, HIGH); //Rudd
  pinMode(ch3, INPUT); digitalWrite(ch3, HIGH); //Aile
  pinMode(ch4, INPUT); digitalWrite(ch4, HIGH); //Elev
  pinMode(LiPo, INPUT); digitalWrite(LiPo, HIGH); //Aux for LiPo
  //PCintPort::attachInterrupt(ch1, Thro_rising,RISING); // for Crius AIO Pro
  PCintPort::attachInterrupt(LiPo, AUX_rising,RISING);
  PCintPort::attachInterrupt(ch2, Rudd_rising,RISING);
  PCintPort::attachInterrupt(ch3, Aile_rising,RISING);
  PCintPort::attachInterrupt(ch4, Elev_rising,RISING);
  // ------------------------------------------
}

void loop() {
  // ------------------------------------------
  Serial.print(Thro_value); Serial.print(" | ");
  Serial.print(Rudd_value); Serial.print(" | ");
  Serial.print(Elev_value); Serial.print(" | ");
  Serial.print(Aile_value); Serial.print(" | ");
  Serial.print("\n");
  // ------------------------------------------
}
// ------------------------------------------
void Thro_rising() {
  //Thro_pin=PCintPort::arduinoPin; // for Crius AIO Pro
  //PCintPort::attachInterrupt(Thro_pin, Thro_falling, FALLING);
  attachInterrupt(0, Thro_falling, FALLING); // for MultiWii SE v2.5
  Thro_prev_time = micros();
}
// ------------------------------------------
void Thro_falling() {
  //Thro_pin=PCintPort::arduinoPin; // for Crius AIO Pro
  //PCintPort::attachInterrupt(Thro_pin, Thro_rising, RISING);
  attachInterrupt(0, Thro_rising, RISING); // for MultiWii SE v2.5
  Thro_value = micros()-Thro_prev_time;
}
// ------------------------------------------
void AUX_rising() {
  AUX_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(AUX_pin, AUX_falling, FALLING);
  AUX_prev_time = micros();
}
// ------------------------------------------
void AUX_falling() {
  AUX_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(AUX_pin, AUX_rising, RISING);
  AUX_value = micros()-AUX_prev_time;
}
// ------------------------------------------
void Rudd_rising() {
  Rudd_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(Rudd_pin, Rudd_falling, FALLING);
  Rudd_prev_time = micros();
}
// ------------------------------------------
void Rudd_falling() {
  Rudd_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(Rudd_pin, Rudd_rising, RISING);
  Rudd_value = micros()-Rudd_prev_time;
}
// ------------------------------------------
void Aile_rising() {
  Aile_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(Aile_pin, Aile_falling, FALLING);
  Aile_prev_time = micros();
}
// ------------------------------------------
void Aile_falling() {
  Aile_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(Aile_pin, Aile_rising, RISING);
  Aile_value = micros()-Aile_prev_time;
}
// ------------------------------------------
void Elev_rising() {
  Elev_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(Elev_pin, Elev_falling, FALLING);
  Elev_prev_time = micros();
}
// ------------------------------------------
void Elev_falling() {
  Elev_pin=PCintPort::arduinoPin;
  PCintPort::attachInterrupt(Elev_pin, Elev_rising, RISING);
  Elev_value = micros()-Elev_prev_time;
}
// ------------------------------------------


The code reads both rising and falling edges of 5 channels from RC receiver and it gives the values btw 1000 and 2000 approximately.

However, it gives me annoying number such as 13198. I think it is total period not duty cycle. When I move any stick, the related channel gives the right value but suddenly changes to 13900, 8621, 4568 ridiculously.

Looking forward to your response...

Post Reply