16f877 with LM335 problem


Closed Thread
Results 1 to 40 of 47

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Cooter

    Your conversion formula is wrong ...

    °K = °C +273.15... and your scaling doesn't meet anything known.

    now, you MUST Download your sensor datasheet ... and wire it decently.

    Can't work at this time !!!

    Alain
    Oh ya, that circuit's is out in the weeds somewhere.
    And when you do get it working, the easiest way I've found to calibrate the system is to dip the sensor in ice water and set the reading to match, not change any resistors or rewire anything, just adjust the math on the PIC to match.
    And are you sure the A/D is working right? Have you tried putting a pot across the A/D input? Does that respond correctly?

  2. #2
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Angry 16f877 Adc Not Working

    hi all,
    am trying to understand how to implament the ADC on the pic 16f877
    my code is for a LM335 temp sensor connected to RA0(pin 2)
    the VDD and VSS is from a 7805 voltage reg that also supplies the LM335

    Cant get ADC to work from my circuit. or is it my code??????????????
    why cant i use decimal ie 0.46 in my maths routine?????????????

    This has had me up all week trying to get it to work

    PLZ someone guide me in the correct direction


    'PIC 16f877 with a LM335 temp sender
    '
    '
    define osc 20 ' 20mhz oscillator
    ' LCD ROUTINES
    DEFINE LCD_DREG PORTB
    DEFINE LCD_DBIT 4 '4,5,6,7
    DEFINE LCD_RSREG PORTB
    DEFINE LCD_RSBIT 3
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 2
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50
    ' Define ADCIN parameters
    Define ADC_BITS 10 ' Set number of bits in result
    define ADC_CLOCK 3 ' Set clock source
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    AD_RAW var word ' Create adval to store result
    AD_RESULT var word


    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %10001110 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %10000001 ' Configure and turn on A/D Module

    Pause 500 ' Wait .5 second

    loop:
    ADCIN 0, AD_RAW ' Read channel 0 to ad_raw
    AD_RESULT = (ad_raw *0.48828) - 273.15 ' Convert Kelvins to Degrees C

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "TEMP ", DEC AD_Result ," C" ' Display the decimal value

    Pause 100 ' Wait .1 second

    Goto loop ' Do it forever
    End
    Attached Images Attached Images  
    IF ITS STOCK IT WONT ROCK

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Here it goes again and again....

    Did you really bought the copy of PBP you have????

    Did it came with it a MANUAL ???

    Did you read the MANUAL ????

    Didn't find any reference as to that PBP is NOT supporting floating maths ???

    I am looking forward to you replying to the above so that we can continue support here.

    Ioannis


    P.S. If you are just connect the sensor to the PIC directly, your useful range will be limited (0C-100C is from 2,7315 to 3,7315 Volts). I suggest to use opamps and extend the range of the sensor from 0C->0Volts to 100C->5 Volts.

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Did you really bought the copy of PBP you have????

    Did it came with it a MANUAL ???

    Did you read the MANUAL ????

    Didn't find any reference as to that PBP is NOT supporting floating maths ???
    Amazing isn't it?

  5. #5
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Did you really bought the copy of PBP you have????

    Did it came with it a MANUAL ???

    Did you read the MANUAL ????

    Didn't find any reference as to that PBP is NOT supporting floating maths ???

    I am looking forward to you replying to the above so that we can continue support here.
    Ton pethanes ton anthropo.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    Ton pethanes ton anthropo.
    Wish I spoke it!
    Even google'd it...everything came up in Greek. Imagine that! I'm lost

  7. #7
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    Ton pethanes ton anthropo.
    You die the man

  8. #8
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by savnik View Post
    You die the man
    Sorry,

    but what do you mean ??? ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  9. #9
    Join Date
    Jun 2006
    Location
    Greece
    Posts
    302


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Sorry,

    but what do you mean ??? ...

    Alain
    The translation is not exactly.
    In greek is a metaphoric phrase.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Sorry,

    but what do you mean ??? ...

    Alain
    What savnik (Geia sou!) said was that I made too many questions like in an interrogation, one after another, so I exhausted him to death!

    Sorry for that, I couldn't resist...

    As for the floating maths, CrazyCooter, you can do real maths with the routines from Microchip (check the melabs site for this), write your own routines, use decimal numbers only with tricks that were many times discussed here or do not use decimal at all.

    For example, 2.3 may be represented as 23 and displayed as "2", ".", "3"

    Also check the manual and forum for applications of DIV32, */ and // operators. These are what you need to do the job.

    Ioannis

  11. #11
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Angry Still seeing red with the ADC

    Quote Originally Posted by Ioannis View Post
    Did you really bought the copy of PBP you have????

    Did it came with it a MANUAL ???

    Did you read the MANUAL ????

    Didn't find any reference as to that PBP is NOT supporting floating maths ???

    I am looking forward to you replying to the above so that we can continue support here.

    Ioannis


    P.S. If you are just connect the sensor to the PIC directly, your useful range will be limited (0C-100C is from 2,7315 to 3,7315 Volts). I suggest to use opamps and extend the range of the sensor from 0C->0Volts to 100C->5 Volts.
    thanks for the quick responce

    got PBP 2.47 from DONTRONICS here in melbourne

    Yes. Read the 213 pages and even been looking up web sites with references. downloaded the data sheet read the A2D converter module.. CH 11 pg 127

    ok just found 1 error in setting the TRISA had 8 bits set to 1 should have been 6 ie TRISA %111111 not TRISA %11111111

    still not workin. even connected a 5k lin pot and got no responce.


    and as Ioannis said using an opamp to extend the range i will be now

    MY CODE WILL NOT COMPILE WITH THIS LINE
    AD_RESULT = (ad_raw *0.48828) - 273.15

    Had to do it this way
    ad_result = (ad_raw * 48828)/1000
    ad_result = ad_result/100
    ad_result = (ad_result *27315)/100
    WHY????????????????????????????????????????
    HMMMMMMM very frustrating
    IF ITS STOCK IT WONT ROCK

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CrazyCooter View Post

    MY CODE WILL NOT COMPILE WITH THIS LINE
    AD_RESULT = (ad_raw *0.48828) - 273.15

    Had to do it this way
    ad_result = (ad_raw * 48828)/1000
    ad_result = ad_result/100
    ad_result = (ad_result *27315)/100
    WHY????????????????????????????????????????
    HMMMMMMM very frustrating
    What do you mean why? Did you read the post earlier? Did you really read it? Let me quote one line from that earlier post:

    "Did you read the MANUAL ????

    Didn't find any reference as to that PBP is NOT supporting floating maths ???"

    How many times do we have to point out to you that PBP does not support floating point math! And if you don't understand the term 'floating point', well, quite frankly 'floating point' means that the decimal is 'floating'...it can move wherever it needs to go according to the math being performed!
    PBP DOES NOT SUPPORT FLOATING POINT MATHS! The decimal point is stuck in one place, all the way to the right, no matter what you do, the decimal point will always be to the right...no fractions, no tenths, no hundreths, no nothing. If you divide 10 by 3, you'll get 3, nothing more nothing less. If you use the remainder function, yes, in the case above, you'll get a 1 from it, but it's still not FLOATING POINT...

    Somebody get me a drill!!!

  13. #13
    Join Date
    Nov 2006
    Location
    Melbourne, Australia
    Posts
    25


    Did you find this post helpful? Yes | No

    Smile

    Thanks skimask for pointing that out.

    ok so i am 1 step closer to getting this to work now.

    so the only way to do floating point maths then is with asm right?

    and thats why my code will not work correctly with the LM335 and the ADC?
    IF ITS STOCK IT WONT ROCK

  14. #14
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Talking Humour of life ...

    QUOTE << Hi, Skimask

    You can also remember Every number can be close-rounded as the division of two integers ... ( PI = 22/7 i.e. )

    That give some brain work to find the couple of the year ... but a small GWBASIC ( LOL !!! ) program can easily sort them.

    With the use of the DIV32 function ... that enables more than you ever dreamed !!!

    Alain >>

    Hi, Scooter

    Sometimes, life is really funny ... that comes from 5 threads down on the list ...
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  15. #15
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by CrazyCooter View Post
    Thanks skimask for pointing that out.

    ok so i am 1 step closer to getting this to work now.

    so the only way to do floating point maths then is with asm right?

    and thats why my code will not work correctly with the LM335 and the ADC?
    Sure, because a byte/word/bit/whatever has a decimal point in it when written in plain text...

    It's possible to do plenty of floating point when using straight PBP, as many digits as you want, as much accuracy as your heart desires......the question is, can you?

  16. #16
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    949


    Did you find this post helpful? Yes | No

    Default Any schematic to achieve this please?

    Quote Originally Posted by Ioannis View Post
    If you are just connect the sensor to the PIC directly, your useful range will be limited (0C-100C is from 2,7315 to 3,7315 Volts). I suggest to use opamps and extend the range of the sensor from 0C->0Volts to 100C->5 Volts.
    Can anyone please help me with a schematic on how to achieve what Ioannis is suggesting or is the example below not far away from what I'm looking for?

    How do I "electronically" rescale 2,7315Volts to an ideal "0V" and/or a 3,7315Volts to an ideal "5V"?

    I don't know...

    As I'd like to use my sensor to control a freezer, the temperature range I need goes from -30°C to +30°C.

    I found quite some info, for example here and I've already ordered some LM358 opamps to build this circuit.

    It looks like this circuit will output 0V at 0°C and 1V at 100°C. It is still "loosing" 4 precious volts, isn't it?

    How can this circuit be modified to, again ideally, match something like -30°C = 0V and +30°C = 5V?



    Last edited by flotulopex; - 10th April 2015 at 23:19. Reason: typo
    Roger

  17. #17
    Join Date
    Jan 2011
    Location
    Sydney, Australia
    Posts
    172


    Did you find this post helpful? Yes | No

    Default Re: Any schematic to achieve this please?

    Why not use the LM35?
    This sensor is calibrated directly in Celcius, has a linear 10mV/degree C scale factor, is rated for -55 to +150 C range and does not require any external calibration or trimming to provide typical accuracies of =/-0.25C at room temperature and +/-0.75C over the full -55 to +150C range.

    Cheers
    Barry
    VK2XBP

  18. #18
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    949


    Did you find this post helpful? Yes | No

    Default Re: Any schematic to achieve this please?

    Thanks for the idea Barry.

    It's just, I have a LM335 in the drawer....

    I can give it a go with the LM35 - need to order one but here, in Switzerland, the LM35 is ten times more expensive than the LM335

    Anyway, I would still like to understand how the LM335 could be used with an opamp.
    Roger

  19. #19
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: Any schematic to achieve this please?

    Attached is one idea. First op-amp works as an adder (or subtracter). It removes the DC offset voltage from the + input. So output is around 0-0,58 volts for -30 to 30 deg.

    Then the second op-amp works as an DC amplifier to boost the 0,58 to 5 volts. So you have to make two adjustments, trimmer R9 at 2,4315 volts and R10 to get 5 Volts for 30 deg.

    Also very critical is to select op-amps that are able to work at 5Volts and be rail to rail. I thing LMC662 is such a chip.

    Ioannis

    Name:  LM335.png
Views: 4449
Size:  10.2 KB

Similar Threads

  1. 16F877 HSERIN problem with 3th party software
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th March 2009, 18:11
  2. LCD problem with 16F877
    By alexx_57 in forum General
    Replies: 10
    Last Post: - 25th July 2007, 14:47
  3. problem using 16f877
    By yrch in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th February 2006, 19:58
  4. 16F877 20MHz problem
    By swordman in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 31st July 2004, 11:02
  5. 16F877, DS18S20 and Serial Comm Problem
    By YellowTang in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th April 2004, 11:36

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