pt100温度阻值换算查表
时间: 2024-06-17 09:05:38 浏览: 187
PT100是一种常见的温度传感器,它的电阻值随温度的变化而变化。因此,我们需要根据电阻值来计算温度。PT100的电阻值换算查表是根据国际标准ITS-90来制定的,表格中给出了不同温度下PT100的电阻值。
下面是一个PT100温度阻值换算表的示例:
| 温度(℃) | 电阻值(Ω) |
| -- | ------ |
| -200 | 18.520 |
| -100 | 60.310 |
| 0 | 100.000|
| 100 | 138.510|
| 200 | 176.990|
例如,如果我们知道了PT100的电阻值为120.345Ω,则可以通过查表得知它所对应的温度约为63℃。
相关问题
帮我写一个stm32 使用PT100测温,使用查表法的程序
好的,以下是一个使用STM32和PT100传感器测温的程序,使用查表法计算温度:
```c
#include "stm32f4xx.h"
#include <math.h>
#define TABLE_SIZE 100
#define VREF 3.3
#define R_REF 100.0
#define R0 100.0
#define A 3.9083e-3
#define B -5.775e-7
float temperature_table[TABLE_SIZE] = {-200, -195, -190, /* ... */ , 995, 1000}; // 温度表格
void delay(uint32_t time)
{
while(time--);
}
int get_adc_value(void)
{
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_480Cycles);
ADC_SoftwareStartConv(ADC1);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC));
return ADC_GetConversionValue(ADC1);
}
float get_resistance(int adc_value)
{
float v = adc_value * VREF / 4096.0;
return (v * R_REF) / (3.3 - v);
}
float get_temperature(float resistance)
{
float t = 0.0;
float r = resistance / R0;
t = (-A + sqrtf(A * A - 4 * B * (1 - r))) / (2 * B);
return t;
}
float lookup_temperature(float resistance)
{
int i = 0;
for(i = 0; i < TABLE_SIZE; i++)
{
if(resistance > resistance_table[i])
{
break;
}
}
return temperature_table[i];
}
int main(void)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_20Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
while(1)
{
int adc_value = get_adc_value();
float resistance = get_resistance(adc_value);
float temperature = lookup_temperature(resistance);
// do something with temperature
delay(1000);
}
}
```
这个程序使用了STM32的ADC模块来读取PT100传感器的电阻值,并使用查表法将电阻值转换为温度。注意,在程序中需要设置正确的ADC通道和引脚配置,以及正确的温度表格。
帮我写一个stm32 使用PT100测温,使用查表法测温,测温范围-120 到80℃,使用hal库
好的,以下是一个使用STM32和PT100传感器测温的程序,使用查表法计算温度,测温范围为-120℃到80℃,使用HAL库:
```c
#include "main.h"
#include <math.h>
#define TABLE_SIZE 201
#define V_REF 3.3f
#define R_REF 100.0f
#define R0 100.0f
#define A 3.9083e-3f
#define B -5.775e-7f
float temperature_table[TABLE_SIZE] = {-120.0f, -119.0f, -118.0f, /* ... */ , 78.0f, 79.0f, 80.0f}; // 温度表格
ADC_HandleTypeDef hadc1;
void SystemClock_Config(void);
int get_adc_value(void)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
return HAL_ADC_GetValue(&hadc1);
}
float get_resistance(int adc_value)
{
float v = (float)adc_value * V_REF / 4096.0f;
return (v * R_REF) / (V_REF - v);
}
float get_temperature(float resistance)
{
float t = 0.0f;
float r = resistance / R0;
t = (-A + sqrtf(A * A - 4 * B * (1 - r))) / (2 * B);
return t;
}
float lookup_temperature(float resistance)
{
int i = 0;
for(i = 0; i < TABLE_SIZE; i++)
{
if(resistance > (float)i)
{
break;
}
}
if(i == 0)
{
return temperature_table[0];
}
else if(i >= TABLE_SIZE)
{
return temperature_table[TABLE_SIZE - 1];
}
else
{
float x1 = (float)(i - 1);
float x2 = (float)i;
float y1 = temperature_table[i - 1];
float y2 = temperature_table[i];
float k = (y2 - y1) / (x2 - x1);
float b = y1 - k * x1;
return k * resistance + b;
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_ADC1_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
while (1)
{
int adc_value = get_adc_value();
float resistance = get_resistance(adc_value);
float temperature = lookup_temperature(resistance);
// do something with temperature
HAL_Delay(1000);
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 180;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
Error_Handler();
}
}
```
这个程序使用了STM32的ADC模块来读取PT100传感器的电阻值,并使用查表法将电阻值转换为温度。注意,在程序中需要设置正确的ADC通道和引脚配置,以及正确的温度表格。此外,程序中还包含了时钟配置函数,以确保系统时钟正确工作。
阅读全文