PCA9629 a stepper motor controller class library

Dependents:   PCA9629_Hello

Class library for PCA9629.

A sample program available on http://mbed.org/users/nxp_ip/code/PCA9629_Hello/

Files at this revision

API Documentation at this revision

Comitter:
nxp_ip
Date:
Fri Feb 03 03:50:55 2012 +0000
Parent:
2:2d07f1c46eb3
Child:
4:9a80b6d63005
Commit message:
initial version

Changed in this revision

PCA9629.cpp Show diff for this revision Revisions of this file
PCA9629.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/PCA9629.cpp	Fri Feb 03 03:44:06 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,198 +0,0 @@
-/** A sample code for PCA9629
- *
- *  @author  Tedd OKANO, NXP Semiconductors
- *  @version 1.0
- *  @date    03-Feb-2011
- *
- *  Released under the MIT License: http://mbed.org/license/mit
- *
- *  An operation sample of PCU9629 stepper motor controller. 
- *  The mbed accesses the PCU9629 registers through I2C. 
- */
-
-#include    "mbed.h"
-#include    "PCA9629.h"
-
-#define     STEP_RESOLUTION     333333      //  1/(3e-6) = 333333
-
-char *reg_name[] = {
-    "MODE", "SUBADR1", "SUBADR2", "SUBADR3", "ALLCALLADR", "WDTC", "WDMOD", "IP",
-    "INTSTAT", "OP", "IOC", "MSK", "CLRINT", "INTMODE1", "INTMODE2", "INT_ACT_SETUP",
-    "INT_MRT_SETUP", "INT_ES_SETUP", "SETMODE", "PHCNTL", "SROTNL", "SROTNH",
-    "CWPWL", "CWPWH", "CCWPWL", "CCWPWH",
-    "CWSCOUNTL", "CWSCOUNTH", "CCWSCOUNTL", "CCWSCOUNTH",
-    "CWRCOUNTL", "CWRCOUNTH", "CCWRCOUNTL", "CCWRCOUNTH",
-    "EXTRASTEPS0", "EXTRASTEPS1", "RAMPX", "LOOPDLY", "MCNTL"
-};
-
-PCA9629::PCA9629(
-    PinName I2C_sda,
-    PinName I2C_scl,
-    char    I2C_address
-) : i2c( I2C_sda, I2C_scl ), i2c_addr( I2C_address ) {
-
-    i2c.frequency( 400 * 1000 );    
-    init_registers();
-}
-
-void PCA9629::init_registers( void ) {
-    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)
-                            0x07, 0x0F, 0x00, 0x0F, 0x0F, 0x00, 0x03, 0x02, 0x01, //  for registers OP - INT_AUTO_CLR (0x09 - 0x11)
-                            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, 0x00                                      //  for registers RMPCNTL - MCNTL (0x24 - 0x26)
-                           };
-
-    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 ) {
-    int     error_code;
-    char    cmd[ 2 ];
-
-    cmd[ 0 ]    = register_name;
-    cmd[ 1 ]    = value;
-
-    error_code  = i2c.write( i2c_addr, cmd, 2 );
-
-    if ( error_code )
-        error( "PCA9629 writing failed\r\n" );
-}
-
-void PCA9629::write( Register16bits register_name, short value ) {
-    int     error_code;
-    char    cmd[ 3 ];
-
-    cmd[ 0 ]    = register_name;
-    cmd[ 1 ]    = value & 0xFF;
-    cmd[ 2 ]    = value >> 8;
-
-    error_code  = i2c.write( i2c_addr, cmd, 3 );
-
-    if ( error_code )
-        error( "PCA9629 writing failed\r\n" );
-}
-
-char PCA9629::read( RegisterName register_name ) {
-    int     error_code;
-    char    cmd;
-    char    data;
-
-    cmd = register_name;
-
-    error_code  = i2c.write( i2c_addr, &cmd, 1, false );
-
-    if ( error_code )
-        error( "PCA9629 reading (command phase) failed\r\n" );
-
-    error_code  = i2c.read( i2c_addr, &data, 1 );
-
-    if ( error_code )
-        error( "PCA9629 reading (data phase) failed\r\n" );
-
-    return ( data );
-}
-
-short PCA9629::read( Register16bits register_name ) {
-    int     error_code;
-    char    cmd;
-    char    data[ 2 ];
-
-    cmd = register_name;
-
-    error_code  = i2c.write( i2c_addr, &cmd, 1, false );
-
-    if ( error_code )
-        error( "PCA9629 reading (command phase) failed\r\n" );
-
-    error_code  = i2c.read( i2c_addr, data, 2 );
-
-    if ( error_code )
-        error( "PCA9629 reading (data phase) failed\r\n" );
-
-    return ( data[ 1 ] << 8 | data[ 0 ] );
-}
-
-void PCA9629::start( Direction dir ) {
-    write( MCNTL, 0xA8 | dir );
-}
-
-void PCA9629::stop( void ) {
-    write( MCNTL, 0x00 );
-}
-
-short PCA9629::pps( Direction dir, PrescalerRange prescaler, int pps ) {
-    int     step_pulse_width;
-
-    step_pulse_width    = STEP_RESOLUTION / ((1 << prescaler) * pps);
-
-    if ( step_pulse_width & 0xE000 ) {  //error( "pps setting: out of range" );
-        step_pulse_width    = 0x1FFF;
-        printf( "the pps forced in to the range that user specified.. %fpps\r\n", (float)STEP_RESOLUTION / ((float)0x1FFF * (float)(1 << prescaler)) );
-    }
-    if ( !step_pulse_width ) {  //error( "pps setting: out of range" );
-        step_pulse_width    = 0x1;
-        printf( "the pps forced in to the range that user specified.. %fpps\r\n", (float)STEP_RESOLUTION / (float)(1 << prescaler) );
-    }
-
-    step_pulse_width    |= (prescaler << 13);
-
-    write( (dir == CW) ? CWPW_ : CCWPW_, step_pulse_width );
-
-    return ( step_pulse_width );
-}
-
-void PCA9629::rotations( Direction dir, int rotations ) {
-    write( (dir == CW) ? CWRCOUNT_ : CCWRCOUNT_, rotations );
-}
-
-void PCA9629::steps( Direction dir, int steps ) {
-    write( (dir == CW) ? CWSCOUNT_ : CCWSCOUNT_, steps );
-}
-
-
-void PCA9629::register_dump( void ) {
-    char    data[ 0x27 ];
-    char    cmd = 0x80;
-    int     i;
-    int     j;
-
-    i2c.write( i2c_addr, &cmd, 1 );
-    i2c.read( i2c_addr, data, sizeof( data ) );
-
-    printf( "PCA9629 register dump\r\n" );
-
-    for ( i = 0, j = 0x14; i <= 0x12; i++, j++ )
-        printf( "  %-13s (0x%02X): 0x%02X    %-13s (0x%02X): 0x%02X\r\n", reg_name[ i ], i, data[ i ], reg_name[ j ], j, data[ j ] );
-
-    printf( "  %-13s (0x%02X): 0x%02X\r\n", reg_name[ 0x13 ], 0x13, data[ 0x13 ] );
-}
-
-
-void PCA9629::speed_change( unsigned short pw ) {
-    char    cmd0[]   = { PCA9629::MCNTL, 0x00};                         //  data for stop the motor
-    char    cmd1[]   = { PCA9629::CW__STEP_WIDTH, pw & 0xFF, pw >> 8 }; //  data for rewrite pulse width
-    char    cmd2[]   = { PCA9629::MCNTL, 0xB4};   //  start             //  data for start again
-    wait_us(10);
-
-    i2c.write( i2c_addr, cmd0, sizeof( cmd0 ), true );  //  stop the motor
-    wait_us(50);
-    i2c.write( i2c_addr, cmd1, sizeof( cmd1 ), true );  //  rewrite pulse width
-    i2c.write( i2c_addr, cmd2, sizeof( cmd2 ), false ); //  start again
-}
-
-
-
--- a/PCA9629.h	Fri Feb 03 03:44:06 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,288 +0,0 @@
-/** A sample code for PCA9629
- *
- *  @author  Tedd OKANO, NXP Semiconductors
- *  @version 1.0
- *  @date    03-Feb-2011
- *
- *  Released under the MIT License: http://mbed.org/license/mit
- *
- *  An operation sample of PCU9629 stepper motor controller.
- *  The mbed accesses the PCU9629 registers through I2C.
- */
-
-#ifndef        MBED_PCA9629
-#define        MBED_PCA9629
-
-#define     INTELIGENT_WRITE
-
-#define     PCA9629_DEFAULT_ADDR      0x42
-
-#define        INIT_VALUE__MODE          0x10;
-#define        INIT_VALUE__SUBADR1       0xE2;
-#define        INIT_VALUE__SUBADR2       0xE4;
-#define        INIT_VALUE__SUBADR3       0xE8;
-#define        INIT_VALUE__ALLCALLADR    0xE0;
-#define        INIT_VALUE__WDTOI         0xFF;
-#define        INIT_VALUE__WDTCNTL       0x00;
-#define        INIT_VALUE__IP            0x00;
-#define        INIT_VALUE__INTSTAT       0x00;
-#define        INIT_VALUE__OP            0x0F;
-#define        INIT_VALUE__IOC           0x03;
-#define        INIT_VALUE__MSK           0x0F;
-#define        INIT_VALUE__CLRINT        0x0C;
-#define        INIT_VALUE__INTMODE       0x00;
-#define        INIT_VALUE__INT_ACT_SETUP 0x00;
-#define        INIT_VALUE__INT_MTR_SETUP 0x00;
-#define        INIT_VALUE__INT_ES_SETUP  0x00;
-#define        INIT_VALUE__INT_AUTO_CLR  0x00;
-#define        INIT_VALUE__SETMODE       0x00;
-#define        INIT_VALUE__PHCNTL        0x00;
-#define        INIT_VALUE__SROTNL        0x30;
-#define        INIT_VALUE__SROTNH        0x00;
-#define        INIT_VALUE__CWPWL         0x00;
-#define        INIT_VALUE__CWPWH         0x00;
-#define        INIT_VALUE__CCWPWL        0x00;
-#define        INIT_VALUE__CCWPWH        0x00;
-#define        INIT_VALUE__CWSCOUNTL     0x00;
-#define        INIT_VALUE__CWSCOUNTH     0x00;
-#define        INIT_VALUE__CCWSCOUNTL    0x00;
-#define        INIT_VALUE__CCWSCOUNTH    0x00;
-#define        INIT_VALUE__CWRCOUNTL     0x00;
-#define        INIT_VALUE__CWRCOUNTH     0x00;
-#define        INIT_VALUE__CCWRCOUNTL    0x00;
-#define        INIT_VALUE__CCWRCOUNTH    0x00;
-#define        INIT_VALUE__EXTRASTEPS0   0x00;
-#define        INIT_VALUE__EXTRASTEPS1   0x00;
-#define        INIT_VALUE__RAMPCNTL      0x00;
-#define        INIT_VALUE__LOOPDLY       0x00;
-#define        INIT_VALUE__MCNTL         0x00;
-
-
-/** PCA9629 class
- *
- */
- 
-class PCA9629 {
-public:
-
-    /** name of registers */
-    typedef enum {
-        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 */
-    } RegisterName;
-
-    /** register names to make 2 bytes access */
-    typedef enum {
-        SROTN_      = SROTNL     | 0x80,    /**< Steps per rotation */
-        CWPW_       = CWPWL      | 0x80,    /**< Step pulse width for CW rotation */
-        CCWPW_      = CCWPWL     | 0x80,    /**< Step pulse width for CCW rotation */
-        CWSCOUNT_   = CWSCOUNTL  | 0x80,    /**< Number of steps CW */
-        CCWSCOUNT_  = CCWSCOUNTL | 0x80,    /**< Number of steps CCW */
-        CWRCOUNT_   = CWRCOUNTL  | 0x80,    /**< Number of rotatations CW */
-        CCWRCOUNT_  = CCWRCOUNTL | 0x80,    /**< Number of rotatations CCW */
-        STEPS_PER_ROATION   = SROTN_,
-        CW__STEP_WIDTH      = CWPW_,
-        CCW_STEP_WIDTH      = CCWPW_,
-        CW__STEP_COUNT      = CWSCOUNT_,
-        CCW_STEP_COUNT      = CCWSCOUNT_,
-        CW__ROTATION_COUNT  = CWRCOUNT_,
-        CCW_ROTATION_COUNT  = CCWRCOUNT_
-    } Register16bits;
-
-    /** keyword to select direction of rotation */
-    typedef enum {
-        CW      = 0,    /**< Clockwise direction */
-        CCW             /**< ConterClockwise direction */
-    } Direction;
-
-    /** plescaler range setting */
-    typedef enum {
-        PRESCALER_FROM_40_TO_333333,    /**< Prescaler range from   3us(333333pps) to   24.576ms(40   pps) */
-        PRESCALER_FROM_20_TO_166667,    /**< Prescaler range from   6us(166667pps) to   49.152ms(20   pps) */
-        PRESCALER_FROM_10_TO_83333,     /**< Prescaler range from  12us( 83333pps) to   98.304ms(10   pps) */
-        PRESCALER_FROM_5_TO_41667,      /**< Prescaler range from  24us( 41667pps) to  196.608ms( 5   pps) */
-        PRESCALER_FROM_2_5_TO_20833,    /**< Prescaler range from  48us( 20833pps) to  393.216ms( 2.5 pps) */
-        PRESCALER_FROM_1_27_TO_10416,   /**< Prescaler range from  96us( 10416pps) to  786.432ms( 1.27pps) */
-        PRESCALER_FROM_0_64_TO_5208,    /**< Prescaler range from 192us(  5208pps) to 1572.864ms( 0.64pps) */
-        PRESCALER_FROM_0_32_TO_2604,    /**< Prescaler range from 384us(  2604pps) to 3145.728ms( 0.32pps) */
-    } PrescalerRange;
-
-    /** Create a PCA9629 instance connected to specified I2C pins with specified address
-     *
-     * @param I2C_sda I2C-bus SDA pin
-     * @param I2C_scl I2C-bus SCL pin
-     * @param I2C_address I2C-bus address (default: 0x42)
-     */
-    PCA9629(
-        PinName I2C_sda,
-        PinName I2C_scl,
-        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
-     *
-     *  @param register_name the register name: data writing into
-     *  @param value 8 bits writing data
-     */
-    void write( RegisterName register_name, char value );
-
-    /** Write 2 bytes data into a register
-     *
-     *  Setting 16 bits data into registers
-     *
-     *  @param register_name the register name: data writing into (it can be "SROTN_", "CWPW_", "CCWPW_", "CWRCOUNT_", "CCWSCOUNT_", "CWRCOUNT_" or "CCWRCOUNT_" )
-     *  @param value 16 bits writing data
-     */
-    void write( Register16bits register_name, short value );
-
-    /** Read 1 byte data from a register
-     *
-     *  Setting data into a register
-     *
-     *  @param register_name the register name: data reading from
-     *  @return read 8 bits data from the register
-     */
-    char read( RegisterName register_name );
-
-    /** Read 2 byte data from registers
-     *
-     *  Setting data into a register
-     *
-     *  @param register_name the register name: data writing into (it can be "SROTN_", "CWPW_", "CCWPW_", "CWRCOUNT_", "CCWSCOUNT_", "CWRCOUNT_" or "CCWRCOUNT_" )
-     *  @return read 16 bits data from the registers
-     */
-    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
-     *
-     */
-    void stop( void );
-
-    /** Set PPS
-     *
-     *  Setting PulsePerSecond
-     *  This interface can be used to set CWPWx or CCWPWx registers
-     *
-     *  @param dir rotate direction ("CW" or "CCW")
-     *  @param prescaler prescaler setting (for 3 bits setting range from 0 to 0x7. See datasheet)
-     *  @param pps pps defineds pulse width for the motor. The pulse width will be 1/pps
-     *  @return 16 bit data that what set to the CWPWx or CCWPWx registers
-     */
-    short pps( Direction dir, PrescalerRange prescaler, int pps );
-
-    /** Set PPS
-     *
-     *  Setting PulsePerSecond
-     *  This interface can be used to set CWPWx or CCWPWx registers
-     *
-     *  @param dir rotate direction ("CW" or "CCW")
-     *  @param prescaler prescaler setting (for 3 bits setting range from 0 to 0x7. See datasheet)
-     *  @param pps pps defineds pulse width for the motor. The pulse width will be 1/pps
-     *  @return 16 bit data that what set to the CWPWx or CCWPWx registers
-     */
-
-    /** Set rotation count
-     *
-     *  Setting rotation count
-     *  This interfaces CWRCOUNTx, CCWRCOUNTx registers
-     *
-     *  @param dir rotate direction ("CW" or "CCW")
-     *  @param rotations sets number of rotations with 16 bit value
-     */
-    void rotations( Direction dir, int rotations );
-
-    /** Set PPS
-     *
-     *  Setting step count
-     *  This interfaces CWSCOUNTx, CCWSCOUNTx registers
-     *
-     *  @param dir rotate direction ("CW" or "CCW")
-     *  @param steps sets number of steps with 16 bit value
-     */
-    void steps( Direction dir, int pps );
-
-
-    /** Register dump
-     *
-     *  Dumping all register data to serial console
-     *
-     */
-    void register_dump( void );
-
-    /** Register dump
-     *
-     *  Dumping all register data to serial console
-     *
-     */
-    void speed_change( unsigned short pw );
-
-private:
-    I2C     i2c;
-    char    i2c_addr;
-};
-
-#endif  //  MBED_PCA9629
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 03 03:50:55 2012 +0000
@@ -0,0 +1,143 @@
+#include "mbed.h"
+#include "PCA9629.h"
+
+BusOut      leds( LED4, LED3, LED2, LED1 );
+PCA9629     motor_controller( p28, p27, 0x42 );
+
+void motor_action_0( void );
+void motor_action_1( void );
+void motor_action_2( void );
+void motor_action_3( void );
+void motor_action_CDE( void );
+
+int main() {
+    printf( "PCA9629 simple sample program\r\n" );
+
+    while ( 1 ) {
+        leds    = 0x1;
+        motor_action_0();
+
+        leds    = 0x3;
+        motor_action_1();
+
+        leds    = 0x7;
+        motor_action_2();
+
+        leds    = 0xF;
+        motor_action_3();
+
+        leds    = 0x0;
+        motor_action_CDE();
+    }
+}
+
+void motor_action_0( void ) {
+
+    motor_controller.stop();
+    motor_controller.init_registers();
+
+    motor_controller.pps( PCA9629::CW, PCA9629::PRESCALER_FROM_40_TO_333333, 100 );
+    motor_controller.steps( PCA9629::CW, 96 );
+
+    motor_controller.pps( PCA9629::CCW, PCA9629::PRESCALER_FROM_40_TO_333333, 50 );
+    motor_controller.steps( PCA9629::CCW, 48 );
+
+    for ( int i = 0; i < 2; i++ ) {
+        motor_controller.start( PCA9629::CW );
+        wait( 2.0 );
+
+        motor_controller.start( PCA9629::CCW );
+        wait( 2.0 );
+    }
+}
+
+void motor_action_1( void ) {
+
+    motor_controller.stop();
+    motor_controller.init_registers();
+
+    //  auto generated example code for PCA9629 on mbed
+    //  setting: total operation time = 2, initial speed = 40.69, rotations = 5, steps = 0, ramp-up enable = enable, ramp-down enable = enable, rotate direction = CW
+
+    //  motor_controller.write( PCA9629::STEPS_PER_ROATION, 48  );
+    motor_controller.write( PCA9629::CW__STEP_WIDTH, 1175  );
+    motor_controller.write( PCA9629::CW__STEP_COUNT, 35  );
+    motor_controller.write( PCA9629::CW__ROTATION_COUNT, 2  );
+    motor_controller.write( PCA9629::RAMPCNTL, 0x37  );
+
+    for ( int i = 0; i < 2; i++ ) {
+        motor_controller.write( PCA9629::MCNTL, 0xA8  );  //  start
+        wait( 2.5 );
+    }
+}
+
+void motor_action_2( void ) {
+
+    motor_controller.stop();
+
+    //  this array is a sample for PCA9629 local interrupt operation
+    //  the P0 and P1 inputs enabled for interrupt in.
+    //  motor rotation will be reversed by interrupt signals.
+    //  the motor direction will be changed 12 steps after when the interrupt happened
+    //
+    //  CW = 40.69pps, CCW = 81.38pps
+
+    char init_array2[] = {    0x80,
+                              0x20, 0xE2, 0xE4, 0xE6, 0xE0, 0xFF, 0x10,             //  for registers MODE - WDCNTL (0x00 - 0x06
+                              0x00, 0x00,                                           //  for registers IP and INTSTAT (0x07, 0x08)
+                              0x0F, 0x03, 0x0C, 0x0F, 0x03, 0x01, 0x03, 0x03, 0x01, //  for registers OP - INT_AUTO_CLR (0x09 - 0x11)
+                              0x00, 0x00, 0x30, 0x00, 0xFF, 0x1F, 0xFF, 0x0F,       //  for registers SETMODE - CCWPWH (0x12 - 0x19)
+                              0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x00, 0x0A, 0x00,       //  for registers CWSCOUNTL - CCWRCOUNTH (0x1A - 0x21)
+                              0x0C, 0x0C,                                           //  for registers EXTRASTEPS0 and EXTRASTEPS1 (0x22, 0x23)
+                              0x00, 0x00, 0xA8                                      //  for registers RMPCNTL - MCNTL (0x24 - 0x26)
+                         };
+
+    motor_controller.set_all_registers( init_array2, sizeof( init_array2 ));
+    wait( 5.0 );
+
+    motor_controller.stop();
+    wait( 0.5 );
+
+}
+
+void motor_action_3( void ) {
+
+    motor_controller.stop();
+    motor_controller.init_registers();
+
+    motor_controller.rotations( PCA9629::CCW, 0xFFFF );
+
+    for ( int i = 0; i < 2; i++ ) {
+        for ( int s = 1; s <= 5; s++ ) {
+            motor_controller.pps( PCA9629::CCW, PCA9629::PRESCALER_FROM_40_TO_333333, 55 * s );
+            motor_controller.start( PCA9629::CCW );
+            wait( 1.0 );
+            motor_controller.stop();
+        }
+    }
+}
+
+void motor_action_CDE( void ) {
+    char    scale[ 8 ]  = { 4, 6, 8, 9, 11, 13, 15, 16 };  //   CDEFGABC from A
+    float   freq[ 8 ];
+
+    motor_controller.stop();
+    motor_controller.init_registers();
+    motor_controller.rotations( PCA9629::CCW, 0xFFFF );
+    motor_controller.write( PCA9629::PHCNTL,0x1 );
+
+    for ( int i = 0; i < 8; i++ )
+        freq[ i ]   = 55.0 * pow( 2.0, (float)(scale[ i ]) / 12.0 );
+
+    for ( int i = 0; i < 2; i++ ) {
+        motor_controller.stop();
+        for ( int s = 0; s < 8; s++ ) {
+            motor_controller.pps( PCA9629::CCW, PCA9629::PRESCALER_FROM_40_TO_333333, (int)(freq[ s ]) );
+            motor_controller.start( PCA9629::CCW );
+            wait( 1 );
+
+            motor_controller.stop();
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Feb 03 03:50:55 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b4b9f287a47e