PCA9629 a stepper motor controller class library
Class library for PCA9629.
A sample program available on http://mbed.org/users/nxp_ip/code/PCA9629_Hello/
Revision 2:2d07f1c46eb3, committed 2012-02-03
- Comitter:
- nxp_ip
- Date:
- Fri Feb 03 03:44:06 2012 +0000
- Parent:
- 1:b3d94e04adfa
- Child:
- 3:b01267479d2e
- Commit message:
Changed in this revision
PCA9629.cpp | Show annotated file Show diff for this revision Revisions of this file |
PCA9629.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/PCA9629.cpp Thu Feb 02 05:23:12 2012 +0000 +++ b/PCA9629.cpp Fri Feb 03 03:44:06 2012 +0000 @@ -36,7 +36,6 @@ } void PCA9629::init_registers( void ) { - int error_code; char init_array[] = { 0x80, // register access start address (0x00) with incremental access flag (MSB) 0x30, 0xE2, 0xE4, 0xE6, 0xE0, 0x02, 0x10, // for registers MODE - WDCNTL (0x00 - 0x06 0x00, 0x00, // for registers IP and INTSTAT (0x07, 0x08) @@ -44,14 +43,20 @@ 0x00, 0x00, 0x30, 0x00, 0x82, 0x66, 0x82, 0x06, // for registers SETMODE - CCWPWH (0x12 - 0x19) 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, // for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21) 0x00, 0x00, // for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23) - 0x00, 0x00, 0x94 // for registers RMPCNTL - MCNTL (0x24 - 0x26) + 0x00, 0x00, 0x00 // for registers RMPCNTL - MCNTL (0x24 - 0x26) }; - error_code = i2c.write( i2c_addr, init_array, sizeof( init_array ) ); + set_all_registers( init_array, sizeof( init_array ) ); +} + +void PCA9629::set_all_registers( char *a, char size ) +{ + int error_code; + + error_code = i2c.write( i2c_addr, a, size ); if ( error_code ) error( "error @ initializing PCA9629" ); - } void PCA9629::write( RegisterName register_name, char value ) { @@ -121,6 +126,10 @@ return ( data[ 1 ] << 8 | data[ 0 ] ); } +void PCA9629::start( Direction dir ) { + write( MCNTL, 0xA8 | dir ); +} + void PCA9629::stop( void ) { write( MCNTL, 0x00 ); }
--- a/PCA9629.h Thu Feb 02 05:23:12 2012 +0000 +++ b/PCA9629.h Fri Feb 03 03:44:06 2012 +0000 @@ -156,12 +156,18 @@ char I2C_address = PCA9629_DEFAULT_ADDR ); - /** + /** Initialize all registers * - * + * The initializing values are defined in the function */ void init_registers( void ); + /** Initialize all registers + * + * The initializing values are defined in the function + */ + void set_all_registers( char *a, char size ); + /** Write 1 byte data into a register * * Setting 8 bits data into a register @@ -198,6 +204,16 @@ */ short read( Register16bits register_name ); + /** 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. + * + * @param dir rotate direction ("CW" or "CCW") + */ + void start( Direction dir ); + /** Motor stop * * Stop command