Connect with us

adc temperature problem

Discussion in 'Microcontrollers, Programming and IoT' started by gurjant.sandhu33, Feb 26, 2014.

Scroll to continue with content
  1. gurjant.sandhu33

    gurjant.sandhu33

    51
    0
    Dec 10, 2013
    i have used the following code with my pic 16f73

    unsigned char myvalue;
    void main()
    org 0x10
    {
    adcon0=0x85;
    adcon1=0x01;
    trisa=0xff;
    trisc=0x00;
    while(1)
    {
    myvalue=adc_read(0);
    portc=myvalue;
    delay_ms(2000);
    }}
    but now i want to use it with pic 16f870
    but it is not showing the right output as pic 16f870 is 10 bit adc and pic 16f73 is 8 bit adc
    so is there any thing i can do to solve it and do i need to adjust the vref value for new pic
     
  2. kpatz

    kpatz

    268
    60
    Feb 24, 2014
    Assuming adc_read() returns the full 10-bit value, you could simply divide by 4 (or shift right 2) to make it an 8 bit value the same as your old PIC.

    Also, with ADFM = 0 (bit 7 of ADCON1), the result is placed with the 8 most significant bits in ADRESH and the 2 least significant bits in ADRESL, giving a result left shifted 6 bits. If you read ADRESH and ignore ADRESL, you'll get the equivalent of an 8-bit A/D conversion.
     
  3. KrisBlueNZ

    KrisBlueNZ Sadly passed away in 2015

    8,393
    1,268
    Nov 28, 2011
    Great answer kpatz. Did you get the PM I sent you? Just below the Electronics Point banner at the top of any page, at the right side, click on Private Messages.
     
  4. gurjant.sandhu33

    gurjant.sandhu33

    51
    0
    Dec 10, 2013
    is this code right

    unsigned char myvalue;
    void main()
    org 0x10
    {
    adcon0=0x85;
    adcon1=0x01;
    trisa=0xff;
    trisc=0x00;
    while(1)
    {
    myvalue=adc_read(0) >> 2;
    portc=myvalue;
    delay_ms(2000);
    }
    }
     
  5. gurjant.sandhu33

    gurjant.sandhu33

    51
    0
    Dec 10, 2013
    please can you tell me the changes i need to make to ADRESH in code
     
  6. kpatz

    kpatz

    268
    60
    Feb 24, 2014
    I found documentation for ADC_Read() which is a MikroC library function. It returns a 10-bit A/D result so simply shift right 2, like in your example code:

    myvalue = ADC_Read(0) >> 2;

    should do the trick.

    BTW, since you're using the ADC library functions you should use ADC_Init() to set up the ADC instead of setting the ADCON registers yourself.
     
    Last edited: Feb 27, 2014
  7. gurjant.sandhu33

    gurjant.sandhu33

    51
    0
    Dec 10, 2013
    yes, adc_read(0) is reading value from temperature sensor connected to the adc 0 port.
    but the code with myvalue=adresh didnt work
     
    Last edited: Feb 28, 2014
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-