PDA

View Full Version : 18F4520 A/D working weird



TurboLS
- 4th April 2005, 22:07
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.

NavMicroSystems
- 4th April 2005, 22:50
What do you mean by


... I have a clean nice looking analog signal on the oscilloscopeand what do you mean by

...as soon as I hook up the input to PORTA.0 ... the signal gets nasty

TurboLS
- 4th April 2005, 23:40
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

NavMicroSystems
- 5th April 2005, 13:06
TurboLS,

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

TurboLS
- 5th April 2005, 15:25
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/acrobat/en/digital/ccd/products/fullframe/KAF-0402ELongSpec.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.

TurboLS
- 6th April 2005, 21:52
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!

TurboLS
- 6th April 2005, 22:06
Is there any way to set PORTA.0 as a low impedance input???

NavMicroSystems
- 6th April 2005, 22:29
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?

TurboLS
- 7th April 2005, 04:56
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??

mister_e
- 7th April 2005, 05:30
opamp, transistors, mosfet, fet.... usually opamp

TurboLS
- 7th April 2005, 05:32
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.

mister_e
- 7th April 2005, 05:47
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

Warrier
- 7th April 2005, 12:59
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

Warrier
- 7th April 2005, 13:09
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

TurboLS
- 7th April 2005, 14:22
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.

TurboLS
- 8th April 2005, 03:51
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.

TurboLS
- 8th April 2005, 04:25
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.

TurboLS
- 11th April 2005, 23:32
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.