Basic DC motor control test, rpm feedback by simple impulse signal, PID speed control.

Dependencies:   FastPWM mbed FastIO MODSERIAL

Committer:
dzoni
Date:
Thu Mar 22 11:23:31 2018 +0000
Revision:
1:70c514e10598
Parent:
0:bd186184ef2a
Child:
2:70918f7f8451
Initial version - FastPWM functionality confirmation test. Compiles without warnings.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dzoni 0:bd186184ef2a 1 #include "mbed.h"
dzoni 1:70c514e10598 2 #include "FastPWM.h"
dzoni 0:bd186184ef2a 3
dzoni 1:70c514e10598 4 FastPWM mypwm(PWM_OUT);
dzoni 0:bd186184ef2a 5
dzoni 0:bd186184ef2a 6 DigitalOut myled(LED1);
dzoni 0:bd186184ef2a 7
dzoni 0:bd186184ef2a 8 int main() {
dzoni 0:bd186184ef2a 9
dzoni 1:70c514e10598 10 mypwm.period_us(100);
dzoni 1:70c514e10598 11 mypwm.write(0.0);
dzoni 0:bd186184ef2a 12
dzoni 0:bd186184ef2a 13 printf("pwm set to %.2f %%\n", mypwm.read() * 100);
dzoni 0:bd186184ef2a 14
dzoni 0:bd186184ef2a 15 while(1) {
dzoni 1:70c514e10598 16 int iCnt = 0;
dzoni 1:70c514e10598 17 double dPwmDuty = 0.0;
dzoni 1:70c514e10598 18
dzoni 1:70c514e10598 19 mypwm.write(dPwmDuty);
dzoni 1:70c514e10598 20
dzoni 1:70c514e10598 21 if (10 < iCnt++) {
dzoni 1:70c514e10598 22 iCnt = 0;
dzoni 1:70c514e10598 23
dzoni 1:70c514e10598 24 dPwmDuty += 0.1;
dzoni 1:70c514e10598 25
dzoni 1:70c514e10598 26 if (1.0 < dPwmDuty) {
dzoni 1:70c514e10598 27 dPwmDuty = 0.0;
dzoni 1:70c514e10598 28 }
dzoni 1:70c514e10598 29 }
dzoni 1:70c514e10598 30
dzoni 0:bd186184ef2a 31 myled = !myled;
dzoni 1:70c514e10598 32
dzoni 0:bd186184ef2a 33 wait(1);
dzoni 0:bd186184ef2a 34 }
dzoni 0:bd186184ef2a 35 }