for checking multiple SOLID T sensors

Dependencies:   DevInterfaces AT30TSE75x I2Cinterfaces

Fork of AT30TSE752TST by wimbeaumont Project

Revision:
1:d175631a5803
Parent:
0:5bc0f4bd5aa0
Child:
2:8ce5a2128381
diff -r 5bc0f4bd5aa0 -r d175631a5803 main.cpp
--- a/main.cpp	Wed Jan 13 14:15:21 2016 +0000
+++ b/main.cpp	Wed Jan 13 19:12:45 2016 +0000
@@ -1,3 +1,11 @@
+/** example program for the use of the MCP4728 class and DACInterface.h classes
+ *
+ *  V 1.0  : tested on the KL05z  but without the MCP4728 connected \
+ * (C) Wim Beaumont Universiteit Antwerpen 2016 
+ */ 
+
+#define MCP4728EXAMPLEVER "1.10                    "
+
 #include "mbed.h"
 
 #if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
@@ -32,6 +40,7 @@
   
    // get the version of getVersion 
    getVersion gv;
+   printf("MCP4728 example program version %s, compile date %s time %s\n\r",MCP4728EXAMPLEVER,__DATE__,__TIME__);
    printf("getVersion :%s\n\r",gv.getversioninfo());
    
    MCP4728  dac( i2cdev ,0, Vdd);  // assuming the address  of the MCP4728 is set to 0 factory default 
@@ -39,7 +48,7 @@
    wait(4);
    float voltage=0;
    int cnt=0;
-   while(1){
+   while(cnt < 4096){
            // first set the 4 channels 
            for ( int cc =0 ; cc <4 ; cc++) { 
                if ( dac.setDACvalue(cnt,cc) )
@@ -47,18 +56,46 @@
             }
             printf("set DAC value  to %d result in",cnt);
                // no else read anyway even if set fails 
-            for ( int cc =0 ; cc <4 ; cc++) { 
-                if ( dac.getVoltage(voltage,cc)) 
-                    printf("\n\rfailed to readback voltage for channel %d\n\r",cc);    
-                else 
+            if(dac.update()) printf("\n\rfailed to readback channel info \n\r");
+            else {
+                for ( int cc =0 ; cc <4 ; cc++) { 
+                 (void)dac.getVoltage(voltage,cc);//no need to test done with updat 
                   printf(" CH%d %f[V]",cc,voltage);
-             }
-             printf("\n\r");
+                }
+                printf("\n\r");
+            }
              cnt++;
              cnt=cnt % 4096;     
              wait_ms(200);
 
-  }  
+  }
+  // now the same with the DAC interface 
+  DACInterface* di = &dac;
+  cnt=0;
+  while(1){
+           // first set the 4 channels 
+           for ( int cc =0 ; cc <4 ; cc++) { 
+               if ( di->setDACvalue(cnt,cc) )
+                   printf("failed to set dac value %d for channel %d\n\r",cnt,cc);
+            }
+            printf("set DAC value  to %d result in",cnt);
+               // no else read anyway even if set fails 
+            if(di->update()) printf("\n\rfailed to readback channel info \n\r");
+            else {
+                for ( int cc =0 ; cc <4 ; cc++) { 
+                 (void)di->getVoltage(voltage,cc);// no need to test done with update
+                  printf(" CH%d %f[V]",cc,voltage);
+                }
+                printf("\n\r");
+            }
+            
+             cnt++;
+             cnt=cnt % 4096;     
+             wait_ms(200);
+
+  }
+  
+    
     // never reach this   
     return 1;
 }