for controlling stepper motor with A4980
Dependents: HIDTympDeviceWithPIDController
motorControl.h@0:9156e6b6bf46, 2014-10-06 (annotated)
- Committer:
- piniels
- Date:
- Mon Oct 06 11:57:45 2014 +0000
- Revision:
- 0:9156e6b6bf46
jkhasd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
piniels | 0:9156e6b6bf46 | 1 | /* |
piniels | 0:9156e6b6bf46 | 2 | ############################################ |
piniels | 0:9156e6b6bf46 | 3 | ## Motor Control v0.1 Library ## |
piniels | 0:9156e6b6bf46 | 4 | ## created by Peter Ilsoee ## |
piniels | 0:9156e6b6bf46 | 5 | ############################################ |
piniels | 0:9156e6b6bf46 | 6 | ---- piniels@gmail.com ----- |
piniels | 0:9156e6b6bf46 | 7 | This library was made for 4-Phase Stepper Motors for A4980 SPI device from Allegro |
piniels | 0:9156e6b6bf46 | 8 | I don't take any resposability for the damage caused to your equipment. |
piniels | 0:9156e6b6bf46 | 9 | |
piniels | 0:9156e6b6bf46 | 10 | */ |
piniels | 0:9156e6b6bf46 | 11 | #ifndef MOTOR_CONTROL_H |
piniels | 0:9156e6b6bf46 | 12 | #define MOTOR_CONTROL_H |
piniels | 0:9156e6b6bf46 | 13 | |
piniels | 0:9156e6b6bf46 | 14 | #include "mbed.h" |
piniels | 0:9156e6b6bf46 | 15 | #include "A4980ControlRegi.h" |
piniels | 0:9156e6b6bf46 | 16 | |
piniels | 0:9156e6b6bf46 | 17 | class motorControl { |
piniels | 0:9156e6b6bf46 | 18 | public: |
piniels | 0:9156e6b6bf46 | 19 | |
piniels | 0:9156e6b6bf46 | 20 | motorControl(int numberOfSteps, PinName step, PinName dir, PinName ms1, PinName ms0, PinName enable, PinName reset, PinName diag); //motor constructor |
piniels | 0:9156e6b6bf46 | 21 | void step(int num_steps, int direction, int speed); |
piniels | 0:9156e6b6bf46 | 22 | |
piniels | 0:9156e6b6bf46 | 23 | void initSpi(); |
piniels | 0:9156e6b6bf46 | 24 | int setConfigRegi0(t_config_control_regi_0 value); |
piniels | 0:9156e6b6bf46 | 25 | int setConfigRegi1(t_config_control_regi_1 value); |
piniels | 0:9156e6b6bf46 | 26 | int setRunRegi(t_run_regi value); |
piniels | 0:9156e6b6bf46 | 27 | int getStepCount(); |
piniels | 0:9156e6b6bf46 | 28 | void setStepCount(int value); |
piniels | 0:9156e6b6bf46 | 29 | void setMicroSteps(int value); |
piniels | 0:9156e6b6bf46 | 30 | int getMicroSteps(); |
piniels | 0:9156e6b6bf46 | 31 | t_config_control_regi_0 getConfigRegi0(); |
piniels | 0:9156e6b6bf46 | 32 | t_config_control_regi_1 getConfigRegi1(); |
piniels | 0:9156e6b6bf46 | 33 | t_run_regi getRunRegi(); |
piniels | 0:9156e6b6bf46 | 34 | void runStepperAtSpeed(bool startStop, int whatSpeed, int direction); |
piniels | 0:9156e6b6bf46 | 35 | void runStepperAtSpeedWithSPI(bool startStop, int whatSpeed, int direction); |
piniels | 0:9156e6b6bf46 | 36 | void goToZeroPosition(int whatSpeed); |
piniels | 0:9156e6b6bf46 | 37 | void openCloseValve(bool openTrue); |
piniels | 0:9156e6b6bf46 | 38 | /** Call back member for timer tick |
piniels | 0:9156e6b6bf46 | 39 | * |
piniels | 0:9156e6b6bf46 | 40 | */ |
piniels | 0:9156e6b6bf46 | 41 | void runMotor(void); |
piniels | 0:9156e6b6bf46 | 42 | void doRamp(int numberOfRampsteps,float endDelay); |
piniels | 0:9156e6b6bf46 | 43 | float calculateStepDelay(int whatSpeed); |
piniels | 0:9156e6b6bf46 | 44 | void step(int num_steps, int delay, bool direction); |
piniels | 0:9156e6b6bf46 | 45 | |
piniels | 0:9156e6b6bf46 | 46 | private: |
piniels | 0:9156e6b6bf46 | 47 | int _Number_OF_STEPS; |
piniels | 0:9156e6b6bf46 | 48 | int _Step_Counter; |
piniels | 0:9156e6b6bf46 | 49 | bool _Bool_Direction; |
piniels | 0:9156e6b6bf46 | 50 | PwmOut _STEP; |
piniels | 0:9156e6b6bf46 | 51 | DigitalOut _DIR; |
piniels | 0:9156e6b6bf46 | 52 | DigitalOut _MS1; |
piniels | 0:9156e6b6bf46 | 53 | DigitalOut _MS0; |
piniels | 0:9156e6b6bf46 | 54 | DigitalOut _ENABLE; |
piniels | 0:9156e6b6bf46 | 55 | DigitalOut _RESET; |
piniels | 0:9156e6b6bf46 | 56 | DigitalIn _DIAG; |
piniels | 0:9156e6b6bf46 | 57 | float step_delay; |
piniels | 0:9156e6b6bf46 | 58 | t_config_control_regi_0 _REGI_0; |
piniels | 0:9156e6b6bf46 | 59 | t_config_control_regi_1 _REGI_1; |
piniels | 0:9156e6b6bf46 | 60 | t_run_regi _REGI_RUN; |
piniels | 0:9156e6b6bf46 | 61 | |
piniels | 0:9156e6b6bf46 | 62 | |
piniels | 0:9156e6b6bf46 | 63 | |
piniels | 0:9156e6b6bf46 | 64 | |
piniels | 0:9156e6b6bf46 | 65 | }; |
piniels | 0:9156e6b6bf46 | 66 | |
piniels | 0:9156e6b6bf46 | 67 | #endif |