demo sample to drive PCU9955 and PCA9629

Dependencies:   mbed I2C_slaves PCU9669 parallel_bus

Fork of mini_board_PCU9669 by InetrfaceProducts NXP

What is this?

This is a sample code to operate PCU9955 (16ch constant-current LED controller) and PCA9629 (intelligent stepper motor controller) through PCU9669 (3 channels (UltraFast mode * 2ch, FastModePlus *1ch) I2C bus controller).

This demo is written based on mini_board_PCU9669 sample code library and its API.
http://mbed.org/users/nxp_ip/code/mini_board_PCU9669/

Demo will shows how the LED controllers and stepper motor controllers works.
It uses a mini_board_PCU9669 board with mbed, 8 of PCU9955s and 5 PCA9629s.

/media/uploads/nxp_ip/dsc_0414ss.png
Demo setup
(left-top: PCU9955 boards, left-bottom: mini-board PCU9669 with mbed, right: PCA9629 x5 board)

/media/uploads/nxp_ip/demo-config-ss.png
Board connections and device addresses

Reference:

User manual of PCU9669 demo board: Mini board PCU9669

http://www.nxp.com/documents/user_manual/UM10580.pdf

sample code : mbed programs

Import programmini_board_PCU9669

mini board PCU9669 (and PCA9665) sample code

Import programPCA9955_Hello

PCA9955 16 channel current drive(sink) LED driver sample code

Import programPCA9955_simple

very simple sample code for PCA9955 (16 channel current control LED driver)

Import programPCA9629_Hello

Sample code for PCA9629 operation

device infomation

PCU9669 (Parallel bus to 1 channel Fm+ and 2 channel UFm I2C-bus controller)
PCU9955 (16-channel UFm I²C-bus 57 mA constant current LED driver)
PCA9955 (16-channel Fm+ I²C-bus 57 mA constant current LED driver)
PCU9629 (Fm+ I2C-bus stepper motor controller)

