+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Newbie level 4
    Points: 196, Level: 2

    Join Date
    Jan 2012
    Posts
    7
    Helped
    1 / 1
    Points
    196
    Level
    2

    How to initialize ADC for PIC18f4620?

    how to intitialize ADC in PIC18f4620?

    what is adcon1,adcon2,vref?
    i'm planning to make a temperature sensor using lm35.. pls help me.. where do i start..

    sorry for my english..

  2. #2
    Advanced Member level 5
    Points: 38,590, Level: 48
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Silicon Valley, California, USA (from Dhaka, Bangladesh)
    Posts
    4,758
    Helped
    1795 / 1795
    Points
    38,590
    Level
    48
    Blog Entries
    22

    Re: How to initialize ADC for PIC18f4620?

    You can find a project here: Tahmid's blog: Digital thermometer with LM35 and PIC18F452

    There are many temperature sensor circuits here: Tahmid's blog

    ADCON1 and ADCON2 are the control registers for the ADC. VREF is the reference voltage.

    You can start reading about ADC here:
    Using Analog to Digital Converter
    http://www.gooligum.com.au/tutorials...C_Mid_A_13.pdf
    http://www.gooligum.com.au/tutorials...IC_Mid_C_8.pdf

    Hope this helps.
    Tahmid.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  3. #3
    Newbie level 4
    Points: 196, Level: 2

    Join Date
    Jan 2012
    Posts
    7
    Helped
    1 / 1
    Points
    196
    Level
    2

    Re: How to initialize ADC for PIC18f4620?

    thank you very much..

    when do i use ADCON1 or ADCON2 sir?

    ADCON2 = 0x80; what is the meaning of "0x80"?

    im using MikroC sir.. PIC18f4620.



  4. #4
    Advanced Member level 5
    Points: 38,590, Level: 48
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Silicon Valley, California, USA (from Dhaka, Bangladesh)
    Posts
    4,758
    Helped
    1795 / 1795
    Points
    38,590
    Level
    48
    Blog Entries
    22

    Re: How to initialize ADC for PIC18f4620?

    0x80 means 80 in hexadecimal which is equal to 128 in decimal and 10000000 in binary.

    I suggest you first download the datasheet for PIC 18F4620: ww1.microchip.com/downloads/en/DeviceDoc/39626b.pdf

    Go to page 227 of the datasheet. There you have the ADCON2 register.
    Writing 0x80 means you're commanding the ADC to display readings as right justified. Acquisition time is 0TAD, conversion clock is FOSC/2.

    Go through the tutorials above and you should be able to understand everything clearly.

    Hope this helps.
    Tahmid.


    1 members found this post helpful.

    •   AltAdvertisment

        
       

  5. #5
    Newbie level 4
    Points: 196, Level: 2

    Join Date
    Jan 2012
    Posts
    7
    Helped
    1 / 1
    Points
    196
    Level
    2

    Re: How to initialize ADC for PIC18f4620?

    sir can you please check what's wrong with my code?
    the problem is i can't get the actual temperature.. for example The value of my LM35 is 31.0C in ISIS, but the output in virtual terminal is 31.2C..
    27.0 c = 27.3 c
    27.1 c = 27.3 c
    27.2 c = 27.3 c
    27.3 c = 27.3 c
    27.4 c = 27.3 c
    27.5 c = 27.8 c

    void main() {
    float temp,AdcTemp;
    int IntegTemp1, IntegTemp2,DeciTemp;
    ADCON2 = 0x82; // Configure analog inputs and Vref
    TRISA = 0xFF; // PORTA is input
    TRISB = 0x3F; // Pins RB7, RB6 are outputs
    TRISD = 0; // PORTD is output
    usart_init(9600);
    delay_ms(500);


    do {
    AdcTemp= Adc_Read(2);
    Temp = (AdcTemp*5000)/1023;
    IntegTemp1 = (int) Temp*.01;
    IntegTemp2 = (int) Temp*.1 - (IntegTemp1*10);
    DeciTemp = (int) Temp*1 - (IntegTemp1*100+(IntegTemp2*10));

    usart_write('T');
    usart_write('E');
    usart_write('M');
    usart_write('P');
    usart_write('=');
    usart_write(IntegTemp1+48);
    usart_write(IntegTemp2+48);
    usart_write('.');
    usart_write(DeciTemp+48);
    usart_write(' ');
    usart_write('C');
    usart_write(13);
    usart_write(10);
    delay_ms(400);
    } while(1);
    }

    the problem actually is the "DeciTemp". Please help sir.



  6. #6
    Advanced Member level 5
    Points: 38,590, Level: 48
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Silicon Valley, California, USA (from Dhaka, Bangladesh)
    Posts
    4,758
    Helped
    1795 / 1795
    Points
    38,590
    Level
    48
    Blog Entries
    22

    Re: How to initialize ADC for PIC18f4620?

    This is because, LM35 provides an output with a guaranteed accuracy of 0.5C. Expecting any better accuracy is useless. So, your reading has to vary by 0.5C steps, not 0.1C steps like your program does.

    Hope this helps.
    Tahmid.
    Last edited by Tahmid; 30th January 2012 at 07:37. Reason: Typo


    1 members found this post helpful.

  7. #7
    Newbie level 4
    Points: 196, Level: 2

    Join Date
    Jan 2012
    Posts
    7
    Helped
    1 / 1
    Points
    196
    Level
    2

    Re: How to initialize ADC for PIC18f4620?

    so if i want better accuracy, i have to change my sensor(LM35)?
    can you suggest other sensor for temperature sir...?



  8. #8
    Advanced Member level 5
    Points: 38,590, Level: 48
    Achievements:
    Created Album pictures Created Blog entry 7 years registered
    Tahmid's Avatar
    Join Date
    Jun 2008
    Location
    Silicon Valley, California, USA (from Dhaka, Bangladesh)
    Posts
    4,758
    Helped
    1795 / 1795
    Points
    38,590
    Level
    48
    Blog Entries
    22

    Re: How to initialize ADC for PIC18f4620?

    Yes, you need to change the sensor. I don't know of any sensor IC that accurate. However, you could see if you can find a suitable thermistor. There are some quite accurate ones.



    •   AltAdvertisment

        
       

  9. #9
    Newbie level 4
    Points: 196, Level: 2

    Join Date
    Jan 2012
    Posts
    7
    Helped
    1 / 1
    Points
    196
    Level
    2

    Re: How to initialize ADC for PIC18f4620?

    Tnx sir.



--[[ ]]--