16f688 Adc


Closed Thread
Results 1 to 5 of 5

Thread: 16f688 Adc

  1. #1
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73

    Unhappy 16f688 Adc

    Another issue regarding the 16F688.
    Setting up the 10-bit ADC I expected a 0 – 1023 range, what I got was 0 to 65472 !!?
    Of cause I made some kind of mistake here but nothing that is obvious to me. Also I have a problem with the right justify and getting the decimal point and scaling (Volts) correct. I have tried a few ways to solve it but I’m having trouble to understand the math. Can somebody explain how to do it correctly?

    Thanks guys!




    Code:
     
    
    OSCCON = %1110111           	'Use Internal OSC at 8MHz
    CMCON0 = %0000111          	'Comparators off
    TRISA =  %000100               	'PortA 0=output- 1=input
    TRISC =  %000000                	'PortC 0=output- 1=input
    ANSEL =  %0000100            	 '(Analog Select) 0=Digital 1=Analog
    
    V VAR WORD
    L VAR WORD
    T VAR WORD
    
    DEFINE ADC_BITS 10          	' 10-bits
    DEFINE ADC_CLOCK 3          	' rc
    DEFINE ADC_SAMPLEUS 50      	' Sample time uS
    
    ADCON0 = %00000001          	' ADC in operation
    ADCON1 = %11001000         	' rightadjust and Vref+
    
    GOSUB movelcd
    
    PAUSE 500
    
    loop:
    
    GOSUB readv
    
    PAUSE 50
    
    GOTO loop
    
    END
    
    '****************** - SUBS - ************************************
    MOVELCD:
    
    DEFINE LCD_DREG  PORTC          	'Data on PORTC PIN 10,9,8,7          
    DEFINE LCD_DBIT    0            	'Start bit for PORTC
    DEFINE LCD_RSREG PORTC          	'Register Select (RS) 
    DEFINE LCD_RSBIT   4            	'RS bit PORTC PIN 6
    DEFINE LCD_EREG  PORTC          	'Enable Port PORTC 
    DEFINE LCD_EBIT    5            	'E bit PORTC PIN 5
    DEFINE LCD_BITS    4            	'bitmode (4-bit)
    DEFINE LCD_LINES   2            	'number of lines (2)
    
    PAUSE 500
    
    RETURN
    '****************************************************************
    readv:
    
    ADCIN 2,V                       ' take reading
    
    T = V
                                         
    LCDOUT $FE,2,"ADC ", DEC T,"    "
    
    lCDOUT $FE,$C0,"DCV = ",DEC (V/100),".",dec2 V," "
    
    RETURN

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    Setting up the 10-bit ADC I expected a 0 – 1023 range, what I got was 0 to 65472 !!?
    That's from the ADFM bit. For 10-bit A/D, use ADCON0.7 = 1 ; right justify

    The math depends on what you're reading, but this might help ..
    http://www.picbasic.co.uk/forum/showthread.php?p=2010
    <br>
    DT

  3. #3
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Thumbs up

    Thanks Darrel!

    I changed the; ADCON0 = %00000001 to ADCON0 = %10000001, and it works!
    And yes, the link helped me do some math too, only; how can I get two decimals?

    Thanks again!

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    For 2 decimals, multiply by 500 instead of 50.

    Then this will display the value with 2 decimal places ...
    Code:
       LCDout $FE,2,"V= ",DEC Volts/100,".",DEC2 Volts//100," Vdc"
    DT

  5. #5
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73


    Did you find this post helpful? Yes | No

    Smile

    Thank you very much Darrel!

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 18:29
  3. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

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