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

L6474_Private_functions

L6474_Private_functions
[L6474]

Functions

void L6474_ApplySpeed (uint8_t deviceId, uint16_t newSpeed)
 Updates the current speed of the device.
void L6474_ComputeSpeedProfile (uint8_t deviceId, uint32_t nbSteps)
 Computes the speed profile according to the number of steps to move.
int32_t L6474_ConvertPosition (uint32_t abs_position_reg)
 Converts the ABS_POSITION register value to a 32b signed integer.
void L6474_ErrorHandler (uint16_t error)
 Error handler which calls the user callback (if defined)
void L6474_FlagInterruptHandler (void)
 Handlers of the flag interrupt which calls the user callback (if defined)
void L6474_SendCommand (uint8_t deviceId, uint8_t param)
 Sends a command without arguments to the L6474 via the SPI.
void L6474_SetRegisterToPredefinedValues (uint8_t deviceId)
 Sets the registers of the L6474 to their predefined values from l6474_target_config.h.
void L6474_WriteBytes (uint8_t *pByteToTransmit, uint8_t *pReceivedByte)
 Write and receive a byte via SPI.
void L6474_SetDeviceParamsToPredefinedValues (void)
 Sets the parameters of the device to predefined values from l6474_target_config.h.
void L6474_StartMovement (uint8_t deviceId)
 Initialises the bridge parameters to start the movement and enable the power bridge.
void L6474_StepClockHandler (uint8_t deviceId)
 Handles the device state machine at each ste.
uint8_t L6474_Tval_Current_to_Par (double Tval)
 Converts mA in compatible values for TVAL register.
uint8_t L6474_Tmin_Time_to_Par (double Tmin)
 Convert time in us in compatible values for TON_MIN register.

Function Documentation

void L6474_ApplySpeed ( uint8_t  deviceId,
uint16_t  newSpeed 
)

Updates the current speed of the device.

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

Definition at line 1080 of file l6474.cpp.

void L6474_ComputeSpeedProfile ( uint8_t  deviceId,
uint32_t  nbSteps 
)

Computes the speed profile according to the number of steps to move.

Parameters:
[in]deviceId(from 0 to 2)
[in]nbStepsnumber of steps to perform
Return values:
None
Note:
Using the acceleration and deceleration of the device, this function determines the duration in steps of the acceleration, steady and deceleration phases. If the total number of steps to perform is big enough, a trapezoidal move is performed (i.e. there is a steady phase where the motor runs at the maximum speed. Else, a triangular move is performed (no steady phase: the maximum speed is never reached.

Definition at line 1123 of file l6474.cpp.

int32_t L6474_ConvertPosition ( uint32_t  abs_position_reg )

Converts the ABS_POSITION register value to a 32b signed integer.

Parameters:
[in]abs_position_regvalue of the ABS_POSITION register
Return values:
operation_result32b signed integer corresponding to the absolute position

Definition at line 1179 of file l6474.cpp.

void L6474_ErrorHandler ( uint16_t  error )

Error handler which calls the user callback (if defined)

Parameters:
[in]errorNumber of the error
Return values:
None

Definition at line 1204 of file l6474.cpp.

void L6474_FlagInterruptHandler ( void   )

Handlers of the flag interrupt which calls the user callback (if defined)

Parameters:
None
Return values:
None

Definition at line 1224 of file l6474.cpp.

void L6474_SendCommand ( uint8_t  deviceId,
uint8_t  param 
)

Sends a command without arguments to the L6474 via the SPI.

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

Definition at line 1244 of file l6474.cpp.

void L6474_SetDeviceParamsToPredefinedValues ( void   )

Sets the parameters of the device to predefined values from l6474_target_config.h.

Parameters:
None
Return values:
None

Definition at line 1404 of file l6474.cpp.

void L6474_SetRegisterToPredefinedValues ( uint8_t  deviceId )

Sets the registers of the L6474 to their predefined values from l6474_target_config.h.

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

Definition at line 1284 of file l6474.cpp.

void L6474_StartMovement ( uint8_t  deviceId )

Initialises the bridge parameters to start the movement and enable the power bridge.

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

Definition at line 1449 of file l6474.cpp.

void L6474_StepClockHandler ( uint8_t  deviceId )

Handles the device state machine at each ste.

Parameters:
[in]deviceId(from 0 to 2)
Return values:
None
Note:
Must only be called by the timer ISR

Definition at line 1496 of file l6474.cpp.

uint8_t L6474_Tmin_Time_to_Par ( double  Tmin )

Convert time in us in compatible values for TON_MIN register.

Parameters:
[in]Tmin
Return values:
TON_MINvalues

Definition at line 1645 of file l6474.cpp.

uint8_t L6474_Tval_Current_to_Par ( double  Tval )

Converts mA in compatible values for TVAL register.

Parameters:
[in]Tval
Return values:
TVALvalues

Definition at line 1634 of file l6474.cpp.

void L6474_WriteBytes ( uint8_t *  pByteToTransmit,
uint8_t *  pReceivedByte 
)

Write and receive a byte via SPI.

Parameters:
[in]pByteToTransmitpointer to the byte to transmit
[in]pReceivedBytepointer to the received byte
Return values:
None

Definition at line 1656 of file l6474.cpp.