新型モータードライバのメインプログラム
Dependencies: mbed
main.cpp@0:cf3829614495, 2016-05-11 (annotated)
- Committer:
- SES01
- Date:
- Wed May 11 07:31:23 2016 +0000
- Revision:
- 0:cf3829614495
- Child:
- 1:e45830806a1c
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SES01 | 0:cf3829614495 | 1 | #include "mbed.h" |
SES01 | 0:cf3829614495 | 2 | |
SES01 | 0:cf3829614495 | 3 | #define F_MD 18000 //PWMキャリア周波数設定 |
SES01 | 0:cf3829614495 | 4 | |
SES01 | 0:cf3829614495 | 5 | /* |
SES01 | 0:cf3829614495 | 6 | * High_A High_B |
SES01 | 0:cf3829614495 | 7 | * ┃ ┃ |
SES01 | 0:cf3829614495 | 8 | * ┃ ┃ |
SES01 | 0:cf3829614495 | 9 | * ┣━━━┫ |
SES01 | 0:cf3829614495 | 10 | * ┃ ┃ |
SES01 | 0:cf3829614495 | 11 | * ┃ ┃ |
SES01 | 0:cf3829614495 | 12 | * Low_A Low_B |
SES01 | 0:cf3829614495 | 13 | */ |
SES01 | 0:cf3829614495 | 14 | |
SES01 | 0:cf3829614495 | 15 | //Serial pc(USBTX, USBRX); |
SES01 | 0:cf3829614495 | 16 | Serial comPort(dp16, dp15); |
SES01 | 0:cf3829614495 | 17 | //DigitalOut myled1(LED1); //汎用IOで使用するためLED1は使用できない |
SES01 | 0:cf3829614495 | 18 | DigitalOut myled(dp24); |
SES01 | 0:cf3829614495 | 19 | DigitalOut driverEnable(dp28); |
SES01 | 0:cf3829614495 | 20 | //dp1 = ローサイドPWM1, dp2 = ローサイドPWM2 |
SES01 | 0:cf3829614495 | 21 | //dp5 = ハイサイドPWM1, dp27 = ハイサイドPWM2 (オープンドレイン) |
SES01 | 0:cf3829614495 | 22 | PwmOut Low_A(dp1); |
SES01 | 0:cf3829614495 | 23 | PwmOut Low_B(dp2); |
SES01 | 0:cf3829614495 | 24 | DigitalOut High_A(dp5); |
SES01 | 0:cf3829614495 | 25 | DigitalOut High_B(dp27); |
SES01 | 0:cf3829614495 | 26 | |
SES01 | 0:cf3829614495 | 27 | AnalogIn ain(dp4); |
SES01 | 0:cf3829614495 | 28 | BusInOut led7(dp6, dp9, dp10, dp11, dp13, dp14, dp17, dp18); |
SES01 | 0:cf3829614495 | 29 | |
SES01 | 0:cf3829614495 | 30 | void com_rx() { |
SES01 | 0:cf3829614495 | 31 | /*switch (comPort.getc()) { |
SES01 | 0:cf3829614495 | 32 | case 255 |
SES01 | 0:cf3829614495 | 33 | |
SES01 | 0:cf3829614495 | 34 | }*/ |
SES01 | 0:cf3829614495 | 35 | } |
SES01 | 0:cf3829614495 | 36 | |
SES01 | 0:cf3829614495 | 37 | int main() { |
SES01 | 0:cf3829614495 | 38 | //comPort.baud(9600); |
SES01 | 0:cf3829614495 | 39 | //comPort.format(8, Serial::None, 1); |
SES01 | 0:cf3829614495 | 40 | comPort.attach(&com_rx, Serial::RxIrq); |
SES01 | 0:cf3829614495 | 41 | |
SES01 | 0:cf3829614495 | 42 | int FP_MD = 1000000 / F_MD; //PWM一周期の周期(マイクロ秒) |
SES01 | 0:cf3829614495 | 43 | |
SES01 | 0:cf3829614495 | 44 | led7.output(); |
SES01 | 0:cf3829614495 | 45 | |
SES01 | 0:cf3829614495 | 46 | High_A = 0; |
SES01 | 0:cf3829614495 | 47 | High_B = 1; |
SES01 | 0:cf3829614495 | 48 | |
SES01 | 0:cf3829614495 | 49 | Low_A.period_us(FP_MD); |
SES01 | 0:cf3829614495 | 50 | Low_A.write(0); |
SES01 | 0:cf3829614495 | 51 | Low_B.period_us(FP_MD); |
SES01 | 0:cf3829614495 | 52 | Low_B.write(0); |
SES01 | 0:cf3829614495 | 53 | //初期設定完了 |
SES01 | 0:cf3829614495 | 54 | |
SES01 | 0:cf3829614495 | 55 | //flipper.attach(&flip, 2.0); |
SES01 | 0:cf3829614495 | 56 | //flipper.attach(&flip, 2.0); |
SES01 | 0:cf3829614495 | 57 | //myled1 = 1; |
SES01 | 0:cf3829614495 | 58 | led7 = 0b11011010; |
SES01 | 0:cf3829614495 | 59 | driverEnable = 1; |
SES01 | 0:cf3829614495 | 60 | while (1) { |
SES01 | 0:cf3829614495 | 61 | Low_A.write((ain.read() - 0.2) * 1.25 < 0 ? 0 : (ain.read() - 0.2) * 1.25); |
SES01 | 0:cf3829614495 | 62 | //pc.printf("%f\n", (ain.read() - 0.2) * 1.25 < 0 ? 0 : (ain.read() - 0.2) * 1.25); |
SES01 | 0:cf3829614495 | 63 | comPort.printf("%d", 0b01010101); |
SES01 | 0:cf3829614495 | 64 | } |
SES01 | 0:cf3829614495 | 65 | } |