Setting up Analog for Thermometer Project using PIC18F4550

Discussion in 'Embedded Systems and Microcontrollers' started by corsair, Mar 26, 2010.

  1. corsair

    Thread Starter Member

    Mar 6, 2010
    51
    1
    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:
    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:
    Code ( (Unknown Language)):
    1. temp:
    2.     call    temp_inits
    3.     bsf    ADCON0,1,0    ; Start the Conversion
    4. temp2    btfsc    ADCON0,1,0    ; Wait for AD Conversion to Complete
    5.     bra    temp2
    6.  
    7.     movf    ADRESH,0,0
    8.     dispW    digit1        ; Displays contents of W(in hex)
    9.     movf    ADRESL,0,0
    10.     dispW    digit2
    11.     return
    12.  
    13. temp_inits:
    14.     movlw    0x1        ; Select AN0 and ADON = 1
    15.     movwf    ADCON0
    16.     movlw    0x0        ; Enable Analog Input from AN0
    17.     movwf    ADCON1
    18.     ; ***** this parts pretty confusing for me
    19.     movlw    0xfb        ; 20Tad, Frc (found ex and used same values)
    20.     movwf    ADCON2
    21.     return
    Anyways, that's my attempt at this temperature probe. Thanks in advance for the help! :)
     
    Last edited: Mar 27, 2010
  2. Tahmid

    Active Member

    Jul 2, 2008
    344
    25
    Hi,
    Try this instead:
    Code ( (Unknown Language)):
    1. temp
    2.     call   temp_inits
    3.     bsf    ADCON0,1,0    ; Start the Conversion
    4.  
    5. temp2
    6.     btfsc  ADCON0,1,0    ; Wait for AD Conversion to Complete
    7.     bra    temp2
    8.  
    9.     movf    ADRESH,w
    10.     movwf   digit1        ; Displays contents of W(in hex)
    11.     movf    ADRESL,w
    12.     movwf   digit2
    13.     return
    14.  
    15. temp_inits
    16.     movlw    0x1        ; Select AN0 and ADON = 1
    17.     movwf    ADCON0
    18.     movlw    0x0        ; Enable Analog Input from AN0, All ADC channels are analog
    19.     movwf    ADCON1
    20.  
    21.     movlw    0x3E       ; 20TAD, FOSC/64
    22.     movwf    ADCON2
    23.     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.
     
    corsair likes this.
Loading...