LibL6474-C-Library 1.0
Library Code documentation
Loading...
Searching...
No Matches
LibL6474.h File Reference
#include "LibL6474Config.h"
+ Include dependency graph for LibL6474.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  L6474_Status
 
struct  L6474x_Platform
 
struct  L6474_BaseParameter_t
 

Macros

#define INC_LIBL6474_H_   INC_LIBL6474_H_
 

Typedefs

typedef enum L6474x_State L6474x_State_t
 
typedef enum L6474x_StepMode L6474x_StepMode_t
 
typedef enum L6474x_Direction L6474x_Direction_t
 
typedef enum L6474x_ErrorCode L6474x_ErrorCode_t
 
typedef struct L6474_Status L6474_Status_t
 
typedef enum L6474x_OCD_TH L6474x_OCD_TH_t
 
typedef struct L6474_Handle * L6474_Handle_t
 
typedef struct L6474x_Platform L6474x_Platform_t
 

Enumerations

enum  L6474x_State { stRESET = 0x00 , stDISABLED = 0x01 , stENABLED = 0x02 , stINVALID = 0x04 }
 
enum  L6474x_StepMode {
  smFULL = 0x00 , smHALF = 0x01 , smMICRO4 = 0x02 , smMICRO8 = 0x03 ,
  smMICRO16 = 0x04
}
 
enum  L6474x_Direction { dirFOREWARD = 0x00 , dirBACKWARD = 0x01 }
 
enum  L6474x_ErrorCode {
  errcNONE = 0 , errcINV_ARG = -1 , errcNULL_ARG = -2 , errcINV_STATE = -3 ,
  errcINTERNAL = -4 , errcLOCKING = -5 , errcDEVICE_STATE = -6 , errcPENDING = -7 ,
  errcFORBIDDEN = -8
}
 
enum  L6474x_OCD_TH {
  ocdth375mA = 0x00 , ocdth750mA = 0x01 , ocdth1125mA = 0x02 , ocdth1500mA = 0x03 ,
  ocdth1875mA = 0x04 , ocdth2250mA = 0x05 , ocdth2625mA = 0x06 , ocdth3000mA = 0x07 ,
  ocdth3375mA = 0x08 , ocdth3750mA = 0x09 , ocdth4125mA = 0x0A , ocdth4500mA = 0x0B ,
  ocdth4875mA = 0x0C , ocdth5250mA = 0x0D , ocdth5625mA = 0x0E , ocdth6000mA = 0x0F
}
 
enum  L6474_Property_t {
  L6474_PROP_TORQUE = 0x09 , L6474_PROP_TON = 0x0F , L6474_PROP_TOFF = 0x10 , L6474_PROP_ADC_OUT = 0x12 ,
  L6474_PROP_OCDTH = 0x13 , L6474_PROP_TFAST = 0x0E
}
 

Functions

L6474_Handle_t L6474_CreateInstance (L6474x_Platform_t *p, void *pIO, void *pGPO, void *pPWM)
 
int L6474_DestroyInstance (L6474_Handle_t h)
 
int L6474_ResetStandBy (L6474_Handle_t h)
 
int L6474_SetBaseParameter (L6474_BaseParameter_t *p)
 
char L6474_EncodePhaseCurrent (float mA)
 
int L6474_EncodePhaseCurrentParameter (L6474_BaseParameter_t *p, float mA)
 
int L6474_Initialize (L6474_Handle_t h, L6474_BaseParameter_t *p)
 
int L6474_SetStepMode (L6474_Handle_t h, L6474x_StepMode_t mode)
 
int L6474_GetStepMode (L6474_Handle_t h, L6474x_StepMode_t *mode)
 
int L6474_SetPowerOutputs (L6474_Handle_t h, int ena)
 
int L6474_GetStatus (L6474_Handle_t h, L6474_Status_t *status)
 
int L6474_GetState (L6474_Handle_t h, L6474x_State_t *state)
 
int L6474_StepIncremental (L6474_Handle_t h, int steps)
 
int L6474_StopMovement (L6474_Handle_t h)
 
int L6474_IsMoving (L6474_Handle_t h, int *moving)
 
int L6474_SetProperty (L6474_Handle_t h, L6474_Property_t prop, int value)
 
int L6474_GetProperty (L6474_Handle_t h, L6474_Property_t prop, int *value)
 
int L6474_GetAbsolutePosition (L6474_Handle_t h, int *position)
 
int L6474_SetAbsolutePosition (L6474_Handle_t h, int position)
 
int L6474_GetElectricalPosition (L6474_Handle_t h, int *position)
 
int L6474_SetElectricalPosition (L6474_Handle_t h, int position)
 
int L6474_GetPositionMark (L6474_Handle_t h, int *position)
 
