afsd
Fork of a4998 by
a4988.cpp@1:88f743f3e7a7, 2018-05-11 (annotated)
- Committer:
- Bilybill
- Date:
- Fri May 11 06:05:21 2018 +0000
- Revision:
- 1:88f743f3e7a7
- Parent:
- 0:173936452e07
afds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
glintligo | 0:173936452e07 | 1 | #include "a4988.h" |
glintligo | 0:173936452e07 | 2 | #include "mbed.h" |
glintligo | 0:173936452e07 | 3 | Stepper::Stepper(PinName _en, PinName _stepPin, PinName _direction):en(_en), |
glintligo | 0:173936452e07 | 4 | stepPin(_stepPin), |
glintligo | 0:173936452e07 | 5 | direction(_direction) |
glintligo | 0:173936452e07 | 6 | { |
glintligo | 0:173936452e07 | 7 | |
glintligo | 0:173936452e07 | 8 | } |
Bilybill | 1:88f743f3e7a7 | 9 | void Stepper::step(int dir, long long int frequency ,volatile long long int _remain) |
glintligo | 0:173936452e07 | 10 | { |
glintligo | 0:173936452e07 | 11 | //fun = &Stepper::step_control; |
glintligo | 0:173936452e07 | 12 | if (dir == 1) { |
glintligo | 0:173936452e07 | 13 | direction = 0; |
glintligo | 0:173936452e07 | 14 | } else if (dir == 0) { |
glintligo | 0:173936452e07 | 15 | direction = 1; |
glintligo | 0:173936452e07 | 16 | } |
glintligo | 0:173936452e07 | 17 | remain = _remain; |
Bilybill | 1:88f743f3e7a7 | 18 | step_ticker.attach(this, &Stepper::step_control,0.5/frequency); |
glintligo | 0:173936452e07 | 19 | } |
glintligo | 0:173936452e07 | 20 | |
glintligo | 0:173936452e07 | 21 | void Stepper::enable() |
glintligo | 0:173936452e07 | 22 | { |
glintligo | 0:173936452e07 | 23 | en = 0; |
glintligo | 0:173936452e07 | 24 | } |
glintligo | 0:173936452e07 | 25 | |
glintligo | 0:173936452e07 | 26 | void Stepper::disable() |
glintligo | 0:173936452e07 | 27 | { |
glintligo | 0:173936452e07 | 28 | en = 1; |
glintligo | 0:173936452e07 | 29 | } |
glintligo | 0:173936452e07 | 30 | |
glintligo | 0:173936452e07 | 31 | void Stepper::step_control() |
glintligo | 0:173936452e07 | 32 | { |
glintligo | 0:173936452e07 | 33 | if(remain == 0) |
glintligo | 0:173936452e07 | 34 | { |
glintligo | 0:173936452e07 | 35 | return; |
glintligo | 0:173936452e07 | 36 | } |
Bilybill | 1:88f743f3e7a7 | 37 | if(remain < 0 ) |
Bilybill | 1:88f743f3e7a7 | 38 | { |
Bilybill | 1:88f743f3e7a7 | 39 | if(stepPin){ |
Bilybill | 1:88f743f3e7a7 | 40 | stepPin = 0; //STEP 1->0 |
Bilybill | 1:88f743f3e7a7 | 41 | }else{ |
Bilybill | 1:88f743f3e7a7 | 42 | stepPin = 1; //STEP 0->1 |
Bilybill | 1:88f743f3e7a7 | 43 | } |
Bilybill | 1:88f743f3e7a7 | 44 | } |
Bilybill | 1:88f743f3e7a7 | 45 | |
Bilybill | 1:88f743f3e7a7 | 46 | if(stepPin){ |
Bilybill | 1:88f743f3e7a7 | 47 | stepPin = 0; //STEP 1->0 |
Bilybill | 1:88f743f3e7a7 | 48 | remain--; |
Bilybill | 1:88f743f3e7a7 | 49 | }else{ |
Bilybill | 1:88f743f3e7a7 | 50 | stepPin = 1; //STEP 0->1 |
Bilybill | 1:88f743f3e7a7 | 51 | } |
glintligo | 0:173936452e07 | 52 | } |