Personal fork of the library

Dependencies:   X_NUCLEO_COMMON

Fork of X_NUCLEO_IHM01A1 by Arkadi Rafalovich

Embed: (wiki syntax)

« Back to documentation index

L6474 Class Reference

Class representing an L6474 component. More...

#include <l6474_class.h>

Inherits StepperMotor.

Public Types

enum  direction_t
 

Rotation modes.

More...

Public Member Functions

 L6474 (PinName flag_irq, PinName standby_reset, PinName direction, PinName pwm, PinName ssel, DevSPI &spi)
 Constructor.
virtual ~L6474 (void)
 Destructor.
virtual int Init (void *init=NULL)
 Initializing the component in 1/16 Microstepping mode.
virtual int ReadID (uint8_t *id=NULL)
 Getting the ID of the component.
virtual unsigned int GetStatus (void)
 Getting the value of the Status Register.
virtual float GetParameter (unsigned int parameter)
 Getting a parameter.
virtual signed int GetPosition (void)
 Getting the position.
virtual signed int GetMark (void)
 Getting the marked position.
virtual unsigned int GetSpeed (void)
 Getting the current speed in pps.
virtual unsigned int GetMaxSpeed (void)
 Getting the maximum speed in pps.
virtual unsigned int GetMinSpeed (void)
 Getting the minimum speed in pps.
virtual unsigned int GetAcceleration (void)
 Getting the acceleration in pps^2.
virtual unsigned int GetDeceleration (void)
 Getting the deceleration in pps^2.
virtual direction_t GetDirection (void)
 Getting the direction of rotation.
virtual void SetParameter (unsigned int parameter, float value)
 Setting a parameter.
virtual void SetHome (void)
 Setting the current position to be the home position.
virtual void SetMark (void)
 Setting the current position to be the marked position.
virtual void SetMaxSpeed (unsigned int speed)
 Setting the maximum speed in pps.
virtual void SetMinSpeed (unsigned int speed)
 Setting the minimum speed in pps.
virtual void SetAcceleration (unsigned int acceleration)
 Setting the acceleration in pps^2.
virtual void SetDeceleration (unsigned int deceleration)
 Setting the deceleration in pps^2.
virtual void GoTo (signed int position)
 Going to a specified position.
virtual void GoHome (void)
 Going to the home position.
virtual void GoMark (void)
 Going to the marked position.
virtual void Run (direction_t direction)
 Running the motor towards a specified direction.
virtual void Move (direction_t direction, unsigned int steps)
 Moving the motor towards a specified direction for a certain number of steps.
virtual void SoftStop (void)
 Stopping the motor through an immediate deceleration up to zero speed.
virtual void HardStop (void)
 Stopping the motor through an immediate infinite deceleration.
virtual void SoftHiZ (void)
 Disabling the power bridge after performing a deceleration to zero.
virtual void HardHiZ (void)
 Disabling the power bridge immediately.
virtual void WaitWhileActive (void)
 Waiting while the motor is active.
virtual motorState_t GetDeviceState (void)
 Getting the device state.
virtual uint16_t ReadStatusRegister (void)
 Reading the Status Register.
virtual void SetStepMode (motorStepMode_t step_mode)
 Setting the Step Mode.
virtual void AttachErrorHandler (void(*fptr)(uint16_t error))
 Attaching an error handler.
virtual void Enable (void)
 Enabling the device.
virtual void Disable (void)
 Disabling the device.
virtual uint8_t GetFwVersion (void)
 Getting the version of the firmware.
void AttachFlagIRQ (void(*fptr)(void))
 Attaching an interrupt handler to the FLAG interrupt.
void EnableFlagIRQ (void)
 Enabling the FLAG interrupt handling.
void DisableFlagIRQ (void)
 Disabling the FLAG interrupt handling.

Protected Member Functions

Status_t Read (uint8_t *pBuffer, uint16_t NumBytesToRead)
 Utility function to read data from L6474.
Status_t Write (uint8_t *pBuffer, uint16_t NumBytesToWrite)
 Utility function to write data to L6474.
