ADC PIC18F2431 or PIC18F4431


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

    Default ADC PIC18F2431 or PIC18F4431

    I have been trying to figure out how to use the
    ADCIN command with the PIC18F2431 or PIC18F4431.

    My problem is using more than one channel. I can get AN0
    to work or AN1. But not togeather. It may be that the results are stored
    in the fifo, which ADCIN does not address?

    If anybody knows how to use the ADC in these chips. With or without adcin and
    can share that would be great.

    I just want to read some pots on AN0 and AN1, nothing fast.

    Thanks
    Mark

    code
    '************************************************* ***************
    '* Name : ADC TEST PIC18F2331 - 4431 *
    '* HIGH SPEED ADC AND PBP *
    '* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
    '* : All Rights Reserved *
    '* Date : 8/24/2010 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************

    DEFINE OSC 20

    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS

    DEFINE LCD_DREG PORTD '
    DEFINE LCD_DBIT 0 ' STARTING BIT LCD PORTD.0 TO PD.3
    DEFINE LCD_RSREG PORTD ' PORTD RS REGISTER
    DEFINE LCD_RSBIT 4 ' LCD RESET PORTD.4
    DEFINE LCD_EREG PORTD ' PORTD E REGISTER
    DEFINE LCD_EBIT 5 ' LCD ENABLE PORTD.5
    DEFINE LCD_BITS 4 ' 4 BIT INPUT VS 8 BIT
    DEFINE LCD_LINES 4 ' LCD DISPLAY LINES


    TRISA =%00011111
    LATA =%00000000
    TRISB =%00001111
    LATB =%00000000
    TRISC =%00000001
    LATC =%00000000
    TRISD =%00000000
    LATD =%00000000
    TRISE =%00000010

    'AD REGISTERS
    ADCON0 = %00000001 'AD ENABLED
    ADCON1 = %00010000 'VREF = RAILS,FIFO
    ADCON2 = %00111001 'LEFT JUSTIFIED, 16 TAD, FOSC/8
    ADCON3 = %11000000 'AD INTERUPTS & TRIGGERS DISABLED
    ADCHS = %00000000 ' ENABLED CH AN0,AN1,AN2,AN3
    ANSEL0 = %00000011 'Select Analog channels AN0:AN2
    ANSEL1 = %00000000 'Not used with PIC18F2331, 2431
    'ADPNT ????????????? NEED TO POINT PROPER FIFO REG FOR RESULTS???

    ADC_AN0 var word
    ADC_AN1 var word

    MAIN:
    PORTE.0 = 1
    ADCIN 0,ADC_AN0
    ADCIN 1,ADC_AN1
    PAUSE 200
    PORTE.0 = 0
    '4X20 LCD DISPLAY AD RESULTS AN0, AN1
    LCDOUT $FE, $80, "PIC18F2431 ADC TEST "
    LCDOUT $FE, $C0, "AN0 ",DEC4 ADC_AN0," "
    LCDOUT $FE, $94, "AN1 ",DEC4 ADC_AN1," "
    LCDOUT $FE, $d4, " "
    PAUSE 200
    GOTO MAIN

    END
    /code

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,613


    Did you find this post helpful? Yes | No

    Default

    Hi, Mark

    I do not think PBP can directly do what you are expecting ...

    you should have a closer read of the ADC chapter of your datasheet and , after , drive the relevant registers ...
    that are somewhat more numerous than those driven by a classical Adcin PBP command.

    You'll also note there are fixed input groups, and Channel 0 + Channel 1 is not a valid group ...

    PBP doesn't do everything for you, in short terms ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Mark

    I do not think PBP can directly do what you are expecting ...

    you should have a closer read of the ADC chapter of your datasheet and , after , drive the relevant registers ...
    that are somewhat more numerous than those driven by a classical Adcin PBP command.

    You'll also note there are fixed input groups, and Channel 0 + Channel 1 is not a valid group ...

    PBP doesn't do everything for you, in short terms ...

    Alain
    Hi Alain,

    Thanks for your reply. Yes I concluded last night that adcin would not work, but was
    hoping otherwise!
    Most likely will need a routine to set the group, channel, GO/DONE and store results on each read.

    Regards
    Mark

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Here's one example of A/D with this series. http://www.picbasic.co.uk/forum/showthread.php?t=6768
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    Here's one example of A/D with this series. http://www.picbasic.co.uk/forum/showthread.php?t=6768
    Thanks Bruce!

    Perfect

    I searched the forum for pic18f4431, not pic18f4331

    Regards

  6. #6
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Cool

    Today I trapped into the same hole...

    ADCIN doesn't work on a PIC18Fxx31.

    I have just written some code to read AN0..AN7 on devices who have this inputs.

    Init-Part:
    Code:
        ;ADC
        ADON=true:ADCON2=%11101101                      ;FOSC/16 AN0-AN4=analog right-justified, 40xTAD Sample
        ANSEL0=%00011111
    Inside Main-Code:
    Code:
            ;ADC-Zyklus
            ;messen, umrechnen und gewichtet mitteln
            ;CtADC contains the ADC-channel
            ADCHS=0:If CtADC.2 Then ADCHS=%01010101     ;Channel-Select
            ADCON0.3=CtADC.1:ADCON0.2=CtADC.0
            GO=true:Repeat:Until !GO                    ;ADC starten
            DummyW.Highbyte=ADRESH:DummyW.Lowbyte=ADRESL
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

Members who have read this thread : 1

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