PDA

View Full Version : ADCIN Problem



JavPar
- 16th December 2008, 16:40
Hello everyone,

I am using a PIC18F4620 to read voltages but I am having aproblem where if I read anything in between 0 or 5 volts, the voltages readings are erratic or oscillate. I have tried using resistors or capacitors on the ADCIN pin but nothing seems to work. I have been trying to solve these for weeks now I have done a lot of research but can't find anything that gives light to what the problem is. I am powering my project with a USB port.

I also noticed that if I disconnect the cable that goes to the ADCIN pin, I still get erratic numbers instead of reading 0. I have tried with code to get an average reading but this makes the code run slow.

Any help on this will be highly appreciated.

Following is an exctract of my code that am using separately to solve the problem with the ADCIN:

DEFINE LOADER_USED 1 'Bootloader Used
@ __CONFIG _CONFIG1H, _OSC_HS_1H
DEFINE OSC 8
' OSCCON=%01110000
Define ADC_BITS 10
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50
adval var word
TRISA = %11111111
ADCON1 = %00000010
ADCON2.7 = 1
'ADCON0 = %11000001
Pause 500
Serout2 PORTD.0,16468,[$1b, $2a, $ff]
loop:
ADCIN 1, adval
pause 50
Serout2 PORTB.7,16468,[dec adval] ' to PC
Serout2 PORTD.0,16468,[$fe, 1]
Serout2 PORTD.0,16468,[dec adval] ' to LCD
Goto loop
End

Javier.

Pic_User
- 16th December 2008, 17:08
Hi Javier,


Hello everyone,

I am using a PIC18F4620 to read voltages but I am having a problem where if I read anything in between 0 or 5 volts, the voltages readings are erratic or oscillate. I have tried using resistors or capacitors on the ADCIN pin but nothing seems to work. I have been trying to solve these for weeks now I have done a lot of research but can't find anything that gives light to what the problem is. I am powering my project with a USB port.

I also noticed that if I disconnect the cable that goes to the ADCIN pin, I still get erratic numbers instead of reading 0. I have tried with code to get an average reading but this makes the code run slow.

Any help on this will be highly appreciated. ....

Javier.

Don’t forget that the A/D module relies on an accurate, known, reference voltage, to compare to an unknown voltage. If your reference is your supply voltage then your supply voltage has to be rock solid. If you are switching loads attached to the supply / reference then the supply has to switch these loads without changing voltage.

You still can use A/D input filters but if the reference voltage is not stable your readings will reflect the variations.

Edited to add: Be sure your DEFINES are in Upper Case
-Adam-

JavPar
- 16th December 2008, 17:54
Hey Adam,

Thank you for your help. I am scratching my head over the reference voltage. From all the ADCIN samples I have seen, I haven't seen one that says anything about a reference voltage. Is this done by setting a register?
I am reading the datasheet right now to see if I find something about that. My defines are in capital letter in my program.

Javier.

JavPar
- 16th December 2008, 20:22
From the datasheet, I am using:

ADCON1 = %00001101

which specifyes that I am using the project's voltage internally from VDD and VSS for voltage reference. I also tried using external voltage for reference but I get the exact same results.

I tried putting a .1uF cap at the voltage in pin but no change.

I am going to tried with another sorce of 5v and not use the USB to see what happens.

Any suggestions will be appreciated.

Javier.

JavPar
- 16th December 2008, 20:47
I tried using a 5V power supply, but I still get the erratic voltage readings.

skimask
- 16th December 2008, 23:34
WHAT are you measuring and how have you got it connected?

Have you tried using a plain old meter?

What is this 5v power supply you speak of? A wall-plug type supply? Benchtop supply?

How much other stuff do you have connected to your '4620?

How about posting a bit of a schematic...

JavPar
- 17th December 2008, 04:25
I have made a separate project just to clean it. I am reading voltage from the project or voltage from a ac/dc wall power supply sending 3V. Also I have tried reading a angular rate sensor and last tried reading nothing and still get erratic readings.

I use a digital multimeter to read the voltages and the readings are 100% stable on the meter.

For supply I have been using the 5 volts from my PC's USB port. I also tried using a wall-plug type supply suppliying 5V.

I cleaned my project so now I only have an LCD, a 4.7K resistor at pin 1 MCLR/VPP, on/off switch, reset button, 8 Mhz crystal with two 15pF from the crystal to ground.

Even with the new clean project, I still get erratic readings.

This is crazy. Will continue trying tomorrow. Thanks for your help.

mackrackit
- 17th December 2008, 09:48
Try adding an LED and make it blink at a steady rate. Give the PIC a heart beat.

Does the LED blink as expected?

Also try the ADC at 8 bit resolution.

Let us know what happens.

When you tried a capacitor on the ADC, did you have it from the ADC pin to ground? Was the value at leat 1uf ? l use 22uf myself.

