-
PIC18F2423, ADC problem
Hi Group
I have purchased a PIC18F2423 to make a pressure meter with 12 bit resolution.
To test the circuit I hooked up a 1k pot to +5 and ground and the wiper to the ADC input AN1. I noticed that the result of the ADC does not output a bit with an input voltage under 11.5mV. Here is the code:
'PIC18F2423, 4MHz Resonator, 4x20 LCD, Input AN1, Vref 4096mV
'Defines ADC
DEFINE ADC_BITS 12
DEFINE ADC_SAMPLEUS 50
Define OSC 4
'Defines LCD
Define LCD_DREG PORTB 'set lcd data port to PORTB
Define LCD_DBIT 0 'set data starting bit to 0 (RC0 to RC3)
Define LCD_RSREG PORTB 'set rs register port to PORTB
Define LCD_RSBIT 4 'set rs register bit to 4 (RC4)
Define LCD_EREG PORTB 'set E register port (PORTB)
Define LCD_EBIT 5 'set E register bit to 5 (RC5)
Define LCD_BITS 4 'set to 4-bit operation
Define LCD_LINES 4 'set to 4-line lcd
Define LCD_COMMANDUS 500 'delay 500us
'Variable
Press Var Word
TrisA =%00111111
'reset lcd display
Lcdout $FE,1
'Start to measure Pressure---------------------------------------
Let Press=0
Adcon1=%00011010 'Analog AN0 to AN4, Ref Gnd, Ext Ref 4096mV
ADCON0=%00000101 'ADC enabled, ADC idle, AN1 on,
Adcon2=%10010100 'Fosc/4, 4Tad, Right justified
Adcon0.1=1 'start conversion
notdon:
IF ADCON0.1 = 1 THEN notdon 'wait for conversion to finish
Press.highbyte=ADRESH 'move result of highbyte to Press
Press.lowbyte=ADRESL 'move result of lowbyte to Press
Pause 100
LCDOUT $FE,$80, "Press " , DEC Press 'to see value of "Press"
Pause 1000
Let Press=Press*5
Pause 50
Lcdout $FE,$94, "Pressure: ",DEC Press/10, ".", DEC1 Press, " mb"
Pause 3000
Goto Start
End
Does anyone know why there is no ADC output with <11.5mV input? Help is appreciated.
-
Hi . I don't kown PIC18F2423.But when I use PIC18F2523,I make a mistack beacuse of not read it's datasheet carefully .Maybe you need alos read PIC18F2423 's datasheet .good luck.
-
Take a look at this example
http://www.rentron.com/PICX2.htm
Or use the ADCIN command built into PBP, looks like you are mixing both ways.
-
Change ADCON2 to use more Acquisition time,
Wait after switching the ADC on (ADCON0) 1
delete this ADC-defines !
maybe ... ad a 1nF C to AN1 against ground
-
Found the problem: when I use " ADCIN 1, Press " instead of
Press.highbyte=ADRESH 'move result of highbyte to Press
Press.lowbyte=ADRESL 'move result of lowbyte to Press
the ADC works correctly. I have used this code many times with other pic's and it always worked. Have to find out why it gave me a headache with this chip.
Thanks everyone for the help, it was a pleasure.