Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC produces very different values

Status
Not open for further replies.
Not yet. That is the plan for tonight. I did not get a chance last night. Can I use the circuit above or do I need to go below 3.3 volts? BTW with the temp sensor, if I heat it up, the adc values go up. Not sure if that means anything.
 
The Vdd voltage of the PIC is often the default V ref unless u specify otherwise. I haven't read the datasheet tho.

To be certain that you are getting correct ADC values...just feed a known voltage < Vdd and compare the expected ADC value with the result from the PIC. If that matches then your problem lies elsewhere.
 
Well, I tired an know voltage and even rewired another pic and I am still getting the same value to my LCD, which is different than my prototype. Can someone review the code? I am not sure what to do next. Two pics, same value, but different than the prototype.
 
But my ADC is calculated. If I follow what you put in the first post what value do I watch? How do I know that I am sampling at 8-bits?

Do I change this:
Code:
void showADC(void) {
	binary_temp =0;
	int voltage =0;
	z=0;
	for (z =0; z<64 ; z++) 
		{
			delay_5msec();
	   		adcvalue = readADC(4);    //select input channel an4 pin 21
   			binary_temp = binary_temp+adcvalue;
		}   
	binary_temp = binary_temp>>6; //get average value
	voltage =0;
	voltage =binary_temp*32;
	voltage = voltage/100;   // display 2xADRESH for thermo vlaue
	binary_to_ASCIIconvert(voltage);
	binary_temp =0;
	}
to this?
Code:
void showADC(void) {
	binary_temp =0;
	int voltage =0;
	z=0;
	for (z =0; z<64 ; z++) 
		{
			delay_5msec();
	   		adcvalue = readADC(4);    //select input channel an4 pin 21
   			binary_temp = binary_temp+adcvalue;
		}   
	binary_temp = binary_temp>>6; //get average value
	voltage =0;
	voltage =binary_temp/3.3; //3.3 ref voltage (I expect binary_temp to be 2V)
	voltage = voltage*256;   // 8-bit sampling
	binary_to_ASCIIconvert(voltage);
	binary_temp =0;
	}
Or is the code changed in the readADC?
 
Even if your ADC samples at 9 -16 bits , once u use the hi 8 bits (left aligned) you are working with an 8 bit sample giving 2^8 = 256 discrete values.

I see u are using the ADRESH data which implies you are using no more than 8 bits, otherwise u would be using the ADRESL data as well.

DID u configure the ADRESH/L registers to be left aligned or right aligned?
Getting that wrong will confuse the ADC results.

When i say 'calculate' the binary ADC value i MEAN MANUALLY do it.

So if u feed in a fixed 2V to the adc input AND u have a 3.3Vdc ref then your ADC value is supposed to be (2/3.3) * 256 ( for an 8 bit adc value)
= 155 .

You can verify this within your code by adding a simple test and lighting an LED. Simply test if for a 2V input: 153<ADC_8bit_SAMPLE<157. Light the LED if it passes.

Then u can apply say a 1V or 3V signal and see if the LED does NOT light, thus verifying the ADC is operational in hardware.
 
Last edited:
Okay, there are a lot of files, but the are all below. I am very grateful for everyone's help. I am so close to finishing this project until I hit this snag.
 

Attachments

  • adc.h
    125 bytes · Views: 131
  • buttons.c
    6.5 KB · Views: 176
  • adc.c
    783 bytes · Views: 131
  • buttons.h
    5.3 KB · Views: 175
  • delay.c
    845 bytes · Views: 114
  • delay.h
    548 bytes · Views: 137
  • main.c
    6.6 KB · Views: 229
  • pmp_lcd.c
    4.9 KB · Views: 224
  • pmp.h
    45.1 KB · Views: 248
  • PWM.h
    367 bytes · Views: 129
  • rtcc.c
    26.4 KB · Views: 309
  • PWM_Final.c
    4.4 KB · Views: 459
  • rtcc.h
    14.3 KB · Views: 292
  • tbanner.c
    9 KB · Views: 164
  • tbanner.h
    165 bytes · Views: 114
  • stdio.h
    6.4 KB · Views: 154
  • system.h
    2.2 KB · Views: 173
  • timer.c
    2.9 KB · Views: 169
  • timer.h
    2.7 KB · Views: 162
