PWM_generator

Dependencies:   mbed

main.cpp

Committer:
higedura
Date:
2012-12-05
Revision:
0:566768f53e4b
Child:
1:1d1a7680a3fe

File content as of revision 0:566768f53e4b:

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx
PwmOut esc(p22);

int main() {

    int pulse_buf   =   0;
    double pulse    =   0;
    
    esc.period(0.018);
    esc.pulsewidth(0.001);
    
    while (1) {
        
        pulse_buf   =   pc.getc()-48;
        pulse   =   0.001+0.0001*(double)pulse_buf;
        if( pulse<0.001 ){  pulse = 0.001;  }
        if( 0.0019<pulse ){ pulse = 0.0019; }
        esc.pulsewidth(pulse);
        pc.printf("%f\r\n", pulse);
        
    }
    
}