A/D Problems!


Closed Thread
Results 1 to 5 of 5

Thread: A/D Problems!

  1. #1
    Join Date
    Mar 2005
    Posts
    37

    Default A/D Problems!

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    let's review it together you declared..
    Code:
    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?
    Last edited by mister_e; - 20th May 2006 at 10:25.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Mar 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Mar 2005
    Posts
    37


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Perfect occasion to move your A/D input to another and use the internal comparator to detect it.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. A/D problems
    By Roddy Wayne in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th June 2009, 03:57
  2. 12f675 A/d Miseries
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 16th December 2008, 03:16
  3. 12F675 A/D and GPIO sleep interrupt
    By macinug in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th September 2008, 15:39
  4. Need advice on A/D
    By james in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th August 2007, 20:30
  5. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 19:57

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts