Menu

ADC problems 16F876A

Help
2010-03-24
2013-05-30
  • David Stephenson

    I've been reading a temperature with a thermistor using a 16F676 and it worked well.

    I migrated the code onto a 16F876A as I needed more program memory, but now the adc reads incorrectly and the reading seems to depend on the supply voltage.

    Is there something extra that I need to set on a 16F876A as opposed to a 16F676?

     
  • JR

    JR - 2010-03-24

    Neither the 16F676 nor the 16F876A has an internal fixed voltage reference, so ADC readings in both of these parts will be highly dependent on the accuracy & stability of the power supply voltage. This might be your entire problem, but it's hard to say unless you can elaborate on "the adc reads incorrectly".

    Joe

     
  • David Stephenson

    Ok I've just read the voltages.
    Supply voltage 4.91
    adc voltage 2.84
    so the expected values the adc should read is high byte=2 low bit=80
    This is exactly the value the 16F676 gives, but the 16F874 has a high byte of 2 and a low byte of 195.

    So the 16F874 reads a voltage of 2.84 as 3.39

     
  • Nobody/Anonymous

    Hi uwidavid here I am having trouble logging in.

    Using the program below I connected the adc to a 10k pot.

    It the adc reaches 1023 when the voltage is 0.8V below the supply voltage. The adc zero is not off-set and comes at zero volts.

    I have not set Vref and connecting the vref pins to  the supply does not alter the readings

    #chip 16F876,20
    #config OSC=HS
    #define LCD_IO 8
    #define LCD_DATA_PORT PORTB
    #define LCD_RS PORTC.1
    #define LCD_NO_RW
    #define LCD_Enable PORTC.3
    dim jj as word
    start:
    wait 1 sec
    cls
    locate 0,0
    jj=0
    jj=readad10(an0)
    lcdword jj
    goto start

     
  • JR

    JR - 2010-03-26

    The ADC isn't accurate with high drive source impedances. Try the same experiment with a 1K pot.

    Joe

     
  • David Stephenson

    Yes I did originally think that was the problem and so I have a unity gain op-amp buffering the input. It makes no difference to the readings.
    I've also tried different clock rates 4,8 and 20 MHz again exactly the same wrong reading.

    It appears that Vref+ is somehow set at 0.8V below Vdd.

     
  • David Stephenson

    Ok I've tried setting Vref+ and then connecting the pin to +ve. Now I get the full range of readings, but it is non-linear.
    Withe a supply of 5.0V I get the following readings
    0V 18
    1V adc reading 230
    2V 442
    3V 655
    4V 857
    5V 1015
    I'm getting exactly the same readings on another 16F876 and changing the adc pin does not help.
    Have I got two bad chips here? The 16F676 gives correct readings connected to the same voltage source.
    If I connect a 16F676 I get correct values.

     
  • Nobody/Anonymous

    Please explain this in clearer language:
    "I've tried setting Vref+ and then connecting the pin to +ve."

    Joe

     
  • David Stephenson

    Pin 5 on the 16F876 can be set to a reference voltage representing the upper limit of the ADC(It also rquires the setting of bit 0 in the ADCON1 register to 1 which I did).
    So I connected pin 5  to Vdd so the ADC should have its full range of 0-1023 when the adc pin goes from Vss to Vdd. As you can see it worked to an extent but the non-linearity is puzzling.

     
  • Nobody/Anonymous

    What are you using for a development hardware platform? Is it a commercial development board, or a plug-board, or something else? Are you sure the PIC is being powered from the power supply pins, and not by the drive on the inputs? Check  that there is no voltage drop between the PIC Vss pin and the power supply ground. Also check that the signal input ground is at the same potential as the PIC Vss. Finally, check that none of the other input signals are driving at a voltage higher then the PIC Vcc voltage.

    Joe

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.