Even if your ADC samples at 9 -16 bits , once u use the hi 8 bits (left aligned) you are working with an 8 bit sample giving 2^8 = 256 discrete values.

I see u are using the ADRESH data which implies you are using no more than 8 bits, otherwise u would be using the ADRESL data as well.

DID u configure the ADRESH/L registers to be left aligned or right aligned?
Getting that wrong will confuse the ADC results.

When i say 'calculate' the binary ADC value i MEAN MANUALLY do it.

So if u feed in a fixed 2V to the adc input AND u have a 3.3Vdc ref then your ADC value is supposed to be (2/3.3) * 256 ( for an 8 bit adc value)
= 155 .

You can verify this within your code by adding a simple test and lighting an LED. Simply test if for a 2V input: 153<ADC_8bit_SAMPLE<157. Light the LED if it passes.

Then u can apply say a 1V or 3V signal and see if the LED does NOT light, thus verifying the ADC is operational in hardware.

Okay, but I am still not sure what value to compare to light the led. For the voltage, can I use a lm317 with and input voltage of 5V and (2) 220 ohm resistors to get a contact output of 2.5v for testing?
 
Yes u can...just measure the voltage with a DMM 1st...it must be < the PIC vdd or bye bye ADC. Prhaps u should put a 1K in series withthe ADC input b4 u give it your ref voltage.

2.5V will work out to 2.5/3.3 * 256 = 193 or 194 ADC value.
 
Last edited:
Okay got your post after I started testing. I can test more tomorrow night and want to test the other two wired pics.

For 2.58V I should get a ADC value of 2.58/3.3 * 256 = 200. I am getting 385

For 3.3V I should get a ADC value of 3.3/3.3 * 256 = 256. I am getting 1010.

DID u configure the ADRESH/L registers to be left aligned or right aligned?
Getting that wrong will confuse the ADC results.
Could this be the problem? How do I configure them?
 
For 2.58V I should get
should be more like 771

Your reading more like a volt

I would put a pot with one side to gnd and top side to vdd and the wiper to your adc input

You can set it at any volts from 0 to 3.3 volts

Like this
 

Attachments

  • an_tester.JPG
    an_tester.JPG
    6.2 KB · Views: 127
I used a LM317 with two 220ohm 1/4W resistors. Vdd out on my DMM reads 2.58V. The pot is a good idea and I believe I have an extra, but I would still have to use my DMM to check the output correct? What would the pot provide that the LM317 is not?

Do I need a common ground between the voltage source and the ADC?
 
You can test a larger range of volts. And I think you'll see whats going on.

See your reading a word and trying to change it into a byte.

That's where your getting your error

Do I need a common ground between the voltage source and the ADC?
Yes
 
Last edited:
You can test a larger range of volts. And I think you'll see whats going on.
Okay, thanks for explaining. I will test it tonight and post my results.

See your reading a word and trying to change it into a byte.
That's where your getting your error
Sorry I do not understand.

I had a common ground, just wanted to make sure they did not have to be isolated.
 
Let me look at your ADC code and I'll post some thing to show you. I'm not sure if you have this set right

Code:
bit 9-8 FORM1:FORM0: Data Output Format bits
11 = Signed fractional (sddd dddd dd00 0000)
10 = Fractional (dddd dddd dd00 0000)
01 = Signed integer (ssss sssd dddd dddd)
00 = Integer (0000 00dd dddd dddd)

You Data Output Format bits are set for Signed fractional
 
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top