-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
159 lines (114 loc) · 2.71 KB
/
functions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "config.h"
#include "Arduino.h"
#include "functions.h"
#include "sensors.h"
#include <Wire.h>
char read_sensors = 0;
// Sensor_board, x,y,z
int acc_raw[3] = {1,2,3};
int gyro_raw[3] = {4,5,6};
int mag_raw[3] = {7,8,9};
unsigned char channel_mapping[13];
//unsigned char PpmIn_PpmOut[13] = {0,1,2,3,4,5,6,7,8,9,10,11,12};
unsigned char PpmIn_PpmOut[13] = {0,
1,2,3,4,5,6,7,8,9,10,11,12};
unsigned int analog_readings[4];
extern unsigned long buttonDownTime;
int test =0;
int test2 =0;
long channel_value[13] ={2100,
2100,2100,2100,2100,2100,2100,2100,2100,2100,2100,2100,2100};
long PPMIn[13] ={2100,
2100,2100,2100,2100,2100,2100,2100,2100,2100,2100,2100,2100};
unsigned char channel_number =1;
// For PPM detection
signed long last_time = 0;
signed long this_time = 0;
signed long servo_time = 0;
unsigned char read_ppm_channel =1;
int temp2 =0;
int timeTest = 0;
char shift = 0;
char time_out =0;
void printPPM() {
for (char j =1; j<13; j++) {
Serial.print(channel_value[j]);
Serial.print(",");
}
Serial.println();
}
void init_timer_interrupt() {
#if (DEBUG)
Serial.println("Timer interrupt initialised");
#endif
TCCR0A =
(0<<WGM00) |
(1<<WGM01) |
(0<<COM0A1) |
(0<<COM0A0) |
(0<<COM0B1) |
(0<<COM0B0);
// 61 hz update-rate:
TCCR0B =
(0<<FOC0A)| //
(0<<FOC0B)| //
(1<<CS00) | //Prescale 1024
(0<<CS01) | //Prescale 1024
(1<<CS02) | //Prescale 1024
(0<<WGM02);
TIMSK0 =
(0<<OCIE0B) |
(1<<OCIE0A) |
(1<<TOIE0);
OCR0B = 64*2;
OCR0A = 64*2;
}
// ===========================
// Timer 0 compare A vector
// Sensor-interrupt
// ===========================
ISR(TIMER0_COMPA_vect) {
/*
for (unsigned char i = 0; i < 4; i++) {
analog_readings[i] = analogRead(i);
}
*/
// Reset counter - should be changed to CTC timer mode.
TCNT0= 0;
// Used to check timing - have the previous calculations been done?
// Will always show in start, but should stop when initialised.
if (shift == 1) {
// digitalWrite(7,HIGH);
shift = 0;
}
else {
// digitalWrite(7,LOW);
shift = 1;
}
#if (DEBUG == 1)
if (read_sensors == 1) {
time_out++;
if (time_out > 10) {
// Serial.println("Timing problem!!!");
time_out = 0;
}
}
#endif
read_sensors = 1;
buttonDownTime += 16; // every 16 milliseconds, at 61 hz.
}
void get_data() {
}
void set_pwm() {
}
// ===========================
// Test function
// ===========================
void test_output() {
Serial.print("Acc x: ");
Serial.print(acc_raw[0]);
Serial.print(" y: ");
Serial.print(acc_raw[1]);
Serial.print(" z: ");
Serial.println(acc_raw[2]);
}