PCA9629 a stepper motor controller class library
PCA9629 Class Reference
#include <PCA9629.h>
Public Types | |
enum | RegisterName { MODE, SUBADR1, SUBADR2, SUBADR3, ALLCALLADR, WDTOI, WDTCNTL, IP, INTSTAT, OP, IOC, MSK, CLRINT, INTMODE, INT_ACT_SETUP, INT_MTR_SETUP, INT_ES_SETUP, INT_AUTO_CLR, SETMODE, PHCNTL, SROTNL, SROTNH, CWPWL, CWPWH, CCWPWL, CCWPWH, CWSCOUNTL, CWSCOUNTH, CCWSCOUNTL, CCWSCOUNTH, CWRCOUNTL, CWRCOUNTH, CCWRCOUNTL, CCWRCOUNTH, EXTRASTEPS0, EXTRASTEPS1, RAMPCNTL, LOOPDLY, MCNTL } |
name of the PCA9629 registers More... | |
enum | RegisterNameFor16bitAccess |
register names for 2 bytes accessing More... | |
enum | Direction { CW = 0, CCW } |
keyword to select direction of rotation More... | |
Public Member Functions | |
PCA9629 (PinName I2C_sda, PinName I2C_scl, short steps_per_rotation, char I2C_address=DEFAULT_PCA9629_ADDR) | |
Create a PCA9629 instance connected to specified I2C pins with specified address. | |
void | software_reset (void) |
Software reset. | |
void | init_registers (void) |
Initialize all registers. | |
void | set_all_registers (char *a, char size) |
Initialize all registers. | |
void | write (RegisterName register_name, char value) |
Write 1 byte data into a register. | |
void | write (RegisterNameFor16bitAccess register_name, short value) |
Write 2 bytes data into a register. | |
char | read (RegisterName register_name) |
Read 1 byte data from a register. | |
short | read (RegisterNameFor16bitAccess register_name) |
Read 2 byte data from registers. | |
void | start (Direction dir) |
Motor start. | |
void | stop (void) |
Motor stop. | |
short | pps (Direction dir, float pulse_per_second) |
Set PPS. | |
void | rotations (Direction dir, int rotation_count) |
Set rotations count. | |
void | steps (Direction dir, int step_count) |
Set steps count. | |
void | rotations_and_steps (Direction dir, int rotation_count, int step_count) |
Set rotations and steps counts. | |
void | register_dump (void) |
Register dump. | |
void | speed_change (unsigned short pw) |
Register dump. |
Detailed Description
PCA9629 class.
This is a driver code for the PCA9629 stepper motor controller. This class provides interface for PCA9629 operation and accessing its registers. Detail information is available on next URL. http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_bus_controller_and_bridge_ics/PCA9629PW.html
Example:
#include "mbed.h" #include "PCA9629.h" PCA9629 motor( p28, p27, 48 ); // SDA, SCL, Steps/rotation, I2C_address (option) int main() { // Speed setting 200pps for clockwise (CW) rotation motor.pps( PCA9629::CW, 200 ); // Set 2 rotations and 24 steps for CW motor.rotations_and_steps( PCA9629::CW, 2, 24 ); // Speed setting 100pps for counterclockwise (CCW) rotation motor.pps( PCA9629::CCW, 100 ); // Set 1 rotation and 24 steps for CCW motor.rotations_and_steps( PCA9629::CCW, 1, 24 ); while ( 1 ) { motor.start( PCA9629::CW ); // Motor start for CW wait( 1.0 ); motor.start( PCA9629::CCW ); // Motor start for CCW wait( 1.0 ); } }
Definition at line 69 of file PCA9629.h.
Member Enumeration Documentation
enum Direction |
enum RegisterName |
name of the PCA9629 registers
- Enumerator:
Constructor & Destructor Documentation
PCA9629 | ( | PinName | I2C_sda, |
PinName | I2C_scl, | ||
short | steps_per_rotation, | ||
char | I2C_address = DEFAULT_PCA9629_ADDR |
||
) |
Create a PCA9629 instance connected to specified I2C pins with specified address.
- Parameters:
-
I2C_sda I2C-bus SDA pin I2C_scl I2C-bus SCL pin steps_per_rotation motor specific setting. This determines how many steps are needed to execute one full turn of motor shaft (360°). I2C_address I2C-bus address (default: 0x42)
Definition at line 36 of file PCA9629.cpp.
Member Function Documentation
void init_registers | ( | void | ) |
Initialize all registers.
The initializing values are defined in the function
Definition at line 55 of file PCA9629.cpp.
short pps | ( | Direction | dir, |
float | pulse_per_second | ||
) |
Set PPS.
Setting PulsePerSecond This interface can be used to set CWPWx or CCWPWx registers
- Parameters:
-
dir rotate direction ("CW" or "CCW") pulse_per_second pps defineds pulse width for the motor. The pulse width will be 1/pps
- Returns:
- 16 bit data that what set to the CWPWx or CCWPWx registers
Definition at line 175 of file PCA9629.cpp.
char read | ( | RegisterName | register_name ) |
Read 1 byte data from a register.
Setting data into a register
- Parameters:
-
register_name the register name: data reading from
- Returns:
- read 8 bits data from the register
Definition at line 105 of file PCA9629.cpp.
short read | ( | RegisterNameFor16bitAccess | register_name ) |
Read 2 byte data from registers.
Setting data into a register
- Parameters:
-
register_name the register name: data writing into (it can be "SROTN_", "CWPW_", "CCWPW_", "CWRCOUNT_", "CCWSCOUNT_", "CWRCOUNT_" or "CCWRCOUNT_" )
- Returns:
- read 16 bits data from the registers
Definition at line 125 of file PCA9629.cpp.
void register_dump | ( | void | ) |
Register dump.
Dumping all register data to serial console
Definition at line 205 of file PCA9629.cpp.
void rotations | ( | Direction | dir, |
int | rotation_count | ||
) |
Set rotations count.
Setting rotation count This interfaces CWRCOUNTx and CCWRCOUNTx registers
- Parameters:
-
dir rotate direction ("CW" or "CCW") rotation_count sets number of rotations with 16 bit value
Definition at line 192 of file PCA9629.cpp.
void rotations_and_steps | ( | Direction | dir, |
int | rotation_count, | ||
int | step_count | ||
) |
Set rotations and steps counts.
Setting rotation and step count This interfaces CWRCOUNTx, CCWRCOUNTx, CWSCOUNTx and CCWSCOUNTx registers
- Parameters:
-
dir rotate direction ("CW" or "CCW") rotation_count sets number of rotations with 16 bit value step_count sets number of steps with 16 bit value
Definition at line 200 of file PCA9629.cpp.
void set_all_registers | ( | char * | a, |
char | size | ||
) |
Initialize all registers.
The initializing values are defined in the function
Definition at line 69 of file PCA9629.cpp.
void software_reset | ( | void | ) |
void speed_change | ( | unsigned short | pw ) |
Register dump.
Dumping all register data to serial console
Definition at line 223 of file PCA9629.cpp.
void start | ( | Direction | dir ) |
Motor start.
Start command This function starts motor operation with hard-stop flag and rotation+step enabled, no repeat will be performed If custom start is required, use "write( PCA9629::MCNTL, 0xXX )" to control each bits.
- Parameters:
-
dir rotate direction ("CW" or "CCW")
Definition at line 145 of file PCA9629.cpp.
void steps | ( | Direction | dir, |
int | step_count | ||
) |
Set steps count.
Setting step count This interfaces CWSCOUNTx and CCWSCOUNTx registers
- Parameters:
-
dir rotate direction ("CW" or "CCW") step_count sets number of steps with 16 bit value
Definition at line 196 of file PCA9629.cpp.
void stop | ( | void | ) |
void write | ( | RegisterName | register_name, |
char | value | ||
) |
Write 1 byte data into a register.
Setting 8 bits data into a register
- Parameters:
-
register_name the register name: data writing into value 8 bits writing data
Definition at line 78 of file PCA9629.cpp.
void write | ( | RegisterNameFor16bitAccess | register_name, |
short | value | ||
) |
Write 2 bytes data into a register.
Setting 16 bits data into registers
- Parameters:
-
register_name the register name: data writing into (it can be "SROTN_", "CWPW_", "CCWPW_", "CWRCOUNT_", "CCWSCOUNT_", "CWRCOUNT_" or "CCWRCOUNT_" ) value 16 bits writing data
Definition at line 91 of file PCA9629.cpp.
Generated on Wed Jul 13 2022 21:18:11 by
