Revision e6c4b5e0
Fixed receiver int should've been u_long, and filtering over rc_avail, not results
arduino/RadioBuggyMega/receiver.c | ||
---|---|---|
1 | 1 |
/** |
2 |
* @file receiver.cpp
|
|
2 |
* @file receiver.c |
|
3 | 3 |
* @brief Contains Code for dealing with RC Receiver |
4 | 4 |
* NOTE: AIL and THR are flipped. |
5 | 5 |
* AIL is on pin 2 |
6 | 6 |
* THR is on pin 3 |
7 |
* |
|
8 |
* @author Matt Sebek (msebek) |
|
9 |
* @author Zach Dawson (zsd) |
|
7 | 10 |
*/ |
8 |
//#include <stdint.h> |
|
9 | 11 |
#include <Arduino.h> |
10 | 12 |
#include "receiver.h" |
11 | 13 |
|
... | ... | |
24 | 26 |
#define THR_RECEIVER_PIN 2 |
25 | 27 |
#define THR_RECEIVER_INT 0 |
26 | 28 |
|
27 |
//#define THR_INDEX 0 |
|
28 |
//#define AIL_INDEX 1 |
|
29 |
// Defined in receiver.h |
|
30 |
// #define THR_INDEX 0 |
|
31 |
// #define AIL_INDEX 1 |
|
29 | 32 |
|
30 | 33 |
// Note: arr[0] is thr, arr[1] is ail |
31 |
static volatile int start_time[2];
|
|
32 |
static volatile int rc_value[2];
|
|
34 |
static volatile unsigned long start_time[2];
|
|
35 |
static volatile unsigned long rc_value[2];
|
|
33 | 36 |
|
34 | 37 |
|
35 | 38 |
// When our code gets really busy this will become inaccurate, |
36 | 39 |
// (i believe since micros gets shifted a bit) but for |
37 | 40 |
// the current application its easy to understand and works very well |
38 | 41 |
// TODO if things start twitching, move to using registers directly. |
42 |
// TODO if this starts twitching, also micros has a resolution of 4us. |
|
39 | 43 |
static void receiver_on_ail_interrupt() { |
40 | 44 |
if(digitalRead(AIL_RECEIVER_PIN) == HIGH) { |
41 | 45 |
start_time[AIL_INDEX] = micros(); |
42 | 46 |
} else { |
43 | 47 |
if(start_time[AIL_INDEX] && (rc_available[AIL_INDEX] == 0)) { |
44 |
rc_value[AIL_INDEX] = (int)(micros() - start_time[AIL_INDEX]);
|
|
48 |
rc_value[AIL_INDEX] = (micros() - start_time[AIL_INDEX]); |
|
45 | 49 |
start_time[AIL_INDEX] = 0; |
46 | 50 |
rc_available[AIL_INDEX] = 1; |
47 | 51 |
} |
... | ... | |
76 | 80 |
rc_available[index] = 0; |
77 | 81 |
return ret_val; |
78 | 82 |
} |
79 |
|
Also available in: Unified diff