Continueous ADC scanning using DT interupts


Closed Thread
Results 1 to 7 of 7
  1. #1

    Question Continueous ADC scanning using DT interupts

    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!'

    Any help appreciated...

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    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?

  4. #4


    Did you find this post helpful? Yes | No

    Default

    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'...

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    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...
    Dave
    Always wear safety glasses while programming.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    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

  7. #7
    JohnMacklo's Avatar
    JohnMacklo Guest


    Did you find this post helpful? Yes | No

    Default

    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!

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