DRV8434S library
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
DRV8434S Class Reference

#include <DRV8434S.h>

Public Member Functions

 DRV8434S ()
 The default constructor. More...
 
void setChipSelectPin (uint8_t pin)
 
void resetSettings ()
 
bool verifySettings ()
 
void applySettings ()
 
void setCurrentPercent (uint8_t percent)
 
void setCurrentMilliamps (uint16_t current, uint16_t fullCurrent=2000)
 
void enableDriver ()
 Enables the driver (EN_OUT = 1). More...
 
void disableDriver ()
 Disables the driver (EN_OUT = 0). More...
 
void setDecayMode (DRV8434SDecayMode mode)
 
void setDirection (bool value)
 
bool getDirection ()
 
void step ()
 
void enableSPIDirection ()
 
void disableSPIDirection ()
 
void enableSPIStep ()
 
void disableSPIStep ()
 
void setStepMode (DRV8434SStepMode mode)
 
void setStepMode (uint16_t mode)
 
uint8_t readFault ()
 
uint8_t readDiag1 ()
 
uint8_t readDiag2 ()
 
void clearFaults ()
 
uint8_t getCachedReg (DRV8434SRegAddr address)
 
void setReg (DRV8434SRegAddr address, uint8_t value)
 

Public Attributes

DRV8434SSPI driver
 

Protected Member Functions

uint8_t * cachedRegPtr (DRV8434SRegAddr address)
 
void writeCachedReg (DRV8434SRegAddr address)
 Writes the cached value of the given register to the device. More...
 

Protected Attributes

uint8_t ctrl1
 
uint8_t ctrl2
 
uint8_t ctrl3
 
uint8_t ctrl4
 
uint8_t ctrl5
 
uint8_t ctrl6
 
uint8_t ctrl7
 

Detailed Description

This class provides high-level functions for controlling a DRV8434S stepper motor driver.

Definition at line 259 of file DRV8434S.h.

Constructor & Destructor Documentation

◆ DRV8434S()

DRV8434S::DRV8434S ( )
inline

The default constructor.

Definition at line 263 of file DRV8434S.h.

Member Function Documentation

◆ applySettings()

void DRV8434S::applySettings ( )
inline

Re-writes the cached settings stored in this class to the device.

You should not normally need to call this function because settings are written to the device whenever they are changed. However, if verifySettings() returns false (due to a power interruption, for instance), then you could use applySettings() to get the device's settings back into the desired state.

Definition at line 326 of file DRV8434S.h.

◆ cachedRegPtr()

uint8_t * DRV8434S::cachedRegPtr ( DRV8434SRegAddr  address)
inlineprotected

Returns a pointer to the variable containing the cached value for the given register.

Definition at line 648 of file DRV8434S.h.

◆ clearFaults()

void DRV8434S::clearFaults ( )
inline

Clears any fault conditions that are currently latched in the driver (CLR_FLT = 1).

WARNING: Calling this function clears latched faults, which might allow the motor driver outputs to reactivate. If you do this repeatedly without fixing an abnormal condition (like a short circuit), you might damage the driver.

The driver automatically clears the CLR_FLT bit after it is written.

Definition at line 611 of file DRV8434S.h.

◆ disableDriver()

void DRV8434S::disableDriver ( )
inline

Disables the driver (EN_OUT = 0).

Definition at line 413 of file DRV8434S.h.

◆ disableSPIDirection()

void DRV8434S::disableSPIDirection ( )
inline

Disables direction control through SPI (SPI_DIR = 0), making the DIR pin control direction instead.

Definition at line 482 of file DRV8434S.h.

◆ disableSPIStep()

void DRV8434S::disableSPIStep ( )
inline

Disables stepping through SPI (SPI_STEP = 0), making the STEP pin control stepping instead.

Definition at line 498 of file DRV8434S.h.

◆ enableDriver()

void DRV8434S::enableDriver ( )
inline

Enables the driver (EN_OUT = 1).

Definition at line 406 of file DRV8434S.h.

◆ enableSPIDirection()

void DRV8434S::enableSPIDirection ( )
inline

Enables direction control through SPI (SPI_DIR = 1), allowing setDirection() to override the DIR pin.

Definition at line 474 of file DRV8434S.h.

◆ enableSPIStep()

void DRV8434S::enableSPIStep ( )
inline

Enables stepping through SPI (SPI_STEP = 1), allowing step() to override the STEP pin.