Status_t ReadWrite (uint8_t *pBufferToRead, uint8_t *pBufferToWrite, uint16_t NumBytes)
 Utility function to read and write data from/to L6474 at the same time.
void L6474_Delay (uint32_t delay)
 Making the CPU wait.
void L6474_EnableIrq (void)
 Enabling interrupts.
void L6474_DisableIrq (void)
 Disabling interrupts.
void L6474_PwmInit (void)
 Initialising the PWM.
void L6474_PwmSetFreq (uint16_t frequency)
 Setting the frequency of PWM.
void L6474_PwmStop (void)
 Stopping the PWM.
void L6474_ReleaseReset (void)
 Putting the device in standby mode.
void L6474_Reset (void)
 Putting the device in reset mode.
void L6474_SetDirectionGpio (uint8_t gpioState)
 Setting the direction of rotation.
uint8_t L6474_SpiWriteBytes (uint8_t *pByteToTransmit, uint8_t *pReceivedByte)
 Writing and reading bytes to/from the component through the SPI at the same time.

Detailed Description

Class representing an L6474 component.

Definition at line 83 of file l6474_class.h.


Member Enumeration Documentation

enum direction_t [inherited]

Rotation modes.

Definition at line 61 of file StepperMotor_class.h.


Constructor & Destructor Documentation

L6474 ( PinName  flag_irq,
PinName  standby_reset,
PinName  direction,
PinName  pwm,
PinName  ssel,
DevSPI &  spi 
)

Constructor.

Parameters:
flag_irqpin name of the FLAG pin of the component.
standby_resetpin name of the STBY pin of the component.
directionpin name of the DIR pin of the component.
pwmpin name of the PWM pin of the component.
sselpin name of the SSEL pin of the SPI device to be used for communication.
spiSPI device to be used for communication.

Definition at line 98 of file l6474_class.h.

virtual ~L6474 ( void   ) [virtual]

Destructor.

Definition at line 121 of file l6474_class.h.


Member Function Documentation

virtual void AttachErrorHandler ( void(*)(uint16_t error)  fptr ) [virtual]

Attaching an error handler.

Parameters:
fptrAn error handler.
Return values:
None.

Definition at line 583 of file l6474_class.h.

void AttachFlagIRQ ( void(*)(void)  fptr )

Attaching an interrupt handler to the FLAG interrupt.

Parameters:
fptrAn interrupt handler.
Return values:
None.

Definition at line 655 of file l6474_class.h.

virtual void Disable ( void   ) [virtual]

Disabling the device.

Parameters:
None.
Return values:
None.

Definition at line 603 of file l6474_class.h.

void DisableFlagIRQ ( void   )

Disabling the FLAG interrupt handling.

Parameters:
None.
Return values:
None.

Definition at line 675 of file l6474_class.h.

virtual void Enable ( void   ) [virtual]

Enabling the device.

Parameters:
None.
Return values:
None.

Definition at line 593 of file l6474_class.h.

void EnableFlagIRQ ( void   )

Enabling the FLAG interrupt handling.

Parameters:
None.
Return values:
None.

Definition at line 665 of file l6474_class.h.

virtual unsigned int GetAcceleration ( void   ) [virtual]

Getting the acceleration in pps^2.

Parameters:
None.
Return values:
Theacceleration in pps^2.

Implements StepperMotor.

Definition at line 289 of file l6474_class.h.

virtual unsigned int GetDeceleration ( void   ) [virtual]

Getting the deceleration in pps^2.

Parameters:
None.
Return values:
Thedeceleration in pps^2.

Implements StepperMotor.

Definition at line 299 of file l6474_class.h.

virtual motorState_t GetDeviceState ( void   ) [virtual]

Getting the device state.

Parameters:
None.
Return values:
Thedevice state.
Note:
The device state can be one of the following: + ACCELERATING + DECELERATING + STEADY + INACTIVE

Definition at line 543 of file l6474_class.h.

virtual direction_t GetDirection ( void   ) [virtual]

Getting the direction of rotation.

Parameters:
None.
Return values:
Thedirection of rotation.

