SAILAPIGuide  1_20_00_02
Data Structures | Typedefs | Enumerations | Functions
stepper.h File Reference

Detailed Description

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().

Defining Stepper_Config, Stepper_Object and Stepper_HWAttrs

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"

typedef enum MSP_EXP432P401R_StepperName {
MSP_EXP432P401R_Stepper_0 = 0, //Stepper number 1 on LaunchPad
MSP_EXP432P401R_StepperCOUNT //Total number of Steppers on the board
} MSP_EXP432P401R_StepperName;

"MSP_EXP432P401R.c"

Stepper_Object Stepper_object[MSP_EXP432P401R_StepperCOUNT];
const Stepper_HWAttrs Stepper_hwAttrs[MSP_EXP432P401R_StepperCOUNT] = {
{
.HC595Index = MSP_EXP432P401R_HC595_0,
},
};
{
.hwAttrs = &Stepper_hwAttrs[0],
.object = &Stepper_object[0],
},
{NULL, NULL}
};

Opening a Stepper with default parameters

The Stepper_open() call must be made in a task context.

Stepper_Handle StepperHandle;
Stepper_initParams(&StepperParams);
StepperHandle = Stepper_open(0,&StepperParams)

#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_ConfigStepper_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 Documentation

§ Stepper_Handle

typedef struct Stepper_Config* Stepper_Handle

A handle that is returned from a HC595_open() call.

§ 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.

§ Stepper_direction

Stepper motor direction options.

A Stepper motor can be moved in either of the two directions clockwise or anti-clockwise.

§ Stepper_motorEnum

Enumeration for number of the motor controlled by Stepper.

A single instance of Stepper can control two motors numbered 1 and 2

§ Stepper_Motor

typedef struct Stepper_Motor Stepper_Motor

This structure contains the properties of a motor.

Each motor can operate asynchronously in a different mode.

§ 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.

§ Stepper_Object

Stepper Object structure.

The application must not access any member variables of this structure!

§ 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.

§ 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.

See also
Stepper_initParams()

Enumeration Type Documentation

§ 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.

Enumerator
Stepper_workMode_fullStep 
Stepper_workMode_halfStep 
Stepper_workMode_waveDrive 

§ Stepper_direction

Stepper motor direction options.

A Stepper motor can be moved in either of the two directions clockwise or anti-clockwise.

Enumerator
Stepper_direction_CW 
Stepper_direction_CCW 

§ Stepper_motorEnum

Enumeration for number of the motor controlled by Stepper.

A single instance of Stepper can control two motors numbered 1 and 2

Enumerator
Stepper_motorEnum_motor1 

step motor1

Stepper_motorEnum_motor2 

step motor2

Stepper_motorEnum_all 

step both motors together

Function Documentation

§ Stepper_initParams()

void Stepper_initParams ( Stepper_Params params)

Function to initialize a Stepper_Params struct to its defaults.

Parameters
paramsA pointer to Stepper_Params structure for initialization.

Default values are: motor1mode = Stepper_workMode_fullStep; motor2mode = Stepper_workMode_halfStep;

References Stepper_defaultParams.

§ Stepper_open()

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.

Precondition
Stepper_init() has to be called first
Parameters
StepperIndexLogical Stepper number indexed into the Stepper_config table
*paramsA pointer to Stepper_Params structure. If NULL, it will use default values.
Returns
A Stepper_Handle on success, or a NULL on failure.
See also
Stepper_init()
Stepper_initParams()
Stepper_close()

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.

§ Stepper_close()

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.

Precondition
Stepper_open() had to be called first.
Parameters
StepperHandleA Stepper_Handle returned from Stepper_open()

§ Stepper_init()

void Stepper_init ( )

Function to initialize Stepper driver.

This function will initialize the Stepper driver.

§ Stepper_step()

bool Stepper_step ( Stepper_Handle  StepperHandle,
Stepper_motorEnum  motorNum,
Stepper_direction  direction 
)

Function to move the stepper motors.

Precondition
Stepper_open() had to be called first.
Parameters
StepperHandleA Stepper_Handle returned from Stepper_open().
motorNumA enumeration describing the motor no. i.e. motor1 or motor2.
directionIt is the direction of rotation of motor.
Returns
true if motor can step else return false

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.

§ Stepper_setWorkMode()

bool Stepper_setWorkMode ( Stepper_Handle  StepperHandle,
Stepper_motorEnum  motorNum,
Stepper_workMode  mode 
)

Function to change the workmode of a motor.

Precondition
Stepper_open() had to be called first.
Parameters
StepperHandleA Stepper_Handle returned from Stepper_open().
motorNumA enumeration describing the motor no. i.e. motor1 or motor2.
modeIt is the Workmode that the user wants to set.
Returns
true if motor can step else return false

References HC595_clear(), Stepper_Motor::motorMode, Stepper_Object::motors, Stepper_Config::object, and Stepper_Object::shiftHandle.

§ Stepper_getMotorMode()

Stepper_workMode Stepper_getMotorMode ( Stepper_Handle  StepperHandle,
Stepper_motorEnum  motorNum 
)

Function to get current workmode of a motor.

Precondition
Stepper_open() had to be called first.
Parameters
StepperHandleA Stepper_Handle returned from Stepper_open().
motorNumA enumeration describing the motor no. i.e. motor1 or motor2.
Returns
A Stepper_workMode on success, or a NULL on failure.

References Stepper_Motor::motorMode, Stepper_Object::motors, and Stepper_Config::object.

Copyright 2018, Texas Instruments Incorporated