script zover
Dependencies: HIDScope MODSERIAL mbed
main.cpp@1:bc2db3bff4bb, 2014-10-13 (annotated)
- Committer:
- wiesdat
- Date:
- Mon Oct 13 11:02:05 2014 +0000
- Revision:
- 1:bc2db3bff4bb
- Parent:
- 0:bed29da02e8b
- Child:
- 2:620ff9f02d62
HP filter met werkende scope, looptimerflag;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wiesdat | 0:bed29da02e8b | 1 | #include "mbed.h" |
wiesdat | 0:bed29da02e8b | 2 | #include "MODSERIAL.h" |
wiesdat | 0:bed29da02e8b | 3 | #include "HIDScope.h" |
wiesdat | 0:bed29da02e8b | 4 | |
wiesdat | 0:bed29da02e8b | 5 | #define A1HP -1.999214978283642 |
wiesdat | 0:bed29da02e8b | 6 | #define A0HP 0.999214978283642 |
wiesdat | 0:bed29da02e8b | 7 | #define B1HP -1.943446330323158 |
wiesdat | 0:bed29da02e8b | 8 | #define B0HP 0.945001709500376 |
wiesdat | 1:bc2db3bff4bb | 9 | #define TSAMP 0.01 |
wiesdat | 1:bc2db3bff4bb | 10 | |
wiesdat | 0:bed29da02e8b | 11 | |
wiesdat | 0:bed29da02e8b | 12 | AnalogIn emg0(PTB1); |
wiesdat | 0:bed29da02e8b | 13 | MODSERIAL pc(USBTX,USBRX); |
wiesdat | 0:bed29da02e8b | 14 | HIDScope scope(2); |
wiesdat | 0:bed29da02e8b | 15 | Ticker timer; |
wiesdat | 0:bed29da02e8b | 16 | float filter(float); |
wiesdat | 0:bed29da02e8b | 17 | float emg_value; |
wiesdat | 0:bed29da02e8b | 18 | static float y,x1=0,y1=0,x2=0,y2=0; |
wiesdat | 1:bc2db3bff4bb | 19 | volatile bool looptimerflag; |
wiesdat | 0:bed29da02e8b | 20 | |
wiesdat | 0:bed29da02e8b | 21 | |
wiesdat | 0:bed29da02e8b | 22 | void read() |
wiesdat | 0:bed29da02e8b | 23 | { |
wiesdat | 1:bc2db3bff4bb | 24 | emg_value=emg0.read_u16(); |
wiesdat | 0:bed29da02e8b | 25 | } |
wiesdat | 0:bed29da02e8b | 26 | |
wiesdat | 0:bed29da02e8b | 27 | float filter(float emg0_value) |
wiesdat | 0:bed29da02e8b | 28 | { |
wiesdat | 0:bed29da02e8b | 29 | y = y1*B1HP-y2*B0HP-x1*A1HP+x2*A0HP; |
wiesdat | 0:bed29da02e8b | 30 | x2 = x1; |
wiesdat | 0:bed29da02e8b | 31 | x1 = emg0_value; |
wiesdat | 0:bed29da02e8b | 32 | y2 = y1; |
wiesdat | 0:bed29da02e8b | 33 | y1 = y; |
wiesdat | 0:bed29da02e8b | 34 | return y; |
wiesdat | 0:bed29da02e8b | 35 | } |
wiesdat | 0:bed29da02e8b | 36 | |
wiesdat | 0:bed29da02e8b | 37 | void viewer() |
wiesdat | 0:bed29da02e8b | 38 | { |
wiesdat | 0:bed29da02e8b | 39 | scope.set(0,emg_value); |
wiesdat | 0:bed29da02e8b | 40 | scope.set(1,y); |
wiesdat | 0:bed29da02e8b | 41 | scope.send(); |
wiesdat | 0:bed29da02e8b | 42 | } |
wiesdat | 0:bed29da02e8b | 43 | |
wiesdat | 1:bc2db3bff4bb | 44 | void setlooptimerflag(void) |
wiesdat | 1:bc2db3bff4bb | 45 | { |
wiesdat | 1:bc2db3bff4bb | 46 | looptimerflag = true; |
wiesdat | 1:bc2db3bff4bb | 47 | } |
wiesdat | 1:bc2db3bff4bb | 48 | |
wiesdat | 0:bed29da02e8b | 49 | int main() |
wiesdat | 0:bed29da02e8b | 50 | { |
wiesdat | 0:bed29da02e8b | 51 | pc.baud(115200); |
wiesdat | 1:bc2db3bff4bb | 52 | timer.attach(setlooptimerflag,TSAMP); |
wiesdat | 1:bc2db3bff4bb | 53 | //timer.attach(scope,0.05); |
wiesdat | 0:bed29da02e8b | 54 | while(1) { |
wiesdat | 1:bc2db3bff4bb | 55 | while(!looptimerflag) |
wiesdat | 1:bc2db3bff4bb | 56 | looptimerflag = false; |
wiesdat | 1:bc2db3bff4bb | 57 | read(); |
wiesdat | 0:bed29da02e8b | 58 | y = filter(emg_value); |
wiesdat | 1:bc2db3bff4bb | 59 | viewer(); |
wiesdat | 1:bc2db3bff4bb | 60 | } |
wiesdat | 0:bed29da02e8b | 61 | } |