AMIS30543 library
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
AMIS30543 Class Reference

#include <AMIS30543.h>

Public Types

enum  stepMode {
  MicroStep128 = 128, MicroStep64 = 64, MicroStep32 = 32, MicroStep16 = 16,
  MicroStep8 = 8, MicroStep4 = 4, MicroStep2 = 2, MicroStep1 = 1,
  CompensatedHalf = MicroStep2, CompensatedFullTwoPhaseOn = MicroStep1, CompensatedFullOnePhaseOn = 200, UncompensatedHalf = 201,
  UncompensatedFull = 202
}
 
enum  nonLatchedStatusFlag {
  OPENY = (1 << 2), OPENX = (1 << 3), WD = (1 << 4), CPFAIL = (1 << 5),
  TW = (1 << 6)
}
 
enum  latchedStatusFlag {
  OVCXNB = (1 << 3), OVCXNT = (1 << 4), OVCXPB = (1 << 5), OVCXPT = (1 << 6),
  TSD = (1 << 10), OVCYNB = (1 << 11), OVCYNT = (1 << 12), OVCYPB = (1 << 13),
  OVCYPT = (1 << 14)
}
 
enum  regAddr {
  WR = 0x0, CR0 = 0x1, CR1 = 0x2, CR2 = 0x3,
  CR3 = 0x9, SR0 = 0x4, SR1 = 0x5, SR2 = 0x6,
  SR3 = 0x7, SR4 = 0xA
}
 

Public Member Functions

 AMIS30543 ()
 
void init (uint8_t slaveSelectPin)
 
void resetSettings ()
 
bool verifySettings ()
 
void applySettings ()
 
void enableDriver ()
 
void disableDriver ()
 
void setCurrentMilliamps (uint16_t current)
 
uint16_t readPosition ()
 
void setDirection (bool value)
 
bool getDirection ()
 
void setStepMode (uint8_t mode)
 
void sleep ()
 
void sleepStop ()
 
void stepOnRisingEdge ()
 
void stepOnFallingEdge ()
 
void setPwmFrequencyDouble ()
 
void setPwmFrequencyDefault ()
 
void setPwmJitterOn ()
 
void setPwmJitterOff ()
 
void setPwmSlope (uint8_t emc)
 
void setSlaGainDefault ()
 
void setSlaGainHalf ()
 
void setSlaTransparencyOff ()
 
void setSlaTransparencyOn ()
 
uint16_t readNonLatchedStatusFlags ()
 
uint16_t readLatchedStatusFlagsAndClear ()
 

Public Attributes

AMIS30543SPI driver
 

Protected Member Functions

uint8_t readStatusReg (uint8_t address)
 
void writeWR ()
 
void writeCR0 ()
 
void writeCR1 ()
 
void writeCR3 ()
 

Protected Attributes

uint8_t wr
 
uint8_t cr0
 
uint8_t cr1
 
uint8_t cr2
 
uint8_t cr3
 

Detailed Description

This class provides high-level functions for controlling an AMIS-30543 micro-stepping motor driver.

It provides access to all the features of the AMIS-30543 SPI interface except the watchdog timer.

Definition at line 93 of file AMIS30543.h.

Member Enumeration Documentation

Bitmasks for the return value of readLatchedStatusFlagsAndClear().

Definition at line 131 of file AMIS30543.h.

Bitmasks for the return value of readNonLatchedStatusFlags().

Definition at line 121 of file AMIS30543.h.

Addresses of control and status registers.

Definition at line 145 of file AMIS30543.h.

Possible arguments to setStepMode().

Definition at line 103 of file AMIS30543.h.

Constructor & Destructor Documentation

AMIS30543::AMIS30543 ( )
inline

The default constructor.

Definition at line 97 of file AMIS30543.h.

Member Function Documentation

void AMIS30543::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 205 of file AMIS30543.h.

void AMIS30543::disableDriver ( )
inline

Sets the MOTEN bit to 0, disabling the driver.

Please read the note about this function in README.md.

Definition at line 236 of file AMIS30543.h.

void AMIS30543::enableDriver ( )
inline

Sets the MOTEN bit to 1, enabling the driver.

Please read the note about this function in README.md.

Definition at line 227 of file AMIS30543.h.

bool AMIS30543::getDirection ( )
inline

Returns the cached value of the DIRCTRL configuration bit.

This does not perform any SPI communication with the driver.

Definition at line 324 of file AMIS30543.h.

void AMIS30543::init ( uint8_t  slaveSelectPin)
inline

Configures this object to use the specified pin as a slave select pin. You must use a slave select pin; the AMIS-30543 requires it.

Definition at line 161 of file AMIS30543.h.

uint16_t AMIS30543::readLatchedStatusFlagsAndClear ( )
inline

Reads the latched status flags from registers SR1 and SR2. They are cleared as a side effect.

The return value is a 16-bit unsigned integer that has one bit for each status flag. You can simply compare the return value to 0 to see if any of the status flags are set, or you can use the logical and operator (&) and the latchedStatusFlag enum to check individual flags.

WARNING: Calling this function clears the latched error bits in SR1 and SR2, which might allow the motor driver outputs to reactivate. The AMIS-30543 datasheet says "successive reading the SPI Status Registers 1 and 2 in case of a short circuit condition, may lead to damage to the drivers".

Definition at line 531 of file AMIS30543.h.

uint16_t AMIS30543::readNonLatchedStatusFlags ( )
inline

Reads the status flags from registers SR0. These flags are not latched, which means they will be cleared as soon as the condition causing them is no longer detected. See the AMIS-30543 datasheet for more information.

This function returns the raw value of SR0, with the parity bit set to 0. You can simply compare the return value to 0 to see if any of the status flags are set, or you can use the logical AND operator (&) and the nonLatchedStatusFlag enum to check individual flags.

uint16_t flags = stepper.readNonLatchedStatusFlags();
if (flags)
{
// At least one flag is set.
if (flags & AMIS30543::OPENX)
{
// Thermal shutdown flag is set.
}
}

Definition at line 513 of file AMIS30543.h.

uint16_t AMIS30543::readPosition ( )
inline

Reads the current microstepping position, which is a number between 0 and 511.

The different positions and their corresponding coil values are listed in Table 9 of the AMIS-30543 datasheet.

The lower two bits of this return value might be inaccurate if the step pin is being toggled while this function runs (e.g. from an interrupt or a PWM signal).

Our tests indicated that the return value of this function might be wrong if you read it within 25 microseconds of commanding the driver to take a step. Therefore we recommend delaying for at least 100 microseconds after taking a step and before calling this function.

Definition at line 295 of file AMIS30543.h.

uint8_t AMIS30543::readStatusReg ( uint8_t  address)
inlineprotected

Reads a status register and returns the lower 7 bits (the parity bit is set to 0 in the return value).

Definition at line 544 of file AMIS30543.h.

void AMIS30543::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 171 of file AMIS30543.h.

void AMIS30543::setCurrentMilliamps ( uint16_t  current)
inline

Sets the per-coil current limit equal to the highest available setting that is less than the given current, in units of milliamps.

Refer to Table 13 of the AMIS-30543 datasheet to see which current limits are available.

Definition at line 247 of file AMIS30543.h.

void AMIS30543::setDirection ( bool  value)
inline

Sets the value of the DIRCTRL configuration bit.

Allowed values are 0 or 1.

You can use this command to control the direction of the stepper motor and simply leave the DIR pin disconnected.

Definition at line 308 of file AMIS30543.h.

void AMIS30543::setPwmFrequencyDefault ( )
inline

Clears the PWMF bit, which sets the PWM frequency to its default value (22.8 kHz).

Definition at line 418 of file AMIS30543.h.

void AMIS30543::setPwmFrequencyDouble ( )
inline

Sets the PWMF bit to 1, which doubles the PWM frequency (45.6 kHz) .

Definition at line 410 of file AMIS30543.h.

void AMIS30543::setPwmJitterOff ( )
inline

