Temperature does not go below 0


Closed Thread
Results 1 to 17 of 17
  1. #1
    Join Date
    Sep 2014
    Posts
    25

    Default Temperature does not go below 0

    IAM MAKING TEMPERATURE CONTROLLER USING ntc THERMISTOR FROM -10 DEGREE TO 50 DEGREE.BUT MY TEMPERATURE IS NOT GOING BELOW 0. PLS CHECK MY CODE AND GUIDE ME.THANKS

    Code:
     DG1 VAR BYTE       
     DG2 VAR BYTE    
     DG3 VAR BYTE
     DIGIT VAR BYTE
     DG VAR BYTE
     COUNTT VAR BYTE
     
     NUMB VAR WORD
     N VAR WORD
     adval var word
     temp var word
     TEMPP VAR WORD
     
     ADCON1=%10000000
     adcon0=%00000101 
     TRISA=1           
     TRISB=%00111000   
     TRISC=0           
     
     numb=0
     gosub mread
     'n=numb
     GOSUB DIGITCALC   
    '-------------------------------------------------------------------------
    
    
     MAIN1:
    
    
     GOSUB DISPLAY
     
     IF PORTB.3=1 THEN MREAD
     
     IF PORTB.3=0 THEN MAIN
     
       
     
     
     GOTO MAIN1
     
     
     
    
    
    
    
    
    
    '-------------------------------------------------------------------------
                         MAIN:
    
    
                            ADCON0.2=1  
    
    
                           GO:
                            IF ADCON0.2=1 THEN GO 
         
                            adval.HIGHBYTE = ADRESH                   
                            adval.lowbyte = ADRESL
                            temp=adval 
                            N=temp
                            gosub display
                            gosub digitcalc
                            
                            
                            If adval>NUMB then PORTB.7=0
                            IF ADVAL< NUMB-5 THEN PORTB.7=1
                            GOTO MAIN1
    
    
    
    
                        '_____________________________________
    
    
                         UP:
                         IF NUMB=50 THEN MAIN
                         NUMB=NUMB+1
                         N=NUMB
                         GOSUB DIGITCALC
                         IF PORTB.4=1 THEN MEMORY
                         GOTO MAIN1
                         
                         
                         memory:
                         WRITE 0,numb.HighByte    
                         
                         WRITE 1,numb.LowByte     
                         
                         GOTO MAIN1
    
    
                        '_____________________________________
    
    
                         DOWN:
                         IF NUMB=-10 THEN MAIN      'MIN LIMIT
                         NUMB=NUMB-1
                         N=NUMB
                         GOSUB DIGITCALC
                         IF PORTB.5=1 THEN MEMORY
                         GOTO MAIN1
                         
                         
                        '_____________________________________
                        MREAD:
                        READ 0,numb.HighByte    
                                                        
                        READ 1,numb.LowByte  
                        
                        n=numb
                        gosub digitcalc
                        IF PORTB.4=1 THEN UP
                        IF PORTB.5=1 THEN DOWN
                        goto main1 
                        
                        
                        
                        
              
                        
                        
                        
                          
                          
                         
           ___________________________________________________
            DISPLAY:
            
            
            FOR COUNTT=0 TO 99
    
    
            PORTC=DG1
            PORTB.2=1
            PAUSEUS 300
            PORTB.2=0
    
    
            PORTC=DG2
            PORTB.1=1
            PAUSEUS 300
            PORTB.1=0
    
    
            PORTC=DG3
            PORTB.0=1
            PAUSEUS 300 
            PORTB.0=0
    
    
            NEXT COUNTT
    
    
            RETURN
    
    
           '________________________________________________________________
    
    
    
    
    
    
    '__________________________________________________________________________
    DIGITCALC:
    
    
    DIGIT=0
    LP1:
    IF N<100 THEN DS1
    N=N-100
    DIGIT=DIGIT+1
    GOTO LP1
            DS1:
            GOSUB FND
            DG1=DG
           
    
    
    DIGIT=0
    LP2:
    IF N<10 THEN DS2
    N=N-10
    DIGIT=DIGIT+1
    GOTO LP2
    
    
            DS2:
            GOSUB FND
            DG2=DG
            
    
    
    DIGIT=N
    GOSUB FND
    DG3=DG
    
    
    
    
     
    RETURN
    
    
    
    
    
    
    
    
    '__________________________________________________________________________
    
    
    
    
    '__________________________________________________________________________
    FND:
    
    
    
    
    
    
    
    
    FND0:
    IF DIGIT>0 THEN FND1
    DG=$7E                       '%0111 1110      
    GOTO FNDEND
    
    
    FND1:
    IF DIGIT>1 THEN FND2
    DG=$48                       '%0100 1000      
    GOTO FNDEND
    
    
    FND2:
    IF DIGIT>2 THEN FND3
    DG=$3D                       '%0011 1101      
    GOTO FNDEND
    
    
    FND3:
    IF DIGIT>3 THEN FND4
    DG=$6D                       '%0110 1101      
    GOTO FNDEND
    
    
    FND4:
    IF DIGIT>4 THEN FND5
    DG=$4B                       '%0100 0011      
    GOTO FNDEND
    
    
    FND5:
    IF DIGIT>5 THEN FND6
    DG=$67                       '%0110 0111      
    GOTO FNDEND
    
    
    FND6:
    IF DIGIT>6 THEN FND7
    DG=$77                       '%0111 0111      
    GOTO FNDEND
    
    
    FND7:
    IF DIGIT>7 THEN FND8
    DG=$4C                       '%0100 1100      
    GOTO FNDEND
    
    
    FND8:
    IF DIGIT>8 THEN FND9
    DG=$7F                       '%0111 1111      
    GOTO FNDEND
    
    
    FND9:
    DG=$6F                       '%0110 1111      
    
    
    FNDEND:
    RETURN
    '_________________________________________________ _________________________
    Last edited by Archangel; - 4th June 2015 at 19:22.

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


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Hi,
    With PBP variables declared as BIT, BYTE and WORD are unsigned, they are always treated as positive.
    Of course you can handle that yourself with something like.
    Code:
    IF NUMB.15=1 THEN          ' MSB set, value is negative
        IF ABS NUMB=10 THEN MAIN   ' MIN LIMIT
    ENDIF
    /Henrik.

  3. #3
    Join Date
    Sep 2014
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    i tried that code but again temp is not going below 0.No minus sign.Name:  IMG_20150604_190043.jpg
Views: 872
Size:  452.4 KB

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    I always add comments to my listings, which also helps others follow the code and my "logic" when I have issues and post the code up seeking advice. I find it hard to work through the OP's code, but if you are using A-D I'm presuming that 0volts would equate to 0 and 5v 255, or something like that. I'm thinking that you need to scale the range or something so that, for example 127 digital (2.5v approx in this example) would be 0 degrees, and that any value between 0 and 127 would be treated as a minus value ? Then using the if then statement similar to if value is less than or equal to 126 then place the - symbol in the 1st LED,

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Use Code Tags

    [code] Your Code Goes Here [/code]
    Last edited by Archangel; - 4th June 2015 at 19:31.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Sep 2014
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Thanks Scampy for clearing my doubts .what you explained is very easy to understand..thanks & regards

  7. #7
    Join Date
    Sep 2014
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    An example needed.iam using 10 bit adc and sensor is 10k thermistor.

  8. #8
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Quote Originally Posted by amodpathak View Post
    An example needed.iam using 10 bit adc and sensor is 10k thermistor.
    A Thermistor changes resistance with temperature change. To read a 'remote' Thermistor a 'completion resistor' (CR), typically 1000 ohms, is used in series and a known voltage is applied to the circuit then the voltage drop across the CR is measured. If the thermistor is on the board then voltage drop across the Thermistor can be measured directly. The resistance changes with temperature change which is not linear and this is required

    http://en.wikipedia.org/wiki/Thermistor#NTC

    Steinhart–Hart equation

    For accurate temperature measurements, the resistance/temperature curve of the device must be described in more detail. The Steinhart–Hart equation is a widely used third-order approximation:
    1 \ T = a + b\,\ln(R) + c\,(\ln(R))^3
    where a, b and c are called the Steinhart–Hart parameters, and must be specified for each device. T is the absolute temperature and R is the resistance.
    As you can see natural logarithms are needed to use this conversion, which are not available with PBP.

  9. #9
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Why not use a DS18B20 - It would be a lot simpler going digital

  10. #10
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    As you can see natural logarithms are needed to use this conversion, which are not available with PBP.
    Or you could simply use a look-up table...

  11. #11
    Join Date
    Sep 2014
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Not able to solve problem.tried many times.

  12. #12
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Does temp read correctly above zero? 'shows sensor connected and only negative indication of code is incorrect

    Can you make the LED blink? 'shows PIC and LED hooked up correctly and working

    I'm a novice programmer but aren't you supposed to RETURN from a sub then GOTO a different subroutine? Most of your FNDx routines GOTO a sub for a RETURN. The first FND is empty. The blinking LED would tell you if the program is stuck somewhere.

    In DIGITCALC won't the variable N always be a negative number? If so PicBasic will always report that as a zero.

    Hope it helps and I don't get flamed too much?

  13. #13
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Quote Originally Posted by AvionicsMaster1 View Post
    I'm a novice programmer but aren't you supposed to RETURN from a sub then GOTO a different subroutine? Most of your FNDx routines GOTO a sub for a RETURN. The first FND is empty. The blinking LED would tell you if the program is stuck somewhere.

    In DIGITCALC won't the variable N always be a negative number? If so PicBasic will always report that as a zero.

    Hope it helps and I don't get flamed too much?
    His code is messy with no comments and lots of spaces so it does make it hard to follow, but there is a FND start and finish.

    Code:
    FND8:
    IF DIGIT>8 THEN FND9
    DG=$7F                       '%0111 1111      
    GOTO FNDEND
    
    FND9:
    DG=$6F                       '%0110 1111      
    
    FNDEND:
    RETURN
    Basically the program go's to the subroutine FND, which then contains a lot of IF DIGIT statements and if it is above a value then jump to the next FNDx label, but if it equals that value then set set value for DG and goto FNDEND, which is a simple RETURN and thus closes the subroutine.

  14. #14
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Thanks for the schooling. I see it now. Though it would be interesting to know if it indicates anything other than zeroes.

    I usually use the LED blinking to help me know when I've done something less than desirable. Just add a TOGGLE to the main loop and a short pause will let you know if the program's hung.

    Best of luck.

  15. #15
    Join Date
    Sep 2014
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Temperature goes above ZERO.Positive temperature is displayed correctly.When i keep thermistor in freezeo then temperature does't go below ZERO.

  16. #16
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Quote Originally Posted by amodpathak View Post
    Temperature goes above ZERO.Positive temperature is displayed correctly.When i keep thermistor in freezeo then temperature does't go below ZERO.
    Try some basic measurements. remove the thermistor from the board and place it in your freezer with wires connected. Measure the resistance using a digital volt meter and note it down, together with the temperature. Repeat the measurement when the thermistor is placed in ice water, and again when under a lamp or something that you can measure the temperature with. This may help you calibrate the routine better.

    One possible issue could be that your chosen thermistor is positive only, ie at zero degrees C it's resistance is zero ohms (or as near to as dam it).

  17. #17
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Temperature does not go below 0

    Without the datasheet for your device, it's impossible to resolve it for you, but here's the data for a typical device:
    http://www.arroyoinstruments.com/thermistors.html It has a table of values vs temperature. So, at -10C it's about 55Kohm, and at +50C it's about 3.6K ohms. So now you need to turn that into a voltage either using a resistor divider, or a current source. This is simple math, easy to do with Excel, and you can create a list of voltages for each degree or half degree or whatever you like. Then use those voltage values to lookup the corresponding temperature.

Similar Threads

  1. IR Temperature Sensor
    By TravisM in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 23rd October 2012, 16:04
  2. read temperature
    By breeno in forum General
    Replies: 16
    Last Post: - 6th October 2010, 13:55
  3. Temperature Logging
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th June 2008, 11: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, 21:01

Members who have read this thread : 1

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