PDA

View Full Version : Continueous ADC scanning using DT interupts



comwarrior
- 16th March 2010, 22:03
18F4550
ok, i have 6 analogue inputs i want to continuously scan.

What i thought of doing was to 'manually' kick off ADC's and using a DT interrupt to grab the result and set the next one...
That way the CPU can be doing math with the 'previous' values and displaying info on an LCD and scanning a keypad.

I'm just a little confused by the manuals explanation

The following steps should be followed to perform an
A/D conversion:
1. Configure the A/D module:
• Configure analog pins, voltage reference and digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D acquisition time (ADCON2)
• Select A/D conversion clock (ADCON2)
• Turn on A/D module (ADCON0)

2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit

3. Wait the required acquisition time (if required).

4. Start conversion:
• Set GO/DONE bit (ADCON0 register)

step 3, wait of the acquisition... i don't get what I'm supposed to wait for and why? and yes i read the section for AD conversion, twice at-least...

Last time i manually wrote a program to set-up, start and collect results from an ADC was with a Z80... [shakes head] 'it hurts, make it stop!' :eek:

Any help appreciated...

mackrackit
- 16th March 2010, 22:47
The registers are just a bit different in this example but if you read through it things should become clearer. If not we will see you later:)
http://rentron.com/PICX2.htm

comwarrior
- 16th March 2010, 23:19
ok, tells me how to do it, which i did already work out but doesn't answer my question...

What is the acquisition time and why do we have to wait?
And also, it says if required, so how do you know if it is required?

comwarrior
- 16th March 2010, 23:24
i've just spotted this bit...

Figure 21-5 shows the operation of the A/D converter
after the GO/DONE bit has been set, the
ACQT2:ACQT0 bits are set to ‘010’ and selecting a
4 TAD acquisition time before the conversion starts.

Which indicates that the program doesn't need to execute a wait before 'hitting go'...

mackrackit
- 16th March 2010, 23:35
And later it tells you this


After the A/D conversion is completed or aborted, a
2 TAD wait is required before the next acquisition can be
started. After this wait, acquisition on the selected
channel is automatically started.
Look at Figure 21-1, all of the ANX's go to the same converter. Needs a little time between reads...

comwarrior
- 16th March 2010, 23:45
I must be awake now because it's starting to make sense...
I hadn't spotted the bit that allows manual acquisition... but in normal mode will do the acquisition automatically before the conversion.
And that's what was confusing me...

[shakes head] seems obvious now...

Thanks for the help

JohnMacklo
- 27th March 2010, 22:18
Try to do this. I have been used this for a while, and it works fine for my purposes.

Loop:
gosub LeeEntradaAnalogica ' calls to subroutine LeeEntradaAnalogica".
goto Lazo
end



LeeEntradaAnalogica:
Auxiliar = 0
For J1 = 0 To 9
ADCIN H2, Auxiliar ' Guarda el valor del canal analσgico en la variable "Auxiliar"
AnlgInput[H2] = AnlgInput[H2] + Auxiliar
for J2 = 0 to 50
pause 1
next J2
Next J1
AnlgInput[H2] = (AnlgInput[H2] /10) ' Divide el valor de Canal[H2] entre 10 para obtener un promedio.
If AnlgInput[H2] < 0 Then ' Si el valor obtenido es menor que 0.
AnlgInput[H2] = 0 ' significa que el valor leido en el canal no es real.
EndIf
If AnlgInput[H2] > 1023 Then ' Si el valor obtenido es mayor que 1023.
AnlgInput[H2] = 1023 ' significa que el valor leido en el canal no es real.
EndIf
Return

I think the comments don't matter. sorry but I think in spanish.
By the way, this piece of code is embedded in a program that uses DT interrupts. Darrel Taylor Rules!