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

A/D Conversion accuracy

Discussion in 'Microcontrollers' started by Kyle-s4h, Aug 7, 2007.

  1. mcs51mc

    mcs51mc New Member

    Joined:
    Feb 7, 2006
    Messages:
    343
    Likes:
    2
    Location:
    Belgium
    Finally someone using 8 bit addressing to the LCD; good point !

    For the key pad I'm still convinced that we don't know how it's working; bad point!
    If your absolutely sure it's only a resistor devider like the sketch I made in a hurry this morning then you should first take your Ohm meter and measure the resistance in all possible combinations.
    Then and only then you can design a correct circuit toward the PIC ADC.
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,213
    Likes:
    640
    Location:
    Derbyshire, UK
    Why would you prefer 8 bit mode?, it's just wasteful of I/O.
     
  3. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    Go back and re-read the thread -- this is one of the first things I did...
     
  4. dave

    Dave New Member

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


     
  5. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1

    Why not, does it look like I'm in need of saving 4 I/O pins? ;)

    A three cylinder car will get you to where you're going -- but an 8 is just wasteful, but so much more fun to drive!
     
    Last edited: Aug 10, 2007
  6. mcs51mc

    mcs51mc New Member

    Joined:
    Feb 7, 2006
    Messages:
    343
    Likes:
    2
    Location:
    Belgium
    I never saw Ohmic values for every key pressed only some weird hex data because of a bad design :p:p

    How do you expect us to help you with a good design since you don't give us the basic data needed ? :(
     
  7. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1

    A few points...

    1) Why would you possibly call the ADC "weird hex data"?

    2) Why would you say this is a "bad design" -- please be specific.

    3) I never asked for design help -- I asked specific questions regarding A/D Conversion.

    4) What the specific resistance values are are irrelevant (but I will post them for you below) -- the point is to get readings from them for A/D Conversion (which is what I asked about).


    I am not concerned with dual button decoding (as mentioned in one of my earlier posts), so dual button resistance values have not been taken at the present time.

    I look forward to your new and improved "good design" based on the quoted resistance values.

    PS - if you want pass-thru voltage readings, I can post them as well.
     
  8. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,213
    Likes:
    640
    Location:
    Derbyshire, UK
    Except in this case the 3 cylinder car performs exactly the same as the 8 cylinder one, but only uses half the petrol :p
     
  9. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    @Nigel -- page 114 of the 16f87X datasheet;

    Thank you -- I will change the resistor (actually, I'll change it a couple of times... ie. 12K, 10K, 2K, 1K, just to see the results).
     
  10. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    Depends on what kind of a guy you are I guess... I'll be there in half the time (and a lot safer... ever seen a "big" 3 cylinder?). :D
     
  11. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,213
    Likes:
    640
    Location:
    Derbyshire, UK
    It varies from PIC to PIC somewhat, the 16F819 is 2.5K, the important thing is that you are aware of the limitation!.
     
  12. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    Oh, I was simply pointing out that you were correct and my 22K resistor was way over the limit! I realize that it will vary from PIC to PIC, but at least I have learned and know to check the datasheet in the future. I'm happy -- the day is young and I've already learned something new today! ;)

    I'm going to go change it and see what kind of results I get.
     
  13. eng1

    eng1 New Member

    Joined:
    Apr 7, 2006
    Messages:
    951
    Likes:
    19
    Location:
    Italy
    The 10k ohms limit is required to meet the pin leakage specification.
    The equivalent resistance 'seen' by the analog input should be as low as possible. You can change the external resistor, but not those inside the lock. The solution is to use an op amp, wired as a voltage follower, to feed the A/D converter.
     
  14. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    Interesting -- I did a quick read on op-amps -- they'll definitely require more reading than I have time for right now! :)

    A question would be -- is that really needed though? If I put a 1K resistor in place of the 22K, with my top resistance reading from the keypad of 7.53K, that would still keep my under the total 10K limit (8.53K), no?

    So, without knowing a whole lot about op amps, it seems to me that replacing the 1K resistor with an op amp would only save me 1K of resistance (seeing as I cannot change the resistors in the keypad). Am I confused? :)
     
  15. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    While reading the datasheet on A/D Conversion, I also noted a "left" and "right" justification for the A/D results -- the default is left justified, which is what I am using. This, to me, makes the above statement make sense -- if I am understanding this correctly.

    When set to left justify, I am using ALL bits of the HIGH byte, and only the 2 MSB of the LOW byte -- correct? That would explain why I only get two readings from the LOW byte (C0 & 80) and all readings for the HIGH byte are different (as posted above).
     
  16. eng1

    eng1 New Member

    Joined:
    Apr 7, 2006
    Messages:
    951
    Likes:
    19
    Location:
    Italy
    The limit for proper operation of the A/D converter is about 2k ohms, as mentioned. Anything lower is better. The op amp provides a low output impedance, in the order of hundreds of ohms.


    Not exactly a replacement. You can still use the external resistor, if required, but it shouldn't be too high or the maximum voltage that appears at the ADC input is far less than 5 V.
     
  17. mcs51mc

    mcs51mc New Member

    Joined:
    Feb 7, 2006
    Messages:
    343
    Likes:
    2
    Location:
    Belgium
    Sorry but wrong again :)
    First calculate what you can expect then change it.

    I suppose the values you posted earlier are kOhm.
    Then I suggest using 8.2 kOhm serie resistor and like eng1 already suggested a opamp with a gain of 2.
    Serie resistor & lock resistors feed from 5V same as Vref of the PIC

    That way you get the following results:

    Key Voltage ADC bits Hex
    # 0 0.000 000 0000
    # 1 0.604 123 007B
    # 2 1.050 215 00D7
    # 3 1.495 306 0132
    # 4 1.976 404 0194
    # 5 2.472 506 01FA
    # 6 2.997 613 0265
    # 7 3.564 729 02D9
    # 8 4.130 845 034D
    # 9 4.787 980 03D4

    Like you see no tricky "either C0/00 or 80/40" stuff (what I call weird hex data) only streight forward data from 0000 to almost 0400 (1024) :D

    If you get other readings than these with this setup your PIC code is wrong :p

    You're welcome.
     
    Last edited: Aug 10, 2007
  18. mcs51mc

    mcs51mc New Member

    Joined:
    Feb 7, 2006
    Messages:
    343
    Likes:
    2
    Location:
    Belgium
    Off topic and with many :):):):):):)
    Typical sales man talk.
    Sell a "bad" product now and an upgrade later on.
    That's twice $$$$$$
    :):):):):):)
     
  19. eblc1388

    eblc1388 Active Member

    Joined:
    Jan 25, 2005
    Messages:
    2,228
    Likes:
    18
    Location:
    UK
    You are correct about the left justification of the ADC result. This is user configurable but after PIC reset, it defaults to left justify on the 16F873.

    You should make provisions for your key value comparison routine because you have not taken into account the two LSBs. So a value of 0x05 in ADRESH could means 0XC0 or 0x00 in the ADRESL register. If you test for equality of 0x05 for a particular key, then by some drifts later the value of ADRESL increased or decreased by one bit, your ADRESH will increment/decrement, becoming 0x06 or 0x04. Your routine will then fail to return the correct key value.
     
  20. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1
    Man, I really don't want to sound stupid here... but is this 2K limit for "proper operation" just something "you have to know", or am I not following you? I mean, the datasheet for the 16F87X says the limit is 10K (as I stated above).

    Page 114 of the datasheet (Figure 11-2) shows an analog input model -- Ric shows a resistor of 1K or less between the sampling switch and the input pin (I am not actually using it BETWEEN, I have it wired as a pull up)... and it also shows a 5pF cap between the input pin and Vss. That would work, and probably better. I have a 0.1 cap on the power rail near the ADC input, but not actually on it. The whole point to the resistor was simply to provide protection against a direct short on initialization -- the cap would do that. It would provide a constant power supply to the ADC input and protect against a direct short, no?
     
  21. Kyle-s4h

    Kyle-s4h Banned

    Joined:
    May 30, 2007
    Messages:
    103
    Likes:
    1

    LOL! Not what I was thinking! I am a service tech and pride myself on having a callback rate of as near to zero as one could hope for. I like to do the job once -- and correctly at that! :)

    I only meant "at this particular minute" -- I usually print stuff like this out and put it beside my La-Z-boy for later perusal! ;)
     
    Last edited: Aug 10, 2007

Share This Page