Hey all,
Problem solved. Had to redo all ADC code.
Here is the working code. Maybe this is usefull for the coders here;
-- ok, now let's configure ADC
pin_AN0_direction = input
-- ADCON0 CONFIG
ADCON0_CHS0 = OFF -- Channel at 0 (Bit 0)
ADCON0_CHS1 = OFF -- Channel at 0 (Bit 1)
ADCON0_CHS2 = OFF -- Channel at 0 (Bit 2)
ADCON0_CHS3 = OFF -- Channel at 0 (Bit 3)
-- ADCON1 CONFIG
ADCON1_PCFG0 = OFF -- AN0 as Analog ONLY (Bit 0)
ADCON1_PCFG1 = ON -- AN0 as Analog ONLY (Bit 1)
ADCON1_PCFG2 = ON -- AN0 as Analog ONLY (Bit 2)
ADCON1_PCFG3 = ON -- AN0 as Analog ONLY (Bit 3)
ADCON1_VCFG0 = OFF -- Vref+ at VDD
ADCON1_VCFG1 = OFF -- Vref- at VSS
-- ADCON2 CONFIG
ADCON2_ADCS0 = OFF -- AD Conversion Clock at Fosc/64 (Bit 0)
ADCON2_ADCS1 = ON -- AD Conversion Clock at Fosc/64 (Bit 1)
ADCON2_ADCS2 = ON -- AD Conversion Clock at Fosc/64 (Bit 2)
ADCON2_ACQT0 = ON -- AD Acq. Time at 2xTAD (Bit 0)
ADCON2_ACQT1 = OFF -- AD Acq. Time at 2xTAD (Bit 1)
ADCON2_ACQT2 = OFF -- AD Acq. Time at 2xTAD (Bit 2)
ADCON2_ADFM = ON -- AD Result Justify at Right
--
const word ADC_RSOURCE = 2_500 -- Input Resistance
const byte ADC_TEMP = 85 -- PIC Max. Temperature
const byte ADC_MAX_TAD = 6 -- (0.8us < TAD < 12.5us as per
-- Datasheet, Pag. 41)
-- AD ACQUISITION TIME (Original VAR: adc_conversion_delay)
-- Tacq = Tamp + Tc + Tcoff
const word tamp = 1 -- (=> 0.2us as per Datasheet, Pag. 30)
const word adc_tc = 2 -- ((TEMP – 25°C)x(0.02 us/°C) => 1.2us as per Datasheet, Pag. 30))
const word adc_tcoff = 2 -- (-(25 pF)x(1 kohm + 4 kohm + RSOURCE)xln(0.0004883)
-- => 1.56us as per Datasheet, Pag. 30)
const byte ADC_TACQ = byte(tamp + adc_tc + adc_tcoff)
-- (Original VAR: adc_conversion_delay)
--
var word adc_word -- return value
var byte adc_byte[2] at adc_word -- byte array overlay
--
function adc_read_high_res(byte in adc_chan) return word is
pragma inline
--
-- Original Code has here the Channel and L/R Justifying
-- These parameters are set above...
--
ADCON0_ADON = TRUE -- turn on ADC module
--
for ADC_TACQ loop
_usec_delay(1) -- wait acquisition time
-- Original:
_usec_delay(10)
end loop
--
ADCON0_GO = TRUE -- start conversion
while ADCON0_GO == TRUE loop -- wait until conversion completed
-- Empty loop.
end loop
--
adc_byte[1] = ADRESH -- copy high order bits
adc_byte[0] = ADRESL -- copy low order bits
-- Choosed High Resolution options here, from Original Code...
--
-- Honor 2 * max Tad time. Note the value is not very accurate, but safe.
_usec_delay(2 * ADC_MAX_TAD) -- As per Datasheet, Pag. 29
--
ADCON0_ADON = false -- turn off ADC module
return adc_word -- back to caller
end function
Best regrads,
FS