A/Dconverterのテストプログラム

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lilac0112_1
Date:
Wed Oct 14 04:18:12 2015 +0000
Parent:
0:b1205daf2a1f
Commit message:
MCP3208*3

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Sep 18 04:47:36 2015 +0000
+++ b/main.cpp	Wed Oct 14 04:18:12 2015 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 
-#define IC_NUM 1    //3
-#define IR_NUM 8    //6
+#define IC_NUM 3
+#define IR_NUM 8
 
 #define START_BIT   0x04
 #define MODE_SINGLE 0x02    // Single-ended mode
@@ -9,26 +9,28 @@
 
 DigitalOut myled(LED1);
 SPI ir(D11, D12, D13);
-DigitalOut cs[IC_NUM] = {D10};
+DigitalOut cs[IC_NUM] = {D10, D9, D8};
 Serial pc(SERIAL_TX, SERIAL_RX);
 
 int main() {
     int i;//ic
     int j;//ch
+    uint8_t ch_num[3]={8, 8, 4};
     int command_high;
     int command_low;
     int high_byte;
     int low_byte;
     
     uint16_t ir_data[IC_NUM][IR_NUM]={0};
+    //clock_t stime,etime;
     
     ir.frequency(1000000);
     
     for(i=0; i<IC_NUM; i++) cs[i]=1;
     while(1) {
+        //stime = clock();
         for(i=0; i<IC_NUM; i++){//IC
-            for(j=0; j<IR_NUM; j++){//Ch
-                
+            for(j=0; j<ch_num[i]; j++){//Ch
                 command_high = START_BIT | MODE_SINGLE | ((j & 0x04) >> 2);
                 command_low = (j & 0x03) << 6;
                 
@@ -44,15 +46,17 @@
                 ir_data[i][j] = (high_byte << 8) | low_byte;
             }
         }
+        //etime = clock();
+        //pc.printf("%.4f\n", (float)(etime-stime)/CLOCKS_PER_SEC);
         pc.printf("%Value is ");
+        pc.printf("%d\t", ir_data[2][0]);
+        pc.printf("%d\t", ir_data[2][1]);
+        pc.printf("%d\t", ir_data[2][2]);
+        pc.printf("%d\t", ir_data[2][3]);
+        pc.printf("%d\t", ir_data[1][2]);
+        pc.printf("%d\t", ir_data[1][4]);
         pc.printf("%d\t", ir_data[0][0]);
-        pc.printf("%d\t", ir_data[0][1]);
-        pc.printf("%d\t", ir_data[0][2]);
-        pc.printf("%d\t", ir_data[0][3]);
         pc.printf("%d\t", ir_data[0][4]);
-        pc.printf("%d\t", ir_data[0][5]);
-        pc.printf("%d\t", ir_data[0][6]);
-        pc.printf("%d\t", ir_data[0][7]);
         pc.printf("\n");
     }
 }
\ No newline at end of file