Setting up Analog for Thermometer Project using PIC18F4550

Thread Starter

corsair

Joined Mar 6, 2010
51
Hi guys,

For my project I am building a mini-weather station, and a part of it includes using a thermal-resistance transducer and a PIC18F4550. For the moment, I do not have the thermometer, but my professor said that I can use a 10k Ohm potentiometer to simulate/calibrate it.

I asked my professor to help me get started, and this is what he said:
You'll want to read Chapter 21 in the PIC18F4550 datasheet. The pins in the PIC's port 'A' (RA0, RA1, etc) which are connected to the switches and the J_ADC connector have alternate names/applications, e.g RA0=AN0, RA1=AN1 etc (see the pin diagram in the datasheet) so you will be physically connecting to those pins in their roles as AN0, etc. The ADC conversion data will be generated and controlled by the ADC registers as described in TAble 21-2 of the datasheet. Its pretty complicated, but you should be able to find some examples online that will help.
So, after having done this, I'm going to you guys for help. :)

Right now, I have a 10k Ohm potentiometer hooked up to AN0, VDD, and GND. In addition, I have a 7-segment display so that I can see the temperature.

I am not sure what I am doing wrong, this is what I have:
Rich (BB code):
temp:
    call    temp_inits
    bsf    ADCON0,1,0    ; Start the Conversion
temp2    btfsc    ADCON0,1,0    ; Wait for AD Conversion to Complete
    bra    temp2

    movf    ADRESH,0,0
    dispW    digit1        ; Displays contents of W(in hex)
    movf    ADRESL,0,0
    dispW    digit2
    return

temp_inits:
    movlw    0x1        ; Select AN0 and ADON = 1
    movwf    ADCON0
    movlw    0x0        ; Enable Analog Input from AN0
    movwf    ADCON1
    ; ***** this parts pretty confusing for me
    movlw    0xfb        ; 20Tad, Frc (found ex and used same values)
    movwf    ADCON2
    return
Anyways, that's my attempt at this temperature probe. Thanks in advance for the help! :)
 
Last edited:

Tahmid

Joined Jul 2, 2008
343
Hi,
Try this instead:
Rich (BB code):
temp
    call   temp_inits
    bsf    ADCON0,1,0    ; Start the Conversion

temp2
    btfsc  ADCON0,1,0    ; Wait for AD Conversion to Complete
    bra    temp2

    movf    ADRESH,w
    movwf   digit1        ; Displays contents of W(in hex)
    movf    ADRESL,w
    movwf   digit2
    return

temp_inits
    movlw    0x1        ; Select AN0 and ADON = 1
    movwf    ADCON0
    movlw    0x0        ; Enable Analog Input from AN0, All ADC channels are analog
    movwf    ADCON1

    movlw    0x3E       ; 20TAD, FOSC/64
    movwf    ADCON2
    return
Just wait for some time, if you need help understanding the code, I will try to explain it to you.

Hope this helps.
Tahmid.
 
Top