Simple readout code for MAX110/111 14-bit ADC

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
oliverb
Date:
Thu Jul 12 10:21:16 2012 +0000
Parent:
1:46c26c1de51f
Commit message:
Added a "flush" stage, ADC seems to calibrate far more consistently?

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 46c26c1de51f -r 41e59824652f main.cpp
--- a/main.cpp	Thu Jul 12 07:40:48 2012 +0000
+++ b/main.cpp	Thu Jul 12 10:21:16 2012 +0000
@@ -80,9 +80,13 @@
 void max_setup(unsigned int mmode)
 {
   max_mode=mmode;
-      pc.printf("setup %x\n",max_mode);
   max_cs=0;
-      wait_us(1);
+      spi.write(0);
+      spi.write(0);
+  max_cs=1;
+  // not sure why the above step helps but it seems to improve restarts after random
+  // reset
+  max_cs=0;
       spi.write((max_mode & 0xff00) >> 8);
       spi.write(max_mode & 0xff);
   max_cs=1;
@@ -96,10 +100,8 @@
     if (max_mode & 0x0c)
     {
       max_mode = max_mode - 0x04;
-      pc.printf("cal %x\r\n",max_mode);
       
       max_cs=0;
-      wait_us(1);
       spi.write((max_mode & 0xff00) >> 8);
       spi.write(max_mode & 0xff);
       max_cs=1;
@@ -110,7 +112,6 @@
     {
       short t;
       max_cs=0;
-      wait_us(1);
       t    =spi.write((max_mode & 0xff00) >> 8);
       t    =spi.write(max_mode & 0xff) | (t<<8);
       *data= (int) t;
@@ -128,16 +129,17 @@
 int main() {
     spi.format(8,0);
     spi.frequency(100000);
-    pc.printf("Start converter\r\n");
+    max_cs=1;
+//    pc.printf("Start converter\r\n");
     max_setup(max_14bit | max_full);
-//    max_busy.mode(PullUp);
     while(1) {
       int val;
       val=0;
       if (max_read(&val))
       {
-        pc.printf("Readout: %d \r",val);
-//        wait(1);
+        pc.printf("Readout: %d \r\n",val);
+// optional: force a recalibrate
+//       max_setup(max_14bit | max_full);
       }
     }
 }