ADC conversion trouble


Closed Thread
Results 1 to 25 of 25
  1. #1
    Join Date
    Dec 2007
    Location
    Sweden
    Posts
    73

    Question ADC conversion trouble

    Hi all,

    I am trying to get a one decimal presentation to a displayed temperature value. I’m using an LM35 which delivers 10mV / C it works almost as expected without decimals. If I test it by squeezing the LM35 between my fingers it goes; 24, 25, 26, 27, 29, 30 skipping 28? When I release it, it goes; 30, 29, 27, 26 and so on? And I cannot figure it out. ??

    And as mentioned; my next problem is how to get one decimal.

    I am using a16F88 set to 10 bit A/D and here’s part of the code:

    ADCIN 0,T

    T = (T*/500)>> 2

    LCDOUT $FE,1,"TEMP= ",DEC T, “C”


    Any ideas?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi PICante,
    What are you using as Vref for the ADC? If you're using your PIC supply as Vref and it is exactly 5.00V you still only get ~2counts per degree C. 5.0V divided by 1024 (10bits) makes one LSB 4,89mV.

    If you aren't using an external Vref for the ADC, I'd try that and see what happens. A Vref of 1.024V in this case would let you meassure up to 102.4°C with a resolution of 0.1° - in a perfect world.

    HTH
    /Henrik.

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


    Did you find this post helpful? Yes | No

    Smile

    Hej Henrik,

    I am using the supply for reference; it’s very stable and good filtered 5.01 Volts, I also realize the limitations it brings. I see your point about the resolution and I would like to try using an external reference if I just knew how. Any good links for studying the suggested solution?

    BTW, do you have any clue about why it skips 28? Could it be something wrong with my math?

    Thank you!
    Tack!

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Use a voltage divider to set the VREF. Darrel has info here.
    http://www.pbpgroup.com/modules/wfse...p?articleid=25

    Try reading your LM35 with a volt meter. Possible it is doing the skipping.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    BTW, do you have any clue about why it skips 28? Could it be something wrong with my math?
    No, not really, except from the fact that you only get two counts per degree from the ADC. You might wan't to try taking 10 or more samples and average them to filter the signal. Also it's possible that you're running into some kind of rounding error in the math due the low resolution but I haven't looked into it that much.

    Regarding the external Vref I'd suggest you look at the datasheet for the particular PIC you're using regarding the ADC and its various Vref options.

    Another option might be to just put an OPAMP after the sensor, boosting the signal by a factor of xx to better utilize the full range of the ADC.

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


    Did you find this post helpful? Yes | No

    Default

    A good current/temperature compensate Vref is always more than welcome... boosting the sensor output... mmmmpppppfffffff maybe not a good idea.

    There's a load of great few bucks constant voltage source ICs here and there.
    Steve

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

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    Hi Steve,
    I agree that a temp compensated Vref source is a better solution here but would you care to explain why you think it's not a good idea to boost the signal from the sensor?

    Yes, the sensor noice will be amplified too but it shouldn't be that bad. Actually, amplifying the signal or lowering Vref shouldn't make any difference, except from non linearity of the amp and possible noice added BY the amp but I don't think that would be a problem in this case.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default

    I guess it depend of the accuracy you need. If you use the internal Vref, when the PSU voltage swing, your accuracy will swing with accordingly right?

    Assuming the supply never ever swing... yeah you may boost the sensor output... carefully designed it has to work. Not something i would test on a breadboard... i'm kinda noise freak
    Steve

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

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default

    I guess it depend of the accuracy you need. If you use the internal Vref, when the PSU voltage swing, your accuracy will swing with accordingly right?
    Yes absolutely, but if you have 20mV noice or swing on the supply rail with a sensor output of 10mV/° you have 2° worth of noice. If you boost the signal to 100mV/° the same noice on the supply rail is now "worth" 0.2° instead.

    PICante,
    In a previous reply I sugested a Vref of 1.024V but after reading the 16F88 datasheet that may not have been a very good advice. Vref needs to be 2V minimum according to the datasheet so keep that in mind if you go for an external reference.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Smile

    Thanks guys!

    Yes I like to try the external reference and I need one decimal accuracy with +- 0.5C overall. Maybe it will take a high stability voltage source to reach this.

    Now I will try to figure out how to connect the Vref + & Vref- also how to set the bits in ANSEL and ADCON1 perhaps even the CVRCON? Not easy being a newbie! :-)

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by PICante View Post
    Not easy being a newbie! :-)
    I know what you mean. But it makes for a good excuse when something does not work or the room fills with smoke!!!
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Talking

    But it's always fun once in a while to have a smoke show huh?



    Steve

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

  13. #13
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Then you tell the kids. "I just did that so you could see what not to do." and "Always wear your safety glasses while programming."
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Don't try it at home, i'm a professional
    Steve

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

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


    Did you find this post helpful? Yes | No

    Talking

    Thanks guys, you are a lot of comfort!

    Unless you see a powerful light at the horizon I’ll be back soon!

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


    Did you find this post helpful? Yes | No

    Default

    mmmm... where's Sweden located from where i am????... Ah... ok i see. I'm waiting for a morse-smoke-coded message now

    Just kidding

    Whatever you do, have fun, and learn from it. We will be there when you will need help.
    Steve

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

  17. #17
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    . . . _ _ _ . . .

    Yeah, have fun!
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    hey that' SOS right?
    Steve

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

  19. #19
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    That is affirmative.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    .-- .... .- - . ...- . .-. / -.-- --- ..- / -.. --- --..-- / -.. --- / .. - / .-- . .-.. .-.. / .- -. -.. / . -. .--- --- -.--
    Steve

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

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


    Did you find this post helpful? Yes | No

    Smile

    Hello again,

    No smoke… yet.

    I made and plugged in a 2.000 Volt reference for Vref+.
    The old brain is partially hibernating and I can’t get the decimal to appear correctly.
    Some changes to the code:

    ANSEL = %00001111 ‘ not sure if I need both AN2 and AN3 for Vref since I only use Vref+ on AN3.. well seems to work so far. Perhaps better to make AN3 an output?

    ADCON1 = %11100000 ‘ right justify – clock/2 - use Vref+.

    ADCIN 0,T

    T = (T*/200)>> 2

    LCDOUT $FE,1,"TEMP= ",DEC T, “.”, DEC1 T, “C”



    Could use a sharper brain!

    Yes, I have fun!

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


    Did you find this post helpful? Yes | No

    Default

    try
    Code:
    LCDOUT $FE,1,"TEMP= ",DEC (T/10), ".", DEC T DIG 0, "C"
    Steve

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

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


    Did you find this post helpful? Yes | No

    Unhappy

    Thanks Steve,

    However this only moved the dot so instead of 26 C I got 2.6 C!

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


    Did you find this post helpful? Yes | No

    Default

    so you just need to adjust this line
    T = (T*/200)>> 2
    PBP works with integers only. If your result=263, you will display 26.3C with the LCDOUT line i've suggested.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Talking

    Thanks Steve!

    I removed this line entirely: “T = (T*/200)>> 2” and now it works as expected!

    Thank you very much guys!

Similar Threads

  1. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  2. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  3. Help with ADC conversion
    By dbachman in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st February 2009, 20:02
  4. ADC trouble with PIC16F88
    By inventosrl in forum mel PIC BASIC
    Replies: 9
    Last Post: - 3rd December 2008, 12:56
  5. ADC problem
    By NacNud in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th December 2004, 02:27

Members who have read this thread : 0

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