PCA9955A test program

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri Aug 01 07:11:31 2014 +0000
Parent:
3:dbe7902d4335
Child:
5:b93b28e126fe
Commit message:
simplified operation of PCA9955A

Changed in this revision

PCA9955A_registers.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PCA9955A_registers.h	Fri Aug 01 07:11:31 2014 +0000
@@ -0,0 +1,79 @@
+enum command_reg {
+    MODE1   = 0x00,
+    MODE2,
+    LEDOUT0,
+    LEDOUT1,
+    LEDOUT2,
+    LEDOUT3,
+    GRPPWM  = 0x06,
+    GRPFREQ,
+    PWM0    = 0x08,
+    PWM1,
+    PWM2,
+    PWM3,
+    PWM4,
+    PWM5,
+    PWM6,
+    PWM7,
+    PWM8,
+    PWM9,
+    PWM10,
+    PWM11,
+    PWM12,
+    PWM13,
+    PWM14,
+    PWM15,
+    IREF0   = 0x18,
+    IREF1,
+    IREF2,
+    IREF3,
+    IREF4,
+    IREF5,
+    IREF6,
+    IREF7,
+    IREF8,
+    IREF9,
+    IREF10,
+    IREF11,
+    IREF12,
+    IREF13,
+    IREF14,
+    IREF15,
+    RAMP_RATE_GRP0  = 0x28,
+    STEP_TIME_GRP0,
+    HOLD_CNTL_GRP0,
+    IREF_GRP0,
+    RAMP_RATE_GRP1,
+    STEP_TIME_GRP1,
+    HOLD_CNTL_GRP1,
+    IREF_GRP1,
+    RAMP_RATE_GRP2,
+    STEP_TIME_GRP2,
+    HOLD_CNTL_GRP2,
+    IREF_GRP2,
+    RAMP_RATE_GRP3,
+    STEP_TIME_GRP3,
+    HOLD_CNTL_GRP3,
+    IREF_GRP3,
+    GRAD_MODE_SEL0  = 0x38,
+    GRAD_MODE_SEL1,
+    GRAD_GRP_SEL0,
+    GRAD_GRP_SEL1,
+    GRAD_GRP_SEL2,
+    GRAD_GRP_SEL3,
+    GRAD_CNTL,
+    OFFSET  = 0x3F,
+    SUBADR1,
+    SUBADR2,
+    SUBADR3,
+    ALLCALLADR,
+    PWMALL,
+    IREFALL,
+    EFLAG0,
+    EFLAG1,
+
+    REGISTER_START          = MODE1,
+    LEDOUT_REGISTER_START   = LEDOUT0,
+    PWM_REGISTER_START      = PWM0,
+    IREF_REGISTER_START     = IREF0,
+};
\ No newline at end of file
--- a/main.cpp	Fri Jul 18 01:42:51 2014 +0000
+++ b/main.cpp	Fri Aug 01 07:11:31 2014 +0000
@@ -1,43 +1,38 @@
 #include "mbed.h"
+#include "PCA9955A_registers.h"
 
 I2C i2c( p28, p27 );    //  SDA, SCL
 
 #define     SLAVE_ADDR              0x02
 
-#define     AUTO_INCREMENT          0x80
-#define     REGISTER_START          0x00
-#define     LEDOUT_REGISTER_START   0x02
-#define     PWM_REGISTER_START      0x08
-#define     IREF_REGISTER_START     0x18
-#define     PWMALL_REGISTER_ADDR    0x44
-#define     IREFALL_REGISTER_ADDR   0x45
-
 void register_write( char addr, char data );
-void manual_control( void );
-
 
 int main()
 {
-    char    init_data0[]    = { AUTO_INCREMENT | REGISTER_START, 0x00, 0x25, 0xAA, 0xAA, 0xAA, 0xAA };
-    char    init_data1[]    = { IREFALL_REGISTER_ADDR, 0x10 };
+    //  initialization
+
+    register_write( MODE1,      0x00 );
+    register_write( MODE2,      0x25 );
+    register_write( LEDOUT0,    0xAA );
+    register_write( LEDOUT1,    0xAA );
+    register_write( LEDOUT2,    0xAA );
+    register_write( LEDOUT3,    0xAA );
+    register_write( IREFALL,    0x10 );
+
+    //  operation loop
 
-    i2c.write( SLAVE_ADDR, init_data0, sizeof( init_data0 ) );
-    i2c.write( SLAVE_ADDR, init_data1, sizeof( init_data1 ) );
+    while ( 1 ) {
+        
+        for ( int i = 0; i < 256; i++ ) {
+            register_write( PWM0, i );
+            wait( 0.01 );
+        }
 
-    for ( int i = 0; i < 256; i++ ) {
-        register_write( PWMALL_REGISTER_ADDR, i );
-        wait( 0.01 );
+        for ( int i = 255; i >= 0; i-- ) {
+            register_write( PWM0, i );
+            wait( 0.01 );
+        }
     }
-
-
-#if 1
-
-    while(1) {
-        manual_control();
-    }
-
-#endif
-
 }
 
 void register_write( char addr, char data )
@@ -49,46 +44,3 @@
     i2c.write( SLAVE_ADDR, d, 2 );
 }
 
-
-
-Serial      pc(USBTX, USBRX);    // tx, rx
-
-void manual_control( void )
-{
-    static char     duty    = 0xFF;
-    static char     freq    = 0x00;
-
-    if ( pc.readable() ) {
-        switch ( pc.getc() ) {
-            case 'b' :
-                printf( "  [b] : blink on\r\n" );
-                register_write( 1, 0x25 );
-                register_write( LEDOUT_REGISTER_START, 0xFF );
-                register_write( LEDOUT_REGISTER_START + 2, 0xFF );
-                break;
-            case 'd' :
-                printf( "  [d] : blink off\r\n" );
-                register_write( 1, 0x05 );
-                register_write( LEDOUT_REGISTER_START, 0xFF );
-                register_write( LEDOUT_REGISTER_START + 2, 0xFF );
-                break;
-            case 'x' :
-                duty    = (duty == 0xFF) ? 0xFF : duty + 1;
-                register_write( 0x06, duty );
-                break;
-            case 'z' :
-                duty    = (duty == 0x00) ? 0x00 : duty - 1;
-                register_write( 0x06, duty );
-                break;
-            case '.' :
-                freq    = (freq == 0xFF) ? 0xFF : freq + 1;
-                register_write( 0x07, freq );
-                break;
-            case ',' :
-                freq    = (freq == 0x00) ? 0x00 : freq - 1;
-                register_write( 0x07, freq );
-                break;
-        }
-        printf( "  GRPPWM=0x%02X, GRPFREQ=0x%02X (period=%.3f)\r", duty, freq, (float)(freq + 1)/15.26 );
-    }
-}