X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=radio_getstat.c;h=ec2357a35f58de85871a5c2c170f1a5700c66c6c;hb=ecaa9d61df13e9de8445bf1233bd3f40848cd286;hp=3e2cad14f6cb2cb40205414e650c1286f27979ca;hpb=3cb2d497f9d89e8d208f925407d0cd4879ec9443;p=openi2cradio%2FOpenI2CRadio.git diff --git a/radio_getstat.c b/radio_getstat.c index 3e2cad1..ec2357a 100644 --- a/radio_getstat.c +++ b/radio_getstat.c @@ -51,44 +51,53 @@ #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(); setup.fmband = akc6955_get_fmband(); setup.fmfreq_bank[setup.fmband] = setup.fmfreq; stereoflag = akc6955_get_stereo(); setup.fmbandwidth = akc6955_get_fmbandwidth(); - } else { + } else { setup.amfreq = akc6955_get_freq(); 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); - do { - idle_time_ms(1); - adc = polladc(); - } while(adc == 0xffff); - 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; } +