Keegan Hu
/
Ex_Stepper
dasf
Fork of Ex_Stepper by
main.cpp@0:19f886d481f3, 2017-10-11 (annotated)
- Committer:
- zhangyx
- Date:
- Wed Oct 11 03:38:41 2017 +0000
- Revision:
- 0:19f886d481f3
- Child:
- 1:6d4a62f98351
initial
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 | 0:19f886d481f3 | 19 | ticker_step.attach(&toggle_step, 0.001); |
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 | 0:19f886d481f3 | 24 | remain = 100; |
zhangyx | 0:19f886d481f3 | 25 | wait(1); |
zhangyx | 0:19f886d481f3 | 26 | dir = 1; |
zhangyx | 0:19f886d481f3 | 27 | remain = 100; |
zhangyx | 0:19f886d481f3 | 28 | wait(1); |
zhangyx | 0:19f886d481f3 | 29 | } |
zhangyx | 0:19f886d481f3 | 30 | } |