X-CUBE-SPN1-20150128 example source code for one motor compiled under mbed. Tested OK on Nucleo F401. l6474.cpp is modified from original with defines in l6474_target_config.h to select the original behaviour (motor de-energised when halted), or new mode to continue powering with a (reduced) current in the coils (braking/position hold capability). On F401 avoid using mbed's InterruptIn on pins 10-15 (any port). Beware of other conflicts! L0 & F0 are included but untested.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Device_Control_Functions

Device_Control_Functions
[L6474]

Functions

void L6474_AttachErrorHandler (void(*callback)(uint16_t))
 Attaches a user callback to the error Handler.
void L6474_AttachFlagInterrupt (void(*callback)(void))
 Attaches a user callback to the flag Interrupt The call back will be then called each time the status flag pin will be pulled down due to the occurrence of a programmed alarms ( OCD, thermal pre-warning or shutdown, UVLO, wrong command, non-performable command)
void L6474_Init (uint8_t nbDevices)
 Starts the L6474 library.
uint16_t L6474_GetAcceleration (uint8_t deviceId)
 Returns the acceleration of the specified device.
uint16_t L6474_GetCurrentSpeed (uint8_t deviceId)
 Returns the current speed of the specified device.
uint16_t L6474_GetDeceleration (uint8_t deviceId)
 Returns the deceleration of the specified device.
motorState_t L6474_GetDeviceState (uint8_t deviceId)
 Returns the device state.
uint8_t L6474_GetFwVersion (void)
 Returns the FW version of the library.
motorDrv_t * L6474_GetMotorHandle (void)
 Return motor handle (pointer to the L6474 motor driver structure)
int32_t L6474_GetMark (uint8_t deviceId)
 Returns the mark position of the specified device.
uint16_t L6474_GetMaxSpeed (uint8_t deviceId)
 Returns the max speed of the specified device.
uint16_t L6474_GetMinSpeed (uint8_t deviceId)
 Returns the min speed of the specified device.
int32_t L6474_GetPosition (uint8_t deviceId)
 Returns the ABS_POSITION of the specified device.
void L6474_GoHome (uint8_t deviceId)
 Requests the motor to move to the home position (ABS_POSITION = 0)
void L6474_GoMark (uint8_t deviceId)
 Requests the motor to move to the mark position.
void L6474_GoTo (uint8_t deviceId, int32_t targetPosition)
 Requests the motor to move to the specified position.
void L6474_HardStop (uint8_t deviceId)
 Immediatly stops the motor and disable the power bridge.
void L6474_Move (uint8_t deviceId, motorDir_t direction, uint32_t stepCount)
 Moves the motor of the specified number of steps.
uint16_t L6474_ReadId (void)
 Read id.
void L6474_ResetAllDevices (void)
 Resets all L6474 devices.
void L6474_Run (uint8_t deviceId, motorDir_t direction)
 Runs the motor.
bool L6474_SetAcceleration (uint8_t deviceId, uint16_t newAcc)
 Changes the acceleration of the specified device.
bool L6474_SetDeceleration (uint8_t deviceId, uint16_t newDec)
 Changes the deceleration of the specified device.
void L6474_SetHome (uint8_t deviceId)
 Set current position to be the Home position (ABS pos set to 0)
void L6474_SetMark (uint8_t deviceId)
 Sets current position to be the Mark position.
bool L6474_SetMaxSpeed (uint8_t deviceId, uint16_t newMaxSpeed)
 Changes the max speed of the specified device.
bool L6474_SetMinSpeed (uint8_t deviceId, uint16_t newMinSpeed)
 Changes the min speed of the specified device.
bool L6474_SoftStop (uint8_t deviceId)
 Stops the motor by using the device deceleration.
void L6474_WaitWhileActive (uint8_t deviceId)
 Locks until the device state becomes Inactive.

Function Documentation

void L6474_AttachErrorHandler ( void(*)(uint16_t)  callback )

Attaches a user callback to the error Handler.

The call back will be then called each time the library detects an error

Parameters:
[in]callbackName of the callback to attach to the error Hanlder
Return values:
None

Definition at line 213 of file l6474.cpp.

void L6474_AttachFlagInterrupt ( void(*)(void)  callback )

Attaches a user callback to the flag Interrupt The call back will be then called each time the status flag pin will be pulled down due to the occurrence of a programmed alarms ( OCD, thermal pre-warning or shutdown, UVLO, wrong command, non-performable command)

Parameters:
[in]callbackName of the callback to attach to the Flag Interrupt
Return values:
None

Definition at line 228 of file l6474.cpp.

uint16_t L6474_GetAcceleration ( uint8_t  deviceId )

Returns the acceleration of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
Accelerationin pps^2

Definition at line 292 of file l6474.cpp.

uint16_t L6474_GetCurrentSpeed ( uint8_t  deviceId )

Returns the current speed of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
Speedin pps

Definition at line 302 of file l6474.cpp.

uint16_t L6474_GetDeceleration ( uint8_t  deviceId )

Returns the deceleration of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
Decelerationin pps^2

Definition at line 312 of file l6474.cpp.

motorState_t L6474_GetDeviceState ( uint8_t  deviceId )

Returns the device state.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
State(ACCELERATING, DECELERATING, STEADY or INACTIVE)

Definition at line 322 of file l6474.cpp.

uint8_t L6474_GetFwVersion ( void   )

Returns the FW version of the library.

Parameters:
None
Return values:
L6474_FW_VERSION

