Werkcollege opgave 23 september BMT K9
Dependencies: Encoder HIDScope MODSERIAL mbed QEI biquadFilter
Diff: main.cpp
- Revision:
- 28:44cb644233eb
- Parent:
- 27:85e5d36bb6c5
- Child:
- 29:601ab5fa6824
--- a/main.cpp Tue Oct 13 12:31:55 2015 +0000 +++ b/main.cpp Tue Oct 13 13:25:56 2015 +0000 @@ -14,8 +14,10 @@ HIDScope scope(3); // Aantal HIDScope kanalen MODSERIAL pc(USBTX,USBRX); volatile bool control_go = false; +volatile bool sample = false; Ticker control_tick; Ticker T1; +double n=0; // [BIQUAD FILTERS] // int Fs = 512; // sampling frequency @@ -44,15 +46,31 @@ led1 = 0; } +void take_sample() //Control flag +{ + if(n==25) + { + sample = true; + led1 = 0; + n=0; + } +} + + void sample_filter() { u1 = input1; y1 = highpass1.step(u1); // filter order is: high-pass --> rectify --> low-pass y1 = fabs(y1); y1 = lowpass1.step(y1);// roughly normalize to a scale of 0 - 1, where 0 is minimum and 1 is roughly the maximum output of dennis. + y1 = 5*y1; - B0 = y1; - MOVAVG=B0*0.1+B1*0.1+B2*0.1+B3*0.1+B4*0.1+B5*0.1+B6*0.1+B7*0.1+B8*0.1+B9*0.1; + take_sample(); + led1=1; + if(sample) + { + sample=false; + B0 = y1; B9=B8; B8=B7; B7=B6; @@ -62,6 +80,11 @@ B3=B2; B2=B1; B1=B0; + } + + MOVAVG=B0*0.1+B1*0.1+B2*0.1+B3*0.1+B4*0.1+B5*0.1+B6*0.1+B7*0.1+B8*0.1+B9*0.1; + + n++; led1 = 1; //De led gaat flikkeren wanneer deze loop uitgevoerd wordt } @@ -74,7 +97,7 @@ pc.baud(9600); while(1) { - led1=0; + led1=1; if(control_go) { sample_filter();