PDA

View Full Version : 18LF14K22 AD Converter Problem



ralfmayr
- 13th April 2010, 18:08
Hi all,
i have the following problem:
I use Aanalog 2 (RA2) and Analog 3 (RA4) to measure DC Voltage on a PIC18LF14K22.

The uP is configured to run with internal oscillator:
OSCCON = %01110010 ' configure internal OSC @ 16MHZ
OSCTUNE = %00000000
While OSCCON.2=0 : wend ' wait until OSC is stable

After that i configure Port A to use RA0 to RA3 as ADC:

TRISA = %111111
ADCON1 = %00000000
ADCON2 = %10000111 ' Right justified, Frc
ANSEL = %00001111
ANSELH = %00000000

Then in two subroutines i read back Aanalog 2 and Analog 3:

1:
ADCON0 = %00001011 ' Start the conversion of ad channel 2
WHILE ADCON0.1 = 1 ' Wait for it to complete
i = 0
WEND
adc2_value = (adc2_value + ((ADRESH * 256) + ADRESL)) / 2 ' get result from AN2 with avg by two

2.
ADCON0 = %00001111 ' Start the conversion of ad channel 3
WHILE ADCON0.1 = 1 ' Wait for it to complete
i = 0
WEND
adc3_value = (adc3_value + ((ADRESH * 256) + ADRESL)) / 2 ' get result from AN3 with avg by two

The result vars are defined as word.

Now the problem:
1. Always delivers correct values

2. Brings always the same value (50), but it should vary between 50 and 200...

Don't know the reason why Analog 3 is always same value, can somebody help!?
Regards,
Ralf

ralfmayr
- 14th April 2010, 10:24
Read the Errata Datasheet :-(

http://ww1.microchip.com/downloads/en/DeviceDoc/80437B.pdf

1. Module: ADC (Analog-to-Digital
Converter)
ADC conversion on AN3/OSC2 will have large INL
error up to approximately 8 LSb.
Work around
None for the AN3 pin. For better accuracy, use
another analog pin.

This PIC is a Big Bug Chip !

Regards,
Ralf

Acetronics2
- 14th April 2010, 10:51
Hi, Ralph

May be you also could leave some sampling time to both channels ... ( you've set it to ZERO Tad) ...

Results would be ... less false !!!

Alain

ralfmayr
- 14th April 2010, 11:13
Hi,
thanks for the answer.
But: No effect. AN3 on this chip seems to be absolutely not useable.