Keegan Hu
/
Ex_Stepper
dasf
Fork of Ex_Stepper by
main.cpp@1:6d4a62f98351, 2017-10-11 (annotated)
- Committer:
- zhangyx
- Date:
- Wed Oct 11 06:19:41 2017 +0000
- Revision:
- 1:6d4a62f98351
- Parent:
- 0:19f886d481f3
- Child:
- 2:c944fc6cdfb7
update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zhangyx | 0:19f886d481f3 | 1 | #include "mbed.h" |
zhangyx | 0:19f886d481f3 | 2 | |
zhangyx | 0:19f886d481f3 | 3 | Ticker ticker_step; |
zhangyx | 0:19f886d481f3 | 4 | DigitalOut step(PB_0), dir(PB_1), en(PA_7); |
zhangyx | 0:19f886d481f3 | 5 | volatile int remain; |
zhangyx | 0:19f886d481f3 | 6 | |
zhangyx | 0:19f886d481f3 | 7 | void toggle_step() { //产生STEP脉冲信号 |
zhangyx | 0:19f886d481f3 | 8 | if(remain == 0) |
zhangyx | 0:19f886d481f3 | 9 | return; |
zhangyx | 0:19f886d481f3 | 10 | if(step){ |
zhangyx | 0:19f886d481f3 | 11 | step = 0; //STEP 1->0 |
zhangyx | 0:19f886d481f3 | 12 | remain--; |
zhangyx | 0:19f886d481f3 | 13 | }else{ |
zhangyx | 0:19f886d481f3 | 14 | step = 1; //STEP 0->1 |
zhangyx | 0:19f886d481f3 | 15 | } |
zhangyx | 0:19f886d481f3 | 16 | } |
zhangyx | 0:19f886d481f3 | 17 | |
zhangyx | 0:19f886d481f3 | 18 | int main() { |
zhangyx | 1:6d4a62f98351 | 19 | ticker_step.attach(&toggle_step, 0.0002); |
zhangyx | 0:19f886d481f3 | 20 | en = 0; //Enable stepper driver |
zhangyx | 0:19f886d481f3 | 21 | |
zhangyx | 0:19f886d481f3 | 22 | while (true) { |
zhangyx | 0:19f886d481f3 | 23 | dir = 0; |
zhangyx | 1:6d4a62f98351 | 24 | remain = 3200; |
zhangyx | 1:6d4a62f98351 | 25 | wait(1.5); |
zhangyx | 0:19f886d481f3 | 26 | dir = 1; |
zhangyx | 1:6d4a62f98351 | 27 | remain = 3200; |
zhangyx | 1:6d4a62f98351 | 28 | wait(1.5); |
zhangyx | 0:19f886d481f3 | 29 | } |
zhangyx | 0:19f886d481f3 | 30 | } |