-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexgpill.ino
57 lines (52 loc) · 1.5 KB
/
exgpill.ino
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
volatile float signal=0;
float prev_signal=0;
void setup() {
cli(); //stop interrupts for till we make the settings
TCCR1A = 0; // Reset entire TCCR1A to 0
TCCR1B = 0; // Reset entire TCCR1B to 0
TCCR1B |= B00000011; //Set CS12 to 1 so we get prescalar 64
TIMSK1 |= B00000010; //Set OCIE1A to 1 so we enable compare match A
OCR1A = 500; //Finally we set compare register A to this value
sei();
Serial.begin(9600);
}
void loop() {
if(signal != prev_signal){
Serial.println(signal);
prev_signal= signal;
}
}
ISR(TIMER1_COMPA_vect){
TCNT1 = 0;
float sensor_value = analogRead(A0);
float output = sensor_value;
{
static float z1, z2; // filter section state
float x = output - 0.05159732*z1 - 0.36347401*z2;
output = 0.01856301*x + 0.03712602*z1 + 0.01856301*z2;
z2 = z1;
z1 = x;
}
{
static float z1, z2; // filter section state
float x = output - -0.53945795*z1 - 0.39764934*z2;
output = 1.00000000*x + -2.00000000*z1 + 1.00000000*z2;
z2 = z1;
z1 = x;
}
{
static float z1, z2; // filter section state
float x = output - 0.47319594*z1 - 0.70744137*z2;
output = 1.00000000*x + 2.00000000*z1 + 1.00000000*z2;
z2 = z1;
z1 = x;
}
{
static float z1, z2; // filter section state
float x = output - -1.00211112*z1 - 0.74520226*z2;
output = 1.00000000*x + -2.00000000*z1 + 1.00000000*z2;
z2 = z1;
z1 = x;
}
signal = output;
}