NTC thermistor temperature measurement microcontroller C and assembly source program

Publisher:星辰耀眼Latest update time:2019-11-11 Source: 51heiKeywords:NTC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

NTC thermistor parameter introduction:


[Nominal resistance]
The nominal resistance is the designed resistance value of the NTC thermistor, which is often marked on the surface of the thermistor. The nominal resistance refers to the zero-power resistance at a reference temperature of 25°C, so it is also called the resistance value R25.


[Rated power]
Rated power refers to the allowable dissipated power of the thermistor under long-term continuous load under atmospheric conditions of ambient temperature 25°C, relative humidity 45% to 80% and atmospheric pressure 0.87 to 1.07 Pa.


[B value range]
The B value range (K) is the thermal sensitivity index of the negative temperature coefficient thermistor, reflecting the resistance change between two temperatures. It is defined as the ratio of the difference between the natural logarithms of the zero-power resistance value at two temperatures and the difference between the reciprocals of these temperatures. The B value can be calculated using the following formula, where   
R1 and R2 are the resistance values ​​(Ω) at absolute temperatures T1 and T2, respectively.


[Zero-power resistance]
The resistance value of a thermistor is measured at a specified temperature. The resistance value measured when the resistance change caused by internal heating of the resistor is negligible relative to the total measurement error.


【Dissipation coefficient δ (mW/℃)】
The dissipation coefficient refers to the ratio of the power consumed by the thermistor to the change in ambient temperature.
 
In the formula, W is the power consumed by the thermistor (mW); T is the temperature at thermal equilibrium (℃); T0 is the ambient temperature (℃); I is the current passing through the thermistor when the temperature is T (A); R is the resistance value of the thermistor when the temperature is T (Ω).


[Time constant τ(s)]
The time constant τ(s) refers to the time required for the resistance of the thermistor to change by 63.2% when the ambient temperature suddenly changes from one specific temperature to another specific temperature under zero power state.


[Resistance Temperature Coefficient]
The resistance temperature coefficient refers to the relative change in the resistance value of a thermistor when the ambient temperature changes by 1°C. Once the resistance temperature coefficient of a certain type of thermistor is known, the actual resistance value of the thermistor at the corresponding temperature can be estimated.


The microcontroller source program is as follows:

/*---------------------------------------------------------------------*/

/* --- STC MCU International Limited ----------------------------------*/

/* --- STC 1T Series MCU Demo Programme -------------------------------*/

/* If you want to use this code in your program, please indicate that you have used the data and program of Macrochip Technology in your program */

/*---------------------------------------------------------------------*/



/**************** Functional description of this program **************


Read ADC and measure temperature.


Use STC's MCU IO method to control 74HC595 to drive 8-bit digital tube.


The user can modify the macro to select the clock frequency.


Users can select common cathode or common anode in "User Defined Macro". It is recommended to use common cathode digital tubes as much as possible.


Use the 16-bit auto-reload of Timer0 to generate a 1ms beat. The program runs at this beat.

When modifying the MCU main clock frequency, it is automatically timed to 1ms.


The 4-digit digital tube on the left shows the reading of the voltage reference TL431 connected to ADC2, and the 4-digit digital tube on the right shows the temperature value with a resolution of 0.1 degrees.


NTC uses MF52 10K@25 degrees C with 1% accuracy.


When measuring temperature, for universality, use 12-bit ADC value and use the bisection lookup table to calculate.

Single-digit numbers are calculated using linear interpolation.


Therefore, the temperature measuring ADC3 performs 4 consecutive ADC samplings and becomes a 12-bit ADC to calculate the temperature.


**********************************************/


#include "config.H"

#include "adc.h"


/****************************** User defined macro***********************************/


#define LED_TYPE 0x00 //define LED type, 0x00--common cathode, 0xff--common anode


#define Timer0_Reload (65536UL -(MAIN_Fosc / 1000)) //Timer 0 interrupt frequency, 1000 times/second


/********************************************************************************/







/**************** Local constant declaration **************/

u8 code t_display[]={ //Standard font library

// 0 1 2 3 4 5 6 7 8 9 A B C D E F

        0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,

//black - H J K L N o P U t G Q r M y

        0x00,0x40,0x76,0x1E,0x70,0x38,0x37,0x5C,0x73,0x3E,0x78,0x3d,0x67,0x50,0x37,0x6e,

        0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0x87,0xFF,0xEF,0x46}; //0. 1. 2. 3. 4. 5. 6. 7. 8. 9. -1