Like skimask said, post a schematic. A picture of you setup might help too.

JavPar
- 18th December 2008, 05:17
Hi guys, arriving late from work. I loaded a little schematic I hope is clear. On my project I have 4 LEDs. On this clean one I will use one. Will try 8 bits. I have used caps .1uF and 10uF connected to GND.

Let you know tomorrow about the 8 bits.

Javier.

Archangel
- 18th December 2008, 05:31
I would suggest bypass caps on the Vcc / Vss and a choke in series with the adcin line to kill off any RF which might affect your circuit. I would ask if you are working near RF sources like Fluorescent lights, microwave ovens, televisions etc . . .

skimask
- 18th December 2008, 11:43
Hi guys, arriving late from work. I loaded a little schematic I hope is clear. On my project I have 4 LEDs. On this clean one I will use one. Will try 8 bits. I have used caps .1uF and 10uF connected to GND.

Let you know tomorrow about the 8 bits.

Javier.

From the picture...
There's a Vdd and Vss on each side of the PIC, 11-12 and 31-32. I only see one of each hooked up. I don't see any cap's across Vdd and Vss on each side.

ardhuru
- 19th December 2008, 06:18
When you tried a capacitor on the ADC, did you have it from the ADC pin to ground? Was the value at leat 1uf ? l use 22uf myself.



I'd second that; except, I use 0.1uf, with a 100K resistor in parallel with the capacitor.

Regards,

Anand

JavPar
- 21st December 2008, 02:17
Ok guys,

1.) Changed to 8 bits.

2.) Put caps 1uF on each side of the pic on the Vdd and Vss.

3.) No microwaves, no TVs, no fluorescent lights close to my project. I scanned my desk for any possible interferences but there is nothing.

4.) Put a .1 uF parallel with a 100K resistor at the ADCIN pin. Tried with different caps.

5.) Added a LED and it blinks ok. Do not see any skips or changes on the blinking rate.

6.) The only thing is that I could not find RF chokes locally (I'm in Panama Central America). I put a ferrite on the cable to the ADCIN pin just in case.

All of the above and problem still persists. I have not seen a single change on the way the erratic readins of voltage behave. I tried to see if there is a pattern to the erratic readings but can not see one.

Is this problem with erratic voltage readings something usual or rare? I have continued searching the web and I don'yt see anything that really talks about this.

Could this be a problem with the PIC18F4620? Or maybe I should not be using a breadboard?

Javier.

ardhuru
- 21st December 2008, 05:23
With what you describe, I feel certain the issue is not of hardware. I have used the ADC on a breadboard, with a far cruder supply (no RF chokes/filters) without a problem.

I have never used a PIC18F4620, though. Which is why I suspect perhaps its to do with some settings specific to that chip.

Could you temporarily replicate that with another PIC, say a 16F877?

JavPar
- 21st December 2008, 05:44
Unfortunatelly, I only have the 4620. I can not find pics locally. I am already looking to order more different pics from the states.

skimask
- 21st December 2008, 06:16
How erratic are the readings? Could you post a 'stream' of the readings?

ardhuru
- 21st December 2008, 08:47
Just to rule out the basics, if you ground the input, do you get a consistent '0'? and connect it to +5, do you get a consistent '255'?

skimask
- 21st December 2008, 09:58
Just to rule out the basics, if you ground the input, do you get a consistent '0'? and connect it to +5, do you get a consistent '255'?

Or a consistent 1023... :)

Acetronics2
- 21st December 2008, 10:16
Hi,

I didn't see the " CMCON = 7 " ... Default value ... yes, but, just to be sure of .

Also, did you try to tie RA.0 to ground or to RA1 ... it makes a superb noise input, as left floating !
Note unused portA pins should be tied to ground through 10 k resistors ...

- or use RA.0 as input !!! and other RA pins as outputs, if unused.

Alain

ardhuru
- 21st December 2008, 11:59
Or a consistent 1023... :)

ADC set to 8 bits, remember? :)

skimask
- 21st December 2008, 20:19
ADC set to 8 bits, remember? :)

Which way are those 8 bits justified? Left? Right? Inverted?

JavPar
- 21st December 2008, 20:36
Test results:

1.) Didn't see any change when changed to 8 bits, so I'm back to using 10 bits.

2.) I edited my code so only RA0 is being used for input analog.

3.) When connect ADCIN pin to any GND on the project, I get steady 0V readings. When connect pin to 5V I get erratic 5V readings BUT, noticed that when connect pin to 5V before my on/off switch, then I get 5V steady. Noticed also that when connected to 5V before on/off switch, this makes the PIC kind of work because my green LED connected to PORTD.2 starts to blinks like if my project is running but LCD stays off. Nothing happends when connect ADCIN pin to 5V after on/off switch. Removed the on/off switch, 5V voltage readings are erratic anywhere in the project.

