Results 1 to 5 of 5

Thread: DEFINE ADC_xxx & ADCIN

  1. #1

    DEFINE ADC_xxx & ADCIN

    In using the command ADCIN, there are obviously other registers that must be set to make the A/D work and do it correctly. There are also the Define's for the A/D, which are the: 1) DEFINE ADC_BITS, 2) DEFINE ADC_CLOCK, and 3) DEFINE ADC_SAMPLEUS.
    For configuring the A/D's the other registers that must be set are the TRISx, ADCON1, ADCON2.
    I am using a PIC18F87K22 device.
    All these seems straight forward except for DEFINE ADC_CLOCK, this is part of the ADCON1 register (bits 7-6), so it seems if you are setting all parameters for the ADCON1( Voltage References, etc), you would not not use the DEFINE ADC_CLOCK, so my questions is what is the purpose of the DEFINE ADC_CLOCK since it only partial sets the register ADCON1 or are there other Defines for eh A/D's that set all parameters when using the ADCIN command. Also are there any DEFINES that are required to make the ADCIN command work, which I assume is only the DEFINE ADC_BITS.

    Thanks for any insights,
    Terry

  2. #2
    Terry, Leaving the ADC_CLOCK value set to a value of 3 should work for all oscillator frequency's between 1 and 64 Mhz. a value of 3 selects an internal RC timing network. If you would like to increase the A/D sampling period you should look up the appropriate value within the data sheet for the processor you are using and the clock frequency. 1 to 2 uS. is optimum. I believe the default for DEFINE ADC_CLOCK is 3.

    Dave Purola,
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Dave,
    Thanks for the response, my questions is trying to philosophically understand the differences between using the ADC Defines versus just setting ADC registers directly (ADCON1, ADCON2) when using the PIC ADCIN command and/or which ADC Defines are required by the ADCIN command. So rather than using the Define ADC_Clock, just set the clock with the ADCON1 register since the voltages reference must be set with the ADCON1 register.

    Terry

  4. #4
    Terry, I have NEVER used the ADCIN command. I have always used the A/D directly as such:

    '*********************************************************************
    READAD: 'READ SYSTEM A/D VOLTAGES (AVERAGE 8 READINGS) 18F67K22
    '*********************************************************************
    ADCON0 = $01 | (ADCHANNEL << 2) ' Set A/D to Channel X, On
    PAUSEUS 10
    ADCON0.1 = ON_ ' START CONVERSION
    WHILE ADCON0.1 = ON_ 'WAIT FOR A/D TO FINISH
    WEND
    AV_VOLTS(ADCHANNEL) = ((ADRESH << 8) + ADRESL) 'BUILD SENSOR WORD (RIGHT JUSTIFIED)
    return

    I have often gathered multiple readings and then did an average on a per channel basis similar to this:


    ADSCRATCH2 = 0 'CLEAR ACCUMULATOR
    ADCON0 = $01 | (ADCHANNEL << 2) ' Set A/D to Channel X, On
    PAUSEUS 10
    ADPOINTER = (ADSAMPLES - 1) 'SETUP FOR 8 READINGS
    '------------ TAKE 8 READINGS OF CHANNEL --------------------------------
    NXTSAMPLE:
    ADCON0.1 = ON_ ' START CONVERSION
    WHILE ADCON0.1 = ON_ 'WAIT FOR A/D TO FINISH
    WEND
    ADSCRATCH2 = ADSCRATCH2 + ((ADRESH << 8) + ADRESL) 'BUILD SENSOR WORD (RIGHT JUSTIFIED)
    ADPOINTER = ADPOINTER - 1 'DECREMENT INDEX
    IF ADPOINTER.7 = 0 THEN NXTSAMPLE
    AV_VOLTS(ADCHANNEL) = ADSCRATCH2 >> 3 'TURN BACK TO 12 BIT RESULT
    RETURN

    Dave Purola,
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Terry,
    The DEFINE ADC_CLOCK 3 simply instructs the compiler to generate code for setting the ADCS bits in ADCON2 (for the 18F87K22). If you want you can generate that code yourself (ie set the register manually), it makes no difference).

    DEFINE ADC_BITS and DEFINE ADC_SAMPLEUS does nothing to the registers, they're basically directives for how the compiler should generate code for the ADCIN command. Ie how many bits of the actual conversion result it should return to the user and how long the delay between switching channels should be (this is not setting ACQT bits).

    /Henrik.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •