#include <MP6602.h>
This class provides high-level functions for controlling an MP6602 stepper motor driver.
Definition at line 163 of file MP6602.h.
◆ MP6602()
The default constructor.
Definition at line 167 of file MP6602.h.
◆ applySettings()
| void MP6602::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 229 of file MP6602.h.
◆ cachedRegPtr()
Returns a pointer to the variable containing the cached value for the given register.
Definition at line 499 of file MP6602.h.
◆ clearFaults()
| void MP6602::clearFaults |
( |
| ) |
|
|
inline |
Clears any fault conditions that are currently latched in the driver, including bits in the OCP register.
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.
Definition at line 456 of file MP6602.h.
◆ disableDriver()
| void MP6602::disableDriver |
( |
| ) |
|
|
inline |
Disables the driver (EN = 0).
You can use this function to disable the driver and simply leave the ENBL (EN) pin disconnected. If ENBL is high, calling this function will enable the driver instead (the driver state is controlled by the logical XOR of the EN bit and the value of the ENBL pin).
Definition at line 318 of file MP6602.h.
◆ enableDriver()
| void MP6602::enableDriver |
( |
| ) |
|
|
inline |
Enables the driver (EN = 1).
You can use this function to enable the driver and simply leave the ENBL (EN) pin disconnected. If ENBL is high, calling this function will disable the driver instead (the driver state is controlled by the logical XOR of the EN bit and the value of the ENBL pin).
Definition at line 306 of file MP6602.h.
◆ getCachedReg()
Gets the cached value of a register. If the given register address is not valid, this function returns 0.
Definition at line 469 of file MP6602.h.
◆ getDirection()
| bool MP6602::getDirection |
( |
| ) |
|
|
inline |
Returns the cached value of the motor direction (DIR).
This does not perform any SPI communication with the driver.
Definition at line 347 of file MP6602.h.
◆ readFault()
| uint16_t MP6602::readFault |
( |
| ) |
|
|
inline |
Reads the FAULT status register of the driver.
The return value is a 10-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 MP6602FaultBit enum to check individual bits. Fault bits are latched and remain set until cleared by writing a 1 to the appropriate bit (you can call clearFaults() to clear all faults).
Example usage:
{
}
@ OVP
Over-voltage protection.
Definition at line 431 of file MP6602.h.
◆ readOCP()
| uint8_t MP6602::readOCP |
( |
| ) |
|
|
inline |
Reads the OCP status register of the driver.
The return value is a 4-bit unsigned integer that has one bit for each OCP 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 MP6602OCPBit enum to check individual bits. OCP bits are latched and remain set until cleared by writing a 1 to the appropriate bit (you can call clearFaults() to clear all faults, including OCP faults).
Definition at line 444 of file MP6602.h.
◆ resetSettings()
| void MP6602::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 189 of file MP6602.h.
◆ setAutoHoldTimeMs()
| void MP6602::setAutoHoldTimeMs |
( |
uint16_t | time | ) |
|
|
inline |
Sets the time that should pass after the last step, in milliseconds, before the driver's automatic hold current feature activates and it switches to the configured holding current.
This function takes an integer value and tries to pick the closest time period that is equal to or higher than the desired one. The available settings range from 15.6 ms to 1000 ms (1 s). See Table 5 in the MP6602 datasheet for the available settings. Calling this function with an argument of 0 disables the automatic hold current feature.
Definition at line 283 of file MP6602.h.
◆ setChipSelectPin()
| void MP6602::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 MP6602 requires it.
Definition at line 179 of file MP6602.h.
◆ setCurrentMilliamps()
| void MP6602::setCurrentMilliamps |
( |
uint16_t | current | ) |
|
|
inline |
Sets the driver's current limit during stepping, in units of milliamps.
This function tries to pick the closest current limit that is equal to or lower than the desired one. The available settings range from 0.125 A to 4 A in increments of 125 mA.
Definition at line 247 of file MP6602.h.
◆ setDirection()
| void MP6602::setDirection |
( |
bool | value | ) |
|
|
inline |
Sets the motor direction (DIR).
Allowed values are 0 or 1.
You can use this command to control the direction of the stepper motor and leave the DIR pin disconnected. (The direction is controlled by the logical XOR of the DIR bit and the value of the DIR pin.)
Definition at line 331 of file MP6602.h.
◆ setHoldCurrentMilliamps()
| void MP6602::setHoldCurrentMilliamps |
( |
uint16_t | current | ) |
|
|
inline |
Sets the driver's current limit during automatic hold mode, in units of milliamps.
This setting only applies if automatic hold mode is enabled, which you can do with with setAutoHoldTimeMs(). This function tries to pick the closest current limit that is equal to or lower than the desired one. The available settings range from 0.125 A to 4 A in increments of 125 mA.
Definition at line 264 of file MP6602.h.
◆ setReg()
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 MP6602SPI::writeReg() directly.
Definition at line 485 of file MP6602.h.
◆ setStepMode() [1/2]
Sets the driver's step mode (MS).
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. Available microstepping modes range from full step to 1/32-step.
If an invalid step mode is passed to this function, then it selects 1/8-step mode, which is the driver's default.
Example usage:
Definition at line 374 of file MP6602.h.
◆ setStepMode() [2/2]
| void MP6602::setStepMode |
( |
uint16_t | mode | ) |
|
|
inline |
Sets the driver's stepping mode (MS).
This version of the function allows you to express the requested microstepping ratio as a number directly.
Example usage:
Definition at line 395 of file MP6602.h.
◆ step()
Advances the indexer by one step (STEP = 1).
The driver automatically clears the STEP bit after it is written.
Definition at line 355 of file MP6602.h.
◆ verifySettings()
| bool MP6602::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. Only registers that contain driver settings are verified (and bits that do not contain settings are masked off and not verified).
- Returns
- 1 if the settings from the device match the cached copies, 0 if they do not.
Definition at line 213 of file MP6602.h.
◆ writeCachedReg()
Writes the cached value of the given register to the device.
Definition at line 513 of file MP6602.h.
◆ bemf
◆ ctrl
◆ ctrl2
◆ driver
This object handles all the communication with the MP6602. Generally, you should not need to use it in your code for basic usage of the driver, but you might want to use it to access more advanced settings that the MP6602 class does not provide functions for.
Definition at line 525 of file MP6602.h.
◆ iset
◆ stall
The documentation for this class was generated from the following file: