![]() |
![]() |
|
SAILAPIGuide
1_20_00_02
|
Dual stepper motor actutor.
===========================================================================
The Stepper header file should be included in an application as follows:
The ULN2003 BoosterPack can have two stepper motors connected to it. Stepper module can be interfaced with HC595(shift register) to perform operations such as single step movement or rotation.
Stepper uses output from ULN2003 which is driven by a shift register. A stepper motor can work in 3 different modes which are Fullstep, Halfstep and Wavedrive which in turn affect the power usage and the desired resolution of the motor. The Stepper module also supports movement in 2 different directions i.e. Clockwise and AntiClockwise.
The APIs in this driver serve as an interface to a DPL(Driver Porting Layer) The specific implementations are responsible for creating all the RTOS specific primitives to allow for thread-safe operation.
This driver has no dynamic memory allocation.
The Stepper_config array should contain pointers to a defined Stepper_HWAttrs and allocated array for the Stepper_Object structures. Stepper_init() must be called prior to using Stepper_open().
Each structure must be defined by the application. The following example is for a MSP432 in which one ULN2003 BoosterPack is setup. One ULN2003 BoosterPack can be connected to two stepper motors which can be controlled using a single Stepper module. The following declarations are placed in "MSP_EXP432P401R.h" and "MSP_EXP432P401R.c" respectively. How the gpioIndices are defined are detailed in the next example.
"MSP_EXP432P401R.h"
"MSP_EXP432P401R.c"
The Stepper_open() call must be made in a task context.
#include <stdint.h>#include <stdbool.h>#include <unistd.h>#include <stddef.h>#include <ti/drivers/GPIO.h>#include <ti/sail/hc595/hc595.h>Go to the source code of this file.
Data Structures | |
| struct | Stepper_Motor |
| This structure contains the properties of a motor. More... | |
| struct | Stepper_HWAttrs |
| Hardware specific settings for a Stepper module. More... | |
| struct | Stepper_Object |
| Stepper Object structure. More... | |
| struct | Stepper_Config |
| Stepper configuration. More... | |
| struct | Stepper_Params |
| Stepper Parameters. More... | |
Typedefs | |
| typedef struct Stepper_Config * | Stepper_Handle |
| A handle that is returned from a HC595_open() call. More... | |
| typedef enum Stepper_workMode | Stepper_workMode |
| Stepper Workmodes types based on control method. More... | |
| typedef enum Stepper_direction | Stepper_direction |
| Stepper motor direction options. More... | |
| typedef enum Stepper_motorEnum | Stepper_motorEnum |
| Enumeration for number of the motor controlled by Stepper. More... | |
| typedef struct Stepper_Motor | Stepper_Motor |
| This structure contains the properties of a motor. More... | |
| typedef struct Stepper_HWAttrs | Stepper_HWAttrs |
| Hardware specific settings for a Stepper module. More... | |
| typedef struct Stepper_Object | Stepper_Object |
| Stepper Object structure. More... | |
| typedef struct Stepper_Config | Stepper_Config |
| Stepper configuration. More... | |
| typedef struct Stepper_Params | Stepper_Params |
| Stepper Parameters. More... | |
Enumerations | |
| enum | Stepper_workMode { Stepper_workMode_fullStep = 0U, Stepper_workMode_halfStep = 1U, Stepper_workMode_waveDrive = 2U } |
| Stepper Workmodes types based on control method. More... | |
| enum | Stepper_direction { Stepper_direction_CW = 0U, Stepper_direction_CCW = 1U } |
| Stepper motor direction options. More... | |
| enum | Stepper_motorEnum { Stepper_motorEnum_motor1 = 0U, Stepper_motorEnum_motor2 = 1U, Stepper_motorEnum_all = 2U } |
| Enumeration for number of the motor controlled by Stepper. More... | |
Functions | |
| void | Stepper_initParams (Stepper_Params *params) |
| Function to initialize a Stepper_Params struct to its defaults. More... | |
| Stepper_Handle | Stepper_open (unsigned int StepperIndex, Stepper_Params *params) |
| Function to open an instance of Stepper. More... | |
| bool | Stepper_close (Stepper_Handle StepperHandle) |
| Function to close a Stepper specified by the Stepper handle. More... | |
| void | Stepper_init () |
| Function to initialize Stepper driver. More... | |
| bool | Stepper_step (Stepper_Handle StepperHandle, Stepper_motorEnum motorNum, Stepper_direction direction) |
| Function to move the stepper motors. More... | |
| bool | Stepper_setWorkMode (Stepper_Handle StepperHandle, Stepper_motorEnum motorNum, Stepper_workMode mode) |
| Function to change the workmode of a motor. More... | |
| Stepper_workMode | Stepper_getMotorMode (Stepper_Handle StepperHandle, Stepper_motorEnum motorNum) |
| Function to get current workmode of a motor. More... | |
| typedef struct Stepper_Config* Stepper_Handle |
A handle that is returned from a HC595_open() call.
| typedef enum Stepper_workMode Stepper_workMode |
Stepper Workmodes types based on control method.
A Stepper motor can be run in one of the 3 different modes i.e. Fullstep, Halfstep and Wavedrive.
| typedef enum Stepper_direction Stepper_direction |
Stepper motor direction options.
A Stepper motor can be moved in either of the two directions clockwise or anti-clockwise.
| typedef enum Stepper_motorEnum Stepper_motorEnum |
Enumeration for number of the motor controlled by Stepper.
A single instance of Stepper can control two motors numbered 1 and 2
| typedef struct Stepper_Motor Stepper_Motor |
This structure contains the properties of a motor.
Each motor can operate asynchronously in a different mode.
| typedef struct Stepper_HWAttrs Stepper_HWAttrs |
Hardware specific settings for a Stepper module.
This structure should be defined and provided by the application. The gpioIndex should be defined in accordance of the GPIO driver. The pin must be configured as GPIO_CFG_INPUT and GPIO_CFG_IN_INT_FALLING.
| typedef struct Stepper_Object Stepper_Object |
Stepper Object structure.
The application must not access any member variables of this structure!
| typedef struct Stepper_Config Stepper_Config |
Stepper configuration.
The Stepper_Config structure contains a set of pointers used to characterize the Stepper driver implementation.
This structure needs to be defined and provided by the application and will be NULL terminated.
| typedef struct Stepper_Params Stepper_Params |
Stepper Parameters.
Stepper parameters are used with the Stepper_open() call. Default values for these parameters are set using Stepper_initParams(). It contains the workmodes for two motors connected to ULN2003 BoosterPack.
| enum Stepper_workMode |
| enum Stepper_direction |
| enum Stepper_motorEnum |
| void Stepper_initParams | ( | Stepper_Params * | params | ) |
Function to initialize a Stepper_Params struct to its defaults.
| params | A pointer to Stepper_Params structure for initialization. |
Default values are: motor1mode = Stepper_workMode_fullStep; motor2mode = Stepper_workMode_halfStep;
References Stepper_defaultParams.
| Stepper_Handle Stepper_open | ( | unsigned int | StepperIndex, |
| Stepper_Params * | params | ||
| ) |
Function to open an instance of Stepper.
Function to initialize a given Stepper specified by the particular index value.
| StepperIndex | Logical Stepper number indexed into the Stepper_config table |
| *params | A pointer to Stepper_Params structure. If NULL, it will use default values. |
References HC595_open(), Stepper_HWAttrs::HC595Index, Stepper_Config::hwAttrs, Stepper_Motor::motorMode, Stepper_Params::motorNumMode, Stepper_Object::motors, Stepper_Config::object, Stepper_Object::shiftHandle, Stepper_count, Stepper_motorEnum_motor1, and Stepper_motorEnum_motor2.
| bool Stepper_close | ( | Stepper_Handle | StepperHandle | ) |
Function to close a Stepper specified by the Stepper handle.
The Stepper close API to close the Stepper instance specified by StepperHandle.
This call will destruct associated timer if running and turn off Stepper, can be hooked up with Power Down sequence in system.
| StepperHandle | A Stepper_Handle returned from Stepper_open() |
| void Stepper_init | ( | ) |
Function to initialize Stepper driver.
This function will initialize the Stepper driver.
| bool Stepper_step | ( | Stepper_Handle | StepperHandle, |
| Stepper_motorEnum | motorNum, | ||
| Stepper_direction | direction | ||
| ) |
Function to move the stepper motors.
| StepperHandle | A Stepper_Handle returned from Stepper_open(). |
| motorNum | A enumeration describing the motor no. i.e. motor1 or motor2. |
| direction | It is the direction of rotation of motor. |
References HC595_shift(), Stepper_Motor::motorMode, Stepper_Object::motors, Stepper_Config::object, Stepper_Object::shiftHandle, Stepper_direction_CW, Stepper_motorEnum_all, Stepper_motorEnum_motor1, Stepper_motorEnum_motor2, and workMode.
| bool Stepper_setWorkMode | ( | Stepper_Handle | StepperHandle, |
| Stepper_motorEnum | motorNum, | ||
| Stepper_workMode | mode | ||
| ) |
Function to change the workmode of a motor.
| StepperHandle | A Stepper_Handle returned from Stepper_open(). |
| motorNum | A enumeration describing the motor no. i.e. motor1 or motor2. |
| mode | It is the Workmode that the user wants to set. |
References HC595_clear(), Stepper_Motor::motorMode, Stepper_Object::motors, Stepper_Config::object, and Stepper_Object::shiftHandle.
| Stepper_workMode Stepper_getMotorMode | ( | Stepper_Handle | StepperHandle, |
| Stepper_motorEnum | motorNum | ||
| ) |
Function to get current workmode of a motor.
| StepperHandle | A Stepper_Handle returned from Stepper_open(). |
| motorNum | A enumeration describing the motor no. i.e. motor1 or motor2. |
References Stepper_Motor::motorMode, Stepper_Object::motors, and Stepper_Config::object.