Definition at line 490 of file DRV8434S.h.

◆ getCachedReg()

uint8_t DRV8434S::getCachedReg ( DRV8434SRegAddr  address)
inline

Gets the cached value of a register. If the given register address is not valid, this function returns 0.

Definition at line 618 of file DRV8434S.h.

◆ getDirection()

bool DRV8434S::getDirection ( )
inline

Returns the cached value of the motor direction (DIR).

This does not perform any SPI communication with the driver.

Definition at line 455 of file DRV8434S.h.

◆ readDiag1()

uint8_t DRV8434S::readDiag1 ( )
inline

Reads the DIAG1 status register of the driver.

The return value is an 8-bit unsigned integer that has one bit for each DIAG1 condition. You can simply compare the return value to 0 to see if any of the bits are set, or you can use the logical AND operator (&) and the DRV8434SDiag1Bit enum to check individual bits.

Definition at line 586 of file DRV8434S.h.

◆ readDiag2()

uint8_t DRV8434S::readDiag2 ( )
inline

Reads the DIAG2 status register of the driver.

The return value is an 8-bit unsigned integer that has one bit for each DIAG2 condition. You can simply compare the return value to 0 to see if any of the bits are set, or you can use the logical AND operator (&) and the DRV8434SDiag2Bit enum to check individual bits.

Definition at line 597 of file DRV8434S.h.

◆ readFault()

uint8_t DRV8434S::readFault ( )
inline

Reads the FAULT status register of the driver.

The return value is an 8-bit unsigned integer that has one bit for each FAULT condition. You can simply compare the return value to 0 to see if any of the bits are set, or you can use the logical AND operator (&) and the DRV8434SFaultBit enum to check individual bits.

Example usage:

if (sd.readFault() & (1 << (uint8_t)DRV8434SFaultBit::UVLO))
{
// Supply undervoltage lockout is active.
}

Definition at line 575 of file DRV8434S.h.

◆ resetSettings()

void DRV8434S::resetSettings ( )
inline

Changes all of the driver's settings back to their default values.

It is good to call this near the beginning of your program to ensure that there are no settings left over from an earlier time that might affect the operation of the driver.

Definition at line 287 of file DRV8434S.h.

◆ setChipSelectPin()

void DRV8434S::setChipSelectPin ( uint8_t  pin)
inline

Configures this object to use the specified pin as a chip select pin. You must use a chip select pin; the DRV8711 requires it.

Definition at line 277 of file DRV8434S.h.

◆ setCurrentMilliamps()

void DRV8434S::setCurrentMilliamps ( uint16_t  current,
uint16_t  fullCurrent = 2000 
)
inline

Sets the driver's current scalar (TRQ_DAC) to produce the specified scaled current limit in milliamps. In order to calculate the correct value for TRQ_DAC, this function also needs to know the full current limit set by VREF (i.e. what the current limit is when the scaling is set to 100%). This is specified by the optional fullCurrent argument, which defaults to 2000 milliamps (2 A).

If the desired current limit is not available, this function tries to pick the closest current limit that is lower than the desired one (although the lowest possible setting is 6.25% of the full current limit).

Example usage:

// This specifies that we want a scaled current limit of 1200 mA and that
// VREF is set to produce a full current limit of 1500 mA. TRQ_DAC will be
// set to 75%, which will produce a 1125 mA scaled current limit.
sd.setCurrentMilliamps(1200, 1500);

Definition at line 393 of file DRV8434S.h.

◆ setCurrentPercent()

void DRV8434S::setCurrentPercent ( uint8_t  percent)
inline

Sets the driver's current scalar (TRQ_DAC), which scales the full current limit (as set by VREF) by the specified percentage. The available settings are multiples of 6.25%.

This function takes an integer, and if the desired current limit is not available, it generally tries to pick the closest current limit that is lower than the desired one (although the lowest possible setting is 6.25%). However, it will round up if the next setting is no more than 0.75% higher; this allows you to specify 43.75% by passing a value of 43, for example.

Example usage:

// This sets TRQ_DAC to 37.5% (the closest setting lower than 42%):
sd.setCurrentPercent(42);
// This sets TRQ_DAC to 43.75% (rounding 43 up by 0.75% to 43.75%):
sd.setCurrentPercent(43);
// This also sets TRQ_DAC to 43.75%; even though the argument is truncated
// to an integer (43), that is then rounded up by 0.75% to 43.75%:
sd.setCurrentPercent(43.75);

