Value of temperature


+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2020
    Posts
    30

    Default Value of temperature

    Hi, I'm always grappling with my firmware on the PIC 16F88 trying to dust some programming.


    1) Ascertained that as PIC I have 16F88
    2) My temperature sensor is an LM235H
    3) located on analog port 0 (PIN17)
    4) The assembly scheme of sensor is:

    Name:  scheme.jpg
Views: 313
Size:  28.8 KB


    I looked a bit at the results obtained in the calculations.
    I used, not for my skill but sifting left and right of the codes found on line of the formulas.

    Ex .:

    to find the temperature, average 20 values read on the analog port and then apply the formula

    Code:
    temperature= (temp*10) */ quanta
    and I'd like to understand why?

    Also, another string makes me do this:
    Code:
    lcdout $ FE, 2, "Temp.", dec2 (temperatures / 100), ".", dec1 (temperatures // 100), $ DF, "C"
    That is, the result obtained from the first, set it in this way to represent it on the display as a number with a comma.

    But making some insights I pull out such a times table:


    temp Temperature= (temp*10) */ quanta Temperature/100 Temperature//100 Display
    666 32519 325,19 25,9
    667 32568 325,68 25,8
    668 32617 326,17 26,7
    669 32666 326,66 26,6
    670 32714 327,14 27,4
    671 32762 327,62 27,3
    672 32812 328,12 28,2
    673 32861 328,61 28,1
    674 32910 329,1 29
    675 32958 329,58 29,8
    676 33007 330,07 30,7
    677 33056 330,56 30,6
    678 33105 331,05 31,5
    679 33154 331,54 31,4


    I read in the PicBasic manual what the various mathematical operators indicate.
    But what amazes me is the fact that worth
    32617 corresponds to a temperature of 26.7 C and that to the value of
    32666 corresponds to a temperature of 26.6 C and so on on the table.

    So what is represented on the display is a lying value?

    Or am I doing something wrong?

    Thanks for the answers.

  2. #2

    Default Re: Value of temperature

    You did not post enough code that we can answer your question. Post all of your code.

  3. #3
    Join Date
    Apr 2020
    Posts
    30

    Default Re: Value of temperature

    Quote Originally Posted by Charlie View Post
    You did not post enough code that we can answer your question. Post all of your code.
    Code:
     
    
    
    
    define osc 4
    adcon1.7=1
    ANSEL = 0001 'Disable Inputs Tranne AN0
    ADCON1 = 001110 
    OSCCON = 100000 'Internal RC set to 4MHZ
    TRISA =  000001 ' impostazioni INP/OUT
    TRISB =  000000 ' delle porte
    '----------------------------------------------------
    DEFINE LCD_DREG PORTB       'Porta B DATA OUT 
    DEFINE LCD_DBIT 4           '0 --> Bit 0-3 : 4 --> Bit 4-7 
    DEFINE LCD_RSREG PORTB      'LCD register select port - Porta B --> RS
    DEFINE LCD_RSBIT 2          'LCD register select bit  - Pin RS B2
    DEFINE LCD_EREG PORTB       'LCD enable port - Porta B --> EN
    DEFINE LCD_EBIT 3           'LCD enable bit - Pin EN B3DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2          'Number lines on LCD DEFINE LCD_COMMANDUS 2000   'Command delay time in us 
    DEFINE LCD_DATAUS 50        'Data delay time in us
    
    
    Rele   VAR    PORTA.6     '                  Pin 15
    '--------------------------------------------------------------
    '---------Define ADCin Parameters   
    DEFINE ADC_BITS 10      'set number of bits in result
    DEFINE ADC_CLOCK 3      'set clock source (3=rc)
    DEFINE ADC_SAMPLEUS 50  'Set sampling time in uS
    
    
    
    
    '    RAM Assignments and Variables
    '=========================================================================== 
    temp var word
    temperature var word
    samples var word
    sample VAR BYTE
    quanta con 1250
    Tmax VAR byte
    Tmin VAR byte
    '===========================================================================
    Tmin=16
    Tmax=30
     
    START:
    Lcdout $FE, 1
    
    
    low rele
    
    
    main:   
    sample = 1
    samples= 0
    FOR sample = 1 TO 20 'Take 20 samples
    ADCIN 0, temp 'Read AN0 into temp variable
    samples = samples + temp
    PAUSE 50 ' Wait 1/4 seconds per reading
    NEXT sample
    temp = samples/20 'Average over 20 samples (Every 5 seconds)
    temperature= temp */ quanta
    
    
    if temp > 675 then high rele  'Instead 675 write the correct RAW number for 30degC 
    if temp < 675 then low rele   'Instead 675 write the correct RAW number for 30degC 
    
    
    LCDOUT $FE, 2 ' ritorna al primo carattere
    lcdout $FE, 2, "Temp ",dec2 (temperature/10),".", dec1 (temperature/10),"C"
    'lcdout $FE, $C0, "Tmin ",#Tmin, " Tmax ",#Tmax            FOR NORMAL OPERATION UNCOMMENT LINE 
    lcdout $FE, $C0, "RAW:",dec temp 'this show the ADC value  FOR NORMAL OPERATION COMMENT OR DELETE THIS LINE
    'lcdout $FE, $C0, "RAW:",dec temperature
    
    'When the display show 30,0 degC look at the RAW number on LCD and rewrite it in lines: if temp > 675 then high rele
    'and if temp < 675 then low rele . 
    
    
    goto main

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,162

    Default Re: Value of temperature

    I believe you are going wrong by not subtracting the zero degree C. offset before you calculated the final value of quanta. Here is what I calculate:

    0 degrees C. = 273.15 degrees K.
    273.15 degrees K. x .01 volts = 2.7316 volts @ 0 degrees C.
    5 volts / 1023 counts = .004887586 volts per count
    2.7315 volts / .004887586 volts per count = 588.86484 counts
    588.86484 raw counts = 0 degrees C. = 273.15 degrees K.

    After subtracting the 588.86 counts from the raw reading, you end up with:
    .01 volts per degree C. / .004887586 volts per count which equals 1 degree C.
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    Mar 2016
    Posts
    86

    Default Re: Value of temperature

    Everything is solved in previous thread.
    Did you read this?
    http://www.picbasic.co.uk/forum/atta...5&d=1586510417
    This is the working code for LM335 probably for LM235 too. Compile it, load to pic and thats all.

  6. #6
    Join Date
    Apr 2020
    Posts
    30

    Default Re: Value of temperature

    Quote Originally Posted by louislouis View Post
    Everything is solved in previous thread.
    Did you read this?
    http://www.picbasic.co.uk/forum/atta...5&d=1586510417
    This is the working code for LM335 probably for LM235 too. Compile it, load to pic and thats all.

    Thanks louislouis you were very kind!

  7. #7
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,976

    Default Re: Value of temperature

    I suppose that cobuccit has hard times understanding the maths behind */ operator and how to find the number used with that operator.

    1. The PBP manual is your friend

    2. Look at this page (down) that is primarily for the Basic Stamp but most if not all apply to PBP too: http://emesystems.com/OLDSITE/BS2index.htm

    Ioannis

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

    Default Re: Value of temperature

    Hi, Ioannis,

    for those calculations ... I suggest you to have a look here : https://www.miscel.dk/MiscEl/miscel.html
    e
    specially here : https://www.miscel.dk/MiscEl/miscelIntegerMath.html

    t
    he program is a bit old ... but just answer "yes" if it shows an error , and it will run fine ...

    best regards
    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 " !!!
    *****************************************

Similar Threads

  1. Temperature does not go below 0
    By amodpathak in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 11th June 2015, 14:56
  2. read temperature
    By breeno in forum General
    Replies: 16
    Last Post: - 6th October 2010, 12:55
  3. Temperature Logging
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th June 2008, 10:29
  4. Temperature Meter
    By Mohammed Mazed in forum Schematics
    Replies: 3
    Last Post: - 18th December 2006, 03:12
  5. temperature controller
    By PoTeToJB in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th April 2006, 20:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts