Keegan Hu
/
Ex_Stepper
dasf
Fork of Ex_Stepper by
main.cpp@2:c944fc6cdfb7, 2018-03-19 (annotated)
- Committer:
- zhangyx
- Date:
- Mon Mar 19 03:34:20 2018 +0000
- Revision:
- 2:c944fc6cdfb7
- Parent:
- 1:6d4a62f98351
- Child:
- 3:46647fcd0269
pin changed
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 | 2:c944fc6cdfb7 | 4 | DigitalOut step(PB_0), dir(PB_1), en(PC_13); |
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 | } |