Committer:
nxp_ip
Date:
Fri Oct 26 07:03:47 2012 +0000
Revision:
21:3b75b545ecfb
Parent:
main_PCU9669.c@20:a266fa588bd8
PCU9669, PCU9955 and PCA9629 demo code version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 20:a266fa588bd8 1 /** A demo code for PCU9669, PCU9955 and PCA9629
nxp_ip 0:de9a15767563 2 *
nxp_ip 20:a266fa588bd8 3 * @author Tedd OKANO, NXP Semiconductors
nxp_ip 6:1fc6a640d320 4 * @version 1.0
nxp_ip 20:a266fa588bd8 5 * @date 26-Oct-2012
nxp_ip 20:a266fa588bd8 6 *
nxp_ip 0:de9a15767563 7 * Released under the MIT License: http://mbed.org/license/mit
nxp_ip 0:de9a15767563 8 *
nxp_ip 20:a266fa588bd8 9 * An operation sample of PCU9669 I2C bus controller.
nxp_ip 20:a266fa588bd8 10 * The mbed accesses the PCU9669's parallel port (8 bit address and 8 bit data) using bit-banging.
nxp_ip 0:de9a15767563 11 * The bit-banging is poerformed by PortInOut function of mbed library.
nxp_ip 0:de9a15767563 12 *
nxp_ip 20:a266fa588bd8 13 * DEMO CODE version
nxp_ip 20:a266fa588bd8 14 * v0.5 written on 13-Oct-2011
nxp_ip 20:a266fa588bd8 15 * v1.0 poerted to PCU9669 sample code API
nxp_ip 0:de9a15767563 16 *
nxp_ip 20:a266fa588bd8 17 * Simple code sample for PCU9669 is available on
nxp_ip 20:a266fa588bd8 18 * http://mbed.org/users/nxp_ip/code/mini_board_PCU9669/
nxp_ip 0:de9a15767563 19 */
nxp_ip 0:de9a15767563 20
nxp_ip 20:a266fa588bd8 21
nxp_ip 20:a266fa588bd8 22 #include "transfer_manager.h"
nxp_ip 20:a266fa588bd8 23 #include "PCU9669_access.h"
nxp_ip 5:57c345099873 24 #include "hardware_abs.h"
nxp_ip 20:a266fa588bd8 25 #include "PCx9955_reg.h"
nxp_ip 0:de9a15767563 26 #include "PCA9629_reg.h"
nxp_ip 20:a266fa588bd8 27 #include "demo_patterns.h"
nxp_ip 0:de9a15767563 28
nxp_ip 20:a266fa588bd8 29 #include "mbed.h"
nxp_ip 5:57c345099873 30
nxp_ip 20:a266fa588bd8 31 #define TICKER_INTERVAL 0.008
nxp_ip 0:de9a15767563 32
nxp_ip 20:a266fa588bd8 33 #define RESET_PULSE_WIDTH_US 10 // Minimum pulse width is 4us for PCU9669
nxp_ip 20:a266fa588bd8 34 #define RESET_RECOVERY_US 1000
nxp_ip 20:a266fa588bd8 35
nxp_ip 20:a266fa588bd8 36 Ticker op;
nxp_ip 0:de9a15767563 37
nxp_ip 0:de9a15767563 38
nxp_ip 20:a266fa588bd8 39 void operation( void );
nxp_ip 20:a266fa588bd8 40 void led_action( int count );
nxp_ip 20:a266fa588bd8 41 void motor_action( int count );
nxp_ip 0:de9a15767563 42 void interrupt_handler( void );
nxp_ip 20:a266fa588bd8 43 void init_slave_devices( void );
nxp_ip 20:a266fa588bd8 44 void single_byte_write_into_a_PCA9629( char ch, char i2c_addr, char reg_addr, char val );
nxp_ip 20:a266fa588bd8 45 void set_one_turn_on_each_end( void );
nxp_ip 0:de9a15767563 46
nxp_ip 0:de9a15767563 47 int main() {
nxp_ip 20:a266fa588bd8 48 printf( "\r\nPCU9669 simple demo program on mbed (16 device check)\r\n build : %s (UTC), %s \r\n\r\n", __TIME__, __DATE__ );
nxp_ip 0:de9a15767563 49
nxp_ip 0:de9a15767563 50 hardware_initialize(); // initializing bit-banging parallel port
nxp_ip 5:57c345099873 51 reset( RESET_PULSE_WIDTH_US, RESET_RECOVERY_US ); // assert hardware /RESET sgnal
nxp_ip 0:de9a15767563 52
nxp_ip 20:a266fa588bd8 53 if ( start_bus_controller( PCU9669_ID ) ) // wait the bus controller ready and check chip ID
nxp_ip 0:de9a15767563 54 return 1;
nxp_ip 0:de9a15767563 55
nxp_ip 0:de9a15767563 56 write_ch_register( CH_FM_PLUS, INTMSK, 0x30 ); // set bus controller to ignore NAK return from Fm+ slaves
nxp_ip 0:de9a15767563 57 install_ISR( &interrupt_handler ); // interrupt service routine install
nxp_ip 0:de9a15767563 58
nxp_ip 20:a266fa588bd8 59 init_slave_devices(); // set all slaves' all registers and configure buffer for the operation
nxp_ip 20:a266fa588bd8 60
nxp_ip 20:a266fa588bd8 61 op.attach( &operation, TICKER_INTERVAL );
nxp_ip 0:de9a15767563 62
nxp_ip 0:de9a15767563 63 while ( 1 ) {
nxp_ip 20:a266fa588bd8 64 }
nxp_ip 20:a266fa588bd8 65 }
nxp_ip 20:a266fa588bd8 66
nxp_ip 20:a266fa588bd8 67 void operation( void ) {
nxp_ip 20:a266fa588bd8 68 pattern_update( gCount );
nxp_ip 0:de9a15767563 69
nxp_ip 20:a266fa588bd8 70 motor_action( gCount ); // motor operation
nxp_ip 20:a266fa588bd8 71 led_action( gCount ); // LED operation
nxp_ip 0:de9a15767563 72
nxp_ip 20:a266fa588bd8 73 gCount++;
nxp_ip 20:a266fa588bd8 74 }
nxp_ip 20:a266fa588bd8 75
nxp_ip 0:de9a15767563 76
nxp_ip 20:a266fa588bd8 77 void led_action( int count ) {
nxp_ip 20:a266fa588bd8 78 buffer_overwrite( CH_UFM1, 0, 1, gLEDs + N_LED_PER_BOARD * 0, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 79 buffer_overwrite( CH_UFM1, 1, 1, gLEDs + N_LED_PER_BOARD * 1, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 80 buffer_overwrite( CH_UFM1, 2, 1, gLEDs + N_LED_PER_BOARD * 2, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 81 buffer_overwrite( CH_UFM1, 3, 1, gLEDs + N_LED_PER_BOARD * 3, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 82 buffer_overwrite( CH_UFM2, 0, 1, gLEDs + N_LED_PER_BOARD * 4, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 83 buffer_overwrite( CH_UFM2, 1, 1, gLEDs + N_LED_PER_BOARD * 5, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 84 buffer_overwrite( CH_UFM2, 2, 1, gLEDs + N_LED_PER_BOARD * 6, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 85 buffer_overwrite( CH_UFM2, 3, 1, gLEDs + N_LED_PER_BOARD * 7, N_LED_PER_BOARD );
nxp_ip 20:a266fa588bd8 86
nxp_ip 20:a266fa588bd8 87 start( CH_UFM1 );
nxp_ip 20:a266fa588bd8 88 start( CH_UFM2 );
nxp_ip 20:a266fa588bd8 89 }
nxp_ip 20:a266fa588bd8 90
nxp_ip 20:a266fa588bd8 91
nxp_ip 20:a266fa588bd8 92 void motor_action( int count ) {
nxp_ip 0:de9a15767563 93 #if 0
nxp_ip 20:a266fa588bd8 94 static char mot_cntl_order[ 5 ] = {
nxp_ip 20:a266fa588bd8 95 MOT_ADDR5, MOT_ADDR6, MOT_ADDR7, MOT_ADDR8, MOT_ADDR9
nxp_ip 20:a266fa588bd8 96 };
nxp_ip 20:a266fa588bd8 97 static char motor_count = 0;
nxp_ip 20:a266fa588bd8 98
nxp_ip 20:a266fa588bd8 99 if ( !(count & 0x1F) ) {
nxp_ip 20:a266fa588bd8 100 single_byte_write_into_a_PCA9629( CH_FM_PLUS, mot_cntl_order[ motor_count % 5 ], 0x26, 0x80 | ((motor_count / 5) & 0x1) );
nxp_ip 20:a266fa588bd8 101 motor_count++;
nxp_ip 20:a266fa588bd8 102 }
nxp_ip 0:de9a15767563 103 #endif
nxp_ip 20:a266fa588bd8 104
nxp_ip 0:de9a15767563 105 }
nxp_ip 0:de9a15767563 106
nxp_ip 0:de9a15767563 107 void interrupt_handler( void ) {
nxp_ip 0:de9a15767563 108 char global_status;
nxp_ip 0:de9a15767563 109 char channel_status;
nxp_ip 0:de9a15767563 110
nxp_ip 0:de9a15767563 111 global_status = read_data( CTRLSTATUS );
nxp_ip 0:de9a15767563 112
nxp_ip 0:de9a15767563 113 if ( global_status & 0x01 ) { // ch0
nxp_ip 0:de9a15767563 114 channel_status = read_ch_register( 0, CHSTATUS );
nxp_ip 0:de9a15767563 115 }
nxp_ip 0:de9a15767563 116 if ( global_status & 0x02 ) {
nxp_ip 0:de9a15767563 117 channel_status = read_ch_register( 1, CHSTATUS );
nxp_ip 0:de9a15767563 118 }
nxp_ip 0:de9a15767563 119 if ( global_status & 0x04 ) {
nxp_ip 0:de9a15767563 120 channel_status = read_ch_register( 2, CHSTATUS );
nxp_ip 0:de9a15767563 121 }
nxp_ip 0:de9a15767563 122 // printf( "ISR channel_status 0x%02X\r\n", channel_status );
nxp_ip 0:de9a15767563 123 }