18F4520 A/D working weird


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    TurboLS's Avatar
    TurboLS Guest

    Exclamation 18F4520 A/D working weird

    OK, I have a clean nice looking analog signal on the oscilloscope, but as soon as I hook up the input to PORTA.0 (to do an 8-bit A/D conversion) on the pic, the signal gets nasty. Is there a reason why it would be doing this?? I will post my code later on tonight. thanks a lot.

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    What do you mean by

    ... I have a clean nice looking analog signal on the oscilloscope
    and what do you mean by
    ...as soon as I hook up the input to PORTA.0 ... the signal gets nasty
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  3. #3
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    What I meant by clean analog signal is that I can distinguish parts of the signal that correspond to known timing signals (the signal is clocked out by TTL signals going into the chip). And when I hook up the analog signal to PORTA.0, I can no longer get good data. It's as if the PIC is loading the circuit down. My code is as follows:

    ' Connect analog input to (RA0)
    ' Connect clocks to PORTB
    ' PORTB.0 is the Reset Clock
    ' PORTB.1 is the Vphase1 clock
    ' PORTB.2 is the Vphase2 clock
    ' PORTB.3 is the Hphase1 clock
    ' PORTB.4 is the Hphase2 clock
    ' The reset will be connected to a HWPM clock pin #17, USE FEEDBACK WIRE!!
    ' Connect pin 2 from the DB9 connector to PORTC.6
    ' Have a +5V source ready to touch PORTA.2 to trigger clocking process

    include "modedefs.bas"

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    DEFINE OSC 20 ' Sets clock speed to 20Mhz

    ' Define HSEROUT parameters
    DEFINE HSER_TXSTA 24h ' High speed baud generator
    DEFINE HSER_BAUD 57600 ' 57600 baud rate

    ' Define HPWM parameters
    DEFINE HPWM1_TIMER 2
    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2 ' RC2

    TRISC.1 = 0 ' HPWM automatically does this for you, but just in case
    CCP1CON = %00001100 ' PWM mode

    HPWM 1,31,3205 ' RC2/CCP1 3.205kHz @ ~1/8% duty

    ' Define interrupt parameters
    INTCON2 = %01000000 ' External Interrupt on Rising Edge
    INTCON.7 = 0 ' Disables global interrupts
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001110 ' Set PORTA digital, except for bit 0
    TRISB = %00000001 ' Set PORTB to all output, except for bit 0
    Pause 500 ' Wait .5 second
    Pause 500 ' Wait .5 second

    horizpulse var byte
    vertpulse var byte
    adval var byte ' Create adval to store result

    horizpulse = 1 ' Initialize counters, initial states
    vertpulse = 1
    PORTB.1 = 0
    PORTB.2 = 0
    PORTB.3 = 1
    PORTB.4 = 0
    PORTB.5 = 0 ' LED off indicates that the camera is not transferring data

    buttonloop:
    IF PORTA.2 = 1 then
    PORTB.5 = 1
    GOTO vertloop
    else
    PORTB.5 = 0
    GOTO buttonloop ' Waits for 5V that signals shutter is closed
    ENDIF
    vertloop:
    horizpulse = 1
    PORTB.1 = 1
    PAUSEUS 312
    PORTB.1 = 0
    PORTB.2 = 1
    PAUSEUS 312
    PORTB.1 = 1
    PORTB.2 = 0
    PAUSEUS 312
    PORTB.1 = 0
    PAUSEUS 312
    vertpulse = vertpulse + 1
    IF vertpulse < 512 THEN
    GOTO horizloop
    ELSE
    PORTB.5 = 0
    GOTO buttonloop
    ENDIF
    horizloop:
    INTCON.1 = 0 ' Resets interrupt flag to 0
    Resetcheck: ' Loops back to make sure the PORTB.3 goes low and
    IF INTCON.1 = 0 THEN ' PORTB.4 goes high as close
    GOTO Resetcheck ' to the external trigger's rising edge as possible
    ENDIF
    PORTB.3 = 0
    PORTB.4 = 1
    PAUSEUS 156
    PORTB.4 = 0
    PORTB.3 = 1
    ADCIN 0, adval ' A/D 8 bit value from PORTA.0 into adval
    HSEROUT [adval] ' Output ASCII character rep of word serially to PC from C.6
    horizpulse = horizpulse + 1
    IF horizpulse < 796 THEN
    GOTO horizloop
    ELSE
    PAUSEUS 312
    GOTO vertloop
    ENDIF
    END

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    TurboLS,

    give us an idea what you "analog signal" looks like and where it is comming from.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  5. #5
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    The analog signal is coming from a sample and hold op amp that is sampling an analog video signal coming from a CCD chip. Please click on the following link and look at the Vout signal on page 13 of the PDF. That is the signal we are getting before we attach the PIC chip.

    http://www.kodak.com/global/plugins/...2ELongSpec.pdf

    Then when we attach it, the signal gets loaded down and all we get is noise in the A/D. thanks again for takin a look.

  6. #6
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Question

    I also tried putting the signal through a buffering op amp and that doesn't seem to help. For some reason, the A/D input of the PIC does not like the signal coming from output of the buffer, nor does it like the input of our sample and hold circuitry, nor the signal coming directly from the CCD. So we tried to amplify the signal before buffering it and the output just becomes noisy as hell with or without the PIC connected.

    HELP!

Similar Threads

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

Members who have read this thread : 0

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