steppermotor driver solar on foils
Dependencies: mbed
Fork of CAN_module_stepper by
Stepper.cpp@1:239c8d704941, 2015-08-11 (annotated)
- Committer:
- Dannis_mbed
- Date:
- Tue Aug 11 08:52:57 2015 +0000
- Revision:
- 1:239c8d704941
Presentation version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Dannis_mbed | 1:239c8d704941 | 1 | |
Dannis_mbed | 1:239c8d704941 | 2 | #include "Stepper.h" |
Dannis_mbed | 1:239c8d704941 | 3 | |
Dannis_mbed | 1:239c8d704941 | 4 | // Contructor |
Dannis_mbed | 1:239c8d704941 | 5 | Stepper::Stepper() : |
Dannis_mbed | 1:239c8d704941 | 6 | counter(0), |
Dannis_mbed | 1:239c8d704941 | 7 | bRampUp(false), |
Dannis_mbed | 1:239c8d704941 | 8 | bRampDown(false) |
Dannis_mbed | 1:239c8d704941 | 9 | {}; |
Dannis_mbed | 1:239c8d704941 | 10 | |
Dannis_mbed | 1:239c8d704941 | 11 | Stepper::~Stepper() |
Dannis_mbed | 1:239c8d704941 | 12 | { |
Dannis_mbed | 1:239c8d704941 | 13 | }; |
Dannis_mbed | 1:239c8d704941 | 14 | |
Dannis_mbed | 1:239c8d704941 | 15 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 16 | // set's // |
Dannis_mbed | 1:239c8d704941 | 17 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 18 | void Stepper::vSetStepCount(uint32_t Value) |
Dannis_mbed | 1:239c8d704941 | 19 | { |
Dannis_mbed | 1:239c8d704941 | 20 | if (Value <= 400) uiInitRampDown = Value/2; |
Dannis_mbed | 1:239c8d704941 | 21 | else uiInitRampDown = 400; |
Dannis_mbed | 1:239c8d704941 | 22 | counter = Value; |
Dannis_mbed | 1:239c8d704941 | 23 | } |
Dannis_mbed | 1:239c8d704941 | 24 | |
Dannis_mbed | 1:239c8d704941 | 25 | void Stepper::vSetOffTimeCount(uint32_t Value) |
Dannis_mbed | 1:239c8d704941 | 26 | { |
Dannis_mbed | 1:239c8d704941 | 27 | offTimeCounter = Value; |
Dannis_mbed | 1:239c8d704941 | 28 | } |
Dannis_mbed | 1:239c8d704941 | 29 | |
Dannis_mbed | 1:239c8d704941 | 30 | void Stepper::vResetOffTimeCount(void) |
Dannis_mbed | 1:239c8d704941 | 31 | { |
Dannis_mbed | 1:239c8d704941 | 32 | offTimeCounter = 1500; // max ramp up/down = 700us |
Dannis_mbed | 1:239c8d704941 | 33 | offTime = true; |
Dannis_mbed | 1:239c8d704941 | 34 | bRampUp = true; |
Dannis_mbed | 1:239c8d704941 | 35 | bRampDown = false; |
Dannis_mbed | 1:239c8d704941 | 36 | } |
Dannis_mbed | 1:239c8d704941 | 37 | |
Dannis_mbed | 1:239c8d704941 | 38 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 39 | // get's // |
Dannis_mbed | 1:239c8d704941 | 40 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 41 | uint32_t Stepper::iGetStepCount(void) |
Dannis_mbed | 1:239c8d704941 | 42 | { |
Dannis_mbed | 1:239c8d704941 | 43 | return counter; |
Dannis_mbed | 1:239c8d704941 | 44 | } |
Dannis_mbed | 1:239c8d704941 | 45 | |
Dannis_mbed | 1:239c8d704941 | 46 | uint32_t Stepper::iGetOffTimeCount(void) |
Dannis_mbed | 1:239c8d704941 | 47 | { |
Dannis_mbed | 1:239c8d704941 | 48 | if (counter == uiInitRampDown) {bRampDown = true; bRampUp = false;} |
Dannis_mbed | 1:239c8d704941 | 49 | return offTimeCounter; |
Dannis_mbed | 1:239c8d704941 | 50 | } |
Dannis_mbed | 1:239c8d704941 | 51 | |
Dannis_mbed | 1:239c8d704941 | 52 | bool Stepper::bGetoffTime(void) |
Dannis_mbed | 1:239c8d704941 | 53 | { |
Dannis_mbed | 1:239c8d704941 | 54 | return offTime; |
Dannis_mbed | 1:239c8d704941 | 55 | } |
Dannis_mbed | 1:239c8d704941 | 56 | |
Dannis_mbed | 1:239c8d704941 | 57 | bool Stepper::bGetRampUp(void) |
Dannis_mbed | 1:239c8d704941 | 58 | { |
Dannis_mbed | 1:239c8d704941 | 59 | return bRampUp; |
Dannis_mbed | 1:239c8d704941 | 60 | } |
Dannis_mbed | 1:239c8d704941 | 61 | |
Dannis_mbed | 1:239c8d704941 | 62 | bool Stepper::bGetRampDown(void) |
Dannis_mbed | 1:239c8d704941 | 63 | { |
Dannis_mbed | 1:239c8d704941 | 64 | return bRampDown; |
Dannis_mbed | 1:239c8d704941 | 65 | } |
Dannis_mbed | 1:239c8d704941 | 66 | |
Dannis_mbed | 1:239c8d704941 | 67 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 68 | // decreases // |
Dannis_mbed | 1:239c8d704941 | 69 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 70 | void Stepper::vDecreaseStepCount(void) |
Dannis_mbed | 1:239c8d704941 | 71 | { |
Dannis_mbed | 1:239c8d704941 | 72 | counter--; |
Dannis_mbed | 1:239c8d704941 | 73 | } |
Dannis_mbed | 1:239c8d704941 | 74 | |
Dannis_mbed | 1:239c8d704941 | 75 | void Stepper::vDecreaseOffTimeCount(void) |
Dannis_mbed | 1:239c8d704941 | 76 | { |
Dannis_mbed | 1:239c8d704941 | 77 | if(offTimeCounter >= 800) // while ramp up isn't complete |
Dannis_mbed | 1:239c8d704941 | 78 | { |
Dannis_mbed | 1:239c8d704941 | 79 | offTimeCounter--; |
Dannis_mbed | 1:239c8d704941 | 80 | offTime = false; // ramp up complete |
Dannis_mbed | 1:239c8d704941 | 81 | if (offTimeCounter == 800) bRampUp = false; |
Dannis_mbed | 1:239c8d704941 | 82 | } |
Dannis_mbed | 1:239c8d704941 | 83 | } |
Dannis_mbed | 1:239c8d704941 | 84 | |
Dannis_mbed | 1:239c8d704941 | 85 | void Stepper::vIncreaseOffTimeCount(void) |
Dannis_mbed | 1:239c8d704941 | 86 | { |
Dannis_mbed | 1:239c8d704941 | 87 | if(offTimeCounter <= 1500) // while ramp down isn't complete |
Dannis_mbed | 1:239c8d704941 | 88 | { |
Dannis_mbed | 1:239c8d704941 | 89 | offTimeCounter++; |
Dannis_mbed | 1:239c8d704941 | 90 | //if (offTimeCounter == 1500) bRampUp = false; // ramp down complete |
Dannis_mbed | 1:239c8d704941 | 91 | } |
Dannis_mbed | 1:239c8d704941 | 92 | } |
Dannis_mbed | 1:239c8d704941 | 93 | |
Dannis_mbed | 1:239c8d704941 | 94 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 95 | // increases // |
Dannis_mbed | 1:239c8d704941 | 96 | ////////////////////////////////////////////////////////////////////////////////////// |
Dannis_mbed | 1:239c8d704941 | 97 | void Stepper::vIncreaseStepCount(void) |
Dannis_mbed | 1:239c8d704941 | 98 | { |
Dannis_mbed | 1:239c8d704941 | 99 | counter++; |
Dannis_mbed | 1:239c8d704941 | 100 | } |
Dannis_mbed | 1:239c8d704941 | 101 |