View previous topic :: View next topic |
Author |
Message |
bauereri
Joined: 16 Jan 2004 Posts: 9
|
ADC on PIC16f876 |
Posted: Thu Jan 29, 2004 8:11 pm |
|
|
Hi,
I have two questions about using the ADC. First, if I dial up my bench power supply to 5V and apply the signal to the input channel, I only read 2.3V on the channel w/ a VOM. And the output of the ADC only goes to about 140. Why does this happen??
Next, if I connect a second signal to the ADC, I get channel interference. I read here in the forum that this is the result of failing to wait long enough after selecting the channel before performing the read. I tried a dealy as long as 1500 mS and the problem remains. Here is how I'm doing it:
Code: | SETUP_ADC_PORTS(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0); // Set the channel to read the motor feedback
delay_ms(150); // Allow the channel to be aquired
value = read_adc(); // Start the conversion
|
Any help is really appreciated!
Eric |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 29, 2004 8:26 pm |
|
|
1. What's your version of the compiler ?
2. What power supply voltage are you using for the PIC ?
3. Are you using a "#device adc=8" or similar statement ?
If so, what is the exact statement ?
4. What crystal frequency are you using ?
5. What is the 2nd signal that is connected to the ADC ?
What are its voltage levels ?
What pin on the PIC is the 2nd signal connected to ?
6. In your sample code that you posted, what is the data
type declaration for the "value" variable ? (ie., int, char,
int8, int16, long, etc.) |
|
|
bauereri
Joined: 16 Jan 2004 Posts: 9
|
|
Posted: Thu Jan 29, 2004 9:08 pm |
|
|
Hi PCM,
See my answers below.
Eric
Quote: | 1. What's your version of the compiler ?
Version 2.734
2. What power supply voltage are you using for the PIC ?
5V
3. Are you using a "#device adc=8" or similar statement ?
If so, what is the exact statement ?
#Device ADC=10
4. What crystal frequency are you using ?
4Mhz
5. What is the 2nd signal that is connected to the ADC ?
What are its voltage levels ? 0-5v on both
What pin on the PIC is the 2nd signal connected to ? AN1
6. In your sample code that you posted, what is the data
type declaration for the "value" variable ? (ie., int, char,
int8, int16, long, etc.)
I typed it as a float and I was suprised to see that it worked. Or did it...
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 29, 2004 10:31 pm |
|
|
I have a few more questions about parts of your post that I had
overlooked.
Quote: | First, if I dial up my bench power supply to 5V and apply the signal to the
input channel, I only read 2.3V on the channel w/ a VOM. And the output
of the ADC only goes to about 140 |
Is the output of the power supply directly connected to Pin A0
on the PIC ?
Or does it go through a resistor or some other circuit ?
If it's a resistor, what is its value ?
If there is some other circuit on Pin A0, then please describe it.
Presumably your bench power supply can deliver at least 1 Amp.
If in fact your PIC is loading it down to 2.3v, I think the PIC would
be getting very hot (or smoking). So I need to know more about
your power supply and A/D input circuit. |
|
|
bauereri
Joined: 16 Jan 2004 Posts: 9
|
|
Posted: Fri Jan 30, 2004 9:30 am |
|
|
Hi PCM,
I was applying the power supply directly to A0 without any peripheral circuitry. The supply is capable if 1A, but it's not putting out that much and the PIC is not getting hot.
I suppose that I could place the 5V across something like a 1k resistor to ground and then take my PIC signal from the top of the resistor.
I'm a little more concerned about the channel interference at this point. What do you think I'm doing wrong there?? Or, are the problems related??
Eric |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 30, 2004 10:08 am |
|
|
Silly question but, do you have the power supply referenced to the circuit? The ground of the power supply connected to the ground of the pic? What happens if you are measuring the voltage (2.3) and keep measuring it while you disconnect it from the circuit? |
|
|
bauereri
Joined: 16 Jan 2004 Posts: 9
|
|
Posted: Fri Jan 30, 2004 10:26 am |
|
|
yep, ground is good. If I disconnect the supply from the pic, the the VOM jumps back up to the 5V.
Strange.....
Eric |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 30, 2004 10:29 am |
|
|
Are you measuring at the supply or at the circuit? If at the supply, something must be drawing a lot of current. If at the circuit then the wire might be bad (high resistance) causing the problem. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Fri Jan 30, 2004 10:31 am |
|
|
What happens if you jumper the 5V power for the circuit to the input?
How did you setup portA? Show the code |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 30, 2004 5:10 pm |
|
|
Quote: | I was applying the power supply directly to A0 without any peripheral circuitry. The supply is capable if 1A, but it's not putting out that much and the PIC is not getting hot.
I suppose that I could place the 5V across something like a 1k resistor to ground and then take my PIC signal from the top of the resistor.
I'm a little more concerned about the channel interference at this point. What do you think I'm doing wrong there?? Or, are the problems related?? |
The fact that your bench power supply voltage drops in half,
when you connect it to an alleged analog pin, is a primary problem.
All other problems are secondary, until this one is solved.
It could be caused by:
1. The PIC pin is really configured as an output pin, and set low.
2. Your bench power supply has a control knob for the output
current level, and it's set to "almost nothing". (somehow)
3. Your bench power supply is defective.
4. Your alligator clip lead, which goes from the power supply to
your board, has a poor connection between the wire and one
of the clip leads, causing it to have a large resistance.
5. The PIC is defective.
6. You have acccidently picked the wrong pin as the AN0 input pin.
You're really connecting the power supply to the PIC's ground pin
(or some such problem).
It's got to be something basic, and something bad. It must be fixed
first. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri Jan 30, 2004 7:11 pm |
|
|
Kind of brings to mind current limiting power supplies. |
|
|
bauereri
Joined: 16 Jan 2004 Posts: 9
|
|
Posted: Wed Feb 04, 2004 7:05 pm |
|
|
Just to put a nice end to this thread.....
I installed a 1k pot in the circuit and took used the wiper signal for the analog input to the PIC. The problem persisted where as soon as I applied the wiper signal to the PIC, the signal would drop to below 2V as well as the 5V for the PIC itself. It appears as though I had a bad PIC because replacement of the part appears to have fixed the problem, for now....
Thanks to all for the suggestions. They were very helpfull.
Regards,
Eric |
|
|
|