10bits adc using 16f877


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

    Default 10bits adc using 16f877

    hi..
    i have a problem..im trying to display a digital value in a row of 10leds. as example i supplied 1.5v as a analog input with the Vref 5V. but y is that the value display on the leds are not the right value.is there something wrong with my codes.my codes are shown below:

    define ADIN_RES 10
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

    MEASURED_VALUE VAR word
    REMAINDER0 VAR word
    MEASURED0 VAR word
    REMAINDER1 VAR word
    MEASURED1 VAR word
    REMAINDER2 VAR word
    MEASURED2 VAR word
    REMAINDER3 VAR word
    MEASURED3 VAR word
    REMAINDER4 VAR word
    MEASURED4 VAR word
    REMAINDER5 VAR word
    MEASURED5 VAR word
    REMAINDER6 VAR word
    MEASURED6 VAR word
    REMAINDER7 VAR word
    MEASURED7 VAR word
    REMAINDER8 VAR word
    MEASURED8 VAR word
    REMAINDER9 VAR word
    MEASURED9 VAR word

    TRISA = %00000001
    TRISB = %00000000
    TRISD.0 = %0
    TRISD.1 = %0
    ADCON0 = %11000101
    ADCON1 = %10000000


    START:


    ADCIN 0 , MEASURED_VALUE

    REMAINDER0 = MEASURED_VALUE // 2
    PORTB.0 = ~REMAINDER0
    MEASURED0 = ( MEASURED_VALUE / 2 )

    REMAINDER1 = MEASURED0 // 2
    PORTB.1 = ~REMAINDER1
    MEASURED1 = ( MEASURED0 / 2 )

    REMAINDER2 = MEASURED1 // 2
    PORTB.2 = ~REMAINDER2
    MEASURED2 = ( MEASURED1 / 2 )

    REMAINDER3 = MEASURED2 // 2
    PORTB.3 = ~REMAINDER3
    MEASURED3 = ( MEASURED2 / 2 )

    REMAINDER4 = MEASURED3 // 2
    PORTB.4 = ~REMAINDER4
    MEASURED4 = ( MEASURED3 / 2 )

    REMAINDER5 = MEASURED4 // 2
    PORTB.5 = ~REMAINDER5
    MEASURED5 = ( MEASURED4 / 2 )

    REMAINDER6 = MEASURED5 // 2
    PORTB.6 = ~REMAINDER6
    MEASURED6 = ( MEASURED5 / 2 )


    REMAINDER7 = MEASURED6 // 2
    PORTB.7 = ~REMAINDER7
    MEASURED7 = ( MEASURED6 / 2 )

    REMAINDER8 = MEASURED7 // 2
    PORTD.0 = ~REMAINDER8
    MEASURED8 = ( MEASURED7 / 2 )

    REMAINDER9 = MEASURED8 // 2
    PORTD.1 = ~REMAINDER9
    GOTO START


    END

    anyone can help me?pls...thank you

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i don't know what you expect, but it display something, it's just reverted. Let's say when the value=0, all i/o=1... but it's working.

    anyways, here's a shorter method
    Code:
            DEFINE ADC_BITS 10
            DEFINE ADC_CLOCK 3
            DEFINE ADC_SAMPLEUS 50
            
            MEASURED_VALUE VAR word
            TRISA = %00000001
            TRISB = %00000000
            TRISD.0 = %0
            TRISD.1 = %0
            ADCON0 = %11000101
            ADCON1 = %10000000
    
    
    START:
            ADCIN 0 , MEASURED_VALUE
            PORTB= MEASURED_VALUE.LOWBYTE
            PORTD.0= MEASURED_VALUE.8
            PORTD.1= MEASURED_VALUE.9
            GOTO START
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3


    Did you find this post helpful? Yes | No

    Default thanks a lot...but..

    Quote Originally Posted by mister_e View Post
    i don't know what you expect, but it display something, it's just reverted. Let's say when the value=0, all i/o=1... but it's working.

    anyways, here's a shorter method
    Code:
            DEFINE ADC_BITS 10
            DEFINE ADC_CLOCK 3
            DEFINE ADC_SAMPLEUS 50
            
            MEASURED_VALUE VAR word
            TRISA = %00000001
            TRISB = %00000000
            TRISD.0 = %0
            TRISD.1 = %0
            ADCON0 = %11000101
            ADCON1 = %10000000
    
    
    START:
            ADCIN 0 , MEASURED_VALUE
            PORTB= MEASURED_VALUE.LOWBYTE
            PORTD.0= MEASURED_VALUE.8
            PORTD.1= MEASURED_VALUE.9
            GOTO START
    hi..
    i've try out ur code..when i supplied 1.5v as an input then the leds displayed 0100010010 instead of 100110011...why is this happen? any suggestion to solve it?

    thanks a lot

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    274 instead of 304... it's not as this far. Everything is related on acurracy of the VREF. IF it's REALLY 5.000000000V then you should have
    (1.5/5)*1024=307

    If my maths are good after 20 hours awake, ((307-274)/1024)*100=3.22 % of error. so your supply line should be around... 5-(3.22%)=4.9844 Volt

    If i use a serial communication here and if i inject 1.499 volt, VDD=5.014, i should read... (1.499/5.016)*1024=306 right? i have 305 wich is real darn close.

    If your ADC input is a little bit noisy, it may change the results, same thing with the VDD line. If you respect the minimum acquisition time and the maximum input impedance... you will have the nice results.

    If you need accuracy, you may decide to use a precision voltage source.

    mmm, maybe 1023 instead of 1024....
    Last edited by mister_e; - 5th March 2007 at 22:40.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    thanks a lot for ur help even after 20hours awake..its realy help me..possibly its caused by the noise..im gonna check it again..thanks a lot

  6. #6


    Did you find this post helpful? Yes | No

    Default hi

    i've check it..but the regulator input is 4.8V..is there posibbly coz by my wrong ADCON1 register?..

    thank you
    Attached Images Attached Images  

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Regulator INput or OUTput?

    if it's output, the results make sense. use the previous calc i did.

    If it's INput... and if it's a simple 7805... the output signal will be pretty bad
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Jan 2007
    Posts
    24


    Did you find this post helpful? Yes | No

    Thumbs up

    If you have a noise problem, try setting the settling time on the ADC to a few microseconds, then initiating a conversion. At the same time, make the PIC SLEEP for around the same length of time as the conversion. This should SIGNIFICANTLY reduce the noise across the PIC silicon substrate and give you a lot better accuracy.

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  3. Replies: 8
    Last Post: - 5th May 2009, 20:10
  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