Motor speed controlled by potmeter
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@9:c9cff697f4ab, 2019-10-03 (annotated)
- Committer:
- s1932896
- Date:
- Thu Oct 03 13:05:48 2019 +0000
- Revision:
- 9:c9cff697f4ab
- Parent:
- 5:78a5043b6658
- Child:
- 10:76dfdbdd20cd
Encoder werkend met X4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobertoO | 0:67c50348f842 | 1 | #include "mbed.h" |
RobertoO | 0:67c50348f842 | 2 | //#include "HIDScope.h" |
s1932896 | 9:c9cff697f4ab | 3 | #include "QEI.h" |
RobertoO | 1:b862262a9d14 | 4 | #include "MODSERIAL.h" |
RobertoO | 0:67c50348f842 | 5 | //#include "BiQuad.h" |
s1932896 | 5:78a5043b6658 | 6 | #include "FastPWM.h" |
RobertoO | 0:67c50348f842 | 7 | |
s1932896 | 9:c9cff697f4ab | 8 | DigitalOut motor1(D4); |
s1932896 | 9:c9cff697f4ab | 9 | PwmOut e1(D5); |
s1932896 | 9:c9cff697f4ab | 10 | PwmOut e2(D6); |
s1932896 | 9:c9cff697f4ab | 11 | DigitalOut motor2(D7); |
s1932896 | 9:c9cff697f4ab | 12 | |
s1932896 | 9:c9cff697f4ab | 13 | DigitalIn encoder1a(D12); |
s1932896 | 9:c9cff697f4ab | 14 | DigitalIn encoder1b(D13); |
s1932896 | 5:78a5043b6658 | 15 | AnalogIn pot1(A1); |
s1932896 | 9:c9cff697f4ab | 16 | AnalogIn pot2(A2); |
RobertoO | 0:67c50348f842 | 17 | |
RobertoO | 1:b862262a9d14 | 18 | MODSERIAL pc(USBTX, USBRX); |
RobertoO | 0:67c50348f842 | 19 | |
RobertoO | 0:67c50348f842 | 20 | int main() |
RobertoO | 0:67c50348f842 | 21 | { |
s1932896 | 9:c9cff697f4ab | 22 | pc.baud(115200); |
s1932896 | 9:c9cff697f4ab | 23 | pc.printf("\r\nStarting...\r\n\r\n"); |
s1932896 | 9:c9cff697f4ab | 24 | QEI enc1(D12,D13,NC,64,QEI::X4_ENCODING); |
s1932896 | 9:c9cff697f4ab | 25 | |
s1932896 | 9:c9cff697f4ab | 26 | while(true) |
s1932896 | 9:c9cff697f4ab | 27 | { |
s1932896 | 5:78a5043b6658 | 28 | |
s1932896 | 9:c9cff697f4ab | 29 | pc.printf("%i ",enc1.getPulses()); |
s1932896 | 9:c9cff697f4ab | 30 | pc.printf("%i ",enc1.getRevolutions()); |
s1932896 | 9:c9cff697f4ab | 31 | pc.printf("%f\r\n",pot1.read()); |
s1932896 | 9:c9cff697f4ab | 32 | wait_ms(100); |
RobertoO | 0:67c50348f842 | 33 | } |
s1932896 | 9:c9cff697f4ab | 34 | |
s1932896 | 9:c9cff697f4ab | 35 | } |