#include "menu.h"
#include "power.h"
#include "adc_int.h"
-
-
void update_status(void)
{
unsigned int adc;
- __bitops_t c;
+ unsigned int ref;
setup.fm = akc6955_get_fm();
recv_signal = akc6955_read_level();
diffstat = akc6955_get_diff();
setup.volume = akc6955_getvolume();
setup.prevolume = akc6955_get_prevolume();
- if(setup.fm != 0){
+ if(setup.fm != 0){
setup.fmfreq = akc6955_get_freq();
- akc6955_get_fmband(setup.fmband);
+ setup.fmband = akc6955_get_fmband();
setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
stereoflag = akc6955_get_stereo();
- akc6955_get_fmbandwidth(setup.fmbandwidth);
- } else {
+ setup.fmbandwidth = akc6955_get_fmbandwidth();
+ } else {
setup.amfreq = akc6955_get_freq();
- akc6955_get_amband(setup.amband);
+ setup.amband = akc6955_get_amband();
setup.amfreq_bank[setup.amband] = setup.amfreq;
- c.byte = akc6955_readcmd(AKC6955_CNR_AM);
- if(c.b7) {
- setup.am_mode3k = 0xff;
- } else {
- setup.am_mode3k = 0;
- }
+ setup.am_mode3k = akc6955_get_mode3k();
stereoflag = 0x00;
- }
- tuneflag = akc6955_tune();
- cnrlevel = akc6955_get_cnr();
- batlevel_6955 = akc6955_get_battery();
- startadc(7);
- idle_time_ms(1);
- polladc2(adc);
- battlevel = adc_rawtobatt(adc, batlevel_6955);
+ }
+ tuneflag = akc6955_tune();
+ cnrlevel = akc6955_get_cnr();
+ // Battery
+// batlevel_6955 = akc6955_get_battery();
+
+ //ADC:reference
+ CVRCON2bits.FVREN = 1;
+ 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;
+ battlevel = adc_rawtobatt(adc, ref);
+// battlevel = adc * 32 * 4; // 322 = 1000/1024 * 330
+// battlevel = (adc * 4 * 32) / 100;
}
+