need help with adc


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    houa's Avatar
    houa Guest

    Default need help with adc

    new to using pbp language

    using pic18f452
    using port A to do conversion
    using strain guage sensor
    lcd on port b
    keypad on port c

    question:
    need help writing code to do adc for strain guage sensor
    to output weight on the lcd

    strain guage conditioned to 0-5v
    weight desired 0-300 or 0-400lbs

    any help would be greatly appreciated
    sorry i don't really know the processes for writing threads yet since i am new
    thanks for any help

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Code:
        DEFINE  OSC 4               ' Set Xtal Frequency
        DEFINE  ADC_BITS 10         ' Set resolution of conversion
        DEFINE  ADC_CLOCK 8         ' Set clock source (x/FOSC or FRC)
        DEFINE  ADC_SAMPLEUS 50     ' Set sampling time (in uS)
    
        ADFM    var     ADCON1.7    ' ADC result format select bit
        PCFG3   var     ADCON1.3    ' ADC port configuration bit
        PCFG2   var     ADCON1.2    ' ADC port configuration bit
        PCFG1   var     ADCON1.1    ' ADC port configuration bit
        PCFG0   var     ADCON1.0    ' ADC port configuration bit
    
        PCFG0 = 0                   ' Configure AN0 as analogue input, others digital 
        PCFG1 = 1
        PCFG2 = 1
        PCFG3 = 1
        ADFM = 1                    ' Right justified result in ADRESL and ADRESH
                                   
        adcin 0,adc_in              ' Place the conversion of channel0 into adc_in
    For 0-300 lbs output = adc_in * 100 / 341
    For 0-400 lbs output = adc_in * 100 / 256

    This will give you an output within 1 lb.
    Last edited by CocaColaKid; - 20th September 2005 at 13:00.

  3. #3
    houa's Avatar
    houa Guest


    Did you find this post helpful? Yes | No

    Default awesome

    thanks a lot

  4. #4
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Theese calculations will overflow when adc_in is greater than 655.

    For 0-300 lbs output = adc_in * 100 / 341
    For 0-400 lbs output = adc_in * 100 / 256

    It would be better to use the "*/" operator for these calculations.

    For 0-300 lbs output = adc_in */ 75
    For 0-400 lbs output = adc_in */ 100

    If you want proper rounding of the result you can use.....

    For 0-300 lbs output = ((adc_in */ 750)+5)/10
    For 0-400 lbs output = ((adc_in */ 1000)+5)/10

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Oops, missed that one. I personally would use this:

    d = 100
    dummy = adc_in * d
    adc_value = DIV32 256

    Substitute 341 for the 256 is using the 0-300 lbs scale. The adc_value variable will contain the lbs.
    Last edited by CocaColaKid; - 21st September 2005 at 13:27.

  6. #6
    houa's Avatar
    houa Guest


    Did you find this post helpful? Yes | No

    Default need further help

    thanks a lot guys
    but more probelms occured...
    after testing the program and testing the voltage received using a multimeter
    the actually voltage range is approx 0.44 volts +/- .009 volts and the max load we were able to obtain is approx 4.99 volts +/- .009 volts.

    can you please explain to me how the equations so i can understand the analog to digital conversion + plus can if possible, derive a new equation to fix this problem.

    here's the source code:

    Define LOADER_USED 1
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 0
    Define LCD_EREG PORTB
    Define LCD_EBIT 1
    DEFINE OSC 4 ' Set Xtal Frequency
    DEFINE ADC_BITS 10 ' Set resolution of conversion
    DEFINE ADC_CLOCK 8 ' Set clock source (x/FOSC or FRC)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time (in uS)
    '---------------------------------------------------------------
    ' INTCON.7 = 0 ' Enable PORTB pullups
    ' ADCON1 = 7 ' Make PORTA and PORTE digital
    Low PORTB.2 ' LCD R/W low (write)
    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10000010 ' Set PORTA analog and right justify result
    '---------------------------------------------------------------
    d VAR word
    dummy var word
    adc_in var word
    W VAR WORD
    adc_value var word

    ADFM var ADCON1.7 ' ADC result format select bit
    PCFG3 var ADCON1.3 ' ADC port configuration bit
    PCFG2 var ADCON1.2 ' ADC port configuration bit
    PCFG1 var ADCON1.1 ' ADC port configuration bit
    PCFG0 var ADCON1.0 ' ADC port configuration bit

    PCFG0 = 0 ' Configure AN0 as analogue input, others digital
    PCFG1 = 1
    PCFG2 = 1
    PCFG3 = 1
    ADFM = 1 ' Right justified result in ADRESL and ADRESH

    loop:
    adcin 0,adc_in ' Place the conversion of channel0 into adc_in
    d = 100
    dummy = adc_in * d
    adc_value = DIV32 256
    W = adc_value
    pause 500
    Lcdout $FE, 1
    Lcdout $FE, $80, #W," lbs"
    pause 500
    goto loop

    anymore help would be appreciated

    thanks a lot

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