Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Receiver Code change (RISING instead of CHANGE)

  • Loading branch information...
commit a0411b81ab5a901dc5b98d091378f67455bab318 1 parent f076236
@sebastianherp authored
View
14 CopterPilot/CopterPilot.ino
@@ -7,6 +7,8 @@
#include "config.h"
#include "classes.h"
+#define DEBUG 1
+
#define ON 1
#define OFF 0
@@ -57,15 +59,25 @@ void setup()
Serial.begin(BAUD);
Wire.begin();
+#ifdef DEBUG
+ Serial.println("Init pilot");
+ Serial.println("...");
+#endif
+
// initialize pilot
pilot.init();
// receiver works with the pin change interrupt
- attachInterrupt(0, receiver_update, CHANGE);
+ attachInterrupt(0, receiver_update, RISING);
timer_old = micros();
timer_counter = 0;
cycleTime = 0;
+
+#ifdef DEBUG
+ Serial.println("Setup done");
+#endif
+
}
byte light_i = 0;
View
3  CopterPilot/Motors.ino
@@ -20,8 +20,9 @@ void Motors::init(int pin1, int pin2, int pin3, int pin4) {
pinMode(_pin3, OUTPUT);
pinMode(_pin4, OUTPUT);
+ // timer settings for both, receiver & motors
TCCR1A = 0; // normal counting mode
- TCCR1B = 0 | (1<<CS11); // | (1<<CS10); // prescaler :8
+ TCCR1B = 0 | (1<<CS11);// | (1<<CS10); // prescaler :8
TIMSK1 |= (1<<OCIE1A); // Enable CTC interrupt
}
View
3  CopterPilot/Pilot.ino
@@ -1,4 +1,3 @@
-
Pilot::Pilot() {
}
@@ -7,6 +6,8 @@ void Pilot::init() {
_receiver.init(RECEIVER_PIN);
_motors.init(MOTOR_PINS);
_imu.init();
+
+
pinMode(A0, INPUT); // amps
pinMode(A1, INPUT); // volts
View
40 CopterPilot/Receiver.ino
@@ -5,13 +5,16 @@ Receiver::Receiver() {
void Receiver::init(int pin) {
_pin = pin;
+
+ pinMode(_pin, INPUT);
+ for(byte channel = 0; channel < LASTCHANNEL; channel++) {
+ rx_values[channel] = 1000;
+ }
+
+ // timer settings for both, receiver & motors
TCCR1A = 0; // normal counting mode
TCCR1B = 0 | (1<<CS11);// | (1<<CS10); // prescaler :8
- pinMode(_pin, INPUT);
- for(byte channel = 0; channel < LASTCHANNEL; channel++) {
- rx_values[channel] = 1000;
- }
}
unsigned int Receiver::get(char channel) {
@@ -22,21 +25,18 @@ unsigned int Receiver::get(char channel) {
* normal values are between 2000 and 4000 (1000 us - 2000 us)
*/
void Receiver::update() {
- if(!digitalRead(_pin)) {
- rx_start = TCNT1;
- } else {
- rx_duration = TCNT1 - rx_start;
- if(rx_duration < 0)
- rx_duration += 65536;
+ rx_duration = TCNT1 - rx_start;
+ rx_start = TCNT1;
+ if(rx_duration < 0)
+ rx_duration += 65536;
- if(rx_duration > 8000)
- rx_channel = 0;
- else {
- rx_values[rx_channel] = rx_duration;
- //rx_values[rx_channel] = (rx_values[rx_channel] * 3 + rx_duration) / 4;
- rx_channel++;
- if(rx_channel >= 8)
- rx_channel = 0;
- }
- }
+ if(rx_duration > 8000) {
+ rx_channel = 0;
+ } else {
+ rx_values[rx_channel] = rx_duration;
+ //rx_values[rx_channel] = (rx_values[rx_channel] * 3 + rx_duration) / 4;
+ rx_channel++;
+ if(rx_channel >= 8)
+ rx_channel = 0;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.