f

Dependencies:   ST_INTERFACES X_NUCLEO_COMMON

Fork of X_NUCLEO_IHM01A1 by ST

Embed: (wiki syntax)

« Back to documentation index

L6474 Class Reference

Class representing an L6474 component. More...

#include <L6474.h>

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 read_id (uint8_t *id=NULL)
 Getting the ID of the component.
virtual unsigned int get_status (void)
 Getting the value of the Status Register.
virtual float get_parameter (unsigned int parameter)
 Getting a parameter.
virtual signed int get_position (void)
 Getting the position.
virtual signed int get_mark (void)
 Getting the marked position.
virtual unsigned int get_speed (void)
 Getting the current speed in pps.
virtual unsigned int get_max_speed (void)
 Getting the maximum speed in pps.
virtual unsigned int get_min_speed (void)
 Getting the minimum speed in pps.
virtual unsigned int get_acceleration (void)
 Getting the acceleration in pps^2.
virtual unsigned int get_deceleration (void)
 Getting the deceleration in pps^2.
virtual direction_t get_direction (void)
 Getting the direction of rotation.
virtual void set_parameter (unsigned int parameter, float value)
 Setting a parameter.
virtual void set_home (void)
 Setting the current position to be the home position.
virtual void set_mark (void)
 Setting the current position to be the marked position.
virtual bool set_max_speed (unsigned int speed)
 Setting the maximum speed in pps.
virtual bool set_min_speed (unsigned int speed)
 Setting the minimum speed in pps.
virtual bool set_acceleration (unsigned int acceleration)
 Setting the acceleration in pps^2.
virtual bool set_deceleration (unsigned int deceleration)
 Setting the deceleration in pps^2.
virtual void go_to (signed int position)
 Going to a specified position.
virtual void go_home (void)
 Going to the home position.
