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?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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?
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
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
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
The ADC isn't accurate with high drive source impedances. Try the same experiment with a 1K pot.
Joe
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.
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.
Please explain this in clearer language:
"I've tried setting Vref+ and then connecting the pin to +ve."
Joe
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.
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