Sample code for PCA9629 operation
What is "PCA9629" ?
Information
The stepper motor controller PCA9629A is available now!
This "A-version (PCA9629A)" is a feature extended version on "non-A (PCA9629)".
If you are thinking new design, the PCA9629A can be a good option.
The PCA9629A has several new features like on-the-fly speed change, extended ramp controls, filter settings for GPIO port inputs, braking and releasing by timeout.. and more.
Please find detail information here.
The "A-version" chip is pin-compatible to "non-A". So it can be replaced easily.
The register mapping and bit fields are re-defined. Those should be cared by software.
A sample code and a class library are available for mbed.
Import programPCA9629A_Hello
Hello program for PCA9629A. Demonstrates basic operations of PCA9629A component library.
Import libraryPCA9629A
PCA9629A component library
A Stepper motor controller
PCA9629 (x5) demo board: PCA9629, 4x FETs and stepper motor
The PCA9629 is an I2C-bus controlled low-power CMOS device that provides all the logic and control required to drive a four phase stepper motor. PCA9629 is intended to be used with external high current drivers to drive the motor coils. The PCA9629 supports three stepper motor drive formats: one-phase (wave drive), two-phase, and half-step. In addition, when used as inputs, four General Purpose Input/Outputs (GPIOs) allow sensing of logic level output from optical interrupter modules and generate active LOW interrupt signal on the INT pin of PCA9629. This is a useful feature in sensing home position of motor shaft or reference for step pulses. Upon interrupt, the PCA9629 can be programmed to automatically stop the motor or reverse the direction of rotation of motor.
Communicate with mbed through I2C. The motor can be operated by register settings
Output wave train is programmable using control registers. The control registers are programmed via the I2C-bus. Features built into the PCA9629 provide highly flexible control of stepper motor, off-load bus master/micro and significantly reduce I2C-bus traffic. These include control of step size, number of steps per single command, number of full rotations and direction of rotation. A ramp-up on start and/or ramp-down on stop is also provided.
Waveforms: Lower 2 lines are I2C bus. Upper 4 lines are output for motor driver stage
Motor moving 16 steps with acceleration and deceleration after register setting via I2C
The PCA9629 is available in a 16-pin TSSOP package and is specified over the -40 deg-C to +85 deg-C industrial temperature range.
TSSOP16 package
Datasheet is available at next URL.
http://www.nxp.com/documents/data_sheet/PCA9629.pdf
Hardware
A sample schematic diagram is shown in next picture.
This schematic diagram shows a sample of the PF35T-48C stepper motor. It is using 12V supply voltage for motor and driving by SI3812DV FETs.
Pull-up resisters: For /RESET and /INT pins : 4.7K-ohms, for I2C signals (SDA and SCL) : >1.3k-ohms.
NOTE
For the correct operation of the "auto interrupt" demo, the GPIO port P0(pin1) and P1(pin2) must be connected to sensor input. signal edge of those pins are treated as the interrupt.
Sample code
This sample code operates the PCA9629 using its class library.
For the details of the library, please find information in library page.
Import libraryPCA9629
PCA9629 a stepper motor controller class library
API details are available in here
This program targets PCA9629 which has I2C address of 0x42 on I2C bus on pin28 and pin27 of mbed. 4 types motor actions are demonstrated in sequence (following 1..4 steps in loop).
- Simple motor turn demo
- Motor moved 96 steps with 100pps (pulse persecond) speed
- Then the motor turn reversed, move 48 steps by 50pps.
- Ramp control demo
- total operation time = 2 seconds, initial speed = 40.69pps, rotations = 5turns+0steps, ramp-up enable = enable, ramp-down enable = enable, rotate direction = CW
- The ramp control can be done with several register settings. The setting value calculation can be done by register setting tool (an Excel worksheet) from NXP.
- Auto interrupt demo
- The GPIO inputs can be used as interrupt for PCA9629. The operation can be stopped or change the direction of turn.
- This is turn direction auto reversing demo. Motor will switch the direction 12 steps after interrupt signal assertion.
- The register setting of interrupt operation can be done by register setting tool also.
- This demo works correctly only when sensor signals available on P0(pin1) and P1(pin2) input pins.
- Speed change demo
- Changing motor speed in 5 steps from 55pps to 275pps.
Revision 2:2e75cedf6565, committed 2012-07-23
- Comitter:
- nxp_ip
- Date:
- Mon Jul 23 05:05:01 2012 +0000
- Parent:
- 1:cab53217fcc1
- Commit message:
- version 1.1 release
Changed in this revision
diff -r cab53217fcc1 -r 2e75cedf6565 PCA9629.lib --- a/PCA9629.lib Tue Apr 24 08:19:06 2012 +0000 +++ b/PCA9629.lib Mon Jul 23 05:05:01 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/nxp_ip/code/PCA9629/#aff87a1c8bd6 +http://mbed.org/users/nxp_ip/code/PCA9629/#199f109eb0c6
diff -r cab53217fcc1 -r 2e75cedf6565 main.cpp --- a/main.cpp Tue Apr 24 08:19:06 2012 +0000 +++ b/main.cpp Mon Jul 23 05:05:01 2012 +0000 @@ -1,22 +1,30 @@ -/** A sample/demo code for PCA9629 +/** A sample code for PCA9629 * * @author Akifumi (Tedd) OKANO, NXP Semiconductors - * @version 1.0 - * @date 24-Apr-2011 + * @version 1.1 + * @date 23-Jul-2012 + * + * revision history + * version 1.0 (24-Apr-2011) : Initial version + * version 1.1 (23-Jul-2012) : API modification + * Correction for comments * * 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. + * An operation sample of PCU9629 stepper motor controller. + * The mbed accesses the PCU9629 registers through I2C. * * This sample code demonstrates 4 type of PCA9629 operation + * + * About PCA9629: + * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_bus_controller_and_bridge_ics/PCA9629PW.html */ #include "mbed.h" #include "PCA9629.h" BusOut leds( LED4, LED3, LED2, LED1 ); -PCA9629 motor_controller( p28, p27, 0x42 ); +PCA9629 motor_controller( p28, p27, 48 ); // SDA, SCL, Steps/rotation, I2C_address (option) void motor_action_0( void ); void motor_action_1( void ); @@ -29,32 +37,32 @@ while ( 1 ) { leds = 0x1; - motor_action_0(); + motor_action_0(); // demo 0 leds = 0x3; - motor_action_1(); + motor_action_1(); // demo 1 leds = 0x7; - motor_action_2(); + motor_action_2(); // demo 2 leds = 0xF; - motor_action_3(); + motor_action_3(); // demo 3 } } void motor_action_0( void ) { // simple motor operation - // the motor spins 2 times (100pps) for clockwise (CW), 1 time (50pps) for counter-clockwise. + // the motor spins 2 times (200pps) for clockwise (CW), 1 time (100pps) for counter-clockwise. 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::CW, 200 ); + motor_controller.rotations_and_steps( PCA9629::CW, 0, 96 ); - motor_controller.pps( PCA9629::CCW, PCA9629::PRESCALER_FROM_40_TO_333333, 50 ); - motor_controller.steps( PCA9629::CCW, 48 ); + motor_controller.pps( PCA9629::CCW, 100 ); + motor_controller.rotations_and_steps( PCA9629::CCW, 0, 48 ); for ( int i = 0; i < 2; i++ ) { motor_controller.start( PCA9629::CW ); @@ -129,7 +137,7 @@ 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.pps( PCA9629::CCW, 55 * s ); motor_controller.start( PCA9629::CCW ); wait( 1.0 ); motor_controller.stop(); @@ -138,21 +146,21 @@ } void motor_action_CDE( void ) { - char scale[ 8 ] = { 4, 6, 8, 9, 11, 13, 15, 16 }; // CDEFGABC from A + char scale[ 8 ] = { 4, 6, 8, 9, 11, 13, 15, 16 }; // CDEFGABC (A=0) float freq[ 8 ]; for ( int i = 0; i < 8; i++ ) - freq[ i ] = 55.0 * pow( 2.0, (float)(scale[ i ]) / 12.0 ); + freq[ i ] = (440.0 / 8.0) * pow( 2.0, (float)(scale[ i ]) / 12.0 ); motor_controller.stop(); motor_controller.init_registers(); motor_controller.rotations( PCA9629::CCW, 0xFFFF ); - motor_controller.write( PCA9629::PHCNTL,0x1 ); + motor_controller.write( PCA9629::PHCNTL, 0x1 ); 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.pps( PCA9629::CCW, freq[ s ] ); motor_controller.start( PCA9629::CCW ); wait( 1 );
diff -r cab53217fcc1 -r 2e75cedf6565 mbed.bld --- a/mbed.bld Tue Apr 24 08:19:06 2012 +0000 +++ b/mbed.bld Mon Jul 23 05:05:01 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/b4b9f287a47e +http://mbed.org/users/mbed_official/code/mbed/builds/b4b9f287a47e \ No newline at end of file