PCA9629 a stepper motor controller class library

Dependents:   PCA9629_Hello

Embed: (wiki syntax)

« Back to documentation index

PCA9629 Class Reference

PCA9629 Class Reference

PCA9629 class. More...

#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

keyword to select direction of rotation

Enumerator:
CW 

Clockwise direction.

CCW 

ConterClockwise direction.

Definition at line 139 of file PCA9629.h.

name of the PCA9629 registers

Enumerator:
MODE 

Mode rgister.

SUBADR1 

I2C-bus subaddress 1.

SUBADR2 

I2C-bus subaddress 2.

SUBADR3 

I2C-bus subaddress 3.

ALLCALLADR 

All call I2C-bus address.

WDTOI 

Watchdog time-out interval register.

WDTCNTL 

Watchdog control register.

IP 

Input port register.

INTSTAT 

Interrupt status register.

OP 

Output port register.

IOC 

I/O configuration register.

MSK 

Mask interrupt register.

CLRINT 

Clear Interrupts.

INTMODE 

Interrupt mode register.

INT_ACT_SETUP 

Interrupt action setup control register.

INT_MTR_SETUP 

Interrupt motor setup control register.

INT_ES_SETUP 

Interrupt extra steps setup control register.

INT_AUTO_CLR 

Interrupt auto clear control register.

SETMODE 

Output state on STOP.

PHCNTL 

Phase control register.

SROTNL 

Steps per rotation low byte.

SROTNH 

Steps per rotation high byte.

CWPWL 

Step pulse width for CW rotation low byte.

CWPWH 

Step pulse width for CW rotation high byte.

CCWPWL 

Step pulse width for CCW rotation low byte.

CCWPWH 

Step pulse width for CCW rotation high byte.

CWSCOUNTL 

Number of steps CW low byte.

CWSCOUNTH 

Number of steps CW high byte.

CCWSCOUNTL 

Number of steps CCW low byte.

CCWSCOUNTH 

Number of steps CCW high byte.

CWRCOUNTL 

Number of rotatations CW low byte.

CWRCOUNTH 

Number of rotatations CW high byte.

CCWRCOUNTL 

Number of rotatations CCW low byte.

CCWRCOUNTH 

Number of rotatations CCW high byte.

EXTRASTEPS0 

Count value for extra steps or rotations for INTP0.

EXTRASTEPS1 

Count value for extra steps or rotations for INTP1.

RAMPCNTL 

Ramp control register.

LOOPDLY 

Loopdelay time register.

MCNTL 

Control start/stop motor.

Definition at line 72 of file PCA9629.h.

register names for 2 bytes accessing

Definition at line 128 of file PCA9629.h.


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_sdaI2C-bus SDA pin
I2C_sclI2C-bus SCL pin
steps_per_rotationmotor specific setting. This determines how many steps are needed to execute one full turn of motor shaft (360°).
I2C_addressI2C-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:
dirrotate direction ("CW" or "CCW")
pulse_per_secondpps 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_namethe 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_namethe 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:
dirrotate direction ("CW" or "CCW")
rotation_countsets 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:
dirrotate direction ("CW" or "CCW")
rotation_countsets number of rotations with 16 bit value
step_countsets 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   )

Software reset.

Performs software reset through I2C bus

Definition at line 48 of file PCA9629.cpp.

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:
dirrotate 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:
dirrotate direction ("CW" or "CCW")
step_countsets number of steps with 16 bit value

Definition at line 196 of file PCA9629.cpp.

void stop ( void   )

Motor stop.

Stop command

Definition at line 149 of file PCA9629.cpp.

void write ( RegisterName  register_name,
char  value 
)

Write 1 byte data into a register.

Setting 8 bits data into a register

Parameters:
register_namethe register name: data writing into
value8 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_namethe register name: data writing into (it can be "SROTN_", "CWPW_", "CCWPW_", "CWRCOUNT_", "CCWSCOUNT_", "CWRCOUNT_" or "CCWRCOUNT_" )
value16 bits writing data

Definition at line 91 of file PCA9629.cpp.