Encoder program for K64F microcontroller with 64 bit confic

Dependencies:   MODSERIAL QEI mbed

Fork of Encoder_program by Robert van der Wal

Committer:
Wallie117
Date:
Wed Sep 23 12:08:31 2015 +0000
Revision:
1:b9fb9ec8a9e6
Parent:
0:9b63614c20f3
Child:
2:3e6f179dfe7d
Een programma om te kijken naar welke hoek is afgelegd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wallie117 0:9b63614c20f3 1 #include "mbed.h"
Wallie117 0:9b63614c20f3 2 #include "QEI.h"
Wallie117 0:9b63614c20f3 3 #include "MODSERIAL.h"
Wallie117 0:9b63614c20f3 4
Wallie117 0:9b63614c20f3 5 Serial pc(USBTX, USBRX);
Wallie117 0:9b63614c20f3 6 DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield)
Wallie117 0:9b63614c20f3 7 PwmOut motor2speed(D5);
Wallie117 0:9b63614c20f3 8 //Use X4 encoding.
Wallie117 0:9b63614c20f3 9 //QEI wheel(p29, p30, NC, 624, QEI::X4_ENCODING);
Wallie117 0:9b63614c20f3 10 //Use X2 encoding by default.
Wallie117 0:9b63614c20f3 11 QEI wheel (D11, D12, NC, 64,QEI::X4_ENCODING); //
Wallie117 1:b9fb9ec8a9e6 12 Ticker flipper;
Wallie117 1:b9fb9ec8a9e6 13
Wallie117 1:b9fb9ec8a9e6 14 void flip() {
Wallie117 1:b9fb9ec8a9e6 15 motor2direction.write(0);
Wallie117 1:b9fb9ec8a9e6 16 for(int i=0;i<21; i++)
Wallie117 1:b9fb9ec8a9e6 17 {
Wallie117 1:b9fb9ec8a9e6 18 wait(0.1);
Wallie117 1:b9fb9ec8a9e6 19 pc.printf("Pulses is: %i\n", (wheel.getPulses()/((64*131)/360)));
Wallie117 1:b9fb9ec8a9e6 20 }
Wallie117 1:b9fb9ec8a9e6 21 }
Wallie117 0:9b63614c20f3 22
Wallie117 0:9b63614c20f3 23 int main() {
Wallie117 1:b9fb9ec8a9e6 24 flipper.attach(&flip, 2.0);
Wallie117 0:9b63614c20f3 25 while(1){
Wallie117 0:9b63614c20f3 26 motor2direction.write(1);
Wallie117 0:9b63614c20f3 27 motor2speed.write(0.2);
Wallie117 0:9b63614c20f3 28 wait(0.1);
Wallie117 1:b9fb9ec8a9e6 29 pc.printf("Pulses is: %i\n", (wheel.getPulses()/((64*131)/360)));
Wallie117 0:9b63614c20f3 30 }
Wallie117 0:9b63614c20f3 31
Wallie117 0:9b63614c20f3 32 }