PDA

View Full Version : 18f2525 with LM34



ronjodu
- 22nd January 2007, 21:37
I've spent the last 2 days working on this and can't seem to solve my problem.

I have a 18f2525 @ 20Mhz connected to a LM34 Temperature sensor on RA5(AN4).
I have a pot connected to RA3 (+Vref) with 2.55 volts on RA3.
I've used Bruce's code, with some changes to suit my app.
I read .68 volts on pin 7 but get bogus numbers on the PC.
"Temperature is 38 Degrees"
"Temperature is 5 Degrees"
I've tried manipulating ADCON0, ADCON1, and ADCON2 with no success.

Here is the code as it was for my last attempt.
<code>
DEFINE LOADER_USED 1 ' Boot loader is being used
define OSC 20 ' We're using a 4 MHz oscillator
DEFINE HSER_RCSTA 90h 'setup receive register
DEFINE HSER_TXSTA 20h 'setup transmit register
DEFINE HSER_BAUD 38400 'setup baud rate
DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
DEFINE ADC_CLOCK 3 ' Set A/D clock
DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS

samples VAR WORD ' Multiple A/D sample accumulator
sample VAR BYTE ' Holds number of samples to take
temp VAR BYTE ' Temperature storage
samples = 0 ' Clear samples accumulator on power-up

PORTA = %00000000
TRISA = %11111111 ' Set PORTA to all input

'ADCON0 = %00010001
ADCON1 = %00011010 ' Set PORTA.0,1,2,5 = A/D, PortA.3 = +Vref
'ADCON2 = %00111011
PAUSE 500 ' Wait .5 second
loop:
FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 5, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20
samples = 0 ' Clear old sample accumulator
GoSub hyperview
GOTO loop ' Do it forever
hyperview:
HSerout ["Temperature is ",dec temp," Degrees", 13,10]
'pause 1000
Return

END
</code>

I'm sure it's something simple, It just hasn't jumped out at me yet.
Any help would be apreciated.

PBP v2.45A, MCSP, MPASM and Microcode Loader

Darrel Taylor
- 22nd January 2007, 22:43
Here's Note 2 from the ADCON1 section of the 2525 datasheet.


2: AN5 through AN7 are available only on 40/44-pin devices.

Added: maybe you wanted ADCIN 4, temp
<br>

ronjodu
- 23rd January 2007, 03:34
Well Darrel, once again you're right on.

I did read the note (AN5 through AN7 are available only on 40/44-pin devices) and put my sensor on AN4 (RA5) but didn't realize the
ADCIN 5, temp problem.

If nothing more at least I got a little schooling on ADCON0, ADCON1 and ADCON2.

As always many thanks.

I'm off to return that tall ladder and short rope I just bought.

Darrel Taylor
- 23rd January 2007, 04:47
The easy one's are often hardest to find (in your own program).
The hard one's you've already gone over a hundred times and can't understand why it's still not working.

It's much easier when it's someone else's program. :)


I'm off to return that tall ladder and short rope I just bought.

Oh thank god,
It would have been horrible for someone to find you like that. :eek:

LOL,