PDA

View Full Version : A/D Problems!



scottl
- 20th May 2006, 02:14
I have the following:

PIC12F675
GPIO.5 for Analog input
GPIO.4 for reset to my transceiver
internal OSC 4Mhz

I run my code and everything seems to be fine. I turn the power off then try again and get flunctuation in my analog samples. I get random numbers! I use my scope and meter to see what the sensor is supplying to the GPIO.5 input and it seems to be a stable output. The PIC and the sensor is within 0.25" from one another. I have tried both the Vref and VDD with the same results.

If someone can look at the following code to see if I have missed anything. Sometimes you get to close and never see the simple stuff.

Do I need to place the following in my code:
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS

[code]

@ device pic12F675,intrc_osc,wdt_off,pwrt_off,protect_off,M CLR_off
INCLUDE "modedefs.bas"

dEFINE OSC 4 ' We're using a 4 MHz oscillator
DEFINE OSCCAL_1k 1 ' DEFINE OSCCAL FOR PIC12C671 or PIC12F675
adval VAR WORD 'Create adval to store result

sample VAR BYTE ' Holds number of samples to take
samples VAR WORD ' Multiple A/D sample accumulator
samples = 0 ' Clear samples accumulator on power-up

ANSEL = %00110001 ' Set ADC clock to Frc and GP0 & GP1 to analog mode
ADCON0 = %10000001 ' Configure and turn on A/D Module:
' Right justify result

High GPIO.4 ' Cycle reset pin for transceiver
pause 5
low GPIO.4
pause 500

loop:
for sample = 1 to 20
ADCON0.1 = 1
notdone:
if ADCON0.1 = 1 then notdone
adval.highbyte = ADRESH
adval.lowbyte = ADRESL
samples = samples + adval
next sample
adval = samples/20

SerOut2 GPIO.5,84, ["+", DEC adval,13,10]

samples = 0 ' Reset samples to 0 for next sampling routine
Pause 1000 ' Wait 2 seconds
GoTo loop ' Do it forever start over at loop
end

[code]

Thanks again Scott

mister_e
- 20th May 2006, 09:16
let's review it together you declared..

ANSEL = %00110001
There you set correctly the FRC as ADCS BUT you set only GPIO.0(ANS0) as analog. If this is what you want... it's not what you said

GPIO.5 for Analog input
.
.
.
.
' Set ADC clock to Frc and GP0 & GP1 to analog mode

So if you want to use ANS0 (GPIO.0) as analog input for your ADC, you should also disable the analog comparator multiplexed on GPIO<1:0>
CMCON=7

Later you set ADCON0=%10000001 which says correctly you want to read from ANS0.

That must be it... or a part of. Personnaly i'll enable the POWER-UP timer to keep boot settle time safe.

Depending of your hardware, you can also try to use a slower ClockSource and or adding a little pause after the Go/Done bit test.

Where your signal come from?
Is it met the maximum impedance of the A/D as stated in the datasheet?

scottl
- 20th May 2006, 14:09
I should take the time and read what I post! I am down to the last part of the project and now this. I have 4 units working perfectly in the field without any problems.

ANSEL = %00110001 is correct I need GPIO.0 not GPIO.5.

I am interfacing with an AD595 to read a thermocouple the output is 10mv/c. I measure the voltage at the sensor output and at the PIC input GPIO.0 and am getting the same 214mv.

Thanks for the reply,

Scott

scottl
- 20th May 2006, 14:52
I think I found the problem! I have changed the battery used for the sensor from a 3.6V to a 3.8V Lithium-ion. I use a 5V charge pump to power the AD595 and the PIC12. The Charge Pump must have its SKIP pin high for voltages greater than 3.6V. Once jumpered to positive terminal of my battery everything seems to be working well.

I will allow the PIC12 to handle this in the future for when the battery falls below the 3.6V threshold.

I will keep everyone posted!

Scott

mister_e
- 20th May 2006, 15:49
Perfect occasion to move your A/D input to another and use the internal comparator to detect it.