script zover
Dependencies: HIDScope MODSERIAL mbed
main.cpp@0:bed29da02e8b, 2014-10-13 (annotated)
- Committer:
- wiesdat
- Date:
- Mon Oct 13 10:44:50 2014 +0000
- Revision:
- 0:bed29da02e8b
- Child:
- 1:bc2db3bff4bb
Eerste werkend script: HP filter, met scope;
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 | 0:bed29da02e8b | 9 | |
wiesdat | 0:bed29da02e8b | 10 | AnalogIn emg0(PTB1); |
wiesdat | 0:bed29da02e8b | 11 | MODSERIAL pc(USBTX,USBRX); |
wiesdat | 0:bed29da02e8b | 12 | HIDScope scope(2); |
wiesdat | 0:bed29da02e8b | 13 | Ticker timer; |
wiesdat | 0:bed29da02e8b | 14 | float filter(float); |
wiesdat | 0:bed29da02e8b | 15 | float emg_value; |
wiesdat | 0:bed29da02e8b | 16 | static float y,x1=0,y1=0,x2=0,y2=0; |
wiesdat | 0:bed29da02e8b | 17 | |
wiesdat | 0:bed29da02e8b | 18 | |
wiesdat | 0:bed29da02e8b | 19 | |
wiesdat | 0:bed29da02e8b | 20 | void read() |
wiesdat | 0:bed29da02e8b | 21 | { |
wiesdat | 0:bed29da02e8b | 22 | emg_value=emg0.read_u16(); |
wiesdat | 0:bed29da02e8b | 23 | } |
wiesdat | 0:bed29da02e8b | 24 | |
wiesdat | 0:bed29da02e8b | 25 | float filter(float emg0_value) |
wiesdat | 0:bed29da02e8b | 26 | { |
wiesdat | 0:bed29da02e8b | 27 | y = y1*B1HP-y2*B0HP-x1*A1HP+x2*A0HP; |
wiesdat | 0:bed29da02e8b | 28 | x2 = x1; |
wiesdat | 0:bed29da02e8b | 29 | x1 = emg0_value; |
wiesdat | 0:bed29da02e8b | 30 | y2 = y1; |
wiesdat | 0:bed29da02e8b | 31 | y1 = y; |
wiesdat | 0:bed29da02e8b | 32 | return y; |
wiesdat | 0:bed29da02e8b | 33 | } |
wiesdat | 0:bed29da02e8b | 34 | |
wiesdat | 0:bed29da02e8b | 35 | void viewer() |
wiesdat | 0:bed29da02e8b | 36 | { |
wiesdat | 0:bed29da02e8b | 37 | scope.set(0,emg_value); |
wiesdat | 0:bed29da02e8b | 38 | scope.set(1,y); |
wiesdat | 0:bed29da02e8b | 39 | scope.send(); |
wiesdat | 0:bed29da02e8b | 40 | } |
wiesdat | 0:bed29da02e8b | 41 | |
wiesdat | 0:bed29da02e8b | 42 | int main() |
wiesdat | 0:bed29da02e8b | 43 | { |
wiesdat | 0:bed29da02e8b | 44 | pc.baud(115200); |
wiesdat | 0:bed29da02e8b | 45 | timer.attach(read,0.05); |
wiesdat | 0:bed29da02e8b | 46 | timer.attach(viewer,0.05); |
wiesdat | 0:bed29da02e8b | 47 | //timer.attach(scope,0.05); |
wiesdat | 0:bed29da02e8b | 48 | while(1) { |
wiesdat | 0:bed29da02e8b | 49 | y = filter(emg_value); |
wiesdat | 0:bed29da02e8b | 50 | } |
wiesdat | 0:bed29da02e8b | 51 | } |