1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

y is that happen

Discussion in 'Microcontrollers' started by sixty9sandals, Mar 5, 2007.

  1. sixty9sandals

    sixty9sandals New Member

    Joined:
    Feb 23, 2007
    Messages:
    8
    Likes:
    0
    10bits adc problem

    hi..
    im very new..n i need someone guides to help me solving this problem. i try 2 display digital values in a row of 10leds by injecting 1.5V as an analog value with 5V as Vref..but the values displayed is 0100010010 instead of 100110011...why is this happen? any suggestion to solve it?my codes are as below..is there possibly caused by my wrong codes?

    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
    pause 500


    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
    pause 100
    GOTO START


    END

    hope somebody willing to lend me help
    thank you..
     

    Attached Files:

    Last edited: Mar 6, 2007
  2. Papabravo

    Papabravo Well-Known Member

    Joined:
    Mar 9, 2006
    Messages:
    2,889
    Likes:
    25
    Location:
    Michigan, USA (GMT-5)
    1st: You seem to be witing a command to do a conversion, read a value and writing it to the LEDS. Don't you have to wait for the conversion to be complete BEFORE reading the result?

    2nd: Don't you have to insert some delay in between one A/D conversion and the next?

    3rd: You gave the value of the analog input voltage, but you didn't tell us what the reference voltage was. How can we know if the value you are getting is correct or the value you expect is correct?

    4th: Ohhh..never mind
     
  3. atferrari

    atferrari Well-Known Member

    Joined:
    Oct 8, 2003
    Messages:
    2,812
    Likes:
    121
    Location:
    Buenos Aires - Argentina
    Vref

    5 V the Vref?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. sixty9sandals

    sixty9sandals New Member

    Joined:
    Feb 23, 2007
    Messages:
    8
    Likes:
    0


    mmm..ya..the Vref value is 5V..as im using adcon1=10000000 which is Vref=Vdd=Vss...pls do correct me if im wrong..im too new to all of this thing..n im using pic 16f877

    thank you
     
    Last edited: Mar 5, 2007
  6. eng1

    eng1 New Member

    Joined:
    Apr 7, 2006
    Messages:
    951
    Likes:
    19
    Location:
    Italy
    You have to check when the GO!DONE bit (ADCON0.2) has been cleared by hardware (conversion completed), if this is not done by the ADCIN instruction (?). Is that a built-in function of your compiler?
    Code (text):

    [u]Pseudo-code[/u]:

    START:    ADCON0.2 = 1;

    WAIT:     IF (ADCON0.2 = 1)
                         GOTO WAIT              

              Get value
     
    You may try with 8-bit resolution and 8 LEDs for a start. Are you sure that you're reading both ADRESH and ADRESL registers with one instructon?
     
    Last edited: Mar 6, 2007
  7. Papabravo

    Papabravo Well-Known Member

    Joined:
    Mar 9, 2006
    Messages:
    2,889
    Likes:
    25
    Location:
    Michigan, USA (GMT-5)
    You went back and edited your original post! Now we have no frame of reference for the discussion.

    Says me if 5V is the reference and 1.5V is the input you should get
    Code (text):

    (1.5/5.0)*1024 = 307 decimal = 0x133 = 01 0011 0011
     
    That's assuming that your code can correctly do an A/D conversion and that it is reading a real result insted of an intermediate value. The value that you got is 274 which is certainly close to 307. In voltage terms it is 1.33 volts. How accurate is your Vcc and how accurate is the measurement of the input? Are they rock solid or do they have some ripple riding on top of them?
     
    Last edited: Mar 6, 2007

Share This Page