int L6474_SetPositionMark (L6474_Handle_t h, int position)
 
int L6474_GetAlarmEnables (L6474_Handle_t h, int *bits)
 
int L6474_SetAlarmEnables (L6474_Handle_t h, int bits)
 

Typedef Documentation

◆ L6474_Handle_t

typedef struct L6474_Handle* L6474_Handle_t

The L6474_Handle_t handle is an instance pointer of the driver library which is generated whenever the L6474_CreateInstance function returns with success. Therefore at least a L6474x_Platform_t platform description pointer is required

◆ L6474_Status_t

typedef struct L6474_Status L6474_Status_t

The L6474_Status_t enum describes the status register content of the stepper driver chip. It is reinterpreted so it can be naturally used in the code to get some of the error codes or state bits of the driver.

◆ L6474x_Direction_t

The L6474x_Direction_t enum describes the direction of the driver and therefore the rotation of the stepper axis.

◆ L6474x_ErrorCode_t

The L6474x_ErrorCode_t enum describes the possible error codes when using the API commands. Those error codes are mostly returned as return value by the API function which has been called previously

◆ L6474x_OCD_TH_t

The L6474x_OCD_TH_t enum describes the possible overcurrent threshold values which can be set in the library and which are then taken into account by the stepper driver

◆ L6474x_Platform_t

The L6474x_Platform_t structure is used to encapsulate platform specific parameters and to provide environment specific functions in a generalized format. Theses functions are malloc and free or some PWM and GPIO abstractions The lock guards and thread safety mechanisms are also abstracted by this structure

◆ L6474x_State_t

The LibL6474Config.h must be provided by the user project. The header in conf folder is only a template!

The L6474x_State_t enum is used to describe the current state of the driver library which helps the user to decide the next steps to be taken or to get notified about an unexpected state which is caused by an error

◆ L6474x_StepMode_t

The L6474x_StepMode_t enum is used to describe the current step mode (resolution) of the driver library and the stepper motor. This changes the internal calculations for speed and position and requires a new reference run in case it will be changed at runtime.

Enumeration Type Documentation

◆ L6474_Property_t

The L6474_Property_t enum is a address representation for externally changeable properties by the library via the API commands. In case the torque shall be changed, the user can call L6474_SetProperty with the L6474_PROP_TORQUE entry. Some of the properties can not be changed while the driver outputs are enabled and the library is in stENABLED state

Enumerator
L6474_PROP_TORQUE 

L6474_PROP_TORQUE is the current setpoint value of each phase of the stepper which follows the torque directly

L6474_PROP_TON 

L6474_PROP_TON is the minimum time for the ON-part of the current control loop

L6474_PROP_TOFF 

L6474_PROP_TOFF is the minimum time for the OFF-part of the current control loop

L6474_PROP_ADC_OUT 

L6474_PROP_ADC_OUT controls the ADC output behavior

L6474_PROP_OCDTH 

L6474_PROP_OCDTH sets the overcurrent threshold detection value

L6474_PROP_TFAST 

L6474_PROP_TFAST is used to change switching times

◆ L6474x_Direction

The L6474x_Direction_t enum describes the direction of the driver and therefore the rotation of the stepper axis.

Enumerator
dirFOREWARD 

dirFOREWARD is interpreted as clock wise rotation

dirBACKWARD 

dirFOREWARD is interpreted as counter clock wise rotation

◆ L6474x_ErrorCode

The L6474x_ErrorCode_t enum describes the possible error codes when using the API commands. Those error codes are mostly returned as return value by the API function which has been called previously

Enumerator
errcNONE 

errcNONE means no error and the operation was successful

errcINV_ARG 

errcINV_ARG means that at least one argument was invalid or out of range

errcNULL_ARG 

errcNULL_ARG means that at least one argument was a null pointer where it was not expected

errcINV_STATE 

errcINV_STATE means that the stepper driver or the library is not in the state of type L6474x_State_t and therefore the operation can not be executed

errcINTERNAL 

errcINTERNAL means an error which happens when calling abstraction functions which then return an error code

errcLOCKING 

errcLOCKING in case the library is used multi-threaded, it might happen, that a function can not be locked because another caller is still using the library (lock guard principle). In mutex case this should not be returned by the API

errcDEVICE_STATE 

errcDEVICE_STATE means that the state of the driver chip permits the operation

errcPENDING 

errcPENDING means that another operation is still pending and therefore the operation can not be executed while there is still a pending one

errcFORBIDDEN 

errcFORBIDDEN means that operation is not possible with the given arguments or this library

◆ L6474x_OCD_TH

The L6474x_OCD_TH_t enum describes the possible overcurrent threshold values which can be set in the library and which are then taken into account by the stepper driver

