PWM_generator

Dependencies:   mbed

Committer:
higedura
Date:
Wed Dec 05 05:27:10 2012 +0000
Revision:
0:566768f53e4b
Child:
1:1d1a7680a3fe
PWM_generator

Who changed what in which revision?

UserRevisionLine numberNew contents of line
higedura 0:566768f53e4b 1 #include "mbed.h"
higedura 0:566768f53e4b 2
higedura 0:566768f53e4b 3 Serial pc(USBTX, USBRX); // tx, rx
higedura 0:566768f53e4b 4 PwmOut esc(p22);
higedura 0:566768f53e4b 5
higedura 0:566768f53e4b 6 int main() {
higedura 0:566768f53e4b 7
higedura 0:566768f53e4b 8 int pulse_buf = 0;
higedura 0:566768f53e4b 9 double pulse = 0;
higedura 0:566768f53e4b 10
higedura 0:566768f53e4b 11 esc.period(0.018);
higedura 0:566768f53e4b 12 esc.pulsewidth(0.001);
higedura 0:566768f53e4b 13
higedura 0:566768f53e4b 14 while (1) {
higedura 0:566768f53e4b 15
higedura 0:566768f53e4b 16 pulse_buf = pc.getc()-48;
higedura 0:566768f53e4b 17 pulse = 0.001+0.0001*(double)pulse_buf;
higedura 0:566768f53e4b 18 if( pulse<0.001 ){ pulse = 0.001; }
higedura 0:566768f53e4b 19 if( 0.0019<pulse ){ pulse = 0.0019; }
higedura 0:566768f53e4b 20 esc.pulsewidth(pulse);
higedura 0:566768f53e4b 21 pc.printf("%f\r\n", pulse);
higedura 0:566768f53e4b 22
higedura 0:566768f53e4b 23 }
higedura 0:566768f53e4b 24
higedura 0:566768f53e4b 25 }