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-23
Revision:
2:70918f7f8451
Parent:
1:70c514e10598
Child:
3:f6c30ada5370

File content as of revision 2:70918f7f8451:

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

FastPWM mypwm(PWM_OUT);

DigitalOut myled(LED1);

Serial pcLink(SERIAL_TX, SERIAL_RX);

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

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

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

        myled = !myled;

        wait(1);
    }
}