ES410 Simple Speed Measurement

Dependencies:   MotCon QEI mbed

Committer:
jebradshaw
Date:
Mon May 23 19:01:51 2016 +0000
Revision:
0:f8cf3c133d6a
ES410 simple speed measurement program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jebradshaw 0:f8cf3c133d6a 1 #include "mbed.h"
jebradshaw 0:f8cf3c133d6a 2 #include "MotCon.h"
jebradshaw 0:f8cf3c133d6a 3 #include "QEI.h"
jebradshaw 0:f8cf3c133d6a 4
jebradshaw 0:f8cf3c133d6a 5 QEI enc1(p24,p23,NC,800, QEI::X4_ENCODING); //Global Motor 800 cpr w x4 encoding
jebradshaw 0:f8cf3c133d6a 6 MotCon motor(p26, p28); //pwm output, direction
jebradshaw 0:f8cf3c133d6a 7
jebradshaw 0:f8cf3c133d6a 8 int main() {
jebradshaw 0:f8cf3c133d6a 9 long e[210]; // vector to save encoder readings
jebradshaw 0:f8cf3c133d6a 10 int k;
jebradshaw 0:f8cf3c133d6a 11
jebradshaw 0:f8cf3c133d6a 12 motor.mot_control(0.5); // sets motor voltage duty cucle, example 25% (12*0.25=3 V)
jebradshaw 0:f8cf3c133d6a 13
jebradshaw 0:f8cf3c133d6a 14 for(k=1;k<=100;k++){ // take x=100 readings
jebradshaw 0:f8cf3c133d6a 15 e[k]=enc1.getPulses(); // read the encoder
jebradshaw 0:f8cf3c133d6a 16 wait(.050); // wait x=50 ms between the readings
jebradshaw 0:f8cf3c133d6a 17 }
jebradshaw 0:f8cf3c133d6a 18 motor.mot_control(0.0);
jebradshaw 0:f8cf3c133d6a 19 for(k=1;k<=100;k++){ // print readings to screen so you can import to MATLAB
jebradshaw 0:f8cf3c133d6a 20 printf("%d\r\n",e[k]);
jebradshaw 0:f8cf3c133d6a 21 }
jebradshaw 0:f8cf3c133d6a 22 }//main