4.) Erratic readings are less npticeable when in 5V ranging from 1020 to 1023. When connect an angular sensor for example I get ranges from 480s to 540s aproximately. Other things I have connect ot ADCIN pin are a 1.5V battery and a 3V wall ac/dc adapter. I get erratic readings from both also.

DEFINE LOADER_USED 1 'Bootloader Used
@ __CONFIG _CONFIG1H, _OSC_HS_1H
DEFINE OSC 8
Define ADC_BITS 10
Define ADC_CLOCK 3
Define ADC_SAMPLEUS 50
adval var word
TRISA = %00000001
ADCON0 = %00000001
ADCON1 = %00001110
'ADCON2.7 = 1
ADCON2 = %10001011
CVRCON.4 = 0
'CMCON = 7
Pause 1000
Serout2 PORTD.0,16468,[$1b, $2a, $ff]
loop:
HIGH PORTD.2
ADCIN 0, adval
pause 50
Serout2 PORTB.7,16468,[dec adval] ' to PC
Serout2 PORTD.0,16468,[$fe, 1]
Serout2 PORTD.0,16468,[dec adval] ' to LCD
LOW PORTD.2
pause 50
Goto loop
End

Archangel
- 21st December 2008, 21:13
Try this setting . . .


ADCON1 = %00001101 ' VREF off A.0 & A.1 as analog
ADCON2.7 = 1 ' Right justified
ADCON0.2 = 1 ' Channel 1 enabled
ADCON0.1 = 1 ' A/D conversion in process
ADCON0.0 = 1 ' A/D Module Enabled
. . . If I read it right . . .
Edit: you posted while I was working on mine . . .

JavPar
- 21st December 2008, 22:58
I tried:

ADCON0 = %00000011

as I am using AN0 pin for input now, no change.

Archangel
- 22nd December 2008, 07:19
I am using AN0 pin for input now, no change.
Somehow I missed the change from AN1to AN0.

Acetronics2
- 22nd December 2008, 09:55
Hi, JavPar

Could you Post your HEX code ???

Purpose is to verify the config real settings ....

Alain

JavPar
- 26th December 2008, 02:50
Hey Alain,

Noticed I can't attach my hex file. It is very long to copy paste here.

Javier.

mackrackit
- 26th December 2008, 08:12
Hey Alain,

Noticed I can't attach my hex file. It is very long to copy paste here.

Javier.
Rename the file to have '.txt' on the end.

JavPar
- 26th December 2008, 14:14
Attached my hex file.

Javier.

mackrackit
- 28th December 2008, 13:04
This is what I get for your configs.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=3071&stc=1&d=1230468909">

Acetronics2
- 28th December 2008, 13:32
Ok guys,

1.) Changed to 8 bits.

2.) Put caps 1uF on each side of the pic on the Vdd and Vss.

3.) No microwaves, no TVs, no fluorescent lights close to my project. I scanned my desk for any possible interferences but there is nothing.

4.) Put a .1 uF parallel with a 100K resistor at the ADCIN pin. Tried with different caps.

5.) Added a LED and it blinks ok. Do not see any skips or changes on the blinking rate.

6.) The only thing is that I could not find RF chokes locally (I'm in Panama Central America). I put a ferrite on the cable to the ADCIN pin just in case.

All of the above and problem still persists. I have not seen a single change on the way the erratic readins of voltage behave. I tried to see if there is a pattern to the erratic readings but can not see one.

Is this problem with erratic voltage readings something usual or rare? I have continued searching the web and I don'yt see anything that really talks about this.

Could this be a problem with the PIC18F4620? Or maybe I should not be using a breadboard?

Javier.

Hi, Javier

Nothing about config.

BUT Your supply filtering looks to me a bit weak ... ( USB voltage stability ... ahem !!! )

I have a board with '452 and another with '2520 ... 220µF at the card pow. input + 10 µF Tantalum + 0.1µF ( closest as possible from PIC pins ).

see scheme attached.

Some capacitor tank ( > 10µF Tant.) close to your LCD could be useful too ...

Alain

JavPar
- 29th December 2008, 04:17
Hey guys I really appreciate your help. Alain, that schematic that you posted has made me think. I used my multimeter to test input voltage right at AN0 pin and the voltage is steady at 2.432 with the last gidit sometimes changing to 1.

I also noticed that measuring voltage in the output pin to my LCD I get oscillating 123mV to 127mV. That makes me think that possibly my PIC is doing something during the A/D convertion that it is outputting oscillating readings? The oscillating readings go out not only to my LCD pin but also to my PC pin.

Alektric
- 19th January 2009, 12:27
Had a similar problem my self - turned out to be the inverter for my LCDs backlight. My voltmeter gave no indication of any fluctuations.

JavPar
- 20th January 2009, 03:36
Alektric, I removed the LCD from the project and still the problem persists.