u8 code T_COM[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //bit code



/**************** IO port definition **************/

sbit P_HC595_SER = P4^0; //pin 14 SER data input

sbit P_HC595_RCLK = P5^4; //pin 12 RCLk store (latch) clock

sbit P_HC595_SRCLK = P4^3; //pin 11 SRCLK Shift data clock



/**************** Local variable declaration **************/


u8 LED8[8]; //display buffer

u8 display_index; //Display bit index

bit B_1ms; //1ms flag


u16 msecond;


/************* Local function declaration **************/

u16 get_temperature(u16 adc);



/**************** External function declaration and external variable declaration*****************/




/********************** ADC configuration function****************************/

void ADC_config(void)

{

        ADC_InitTypeDef ADC_InitStructure; //Structure definition

        ADC_InitStructure.ADC_Px = ADC_P12 | ADC_P13; //Set IO to be ADC, ADC_P10 ~ ADC_P17 (or operation), ADC_P1_All

        ADC_InitStructure.ADC_Speed ​​= ADC_90T; //ADC speed ADC_90T, ADC_180T, ADC_360T, ADC_540T

        ADC_InitStructure.ADC_Power = ENABLE; //ADC power enable/disable ENABLE,DISABLE

        ADC_InitStructure.ADC_AdjResult = ADC_RES_H8L2; //ADC result adjustment, ADC_RES_H2L8,ADC_RES_H8L2

        ADC_InitStructure.ADC_Polity = PolityLow; //Priority setting PolityHigh,PolityLow

        ADC_InitStructure.ADC_Interrupt = DISABLE; //Interrupt enable ENABLE, DISABLE

        ADC_Inilize(&ADC_InitStructure); //Initialization

        ADC_PowerControl(ENABLE); //Individual ADC power operation function, ENABLE or DISABLE

}



/**************************************************/

void main(void)

{

        u8 i;

        u16 j;

        

        display_index = 0;

        ADC_config();

        

        Timer0_1T();

        Timer0_AsTimer();

        Timer0_16bitAutoReload();

        Timer0_Load(Timer0_Reload);

        Timer0_InterruptEnable();

        Timer0_Run();

        EA = 1; // Enable general interrupt

        

        for(i=0; i<8; i++) LED8[i] = 0x10; //Blanking on power-up


        

        while(1)

        {

                if(B_1ms) //1ms to

                {

                        B_1ms = 0;

                        if(++msecond >= 300) //300ms to

                        {

                                msecond = 0;

                                j = Get_ADC10bitResult(2); //Parameters 0~7, query mode to do an ADC, the return value is the result, == 1024 is an error

                                

                                if(j < 1024)

                                {

                                        LED8[0] = j / 1000; //Display ADC value

                                        LED8[1] = (j % 1000) / 100;

                                        LED8[2] = (j % 100) / 10;

                                        LED8[3] = j % 10;

                                        if(LED8[0] == 0) LED8[0] = DIS_BLACK;

                                }

                                else //error

                                {

                                        for(i=0; i<4; i++) LED8[i] = DIS_;

                                }

                                


                                j = Get_ADC10bitResult(3); //Parameters 0~7, query mode to do an ADC, the return value is the result, == 1024 is an error

                                j += Get_ADC10bitResult(3);

                                j += Get_ADC10bitResult(3);

                                j += Get_ADC10bitResult(3);


                                if(j < 1024*4)

                                {

                                /*

                                        LED8[0] = j / 1000; //Display ADC value

                                        LED8[1] = (j % 1000) / 100;

                                        LED8[2] = (j % 100) / 10;

                                        LED8[3] = j % 10;

                                        if(LED8[0] == 0) LED8[0] = DIS_BLACK;

                                */

                                        j = get_temperature(j); //Calculate temperature value


                                        if(j >= 400) F0 = 0, j -= 400; //temperature >= 0 degrees

                                        else F0 = 1, j = 400 - j; //temperature < 0 degrees

                                        LED8[4] = j / 1000; //Display temperature value

                                        LED8[5] = (j % 1000) / 100;

                                        LED8[6] = (j % 100) / 10 + DIS_DOT;

                                        LED8[7] = j % 10;

                                        if(LED8[4] == 0) LED8[4] = DIS_BLACK;

                                        if(F0) LED8[4] = DIS_; //display-

                                }

                                else //error

                                {

                                        for(i=0; i<8; i++) LED8[i] = DIS_;

                                }

                        }


                }

        }

/**************************************************/



// MF52E 10K at 25, B = 3950, ADC = 12 bits

u16 code temp_table[]={

                140, //;-40 0

[1] [2]
Keywords:NTC Reference address:NTC thermistor temperature measurement microcontroller C and assembly source program

Previous article:STC15 MCU ADC thermistor temperature measurement source program
Next article:STC15w4k58s4 MCU 4 serial ports simultaneous sending and receiving routine

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号