12 bit or higher ADC on a PIC that works with PBP?


Closed Thread
Results 1 to 9 of 9

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    As far as I can tell the 16F882 is 10-bit. I wouldn't think the 882 had 12-bit when the rest
    of the same family like 883, 884, 886 and 887 were all 10-bit.

    I've used the 18F2553 and 18F2523 12-bit A/D. Here's a short code example;
    Code:
    'CONFIG settings in 18F2553.INC
    'CONFIG PLLDIV=5,CPUDIV=OSC1_PLL2,USBDIV=2,FOSC=HS,FCMEN=OFF,IESO=OFF
    'CONFIG VREGEN=OFF,CCP2MX=ON,WDT=OFF,WDTPS=32768,PBADEN=OFF,PWRT=OFF,MCLRE=OFF
    'CONFIG LPT1OSC=OFF,BOR=ON,BORV=2,STVREN=ON,LVP=OFF,XINST=OFF,DEBUG=OFF,WRTB=ON
        
        DEFINE OSC 20
        DEFINE DEBUG_REG PORTC
        DEFINE DEBUG_BIT 6    ' Hardware USART TX pin
        DEFINE DEBUG_BAUD 9600
        DEFINE DEBUG_MODE 0   ' Non-inverted mode through MAX233
        
        ADResult VAR WORD
        
        Q CON 3126         ' (5/4095)*256=0.312576313. rounded up to 3126
        
        ADCON0 = %00000001 ' A/D module enabled, channel 0
        ADCON1 = %00001110 ' Vref = Vdd & Vss, AN0 = analog
        ADCON2 = %10101011 ' Right justified, 12 Tad, Frc clock
        INTCON = %01000000 ' Global ints disabled, enable peripheral interrupts
        PIE1.6=1           ' A/D interrupt enabled (for wake from sleep)
        
        ' Note we don't use an interrupt routine since the A/D complete
        ' interrupt is only waking the PIC from sleep.
        
    Main:
        ADCON0.1=1           ' Start the A/D conversion
        @ SLEEP              ' Sleep until A/D conversion finished
        WHILE ADCON0.1       ' A/D complete?
        WEND                 ' 
        PIR1.6=0             ' Clear A/D int flag
        
        ASM
         MOVFF ADRESL,_ADResult   ; get low byte
         MOVFF ADRESH,_ADResult+1 ; get high byte
        ENDASM
        
        DEBUG "Raw A/D val = ",DEC ADResult,13,10
        ADResult = ADResult */ Q
        DEBUG "ADResult */ ",DEC Q," = ",DEC ADRESULT,13,10
        DEBUG "ADResult = ",DEC ADResult DIG 4,".",DEC ADResult DIG 3,_
        DEC ADResult DIG 2,DEC ADResult DIG 1,"V",13,10
        PAUSE 2000
        GOTO Main
        
        END
    Regards,

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

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I have used the new 18F8723 with 12 bit A/D.

    To get the the full resolution, you have to use DEFINE

    "DEFINE ADC_BITS 10"

    Because PBP only "knows about" 8 and 10 bit converters.
    If the DEFINE is missing or not interpreted properly in the
    compiler, it will default to 8 bits.

    If you use the line above at the top of your program,
    and have a 12-bit converter in your chip, the result will
    indeed have a full 12 bits of resolution.
    Charles Linquist

Similar Threads

  1. decoding quadrature encoders
    By ice in forum mel PIC BASIC Pro
    Replies: 93
    Last Post: - 28th February 2017, 10:02
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 17:10
  3. Replies: 2
    Last Post: - 10th February 2006, 02:04
  4. PBP 16-bit ADC result math
    By sonic in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2005, 15:21
  5. Using PBP Hex Files with FED Pic Programmer
    By jrudd in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th February 2005, 11:57

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