◆ L6474x_State

The LibL6474Config.h must be provided by the user project. The header in conf folder is only a template!

The L6474x_State_t enum is used to describe the current state of the driver library which helps the user to decide the next steps to be taken or to get notified about an unexpected state which is caused by an error

Enumerator
stRESET 

stRESET is used to signal the initial power up state or a full device reset state in which the chip is kept until the user releases a reset state

stDISABLED 

stDISABLED is used to signal the ready but disabled state of the chip. It is kept in this step until the user enables the power output stages

stENABLED 

stENABLED is used to signal the ready and enabled state of the chip. It is kept in this step until the user disables the power output stages or an error happens

stINVALID 

stINVALID is used to signal a state which requires user interaction because something is completely wrong in regular cases, this state can not be present. This is an indicator of memory corruption or misleading usage of the library

◆ L6474x_StepMode

The L6474x_StepMode_t enum is used to describe the current step mode (resolution) of the driver library and the stepper motor. This changes the internal calculations for speed and position and requires a new reference run in case it will be changed at runtime.

Enumerator
smFULL 

smFULL requires minimum of 4 steps for a full turn of the motor axis. This mode results in the highest torque but in the most noisy operation and the lowest resolution

smHALF 

smHALF requires minimum of 8 steps for a full turn of the motor axis. better resolution but less torque

smMICRO4 

smMICRO4 requires minimum of 16 steps for a full turn of the motor axis. better resolution but less torque

smMICRO8 

smMICRO8 requires minimum of 32 steps for a full turn of the motor axis. better resolution but less torque

smMICRO16 

smMICRO16 requires minimum of 64 steps for a full turn of the motor axis. better resolution but less torque

Function Documentation

◆ L6474_CreateInstance()

L6474_Handle_t L6474_CreateInstance ( L6474x_Platform_t * p,
void * pIO,
void * pGPO,
void * pPWM )

L6474_CreateInstance is used once to create a library instance which encapsulates the handling for one stepper driver chip It needs a L6474x_Platform_t abstraction pointer and optionally some context pointers which are platform specific. The context pointers are passed to the abstraction functions which are provided by the platform structure.

In case it fails, a null pointer is returned. In case it was successful, a handle pointer is returned which is always required for all other API calls

◆ L6474_DestroyInstance()

int L6474_DestroyInstance ( L6474_Handle_t h)

L6474_DestroyInstance is used to destroy a library instance which has been previously created by a call to L6474_CreateInstance

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

◆ L6474_EncodePhaseCurrent()

char L6474_EncodePhaseCurrent ( float mA)

Calling L6474_EncodePhaseCurrent converts the requested phase current into the register value which is required in the base parameter structure. The member for this value is named TorqueVal

The function returns a register value which represents the given current value

◆ L6474_EncodePhaseCurrentParameter()

int L6474_EncodePhaseCurrentParameter ( L6474_BaseParameter_t * p,
float mA )

Calling L6474_EncodePhaseCurrentParameter converts the requested phase current into the register value which is required in the base parameter structure. The member for this value is named TorqueVal. This function directly inserts the converted value into the given base parameter structure.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

◆ L6474_GetAbsolutePosition()

int L6474_GetAbsolutePosition ( L6474_Handle_t h,
int * position )

func L6474_GetAbsolutePosition is used to read the current stepper position. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required. It returns the position

◆ L6474_GetAlarmEnables()

int L6474_GetAlarmEnables ( L6474_Handle_t h,
int * bits )

func L6474_GetAlarmEnables is used to read the current enable bits for the ERROR ALARM and FLAG Pin. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param bits is required. The bitmask can be found in the datasheet

◆ L6474_GetElectricalPosition()

int L6474_GetElectricalPosition ( L6474_Handle_t h,
int * position )

func L6474_GetElectricalPosition is used to read the current stepper electrical position. The library must not be in stRESET state to perform this operation. The electrical Position returns the step state and micro step component of the driver.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_GetPositionMark()

int L6474_GetPositionMark ( L6474_Handle_t h,
int * position )

func L6474_GetPositionMark is used to read the current stepper position mark. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_GetProperty()

int L6474_GetProperty ( L6474_Handle_t h,
L6474_Property_t prop,
int * value )

func L6474_SetProperty is used to read a property of the type of L6474_Property_t. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param prop is required.

param value is required. The value formats can be found in the datasheet

◆ L6474_GetState()

int L6474_GetState ( L6474_Handle_t h,
L6474x_State_t * state )

func L6474_GetState is used to read back the current libraries state. The library can be in state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param state is required. And must not be null

◆ L6474_GetStatus()

int L6474_GetStatus ( L6474_Handle_t h,
L6474_Status_t * status )

func L6474_GetStatus is used to read back the current libraries and devices status. The library must not be in stRESET to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param status is required. And must not be null

◆ L6474_GetStepMode()

int L6474_GetStepMode ( L6474_Handle_t h,
L6474x_StepMode_t * mode )

func L6474_SetStepMode is used to read back the step mode and therefore the resolution. The library must not be in stRESET to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param mode is required and is one out of L6474x_StepMode_t

◆ L6474_Initialize()

int L6474_Initialize ( L6474_Handle_t h,
L6474_BaseParameter_t * p )

func L6474_Initialize is used to set all basic parameters and take the required steps to bring up the driver into an idle state. It sets the library to stDISABLED in case no error happens.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param p is required and can not be null. the struct can be filled by calling L6474_SetBaseParameter before.

◆ L6474_IsMoving()

int L6474_IsMoving ( L6474_Handle_t h,
int * moving )

func L6474_IsMoving is used to read the state of movement. In case the stepper moves, it returns true. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param moving is required. It returns 0 when no movement is pending or 1 when there is a movement.

◆ L6474_ResetStandBy()

int L6474_ResetStandBy ( L6474_Handle_t h)

Calling L6474_ResetStandBy sets the driver in deep power down or reset state and the library will be set to default startup state again. All initialization steps must be done again by at least calling L6474_Initialize. The library is set to stRESET from any other state before.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

note that in case the stepper is enabled an moving, the operation will be safely disabled but depending on the speed, the position can not be tracked properly anymore. So a new reference run after re-initialization is required!

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

◆ L6474_SetAbsolutePosition()

int L6474_SetAbsolutePosition ( L6474_Handle_t h,
int position )

func L6474_SetAbsolutePosition is used to write the current stepper position. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required. It sets the position

◆ L6474_SetAlarmEnables()

int L6474_SetAlarmEnables ( L6474_Handle_t h,
int bits )

func L6474_SetAlarmEnables is used to write the current enable bits for the ERROR ALARM and FLAG Pin. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param bits is required. The bitmask can be found in the datasheet

◆ L6474_SetBaseParameter()

int L6474_SetBaseParameter ( L6474_BaseParameter_t * p)

Calling L6474_SetBaseParameter sets the basic global default parameters for all properties in the L6474_BaseParameter_t structure. These parameters are required when calling L6474_Initialize

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error

◆ L6474_SetElectricalPosition()

int L6474_SetElectricalPosition ( L6474_Handle_t h,
int position )

func L6474_SetElectricalPosition is used to write the current stepper electrical position. The library must not be in stRESET state to perform this operation. The electrical Position consists of the step state and micro step component of the driver.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_SetPositionMark()

int L6474_SetPositionMark ( L6474_Handle_t h,
int position )

func L6474_SetPositionMark is used to write the current stepper position mark. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param position is required.

◆ L6474_SetPowerOutputs()

int L6474_SetPowerOutputs ( L6474_Handle_t h,
int ena )

func L6474_SetPowerOutputs is used to enable or disable the driver output stages. The library must not be in stRESET to perform this operation. The libraries state will be changed to stENABLED or stDISABLED depending on the ena parameter.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param ena is required and is either 0 when disabling or 1 when enabling is requested

◆ L6474_SetProperty()

int L6474_SetProperty ( L6474_Handle_t h,
L6474_Property_t prop,
int value )

func L6474_SetProperty is used to write a property of the type of L6474_Property_t. The library must not be in stRESET state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param prop is required.

param value is required. The value formats can be found in the datasheet

◆ L6474_SetStepMode()

int L6474_SetStepMode ( L6474_Handle_t h,
L6474x_StepMode_t mode )

func L6474_SetStepMode is used to change the step mode and therefore the resolution. It is required to execute a new reference run because the position value of the lib does not match the stepping mode anymore. The library must not be in stRESET to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param mode is required and is one out of L6474x_StepMode_t

◆ L6474_StepIncremental()

int L6474_StepIncremental ( L6474_Handle_t h,
int steps )

func L6474_StepIncremental is used to issue a movement with the given amount of steps. The library has to be in stENABLED state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.

param steps is required. negative values lead to a counter clock wise movement, 0 does not lead to any movement but returns errcNONE in case no other issue is present.

◆ L6474_StopMovement()

int L6474_StopMovement ( L6474_Handle_t h)

func L6474_StopMovement is used to stop a pending movement in case it has been configured as async. If not, it always return errcNONE in case no other issue is present. The library has to be in stENABLED state to perform this operation.

The function returns errcNONE in case no error happens or any other error code from L6474x_ErrorCode_t enum in case of an error.

param h is required and can not be null. the handle can be created by calling L6474_CreateInstance before.