TI中文支持网
TI专业的中文技术问题搜集分享网站

TM4C123x 程序小练 ADC温度传感器

/*******************************************
开发坏境:CCSv5.4
开发板:TIVA C Launchpad(TM4C123GH6PM)
程序功能:ADC温度传感器,显示摄氏和华氏温度
程序说明:将ADC0的序列发生器SS1的4个采样值平均,来提高精度
编程者:Linchpin
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"

int main(void)
{
	uint32_t ui32ADC0Value[4];
	volatile uint32_t ui32TempAvg;
	volatile uint32_t ui32TempValueC;
	volatile uint32_t ui32TempValueF;

	SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
	//5分频,使用PLL,外部晶振16M,system时钟源选择 main osc。系统时钟40MHZ
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
	//使能ADC0
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
	//We want to use ADC0, sample sequencer 1,
	//we want the processor to trigger the sequence and we want to use the highest priority
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	//Configure steps 0 - 2 on sequencer 1 to sample the temperature sensor (ADC_CTL_TS).
	ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
	//Sample the temperature sensor (ADC_CTL_TS) and configure the interrupt flag (ADC_CTL_IE)
	//Tell the ADC logic that this is the last conversion on sequencer1 (ADC_CTL_END).
	ADCSequenceEnable(ADC0_BASE, 1);
	//enable ADC sequencer 1while(1)
	{ADCIntClear(ADC0_BASE, 1);ADCProcessorTrigger(ADC0_BASE, 1);//trigger the ADC conversion with softwarewhile(!ADCIntStatus(ADC0_BASE, 1, false)){}//wait for the conversion to completeADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;//Since 2/4 = 1/2 = 0.5, 1.5 will be rounded to 2.0 with//the addition of 0.5. In the case of 1.0, when 0.5 is added to yield 1.5, this will be rounded//back down to 1.0 due to the rules of integer math.即四舍五入ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;//TEMP = 147.5 – ((75 * (VREFP – VREFN) * ADCVALUE) / 4096)//VREFP – VREFN=3.3Vui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;//F = ( C * 9)/5 +32
	}
}
Maka Luo:

如果TM4C129X那个评估版做,可以直观显示,更赞。

xyz549040622:

回复 Maka Luo:

官方DK的板子太贵了,有没有折扣码可以放出来呢?

Maka Luo:

回复 xyz549040622:

没有折扣,建议联系当地TI office

赞(0)
未经允许不得转载:TI中文支持网 » TM4C123x 程序小练 ADC温度传感器
分享到: 更多 (0)