Definition at line 363 of file DRV8434S.h.

◆ setDecayMode()

void DRV8434S::setDecayMode ( DRV8434SDecayMode  mode)
inline

Sets the driver's decay mode (DECAY).

Example usage:

sd.setDecayMode(DRV8434SDecayMode::SmartTuneDynamicDecay);

Definition at line 425 of file DRV8434S.h.

◆ setDirection()

void DRV8434S::setDirection ( bool  value)
inline

Sets the motor direction (DIR).

Allowed values are 0 or 1.

You must first call enableSPIDirection() to allow the direction to be controlled through SPI. Once you have done so, you can use this command to control the direction of the stepper motor and leave the DIR pin disconnected.

Definition at line 439 of file DRV8434S.h.

◆ setReg()

void DRV8434S::setReg ( DRV8434SRegAddr  address,
uint8_t  value 
)
inline

Writes the specified value to a register after updating the cached value to match.

Using this function keeps this object's cached settings consistent with the settings being written to the driver, so if you are using verifySettings(), applySettings(), and/or any of the other functions for specific settings that this library provides, you should use this function for direct register accesses instead of calling DRV8434SSPI::writeReg() directly.

Definition at line 634 of file DRV8434S.h.

◆ setStepMode() [1/2]

void DRV8434S::setStepMode ( DRV8434SStepMode  mode)
inline

Sets the driver's stepping mode (MICROSTEP_MODE).

This affects many things about the performance of the motor, including how much the output moves for each step taken and how much current flows through the coils in each stepping position.

If an invalid stepping mode is passed to this function, then it selects 1/16 micro-step, which is the driver's default.

Example usage:

sd.setStepMode(DRV8434SStepMode::MicroStep32);

Definition at line 517 of file DRV8434S.h.

◆ setStepMode() [2/2]

void DRV8434S::setStepMode ( uint16_t  mode)
inline

Sets the driver's stepping mode (MICROSTEP_MODE).

This version of the function allows you to express the requested microstepping ratio as a number directly.

Example usage:

sd.setStepMode(32);

Definition at line 538 of file DRV8434S.h.

◆ step()

void DRV8434S::step ( )
inline

Advances the indexer by one step (STEP = 1).

You must first call enableSPIStep() to allow stepping to be controlled through SPI. Once you have done so, you can use this command to step the motor and leave the STEP pin disconnected.

The driver automatically clears the STEP bit after it is written.

Definition at line 467 of file DRV8434S.h.

◆ verifySettings()

bool DRV8434S::verifySettings ( )
inline

Reads back the SPI configuration registers from the device and verifies that they are equal to the cached copies stored in this class.

This can be used to verify that the driver is powered on and has not lost them due to a power failure. The STATUS register is not verified because it does not contain any driver settings.

Returns
1 if the settings from the device match the cached copies, 0 if they do not.

Definition at line 308 of file DRV8434S.h.

◆ writeCachedReg()

void DRV8434S::writeCachedReg ( DRV8434SRegAddr  address)
inlineprotected

Writes the cached value of the given register to the device.

Definition at line 664 of file DRV8434S.h.

Member Data Documentation

◆ ctrl1

uint8_t DRV8434S::ctrl1
protected

Definition at line 644 of file DRV8434S.h.

◆ ctrl2

uint8_t DRV8434S::ctrl2
protected

Definition at line 644 of file DRV8434S.h.

◆ ctrl3

uint8_t DRV8434S::ctrl3
protected

Definition at line 644 of file DRV8434S.h.

◆ ctrl4

uint8_t DRV8434S::ctrl4
protected

Definition at line 644 of file DRV8434S.h.

◆ ctrl5

uint8_t DRV8434S::ctrl5
protected

Definition at line 644 of file DRV8434S.h.

◆ ctrl6

uint8_t DRV8434S::ctrl6
protected

Definition at line 644 of file DRV8434S.h.

◆ ctrl7

uint8_t DRV8434S::ctrl7
protected

Definition at line 644 of file DRV8434S.h.

◆ driver

DRV8434SSPI DRV8434S::driver

This object handles all the communication with the DRV8711. Generally, you should not need to use it in your code for basic usage of a High-Power Stepper Motor Driver, but you might want to use it to access more advanced settings that the HighPowerStepperDriver class does not provide functions for.

Definition at line 677 of file DRV8434S.h.


The documentation for this class was generated from the following file: