LibL6474-C-Library 1.0
Library Code documentation
Loading...
Searching...
No Matches
Stepper Library Lib6474

Introduction

The following code documentation is a set of tips and diagrams as well as function and structure descriptions which help when using the library. It is used to increase the implementation speed. Some examples are attached in this documentation as well

Static compile flags

LIBL6474_STEP_ASYNC: This DEFINE is used to switch from blocking synchronous mode to asynchronous non-blocking step mode. This changes the API behavior

LIBL6474_HAS_LOCKING: This DEFINE is used to enable the lock guard and thread synchronization guard abstraction, which requires additional abstraction functions

LIBL6474_DISABLE_OCD: Should only be used for debugging purposes and not for productive code! This DEFINE is used to disable the overcurrent detection feature in the library and the stepper driver

LIBL6474_HAS_FLAG: enables the support of the flag pin This DEFINE is used to enable the FLAG pin support, which requires additional abstraction functions

State diagram

The following state diagram shows the internal state machine handling which follows or represents the state of the stepper driver chip. The fault conditions are not depicted in the diagram but in all regular cases the error handling is done by resetting and reinitialization of the stepper driver by the library.

dot_inline_dotgraph_1.png

Examples

The following example shows a part of the abstraction functions which are required for the usage of the Stepper library. It also shows how to create a instance of the stepper library.

static void* StepLibraryMalloc( unsigned int size )
{
return malloc(size);
}
static void StepLibraryFree( const void* const ptr )
{
free((void*)ptr);
}
static int StepDriverSpiTransfer( void* pIO, char* pRX, const char* pTX, unsigned int length )
{
// byte based access, so keep in mind that only single byte transfers are performed!
for ( unsigned int i = 0; i < length; i++ )
{
...
}
return 0;
}
...
// pass all function pointers required by the stepper library
// to a separate platform abstraction structure
L6474x_Platform_t p;
p.malloc = StepLibraryMalloc;
p.free = StepLibraryFree;
p.transfer = StepDriverSpiTransfer;
p.reset = StepDriverReset;
p.sleep = StepLibraryDelay;
p.stepAsync = StepTimerAsync;
p.cancelStep = StepTimerCancelAsync;
// now create the handle
L6474_Handle_t h = L6474_CreateInstance(&p, null, null, null);
struct L6474_Handle * L6474_Handle_t
Definition LibL6474.h:258
L6474_Handle_t L6474_CreateInstance(L6474x_Platform_t *p, void *pIO, void *pGPO, void *pPWM)
Definition LibL6474x.c:440

The following example shows a really simple instantiation and usage of the library with a simple default and straight forward configuration and no calculation of any step widths or resolutions

...
int result = 0;
...
// reset all and take all initialization steps
result |= L6474_ResetStandBy(h);
result |= L6474_Initialize(h, &param);
result |= L6474_SetPowerOutputs(h, 1);
...
// in case we have no error, we can enable the drivers
// and then we step a bit
if ( result == 0 )
{
result |= L6474_StepIncremental(h, 1000 );
}
else
{
// error handling
...
}
...
int L6474_SetPowerOutputs(L6474_Handle_t h, int ena)
Definition LibL6474x.c:819
int L6474_Initialize(L6474_Handle_t h, L6474_BaseParameter_t *p)
Definition LibL6474x.c:601
int L6474_ResetStandBy(L6474_Handle_t h)
Definition LibL6474x.c:521
int L6474_StepIncremental(L6474_Handle_t h, int steps)
Definition LibL6474x.c:1283

The following example shows how to change the phase current (max torque) of the stepper. This can be achieved by reinitializing the library or by changing the parameter by calling L6474_SetProperty;

...
int result = 0;
...
// first way: set the torque on initialization
result |= L6474_ResetStandBy(h);
result |= L6474_EncodePhaseCurrentParameter(&param, 1200.0f);
result |= L6474_Initialize(h, &param);
...
// second way: set the torque after initialization
char torqueval = L6474_EncodePhaseCurrent(1500.0f);
result |= L6474_SetProperty(h, L6474_PROP_TORQUE, torqueval);
...
@ L6474_PROP_TORQUE
Definition LibL6474.h:465
int L6474_EncodePhaseCurrentParameter(L6474_BaseParameter_t *p, float mA)
Definition LibL6474x.c:591
char L6474_EncodePhaseCurrent(float mA)
Definition LibL6474x.c:581
int L6474_SetProperty(L6474_Handle_t h, L6474_Property_t prop, int value)
Definition LibL6474x.c:1086