PDA

View Full Version : PIC18f2423 two 12bit adc input problems



Brandon
- 15th December 2007, 05:51
Hi all,

I got some pic18F2423 chips so I could monitor two pots on two pins at 12bit.
Everything ALMOST works. I can't seem to get the second adc (porta.1) to work.
It is not the pots, if i siwtch them porta.1 stays dead, or i should say, outputs whatever is on porta.0.

Any help would be great, i am sure it is a newbie queston :(


'pic18f2423 with 12bit adc

define OSC 20
DEFINE ADC_BITS 12 'SETS NUMBER OF BITS IN RESULTS 8,10,12
DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS
ADCON2.7 = 1 'right justify port a
W0 Var WORD
W1 Var WORD
b0 Var w0.Byte0 'high byte of word w0
b1 Var w0.Byte1 'low byte of word w0
b2 Var w1.Byte0 'high byte of word w1
b3 Var w1.Byte1 'low byte of word w1
include "modedefs.bas"

loop:
ADCIN PORTA.0,W0
pauseus 100
ADCIN PORTA.1,W1
pauseus 100
LOW 0 'turn off led for testing
SEROUT PORTB.3, T9600, ["T"] 'TILT
SEROUT PORTB.3, T9600, [#w0,10]
HIGH 0'turn on led for testing
SEROUT PORTB.3, T9600, ["P"] 'PAN
SEROUT PORTB.3, T9600, [#w1,10]

goto loop

end

Raflex
- 15th December 2007, 18:34
Hello, you need to configure the ADCON1 register, refer to datasheet page 228.

Brandon
- 15th December 2007, 21:34
I've read the datasheet over and over, and I think I have all the ADCONs set to read analog from AN0 and AN1 but I can only get AN0 to work, AN1 just reads whatever is coming in AN0. Any help would be great :)


'pic18f2423 with 12bit adc

define OSC 20
DEFINE ADC_BITS 12 'SETS NUMBER OF BITS IN RESULTS 8,10,12
DEFINE ADC_CLOCK 3 'SETS CLOCK SOURCE (RC = 3)
DEFINE ADC_SAMPLEUS 50 'SETS SAMPLING TIME IN MICROSECONDS
ADCON1 = %00001101 'SET ANALOG PINS AN0 AND AN1
ADCON2.7 = 1 'right justify port A
W0 Var WORD
W1 Var WORD
'b0 Var w0.Byte0 'high byte of word w0
'b1 Var w0.Byte1 'low byte of word w0
'b2 Var w1.Byte0 'high byte of word w1
'b3 Var w1.Byte1 'low byte of word w1
include "modedefs.bas"

loop:
ADCIN PORTA.0,W0
pauseus 100
ADCIN PORTA.1,W1
pauseus 100
LOW 0 'turn off led for testing
SEROUT PORTB.3, T9600, ["T"] 'TILT
SEROUT PORTB.3, T9600, [#w0,10]
HIGH 0'turn on led for testing
SEROUT PORTB.3, T9600, ["P"] 'PAN
SEROUT PORTB.3, T9600, [#w1,10]

goto loop

end

Darrel Taylor
- 15th December 2007, 21:54
Use the AN? number, not the PORT pin.

ADCIN 0,W0
ADCIN 1,W1

With the original statements ...

ADCIN PORTA.1,W1

It reads PORTA.1 as a DIGITAL bit value. And since the pin is in analog mode, it always reads 0.

It then uses that number for the AN? channel. So ADCIN always reads Channel AN0.
<br>

Brandon
- 15th December 2007, 22:15
That was the problem, thanks a lot! boy do I feel dumb.

Darrel Taylor
- 15th December 2007, 22:55
The longer you hang around here.

The less you'll have that feeling. :)
<br>

mister_e
- 16th December 2007, 09:47
Are you really sure of it ;)