hige dura
/
PWM_generator
PWM_generator
main.cpp@1:1d1a7680a3fe, 2012-12-05 (annotated)
- Committer:
- higedura
- Date:
- Wed Dec 05 05:53:03 2012 +0000
- Revision:
- 1:1d1a7680a3fe
- Parent:
- 0:566768f53e4b
PWM_generator
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:1d1a7680a3fe | 8 | int key_in = 0; |
higedura | 1:1d1a7680a3fe | 9 | double pulse_buf2 = 0; |
higedura | 1:1d1a7680a3fe | 10 | double pulse = 0; |
higedura | 1:1d1a7680a3fe | 11 | |
higedura | 0:566768f53e4b | 12 | esc.period(0.018); |
higedura | 0:566768f53e4b | 13 | esc.pulsewidth(0.001); |
higedura | 0:566768f53e4b | 14 | |
higedura | 0:566768f53e4b | 15 | while (1) { |
higedura | 0:566768f53e4b | 16 | |
higedura | 1:1d1a7680a3fe | 17 | // ASCII henkan omazinai |
higedura | 1:1d1a7680a3fe | 18 | key_in = pc.getc()-48; |
higedura | 1:1d1a7680a3fe | 19 | //pc.printf("%d",key_in); |
higedura | 1:1d1a7680a3fe | 20 | |
higedura | 1:1d1a7680a3fe | 21 | //if(){ |
higedura | 1:1d1a7680a3fe | 22 | //pulse_buf ni value wo input |
higedura | 1:1d1a7680a3fe | 23 | //} |
higedura | 1:1d1a7680a3fe | 24 | |
higedura | 1:1d1a7680a3fe | 25 | // pulse no tasizan 0.001 ~ 0.002 |
higedura | 1:1d1a7680a3fe | 26 | //pulse = 0.001+0.0001*(double)pulse_buf; |
higedura | 1:1d1a7680a3fe | 27 | |
higedura | 1:1d1a7680a3fe | 28 | // limmiter |
higedura | 0:566768f53e4b | 29 | if( pulse<0.001 ){ pulse = 0.001; } |
higedura | 0:566768f53e4b | 30 | if( 0.0019<pulse ){ pulse = 0.0019; } |
higedura | 1:1d1a7680a3fe | 31 | |
higedura | 1:1d1a7680a3fe | 32 | // updating pulse width |
higedura | 0:566768f53e4b | 33 | esc.pulsewidth(pulse); |
higedura | 1:1d1a7680a3fe | 34 | |
higedura | 0:566768f53e4b | 35 | pc.printf("%f\r\n", pulse); |
higedura | 0:566768f53e4b | 36 | |
higedura | 0:566768f53e4b | 37 | } |
higedura | 0:566768f53e4b | 38 | |
higedura | 0:566768f53e4b | 39 | } |