Definition at line 332 of file l6474.cpp.

int32_t L6474_GetMark ( uint8_t  deviceId )

Returns the mark position of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
Markregister value converted in a 32b signed integer

Definition at line 352 of file l6474.cpp.

uint16_t L6474_GetMaxSpeed ( uint8_t  deviceId )

Returns the max speed of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
maxSpeedin pps

Definition at line 362 of file l6474.cpp.

uint16_t L6474_GetMinSpeed ( uint8_t  deviceId )

Returns the min speed of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
minSpeedin pps

Definition at line 372 of file l6474.cpp.

motorDrv_t* L6474_GetMotorHandle ( void   )

Return motor handle (pointer to the L6474 motor driver structure)

Parameters:
None
Return values:
Pointerto the motorDrv_t structure

Definition at line 342 of file l6474.cpp.

int32_t L6474_GetPosition ( uint8_t  deviceId )

Returns the ABS_POSITION of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
ABS_POSITIONregister value converted in a 32b signed integer

Definition at line 382 of file l6474.cpp.

void L6474_GoHome ( uint8_t  deviceId )

Requests the motor to move to the home position (ABS_POSITION = 0)

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None

Definition at line 394 of file l6474.cpp.

void L6474_GoMark ( uint8_t  deviceId )

Requests the motor to move to the mark position.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None

Definition at line 404 of file l6474.cpp.

void L6474_GoTo ( uint8_t  deviceId,
int32_t  targetPosition 
)

Requests the motor to move to the specified position.

Parameters:
[in]deviceId(from 0 to 2)
[in]targetPositionabsolute position in steps
Return values:
None

Definition at line 418 of file l6474.cpp.

void L6474_HardStop ( uint8_t  deviceId )

Immediatly stops the motor and disable the power bridge.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None

Definition at line 467 of file l6474.cpp.

void L6474_Init ( uint8_t  nbDevices )

Starts the L6474 library.

Parameters:
[in]nbDevicesNumber of L6474 devices to use (from 1 to 3)
Return values:
None

Definition at line 238 of file l6474.cpp.

void L6474_Move ( uint8_t  deviceId,
motorDir_t  direction,
uint32_t  stepCount 
)

Moves the motor of the specified number of steps.

Parameters:
[in]deviceId(from 0 to 2)
[in]directionFORWARD or BACKWARD
[in]stepCountNumber of steps to perform
Return values:
None

Definition at line 510 of file l6474.cpp.

uint16_t L6474_ReadId ( void   )

Read id.

Parameters:
None
Return values:
Idof the l6474 Driver Instance

Definition at line 541 of file l6474.cpp.

void L6474_ResetAllDevices ( void   )

Resets all L6474 devices.

Parameters:
None
Return values:
None

Definition at line 551 of file l6474.cpp.

void L6474_Run ( uint8_t  deviceId,
motorDir_t  direction 
)

Runs the motor.

It will accelerate from the min speed up to the max speed by using the device acceleration.

Parameters:
[in]deviceId(from 0 to 2)
[in]directionFORWARD or BACKWARD
Return values:
None

Definition at line 580 of file l6474.cpp.

bool L6474_SetAcceleration ( uint8_t  deviceId,
uint16_t  newAcc 
)

Changes the acceleration of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
[in]newAccNew acceleration to apply in pps^2
Return values:
trueif the command is successfully executed, else false
Note:
The command is not performed is the device is executing a MOVE or GOTO command (but it can be used during a RUN command)

Definition at line 605 of file l6474.cpp.

bool L6474_SetDeceleration ( uint8_t  deviceId,
uint16_t  newDec 
)

Changes the deceleration of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
[in]newDecNew deceleration to apply in pps^2
Return values:
trueif the command is successfully executed, else false
Note:
The command is not performed is the device is executing a MOVE or GOTO command (but it can be used during a RUN command)

Definition at line 626 of file l6474.cpp.

void L6474_SetHome ( uint8_t  deviceId )

Set current position to be the Home position (ABS pos set to 0)

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None

Definition at line 644 of file l6474.cpp.

void L6474_SetMark ( uint8_t  deviceId )

Sets current position to be the Mark position.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None

Definition at line 654 of file l6474.cpp.

bool L6474_SetMaxSpeed ( uint8_t  deviceId,
uint16_t  newMaxSpeed 
)

Changes the max speed of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
[in]newMaxSpeedNew max speed to apply in pps
Return values:
trueif the command is successfully executed, else false
Note:
The command is not performed is the device is executing a MOVE or GOTO command (but it can be used during a RUN command).

Definition at line 668 of file l6474.cpp.

bool L6474_SetMinSpeed ( uint8_t  deviceId,
uint16_t  newMinSpeed 
)

Changes the min speed of the specified device.

Parameters:
[in]deviceId(from 0 to 2)
[in]newMinSpeedNew min speed to apply in pps
Return values:
trueif the command is successfully executed, else false
Note:
The command is not performed is the device is executing a MOVE or GOTO command (but it can be used during a RUN command).

Definition at line 691 of file l6474.cpp.

bool L6474_SoftStop ( uint8_t  deviceId )

Stops the motor by using the device deceleration.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
trueif the command is successfully executed, else false
Note:
The command is not performed is the device is in INACTIVE state.

Definition at line 712 of file l6474.cpp.

void L6474_WaitWhileActive ( uint8_t  deviceId )

Locks until the device state becomes Inactive.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None

Definition at line 728 of file l6474.cpp.