18F4520 A/D working weird


Closed Thread
Results 1 to 18 of 18
  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!

  7. #7
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Question

    Is there any way to set PORTA.0 as a low impedance input???

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


    Did you find this post helpful? Yes | No

    Default

    we tried to amplify the signal before buffering it and the output just becomes noisy as hell with or without the PIC connected.
    So it's not a PIC problem, it's more a problem with the output of your sensor.

    Is there any way to set PORTA.0 as a low impedance input???
    With external hardware.


    It's still not really clear to me what you are trying to achieve.

    What does the timing of the analog signal look like?
    regards

    Ralph

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



  9. #9
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    I would post the picture from that PDF file if I could. But the signal I get before the PIC is just like the one on page 13 labeled "Vout" and it is in phase with the horizontal clocks and the reset clock in that same corner of the page. I figured that putting the signal through a buffer would take care of the low impedance issue, but it doesn't. What external hardware would you recommend for lowering the impedance??

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


    Did you find this post helpful? Yes | No

    Default

    opamp, transistors, mosfet, fet.... usually opamp
    Steve

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

  11. #11
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    that's what i figured, but i tried an LF411 and an LM741 and it doesn't seem to make a difference at the input to the PIC.

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


    Did you find this post helpful? Yes | No

    Default

    depending wich configuration you have play with... did you use a simple buffer circuit (inverted input => to the output)?

    what is the actual frequency of this signal???

    Personnaly, for that kind of signal, i'll prefer to use multiple external or internal voltage comparators instead. Faster than a/d IMO
    Last edited by mister_e; - 7th April 2005 at 06:01.
    Steve

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

  13. #13
    Warrier's Avatar
    Warrier Guest


    Did you find this post helpful? Yes | No

    Default A/D on 18F4520

    Well, may be I am all wrong but here is what I see as some fundamental problems!

    The Kodak chip is outputting video signal at a typical frequency of 4MHZ and this is before any anti-aliasing filter which means high edge transitions from the CCD.

    Even at 20MHz, A/D acquisition time is about 2.4usec - refer to data on page 230-231. This is defined by the internal S/H cap =20pF and the sampling switch impedance. You haven't given the settings for ADCON2?

    You are trying to use LF411 or LM741 - these op amps CANNOT handle the signal bandwidth as they will slew rate limit the signal with heavy distortion. But this is academic as you cannot sample the input signal adequately (remember Nyquist) with a Tacq=2usec and even with a minimum Tad =2.

    So unless your read out clock is slowed down so that CCD analog output is limited to around 400kHz, I think you are out of luck with the PIC. They don't have video bandwidth ADC.

    As Ralph and Steve are trying to figure out from your posting, there is really no info on signal amplitude and shape! Oscilloscope can obviously show these waveforms as it has adequate input bandwidth. Hence my discouraging input..... Anyway, please read datasheet Section 19 and you will get a better idea of how the ADC is configured.

    -warrier

  14. #14
    Warrier's Avatar
    Warrier Guest


    Did you find this post helpful? Yes | No

    Default ADC acting up...

    Oh, I forgot to mention another point. LF411 or LM741 CANNOT be used with single rail supply unless you bias the input up half way and ac couple the input....Then you are going to lose dynamic range (video signal is referenced to zero so you need balck level clamping).

    If you are using the 741/411 with 0-5volt supply then your output will be "stuck" high or low depending on input and no signal will be seen at the output of the buffer!

    - warrier

  15. #15
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    First of all about the frequency, this CCD is being run very slow... approximately 3.6kHz and as such, the frequency of the vout signal is also 3.6khz.

    I will definitely take a look at the adcon 2 register to see if maybe that will fix the problem.

    We were using a simple buffer with a negative feedback loop and powered with positive 18V and negative 18V.

    I also read in the manual that the maximum input impedance for an analog signal is 2.5kohms. Does anyone know what the minimum or recommended impedance is>?

    Thanks for everyone's help. Hopefully I can figure out a way to get the PIC to work with this setup.
    Last edited by TurboLS; - 7th April 2005 at 15:35.

  16. #16
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    Well, I slope coupled the input with a 1200pF cap and a 10k resistor and if go directly from that into a non-inverting x10 opamp circuit and then to the PIC, I can actually see a signal. As of yet, all I can get is noise on the A/D tho, so it may just be that I have to change the point at which I do the A/D operation in the software. I will be trying a combination of circuits with the slope coupler, amplifier, buffer, and sampling opamp circuitry.

    Also, since I am running the chip so slow, I don't think the slew rate nor the ADCON2 register would be a problem.

  17. #17
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default

    also, do i expressly need the following line in my code?

    ADCON0.0 = 1 ' enable a/d

    Cuz I can do A/D without it, but I was just wondering if it might have been a config error. thanks.

  18. #18
    TurboLS's Avatar
    TurboLS Guest


    Did you find this post helpful? Yes | No

    Default Best way to measure input impedance on a PIC?

    I am pretty sure I just measure the impedance in parallel, but how do I do that (on the PORTA.0 A/D channel) with the PIC? thanks.

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