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

Dependencies:   FastPWM mbed FastIO MODSERIAL

main.cpp

Committer:
dzoni
Date:
2018-03-22
Revision:
1:70c514e10598
Parent:
0:bd186184ef2a
Child:
2:70918f7f8451

File content as of revision 1:70c514e10598:

#include "mbed.h"
#include "FastPWM.h"

FastPWM mypwm(PWM_OUT);

DigitalOut myled(LED1);

int main() {
    
    mypwm.period_us(100);
    mypwm.write(0.0);
  
    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
    
    while(1) {
        int iCnt = 0;
        double dPwmDuty = 0.0;
        
        mypwm.write(dPwmDuty);

        if (10 < iCnt++) {        
            iCnt = 0;

            dPwmDuty += 0.1;
        
            if (1.0 < dPwmDuty) {
                dPwmDuty = 0.0;
            }
        }

        myled = !myled;

        wait(1);
    }
}