encoder

Dependencies:   QEI mbed

Committer:
Joshua_Cheung
Date:
Fri Nov 10 19:23:08 2017 +0000
Revision:
2:aa961ba3199e
Parent:
1:1b18e69bf50f
PID control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Joshua_Cheung 2:aa961ba3199e 1 /*
kensterino 0:b9e03a03e580 2 #include "mbed.h"
kensterino 0:b9e03a03e580 3 #include "QEI.h"
kensterino 0:b9e03a03e580 4 Serial pc (PA_2, PA_3); //serial comm enabled on pins pa_2 and pa_3
kensterino 0:b9e03a03e580 5 QEI encoder_Right(PB_3, PA_15, NC, 360, QEI::X4_ENCODING);
kensterino 0:b9e03a03e580 6 QEI encoder_Left(PA_1, PC_4, NC, 360, QEI::X4_ENCODING); //forward increases pulses
Joshua_Cheung 2:aa961ba3199e 7 PwmOut m_Right_B(PC_7);
Joshua_Cheung 2:aa961ba3199e 8 PwmOut m_Right_F(PB_10);
Joshua_Cheung 2:aa961ba3199e 9 PwmOut m_Left_F(PA_7);
Joshua_Cheung 2:aa961ba3199e 10 PwmOut m_Left_B(PB_6);
Joshua_Cheung 2:aa961ba3199e 11 */
kensterino 0:b9e03a03e580 12
kensterino 0:b9e03a03e580 13 //QEI functions
kensterino 0:b9e03a03e580 14 /*
kensterino 0:b9e03a03e580 15 void reset (void)
kensterino 0:b9e03a03e580 16 Reset the encoder.
kensterino 0:b9e03a03e580 17 int getCurrentState (void)
kensterino 0:b9e03a03e580 18 Read the state of the encoder.
kensterino 0:b9e03a03e580 19 int getPulses (void)
kensterino 0:b9e03a03e580 20 Read the number of pulses recorded by the encoder.
kensterino 0:b9e03a03e580 21 int getRevolutions (void)
kensterino 0:b9e03a03e580 22 Read the number of revolutions recorded by the encoder on the index channel.
kensterino 0:b9e03a03e580 23 */
Joshua_Cheung 2:aa961ba3199e 24 /*
kensterino 0:b9e03a03e580 25 int main()
kensterino 0:b9e03a03e580 26 {
Joshua_Cheung 2:aa961ba3199e 27 m_Right_F.write(0.5);
Joshua_Cheung 2:aa961ba3199e 28 //m_Left_F.write(.25);
Joshua_Cheung 2:aa961ba3199e 29 //m_Left_B.write(.25);
kensterino 0:b9e03a03e580 30 while(1) {
kensterino 0:b9e03a03e580 31 wait(0.1);
Joshua_Cheung 2:aa961ba3199e 32
kensterino 0:b9e03a03e580 33 pc.printf("Pulses is: %i\n", encoder_Right.getPulses());
kensterino 0:b9e03a03e580 34 //pc.printf("Pulses is: %i\n", encoder_Left.getPulses());
kensterino 0:b9e03a03e580 35 }
mbshark 1:1b18e69bf50f 36
mbshark 1:1b18e69bf50f 37
kensterino 0:b9e03a03e580 38
Joshua_Cheung 2:aa961ba3199e 39 }
Joshua_Cheung 2:aa961ba3199e 40 */