Implements StepperMotor.

Definition at line 309 of file l6474_class.h.

virtual uint8_t GetFwVersion ( void   ) [virtual]

Getting the version of the firmware.

Parameters:
None.
Return values:
Theversion of the firmware.

Definition at line 613 of file l6474_class.h.

virtual signed int GetMark ( void   ) [virtual]

Getting the marked position.

Parameters:
None.
Return values:
Themarked position.

Implements StepperMotor.

Definition at line 249 of file l6474_class.h.

virtual unsigned int GetMaxSpeed ( void   ) [virtual]

Getting the maximum speed in pps.

Parameters:
None.
Return values:
Themaximum speed in pps.

Implements StepperMotor.

Definition at line 269 of file l6474_class.h.

virtual unsigned int GetMinSpeed ( void   ) [virtual]

Getting the minimum speed in pps.

Parameters:
None.
Return values:
Theminimum speed in pps.

Implements StepperMotor.

Definition at line 279 of file l6474_class.h.

virtual float GetParameter ( unsigned int  parameter ) [virtual]

Getting a parameter.

Parameters:
parameterA parameter's register adress.
Return values:
Theparameter's value.
Note:
The Status Register's flags are cleared, contrary to ReadStatusRegister(). parameter can be one of the following: + L6474_ABS_POS + L6474_EL_POS + L6474_MARK + L6474_RESERVED_REG01 + L6474_RESERVED_REG02 + L6474_RESERVED_REG03 + L6474_RESERVED_REG04 + L6474_RESERVED_REG05 + L6474_RESERVED_REG06 + L6474_TVAL : value in mA + L6474_RESERVED_REG07 + L6474_RESERVED_REG08 + L6474_RESERVED_REG09 + L6474_RESERVED_REG10 + L6474_T_FAST + L6474_TON_MIN : value in us + L6474_TOFF_MIN : value in us + L6474_RESERVED_REG11 + L6474_ADC_OUT + L6474_OCD_TH + L6474_RESERVED_REG12 + L6474_STEP_MODE + L6474_ALARM_EN + L6474_CONFIG + L6474_STATUS + L6474_RESERVED_REG13 + L6474_RESERVED_REG14 + L6474_INEXISTENT_REG

Implements StepperMotor.

Definition at line 212 of file l6474_class.h.

virtual signed int GetPosition ( void   ) [virtual]

Getting the position.

Parameters:
None.
Return values:
Theposition.

Implements StepperMotor.

Definition at line 239 of file l6474_class.h.

virtual unsigned int GetSpeed ( void   ) [virtual]

Getting the current speed in pps.

Parameters:
None.
Return values:
Thecurrent speed in pps.

Implements StepperMotor.

Definition at line 259 of file l6474_class.h.

virtual unsigned int GetStatus ( void   ) [virtual]

Getting the value of the Status Register.

Parameters:
None.
Return values:
None.
Note:
The Status Register's flags are cleared, contrary to ReadStatusRegister().

Implements StepperMotor.

Definition at line 172 of file l6474_class.h.

virtual void GoHome ( void   ) [virtual]

Going to the home position.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 445 of file l6474_class.h.

virtual void GoMark ( void   ) [virtual]

Going to the marked position.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 455 of file l6474_class.h.

virtual void GoTo ( signed int  position ) [virtual]

Going to a specified position.

Parameters:
positionThe desired position.
Return values:
None.

Implements StepperMotor.

Definition at line 435 of file l6474_class.h.

virtual void HardHiZ ( void   ) [virtual]

Disabling the power bridge immediately.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 517 of file l6474_class.h.

virtual void HardStop ( void   ) [virtual]

Stopping the motor through an immediate infinite deceleration.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 496 of file l6474_class.h.

virtual int Init ( void *  init = NULL ) [virtual]

Initializing the component in 1/16 Microstepping mode.

Parameters:
initPointer to device specific initalization structure.
Return values:
0in case of success, an error code otherwise.

Implements Component.

Definition at line 151 of file l6474_class.h.

void L6474_Delay ( uint32_t  delay ) [protected]

Making the CPU wait.

Parameters:
None.
Return values:
None.

Definition at line 804 of file l6474_class.h.

void L6474_DisableIrq ( void   ) [protected]

Disabling interrupts.

Parameters:
None.
Return values:
None.

Definition at line 824 of file l6474_class.h.

void L6474_EnableIrq ( void   ) [protected]

Enabling interrupts.

Parameters:
None.
Return values:
None.

Definition at line 814 of file l6474_class.h.

void L6474_PwmInit ( void   ) [protected]

Initialising the PWM.

Parameters:
None.
Return values:
None.

Definition at line 834 of file l6474_class.h.

void L6474_PwmSetFreq ( uint16_t  frequency ) [protected]

Setting the frequency of PWM.

The frequency controls directly the speed of the device.

Parameters:
frequencythe frequency of PWM.
Return values:
None.

Definition at line 842 of file l6474_class.h.

void L6474_PwmStop ( void   ) [protected]

Stopping the PWM.

Parameters:
None.
Return values:
None.

Definition at line 860 of file l6474_class.h.

void L6474_ReleaseReset ( void   ) [protected]

Putting the device in standby mode.

Parameters:
None.
Return values:
None.

Definition at line 871 of file l6474_class.h.

void L6474_Reset ( void   ) [protected]

Putting the device in reset mode.

Parameters:
None.
Return values:
None.

Definition at line 881 of file l6474_class.h.

void L6474_SetDirectionGpio ( uint8_t  gpioState ) [protected]

Setting the direction of rotation.

Parameters:
gpioStatedirection of rotation: "1" for forward, "0" for backward.
Return values:
None.

Definition at line 891 of file l6474_class.h.

uint8_t L6474_SpiWriteBytes ( uint8_t *  pByteToTransmit,
uint8_t *  pReceivedByte 
) [protected]

Writing and reading bytes to/from the component through the SPI at the same time.

Parameters:
[in]pByteToTransmitpointer to the buffer of data to send.
[out]pReceivedBytepointer to the buffer to read data into.
Return values:
0in case of success, "1" otherwise.

Definition at line 902 of file l6474_class.h.

virtual void Move ( direction_t  direction,
unsigned int  steps 
) [virtual]

Moving the motor towards a specified direction for a certain number of steps.

Parameters:
directionThe direction of rotation.
stepsThe desired number of steps.
Return values:
None.

Implements StepperMotor.

Definition at line 476 of file l6474_class.h.

Status_t Read ( uint8_t *  pBuffer,
uint16_t  NumBytesToRead 
) [protected]

Utility function to read data from L6474.

Parameters:
[out]pBufferpointer to the buffer to read data into.
[in]NumBytesToReadnumber of bytes to read.
Return values:
COMPONENT_OKin case of success, COMPONENT_ERROR otherwise.

Definition at line 761 of file l6474_class.h.

virtual int ReadID ( uint8_t *  id = NULL ) [virtual]

Getting the ID of the component.

Parameters:
idPointer to an allocated variable to store the ID into.
Return values:
0in case of success, an error code otherwise.

Implements Component.

Definition at line 161 of file l6474_class.h.

virtual uint16_t ReadStatusRegister ( void   ) [virtual]

Reading the Status Register.

Parameters:
None.
Return values:
None.
Note:
The Status Register's flags are not cleared, contrary to GetStatus().

Definition at line 554 of file l6474_class.h.

Status_t ReadWrite ( uint8_t *  pBufferToRead,
uint8_t *  pBufferToWrite,
uint16_t  NumBytes 
) [protected]

Utility function to read and write data from/to L6474 at the same time.

Parameters:
[out]pBufferToReadpointer to the buffer to read data into.
[in]pBufferToWritepointer to the buffer of data to send.
[in]NumBytesnumber of bytes to read and write.
Return values:
COMPONENT_OKin case of success, COMPONENT_ERROR otherwise.

Definition at line 788 of file l6474_class.h.

virtual void Run ( direction_t  direction ) [virtual]

Running the motor towards a specified direction.

Parameters:
directionThe direction of rotation.
Return values:
None.

Implements StepperMotor.

Definition at line 465 of file l6474_class.h.

virtual void SetAcceleration ( unsigned int  acceleration ) [virtual]

Setting the acceleration in pps^2.

Parameters:
accelerationThe acceleration in pps^2.
Return values:
None.

Implements StepperMotor.

Definition at line 415 of file l6474_class.h.

virtual void SetDeceleration ( unsigned int  deceleration ) [virtual]

Setting the deceleration in pps^2.

Parameters:
decelerationThe deceleration in pps^2.
Return values:
None.

Implements StepperMotor.

Definition at line 425 of file l6474_class.h.

virtual void SetHome ( void   ) [virtual]

Setting the current position to be the home position.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 375 of file l6474_class.h.

virtual void SetMark ( void   ) [virtual]

Setting the current position to be the marked position.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 385 of file l6474_class.h.

virtual void SetMaxSpeed ( unsigned int  speed ) [virtual]

Setting the maximum speed in pps.

Parameters:
speedThe maximum speed in pps.
Return values:
None.

Implements StepperMotor.

Definition at line 395 of file l6474_class.h.

virtual void SetMinSpeed ( unsigned int  speed ) [virtual]

Setting the minimum speed in pps.

Parameters:
speedThe minimum speed in pps.
Return values:
None.

Implements StepperMotor.

Definition at line 405 of file l6474_class.h.

virtual void SetParameter ( unsigned int  parameter,
float  value 
) [virtual]

Setting a parameter.

Parameters:
parameterA parameter's register adress.
valueThe parameter's value.
Return values:
None.
Note:
parameter can be one of the following: + L6474_ABS_POS + L6474_EL_POS + L6474_MARK + L6474_RESERVED_REG01 + L6474_RESERVED_REG02 + L6474_RESERVED_REG03 + L6474_RESERVED_REG04 + L6474_RESERVED_REG05 + L6474_RESERVED_REG06 + L6474_TVAL : value in mA + L6474_RESERVED_REG07 + L6474_RESERVED_REG08 + L6474_RESERVED_REG09 + L6474_RESERVED_REG10 + L6474_T_FAST + L6474_TON_MIN : value in us + L6474_TOFF_MIN : value in us + L6474_RESERVED_REG11 + L6474_ADC_OUT + L6474_OCD_TH + L6474_RESERVED_REG12 + L6474_STEP_MODE + L6474_ALARM_EN + L6474_CONFIG + L6474_STATUS + L6474_RESERVED_REG13 + L6474_RESERVED_REG14 + L6474_INEXISTENT_REG

Implements StepperMotor.

Definition at line 349 of file l6474_class.h.

virtual void SetStepMode ( motorStepMode_t  step_mode ) [virtual]

Setting the Step Mode.

Parameters:
step_modeThe Step Mode.
Return values:
None.
Note:
step_mode can be one of the following: + STEP_MODE_FULL + STEP_MODE_HALF + STEP_MODE_1_4 + STEP_MODE_1_8 + STEP_MODE_1_16 + STEP_MODE_1_32 + STEP_MODE_1_64 + STEP_MODE_1_128

Definition at line 573 of file l6474_class.h.

virtual void SoftHiZ ( void   ) [virtual]

Disabling the power bridge after performing a deceleration to zero.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 506 of file l6474_class.h.

virtual void SoftStop ( void   ) [virtual]

Stopping the motor through an immediate deceleration up to zero speed.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 486 of file l6474_class.h.

virtual void WaitWhileActive ( void   ) [virtual]

Waiting while the motor is active.

Parameters:
None.
Return values:
None.

Implements StepperMotor.

Definition at line 528 of file l6474_class.h.

Status_t Write ( uint8_t *  pBuffer,
uint16_t  NumBytesToWrite 
) [protected]

Utility function to write data to L6474.

Parameters:
[in]pBufferpointer to the buffer of data to send.
[in]NumBytesToWritenumber of bytes to write.
Return values:
COMPONENT_OKin case of success, COMPONENT_ERROR otherwise.

Definition at line 774 of file l6474_class.h.