virtual void go_mark (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 soft_stop (void)
 Stopping the motor through an immediate deceleration up to zero speed.
virtual void hard_stop (void)
 Stopping the motor through an immediate infinite deceleration.
virtual void soft_hiz (void)
 Disabling the power bridge after performing a deceleration to zero.
virtual void hard_hiz (void)
 Disabling the power bridge immediately.
virtual void wait_while_active (void)
 Waiting while the motor is active.
virtual motorState_t get_device_state (void)
 Getting the device state.
virtual uint16_t read_status_register (void)
 Reading the Status Register.
virtual bool set_step_mode (step_mode_t step_mode)
 Setting the Step Mode.
virtual void attach_error_handler (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 get_fw_version (void)
 Getting the version of the firmware.
void attach_flag_irq (void(*fptr)(void))
 Attaching an interrupt handler to the FLAG interrupt.
void enable_flag_irq (void)
 Enabling the FLAG interrupt handling.
void disable_flag_irq (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.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.h.

virtual ~L6474 ( void   ) [virtual]

Destructor.

Definition at line 122 of file L6474.h.


Member Function Documentation

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

Attaching an error handler.

Parameters:
fptrAn error handler.
Return values:
None.

Definition at line 606 of file L6474.h.

void attach_flag_irq ( void(*)(void)  fptr )

Attaching an interrupt handler to the FLAG interrupt.

Parameters:
fptrAn interrupt handler.
Return values:
None.

Definition at line 678 of file L6474.h.

virtual void disable ( void   ) [virtual]

Disabling the device.

Parameters:
None.
Return values:
None.

Definition at line 626 of file L6474.h.

void disable_flag_irq ( void   )

Disabling the FLAG interrupt handling.

Parameters:
None.
Return values:
None.

Definition at line 698 of file L6474.h.

virtual void enable ( void   ) [virtual]

Enabling the device.

Parameters:
None.
Return values:
None.

Definition at line 616 of file L6474.h.

void enable_flag_irq ( void   )

Enabling the FLAG interrupt handling.

Parameters:
None.
Return values:
None.

Definition at line 688 of file L6474.h.

virtual unsigned int get_acceleration ( void   ) [virtual]

Getting the acceleration in pps^2.

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

Definition at line 291 of file L6474.h.

virtual unsigned int get_deceleration ( void   ) [virtual]

Getting the deceleration in pps^2.

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

Definition at line 301 of file L6474.h.

virtual motorState_t get_device_state ( 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 564 of file L6474.h.

virtual direction_t get_direction ( void   ) [virtual]

Getting the direction of rotation.

Parameters:
None.
Return values:
Thedirection of rotation.

Definition at line 311 of file L6474.h.

virtual uint8_t get_fw_version ( void   ) [virtual]

Getting the version of the firmware.

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

Definition at line 636 of file L6474.h.

virtual signed int get_mark ( void   ) [virtual]

Getting the marked position.

Parameters:
None.
Return values:
Themarked position.

Definition at line 251 of file L6474.h.

virtual unsigned int get_max_speed ( void   ) [virtual]

Getting the maximum speed in pps.

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

Definition at line 271 of file L6474.h.

virtual unsigned int get_min_speed ( void   ) [virtual]

Getting the minimum speed in pps.

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

Definition at line 281 of file L6474.h.

virtual float get_parameter ( unsigned int  parameter ) [virtual]

Getting a parameter.

Parameters:
parameterA parameter's register address.
Return values:
Theparameter's value.
Note:
The Status Register's flags are cleared, contrary to the read_status_register() method. The 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

Definition at line 215 of file L6474.h.

virtual signed int get_position ( void   ) [virtual]

Getting the position.

Parameters:
None.
Return values:
Theposition.

Definition at line 241 of file L6474.h.

virtual unsigned int get_speed ( void   ) [virtual]

Getting the current speed in pps.

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

Definition at line 261 of file L6474.h.

virtual unsigned int get_status ( void   ) [virtual]

Getting the value of the Status Register.

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

Definition at line 174 of file L6474.h.

virtual void go_home ( void   ) [virtual]

Going to the home position.

Parameters:
None.
Return values:
None.

Definition at line 466 of file L6474.h.

virtual void go_mark ( void   ) [virtual]

Going to the marked position.

Parameters:
None.
Return values:
None.

Definition at line 476 of file L6474.h.

virtual void go_to ( signed int  position ) [virtual]

Going to a specified position.

Parameters:
positionThe desired position.
Return values:
None.

Definition at line 456 of file L6474.h.

virtual void hard_hiz ( void   ) [virtual]

Disabling the power bridge immediately.

Parameters:
None.
Return values:
None.

Definition at line 538 of file L6474.h.

virtual void hard_stop ( void   ) [virtual]

Stopping the motor through an immediate infinite deceleration.

Parameters:
None.
Return values:
None.

Definition at line 517 of file L6474.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.

Definition at line 152 of file L6474.h.

void L6474_Delay ( uint32_t  delay ) [protected]

Making the CPU wait.

Parameters:
None.
Return values:
None.

Definition at line 830 of file L6474.h.

void L6474_DisableIrq ( void   ) [protected]

Disabling interrupts.

Parameters:
None.
Return values:
None.

Definition at line 850 of file L6474.h.

void L6474_EnableIrq ( void   ) [protected]

Enabling interrupts.

Parameters:
None.
Return values:
None.

Definition at line 840 of file L6474.h.

void L6474_PwmInit ( void   ) [protected]

Initialising the PWM.

Parameters:
None.
Return values:
None.

Definition at line 860 of file L6474.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 868 of file L6474.h.

void L6474_PwmStop ( void   ) [protected]

Stopping the PWM.

Parameters:
None.
Return values:
None.

Definition at line 886 of file L6474.h.

void L6474_ReleaseReset ( void   ) [protected]

Putting the device in standby mode.

Parameters:
None.
Return values:
None.

Definition at line 897 of file L6474.h.

void L6474_Reset ( void   ) [protected]

Putting the device in reset mode.

Parameters:
None.
Return values:
None.

Definition at line 907 of file L6474.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 917 of file L6474.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 928 of file L6474.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.

Definition at line 497 of file L6474.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 784 of file L6474.h.

virtual int read_id ( 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.

Definition at line 162 of file L6474.h.

virtual uint16_t read_status_register ( void   ) [virtual]

Reading the Status Register.

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

Definition at line 576 of file L6474.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 813 of file L6474.h.

virtual void run ( direction_t  direction ) [virtual]

Running the motor towards a specified direction.

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

Definition at line 486 of file L6474.h.

virtual bool set_acceleration ( unsigned int  acceleration ) [virtual]

Setting the acceleration in pps^2.

Parameters:
accelerationThe acceleration in pps^2.
Return values:
truein case of success, "false" otherwise.

Definition at line 434 of file L6474.h.

virtual bool set_deceleration ( unsigned int  deceleration ) [virtual]

Setting the deceleration in pps^2.

Parameters:
decelerationThe deceleration in pps^2.
Return values:
truein case of success, "false" otherwise.

Definition at line 445 of file L6474.h.

virtual void set_home ( void   ) [virtual]

Setting the current position to be the home position.

Parameters:
None.
Return values:
None.

Definition at line 392 of file L6474.h.

virtual void set_mark ( void   ) [virtual]

Setting the current position to be the marked position.

Parameters:
None.
Return values:
None.

Definition at line 402 of file L6474.h.

virtual bool set_max_speed ( unsigned int  speed ) [virtual]

Setting the maximum speed in pps.

Parameters:
speedThe maximum speed in pps.
Return values:
truein case of success, "false" otherwise.

Definition at line 412 of file L6474.h.

virtual bool set_min_speed ( unsigned int  speed ) [virtual]

Setting the minimum speed in pps.

Parameters:
speedThe minimum speed in pps.
Return values:
truein case of success, "false" otherwise.

Definition at line 423 of file L6474.h.

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

Setting a parameter.

Parameters:
parameterA parameter's register address.
valueThe parameter's value.
Return values:
None.
Note:
The 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
Warning:
Some registers can only be written in particular conditions (see L6474's datasheet). Any attempt to write one of those registers when the conditions are not satisfied causes the command to be ignored and the NOTPERF_CMD flag to rise at the end of the last argument byte. Any attempt to set an inexistent register (wrong address value) causes the command to be ignored and the WRONG_CMD flag to rise. For example, setting some parameters requires first to disable the power bridge; this can be done through the soft_hiz() method. They are the following: + L6474_EL_POS + L6474_T_FAST + L6474_TON_MIN : value in us + L6474_TOFF_MIN : value in us + L6474_ADC_OUT + L6474_STEP_MODE + L6474_CONFIG + L6474_STATUS

Definition at line 367 of file L6474.h.

virtual bool set_step_mode ( step_mode_t  step_mode ) [virtual]

Setting the Step Mode.

Parameters:
step_modeThe Step Mode.
Return values:
truein case of success, "false" otherwise.
Warning:
Setting the step mode implies first disabling the power bridge through the soft_hiz() method.
Every time step mode is changed, the values of the home and mark positions lose meaning and are reset.

Definition at line 590 of file L6474.h.

virtual void soft_hiz ( void   ) [virtual]

Disabling the power bridge after performing a deceleration to zero.

Parameters:
None.
Return values:
None.

Definition at line 527 of file L6474.h.

virtual void soft_stop ( void   ) [virtual]

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

Parameters:
None.
Return values:
None.

Definition at line 507 of file L6474.h.

virtual void wait_while_active ( void   ) [virtual]

Waiting while the motor is active.

Parameters:
None.
Return values:
None.

Definition at line 549 of file L6474.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 798 of file L6474.h.