#include "menu.h"
#include "power.h"
#include "adc_int.h"
-
-#ifndef ADC_BATT_CH
-#define ADC_BATT_CH 7
-#endif
-
-
void update_status(void)
{
cnrlevel = akc6955_get_cnr();
// Battery
// batlevel_6955 = akc6955_get_battery();
- //ADC:Battery
- startadc(ADC_BATT_CH);
- adc = polladc2();
+
//ADC:reference
CVRCON2bits.FVREN = 1;
- while(CVRCON2bits.FVRST == 0);
+ while(CVRCON2bits.FVRST == 0) idle(100);
+ // 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;
+ startadc(_BATT_ADC);
+ adc = polladc2();
+ startadc(_BATT_ADC);
+ adc = polladc2();
CVRCON2bits.FVREN = 0;
- //ADC:reference
battlevel = adc_rawtobatt(adc, ref);
+// battlevel = adc * 32 * 4; // 322 = 1000/1024 * 330
+// battlevel = (adc * 4 * 32) / 100;
}
+