Clears the PWMJ bit, which disables artificial jittering in the PWM signal used to control the current to each coil. This is the default setting.

Definition at line 435 of file AMIS30543.h.

void AMIS30543::setPwmJitterOn ( )
inline

Sets the PWMJ bit, which enables artificial jittering in the PWM signal used to control the current to each coil.

Definition at line 426 of file AMIS30543.h.

void AMIS30543::setPwmSlope ( uint8_t  emc)
inline

This sets the EMC[1:0] bits, which determine how long it takes the PWM signal to rise or fall. Valid values are 0 through 3. Higher values correspond to longer rise and fall times.

Definition at line 444 of file AMIS30543.h.

void AMIS30543::setSlaGainDefault ( )
inline

Clears the SLAG bit, which configures the signal on SLA pin to have a gain of 0.5 (the default).

Please read the note about this function in README.md.

Definition at line 454 of file AMIS30543.h.

void AMIS30543::setSlaGainHalf ( )
inline

Sets the SLAG bit to 1, which configures the signal on SLA pin to have a gain of 0.25 (half of the default).

Please read the note about this function in README.md.

Definition at line 464 of file AMIS30543.h.

void AMIS30543::setSlaTransparencyOff ( )
inline

Set the SLAT bit to 0 (the default), which disables transparency on the SLA pin. See the AMIS-30543 datasheet for more information.

Please read the note about this function in README.md.

Definition at line 474 of file AMIS30543.h.

void AMIS30543::setSlaTransparencyOn ( )
inline

Sets the SLAT bit to 1, which enables transparency on the SLA pin. See the AMIS-30543 datasheet for more information.

Please read the note about this function in README.md.

Definition at line 484 of file AMIS30543.h.

void AMIS30543::setStepMode ( uint8_t  mode)
inline

Configures the driver to have the specified stepping 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.

The argument to this function should be one of the members of the stepMode enum.

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

Definition at line 340 of file AMIS30543.h.

void AMIS30543::sleep ( )
inline

Sets the SLP bit 1, enabling sleep mode.

According to the AMIS-30543 datasheet, the motor supply voltage must be at least 9 V before entering sleep mode.

You can call sleepStop() to disable sleep mode.

Please read the note about this function in README.md.

Definition at line 377 of file AMIS30543.h.

void AMIS30543::sleepStop ( )
inline

Sets the SLP bit 0, disabling sleep mode.

Please read the note about this function in README.md.

Definition at line 386 of file AMIS30543.h.

void AMIS30543::stepOnFallingEdge ( )
inline

Sets the value of the NXTP configuration bit to 1, which means that new steps are triggered by a falling edge on the NXT/STEP pin.

Definition at line 403 of file AMIS30543.h.

void AMIS30543::stepOnRisingEdge ( )
inline

Sets the value of the NXTP configuration bit to 0, which means that new steps are triggered by a rising edge on the NXT/STEP pin. This is the default behavior.

Definition at line 395 of file AMIS30543.h.

bool AMIS30543::verifySettings ( )
inline

Reads back all the SPI control 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. However this function will probably return true if the driver is not powered and all of the cached settings are the default values. Therefore, we only recommend calling this after you have changed at least one of the settings from its default value, for example by calling enableDriver().

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

Definition at line 189 of file AMIS30543.h.

void AMIS30543::writeCR0 ( )
inlineprotected

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

Definition at line 559 of file AMIS30543.h.

void AMIS30543::writeCR1 ( )
inlineprotected

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

Definition at line 565 of file AMIS30543.h.

void AMIS30543::writeCR3 ( )
inlineprotected

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

Definition at line 571 of file AMIS30543.h.

void AMIS30543::writeWR ( )
inlineprotected

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

Definition at line 553 of file AMIS30543.h.

Member Data Documentation

AMIS30543SPI AMIS30543::driver

This object handles all the communication with the AMIS-30543. It is only marked as public for the purpose of testing this library; you should not use it in your code.

Definition at line 580 of file AMIS30543.h.


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