Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MODSERIAL mbed Encoder
main.cpp
- Committer:
- Socrates
- Date:
- 2013-10-16
- Revision:
- 3:935347ab4e12
- Parent:
- 2:3dab90d3aac2
- Child:
- 4:513c33bba011
File content as of revision 3:935347ab4e12:
#include "mbed.h" #include "MODSERIAL.h" AnalogIn emg(PTB0); MODSERIAL pc(USBTX,USBRX); volatile bool looptimerflag; void setlooptimerflag(void) { looptimerflag = true; } int main() { Ticker looptimer; const float ts=0.001; looptimer.attach(setlooptimerflag,ts); float x,y,y1,x1,z1,yabs,z,yabs1,k,numh1,numh2,denh1,denh2,numl1,numl2,denl1,denl2; x1=0; y1=0; z1=0; yabs1=0; numh1=0.996868235770807; numh2=-0.996868235770807; //denh1=1; denh2=-0.993736471541615; numl1=0.006244035046343; numl2=-0.006244035046343; //denl1=1; denl2=-0.987511929907314; pc.baud(115200); while(1) { while(looptimerflag != true); looptimerflag = false; k=emg.read(); x=(k-0.5)*2.0; //High pass, 1 Hz //Waarom heb ik geen - gebruikt bij y1/denh2? //y=(y1/1.000994230391224-(0.996868235770807/1.000994230391224)*x1+(0.997865599482850/1.000994230391224)*x); //Met bovenstaande zijn de metingen gedaan. //Dat is //y=(y1/denh2-(numh1/denh2)*x1+(numh2/denh2)*x) y=x*numh1+x1*numh2-y1*denh2; //Rectify yabs=abs(y); //Low pass, 1 Hz //Waarom heb ik geen - gebruikt bij z1/denl2? //z=(z1/1.000987999680353-(0.006244035046343/1.000987999680353)*yabs1+(0.006237787927252/1.000987999680353)*yabs); //Met bovenstaande zijn de metingen gedaan. //Dat is //z=(z1/denl2-(numl1/denl2)*y1+(numl2/denl2)*y) z=yabs*numl1+yabs1*numl2-z1*denl2; pc.printf("%f\n\r",z); x1=x; y1=y; z1=z; yabs1=yabs; } }