Motor speed controlled by potmeter

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Committer:
s1932896
Date:
Thu Oct 03 13:26:09 2019 +0000
Revision:
10:76dfdbdd20cd
Parent:
9:c9cff697f4ab
Child:
11:ea15cf0230cd
Motor draait op code; Encoder telt alleen pulses

Who changed what in which revision?

UserRevisionLine numberNew 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 10:76dfdbdd20cd 24 QEI enc1(D12,D13,NC,64);
s1932896 10:76dfdbdd20cd 25 motor1 = 1;
s1932896 9:c9cff697f4ab 26 while(true)
s1932896 9:c9cff697f4ab 27 {
s1932896 10:76dfdbdd20cd 28 int value;
s1932896 10:76dfdbdd20cd 29 for(value = 100 ; value <= 255; value+=5)
s1932896 10:76dfdbdd20cd 30 {
s1932896 10:76dfdbdd20cd 31 motor1.write(1);
s1932896 10:76dfdbdd20cd 32 motor2.write(1);
s1932896 10:76dfdbdd20cd 33 e1.write(value); //PWM Speed Control
s1932896 10:76dfdbdd20cd 34 e2.write(value); //PWM Speed Control
s1932896 10:76dfdbdd20cd 35 wait_ms(50);
s1932896 9:c9cff697f4ab 36 pc.printf("%i ",enc1.getPulses());
s1932896 10:76dfdbdd20cd 37 }
s1932896 10:76dfdbdd20cd 38
s1932896 10:76dfdbdd20cd 39 wait_ms(500);
RobertoO 0:67c50348f842 40 }
s1932896 9:c9cff697f4ab 41
s1932896 9:c9cff697f4ab 42 }