【MSPM0L1306 LaunchPad】板卡上温度传感器测试
[复制链接]
本帖最后由 TL-LED 于 2023-11-8 14:21 编辑
这篇来测试下板卡上的温度传感器,打印串口的温度值。
一、硬件电路
测试硬件选择,短路J15,J1选择1-2,选择PA15端口采集温度电压值。
二、温度传感器
板卡上温度传感器型号是TMP6131DECT
官网资料:https://www.ti.com.cn/tool/cn/download/TMP6-THERMISTOR-DESIGN
官网提供设计软件,下载地址:Thermistor Design Tool
通过软件来选择温度电阻的应用和采样方式。
三、配置ADC
配置PA15
四、代码
4.1、adc.c
#include "ti_msp_dl_config.h"
#include "adc/adc.h"
#include <stdio.h>
volatile bool gCheckADC;
volatile uint16_t gAdcResult;
float VBias = 3.30;
uint16_t ADC_BITS = 4096;
float VTEMP = 0;
float THRM_TEMP = 0;
int THRM_ADC;
void ADC12_0_INST_IRQHandler(void)
{
switch (DL_ADC12_getPendingInterrupt(ADC12_0_INST))
{
case DL_ADC12_IIDX_MEM0_RESULT_LOADED:
gCheckADC = true;
break;
default:
break;
}
}
float thermistor(int raw_ADC)
{
VTEMP=0;
THRM_ADC=raw_ADC;
float THRM_A0 = -4.232811E+02;
float THRM_A1 = 4.728797E+02;
float THRM_A2 = -1.988841E+02;
float THRM_A3 = 4.869521E+01;
float THRM_A4 = -1.158754E+00;
VTEMP = (VBias/ADC_BITS)*THRM_ADC;
THRM_TEMP =(THRM_A4*powf(VTEMP,4))+(THRM_A3*powf(VTEMP,3))+(THRM_A2*powf(VTEMP,2))+(THRM_A1*VTEMP)+THRM_A0;
return THRM_TEMP;
}
void init_adc(void)
{
NVIC_EnableIRQ(ADC12_0_INST_INT_IRQN);
gCheckADC = false;
}
void adc_test(void)
{
float adv=0.0;
DL_ADC12_startConversion(ADC12_0_INST);
if(gCheckADC==true)
{
gCheckADC = false;
gAdcResult = DL_ADC12_getMemResult(ADC12_0_INST, DL_ADC12_MEM_IDX_0);
adv=thermistor(gAdcResult);
printf("temp=%.2f℃\r\n",adv);
DL_ADC12_enableConversions(ADC12_0_INST);
}
}
4.2、main.c
#include "ti_msp_dl_config.h"
#include "systick/systick.h"
#include "led/led.h"
#include "uart/uart.h"
#include <string.h>
#include <stdio.h>
#include "adc/adc.h"
#include "spi/spi.h"
#include "x2515/x2515.h"
int main(void)
{
uint8_t can_txbuf[8]={0};
uint8_t js=0;
SYSCFG_DL_init();
init_adc();
led2_r_off();
led2_g_off();
led2_b_off();
while (1)
{
adc_test();
SysTick_Delay_ms(100);
}
}
五、运行结果
打印温度值
|