K64F internal ADC channels: bandgap, VREF, temperature sensor derived from teensy 3.1 firmware analog.c

Dependencies:   mbed

K64F internal ADC channels: bandgap, VREF, temperature sensor derived from teensy 3.1 firmware analog.c

Files at this revision

API Documentation at this revision

Comitter:
manitou
Date:
Thu Nov 19 17:44:52 2015 +0000
Parent:
1:9a99de9cc5d5
Commit message:
does temp sensor need internal analog reference?

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9a99de9cc5d5 -r 71d82e4b3777 main.cpp
--- a/main.cpp	Thu Nov 19 12:13:06 2015 +0000
+++ b/main.cpp	Thu Nov 19 17:44:52 2015 +0000
@@ -9,6 +9,7 @@
 
 #define PRREG(z) printf(#z" 0x%x\n",z)
 //AnalogIn adc(A0);
+AnalogOut dac(DAC0_OUT);
 Timer tmr;
 static uint32_t t;
 
@@ -117,6 +118,7 @@
     printf("\nSystemCoreClock %d  %s %s\n",SystemCoreClock,__TIME__,__DATE__);
     tmr.start();
     adc_init();
+    dac.write(0.5);   // 3.3/2 jumper to A0 and read internal
 
     PRREG(SIM_SCGC6);
     PRREG(SIM_SCGC3);
@@ -129,19 +131,32 @@
     PRREG(ADC0_CFG2);
     PRREG(ADC0->SC2);
     PRREG(ADC0->SC3);
+    PRREG(ADC1->SC1[0]);      // ADC1
+    PRREG(ADC1->SC1[1]);
+    PRREG(ADC1->CFG1);
+    PRREG(ADC1_CFG2);
+    PRREG(ADC1->SC2);
+    PRREG(ADC1->SC3);
+
     printf("res %d average %d calibration %d us\n",analog_config_bits,analog_num_average,t);
     val = adc_read(ADC1,18);    // VREF OUT
     Vcc = ADCmax*1.195/val;
     printf("VREF val %d %.2f v\n",val,Vcc);
-    val = adc_read(ADC0,26);    // temp sensor
-    tempc = ((val-val25)/slope) + 25.f;
-    printf("temp val %d %.1f C\n",val,tempc);
     val = adc_read(ADC0,27);     // bandgap
     Vcc = ADCmax*1.0/val;
     printf("bandgap val %d %.2f v\n",val,Vcc);
-    printf("A0 val %d\n",adc_read(ADC0,12));  // didn't do GPIO init for A0
+    val = adc_read(ADC0,12);   // didn't do GPIO init for A0
+    printf("A0 val %d  %.2f v\n",val,3.3*val/ADCmax);  
+    val = adc_read(ADC1,23);   // DAC to internal ADC
+    printf("DAC val %d  %.2f v\n",val,3.3*val/ADCmax);  
     t=tmr.read_us();
     for(i=0;i<1000;i++) adc_read(ADC0,12);
     t=tmr.read_us()-t;
     printf("avrg A0 read %d us\n",t/1000);
+    //  need internal VREF for temp sensor ??  TODO
+    analog_reference_internal = 1;
+    adc_init();  // re init and calibrate
+    val = adc_read(ADC0,26);    // temp sensor
+    tempc = ((val-val25)/slope) + 25.f;
+    printf("temp val %d %.1f C\n",val,tempc); 
 }
\ No newline at end of file