OSDN Git Service

[Build] Add some sourcefiles.
[openi2cradio/OpenI2CRadio.git] / radio_getstat.c
index 647fb75..0407d41 100644 (file)
@@ -79,16 +79,25 @@ void update_status(void)
     cnrlevel = akc6955_get_cnr();
     // Battery
 //    batlevel_6955 = akc6955_get_battery();
-    //ADC:Battery - AN7, 28pins PIC should be changed AN number.
-    startadc(_BATT_ADC);
-    adc = polladc2();
+  
     //ADC:reference
-    CVRCON2bits.FVREN = 1;
-    while(CVRCON2bits.FVRST == 0) idle_time_ms(1);
+    // Workaround of Errata:
+    // Section 5 of http://ww1.microchip.com/downloads/en/DeviceDoc/80000425K.pdf .
+    // Sample twice on first.
+    startadc(_REF_ADC);
+    ref = polladc2();
     startadc(_REF_ADC);
     ref = polladc2();
+    TRISEbits.TRISE2 = 1;
+    CVRCON2bits.FVREN = 1;
+    while(CVRCON2bits.FVRST == 0) idle(100);
+//    startadc(_BATT_ADC);
+//    adc = polladc2();
+    startadc(_BATT_ADC);
+    adc = polladc2();
     CVRCON2bits.FVREN = 0;
-    //ADC:reference
     battlevel = adc_rawtobatt(adc, ref);
-//    battlevel = ref;
+//    battlevel = adc *  32 * 4; // 322 = 1000/1024 * 330
+//    battlevel = (adc * 4 * 32) / 100;
 }
+