NTC thermistor temperature sensing


Closed Thread
Results 1 to 37 of 37

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Never trust a sim.
    But this time I think the sim is correct. I think you ment to set ADCON2, not ADCON1. ADCON 2 sets right or left justified. Default is left justified.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by cncmachineguy View Post
    But this time I think the sim is correct. I think you ment to set ADCON2, not ADCON1. ADCON 2 sets right or left justified. Default is left justified.
    How do you right-justify bits?
    tb0=ntc>>8?

    Or there is an another command?

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by pxidr84 View Post
    How do you right-justify bits?
    tb0=ntc>>8?

    Or there is an another command?
    Look at the datasheet for ADCON2. I feel like the setting you have for ADCON1 is really ment for ADCON2. ADCON1 only has 2 valid bits. Not the 2 you have set.

    BTW, tb0=ntc>>8 will shift it 8 places. you would only need to shift 6 times. Yes this will work, but better to just set the registers up for what you want, then no un-needed code
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Code:
    From your code:
    
    ADCIN 1,ntc
    tb0=ntc
    if tb0>=16170 then
    tb1=tb0-16170 
    ELSE 
    tb0=0
    ENDIF
    Since ntc could be 0 or 1023 maximum, the condition if tb0>=16170 then is always false so tbo will be always zero and tb1 will be never setted with your required calculation tb1=tb0-16170.

    Cheers

    Al.
    Last edited by aratti; - 15th January 2011 at 17:19.
    All progress began with an idea

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    Code:
    From your code:
    
    ADCIN 1,ntc
    tb0=ntc
    if tb0>=16170 then
    tb1=tb0-16170 
    ELSE 
    tb0=0
    ENDIF
    Since ntc could be 0 or 1023 maximum, the condition if tb0>=16170 then is always false so tbo will be always zero and tb1 will be never setted with your required calculation tb1=tb0-16170.

    Cheers

    Al.
    The code works for me because the value of my ADC varies from 0 to 65525 (it's a 10-bit ADC, but with bits shifted to a 16-bit value).

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Sorry ...

    But my Easy Pic5 outputs " ITS : ...00.00°C " with all the processor settings I gave you in previous code, but 10 bits ADC ... ( Whistle and Bells ... )

    I also asked for printing ntc Value ...

    comprised between 0 and 1023 ...

    try this :


    ntc VAR WORD
    tb0 VAR WORD
    tb1 VAR WORD
    tb2 VAR WORD
    TRISA=%11111111

    PAUSE 700
    LCDOUT $fe,1

    lp:
    ADCIN 1,ntc
    tb0 = ntc
    if tb0 >= 16170 then
    tb1 = tb0-16170
    ELSE
    tb1 = 0
    ENDIF
    tb1 = tb1*100
    tb2 = Div32 634
    tb0 = tb2/100
    tb1 = tb2//100

    LCDOUT $FE,2,DEC4 ntc
    Lcdout $FE,$C0,"ITS: ",DEC3 tb0,".",DEC2 tb1,"°C"
    goto lp
    so ... take your own conclusions !!!

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

  7. #7


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Sorry ...

    But my Easy Pic5 outputs " ITS : ...00.00°C " with all the processor settings I gave you in previous code, but 10 bits ADC ... ( Whistle and Bells ... )

    I also asked for printing ntc Value ...

    comprised between 0 and 1023 ...

    try this :



    so ... take your own conclusions !!!

    Alain
    Your code works, but it still show ADC values>1024... or less on my PIC (for exemple 1616 for 24,26°C)...
    The temperature reading is correct.
    Last edited by pxidr84; - 15th January 2011 at 18:32.

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


    Did you find this post helpful? Yes | No

    Default

    One more thing ...

    The compiler doesn't like " ° " ( "Maj" + "=" ) character ...

    better use

    Code:
    Lcdout $FE,$C0,"ITS: ",DEC3 tb0,".",DEC2 tb1, 223, "C"
    where 223 ( sometimes 178 ) is supposed to be the ASCII code of " ° " ...

    That said ... ADC value NEVER is > 1023 ...

    from your firsts explanations ( post #1) ... I get That : ( 16F877A on EasyPic5 )

    Code:
     
    DEFINE ADC_BITS 10      ' Set number of bits in result
    DEFINE LCD_DREG PORTB       ' Set LCD Data port
    DEFINE LCD_DBIT 0           ' Set starting Data bit (0 or 4) if 4-bit bus .7
    DEFINE LCD_RSREG PORTB      ' Set LCD Register Select port
    DEFINE LCD_RSBIT 4          ' Set LCD Register Select bit 
    DEFINE LCD_EREG PORTB       ' Set LCD Enable port
    DEFINE LCD_EBIT 5           ' Set LCD Enable bit i.e, PORTE.4
    DEFINE LCD_BITS 4           ' Set LCD bus size ot 4 bit Upper Nibble (4 or 8 bits)
    DEFINE LCD_LINES 2         ' Set number of lines on LCD to 4 Lines
     
    TRISA  = %11111111
    TRISB  = 0
    TRISC  = 0
     
    CMCON  = 7
    ADCON0 = %11000001
    ADCON1 = %10000100   
     
    ntc VAR WORD
    tb0 VAR WORD
    tb1 VAR WORD
    tb2 VAR WORD
     
    PAUSE 700
    LCDOUT $fe,1
    lp:
    ADCIN 1,ntc
    tb0 = ntc * 33 /92 
    tb1 = tb0*721                                     
    tb2 = Div32 255
    tb2 = tb2 - 64
    tb0 = tb2/10   
    tb1 = tb2//10    
     
    PAUSE 200
     
    LCDOUT $FE,2,DEC4 ntc
    Lcdout $FE,$C0,"ITS: ",DEC3 tb0,".",DEC1 tb1,178,"C"
    goto lp
    Gives me a 0 - 100°C scale for adc = 67 to 1023 ...

    so, i suppose it to be " not so bad , but to confirm "
    Alain
    Last edited by Acetronics2; - 15th January 2011 at 20:08.
    ************************************************** ***********************
    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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    One more thing ...

    The compiler doesn't like " ° " ( "Maj" + "=" ) character ...

    better use

    Code:
    Lcdout $FE,$C0,"ITS: ",DEC3 tb0,".",DEC2 tb1, 223, "C"
    where 223 ( sometimes 178 ) is supposed to be the ASCII code of " ° " ...

    That said ... ADC value NEVER is > 1023 ...

    from your firsts explanations ( post #1) ... I get That : ( 16F877A on EasyPic5 )

    Code:
     
    DEFINE ADC_BITS 10      ' Set number of bits in result
    DEFINE LCD_DREG PORTB       ' Set LCD Data port
    DEFINE LCD_DBIT 0           ' Set starting Data bit (0 or 4) if 4-bit bus .7
    DEFINE LCD_RSREG PORTB      ' Set LCD Register Select port
    DEFINE LCD_RSBIT 4          ' Set LCD Register Select bit 
    DEFINE LCD_EREG PORTB       ' Set LCD Enable port
    DEFINE LCD_EBIT 5           ' Set LCD Enable bit i.e, PORTE.4
    DEFINE LCD_BITS 4           ' Set LCD bus size ot 4 bit Upper Nibble (4 or 8 bits)
    DEFINE LCD_LINES 2         ' Set number of lines on LCD to 4 Lines
     
    TRISA  = %11111111
    TRISB  = 0
    TRISC  = 0
     
    CMCON  = 7
    ADCON0 = %11000001
    ADCON1 = %10000100   
     
    ntc VAR WORD
    tb0 VAR WORD
    tb1 VAR WORD
    tb2 VAR WORD
     
    PAUSE 700
    LCDOUT $fe,1
    lp:
    ADCIN 1,ntc
    tb0 = ntc * 33 /92 
    tb1 = tb0*721                                     
    tb2 = Div32 255
    tb2 = tb2 - 64
    tb0 = tb2/10   
    tb1 = tb2//10    
     
    PAUSE 200
     
    LCDOUT $FE,2,DEC4 ntc
    Lcdout $FE,$C0,"ITS: ",DEC3 tb0,".",DEC1 tb1,178,"C"
    goto lp
    Gives me a 0 - 100°C scale for adc = 67 to 1023 ...

    so, i suppose it to be " not so bad , but to confirm "
    Alain
    Ok, my problem is largely solved, and if change my PIC, I'll be warn of ADC values. I think my PIC is a special case.
    Thanks everyone.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Epilog ...

    for general knowledge ... a look at Microchip AN 942 may be valuable ...

    Ok, my problem is largely solved


    I think my PIC is a special case.


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

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