This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
您好!
我在配置 ADC 时遇到困难、下面是我的代码:
#include #include #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "inc/tm4c123gh600.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #volatile tatile tpotm/timer.ft = 32 nvolatile fatile ft ft float = 32 natile ft/ft inc = 32 nvolatile ft ft ft/voltatile ft fatile ft.h;ft ft ft.inc = 32 natile ft ft/volt.h = natile ft ft ft fotrupt.h = 32 natile ft ft.intratile t.h = volatile uint32_t TempF; void ObtMuestra (void); void TimerTemp (){ SysCtlPeripheralEnable (SYSCTL_Periph_TIMER0); TimerConfigure (TIMER0_BASE、TIMER_CFG_A_PERIODICASE); TimerLoadSet (TIMER0_BASE、TIMER_A、SysCtlClockGet ()/FsSensor - 1);//40MHz/125KHz TimerControlTrigger (TIMER0_BASE、TIMER_A、TRUE); TimerEnable (TIMER0_BASE、TIMER_A); } void TimerPot (){ SysCtlPeripheralEnable (SYSCTL_Periph_Timer1); TimerPot1(); TimerPot2(); } void TimerPot1(){ TimerConfigure (Timer1_base、timer_CFG_A_PERIODICRACRACASE); TimerLoadSet (Timer1_base、timer_A、SysCtlClockGet ()/FsPotA - 1);//40MHz/40KHz TimerControlTrigger (Timer1_base、timer_A、true); TimerEnable (Timer1_base、timer_A); } void TimerPot2 (){ TimerConfigure (Timer1_base、TIMER_CFG_B_PERIODICRACRACASE); TimerLoadSet (Timer1_base、timer_B、SysCtlClockGet ()/FsPotB - 1);//40MHz/20kHz TimerControlTrigger (Timer1_base、timer_B、true); TimerEnable (Timer1_base、timer_B); } //ADC 配置 空 ADCconfig(){ SysCtlPeripheralEnable (SYSCTL_Periph_ADC0); SysCtlPeripheralEnable (SYSCTL_Periph_GPIOE); GPIOPinTypeADC (GPIO_Porte _BASE、GPIO_PIN_1);//CH2 GPIOPinTypeADC (GPIO_Porte _BASE、GPIO_PIN_2);//CH1 ADCSequenceConfigure (ADC0_BASE、0、ADC_TRIGGER_TIMER、0); ADCSequenceStepConfigure (ADC0_BASE、0、0、ADC_CTL_CH2);//POTA ADCSequenceStepConfigure (ADC0_BASE、0、1、ADC_CTL_CH2);//POTA ADCSequenceStepConfigure (ADC0_BASE、0、2、ADC_CTL_CH1);//PotB ADCSequenceStepConfigure (ADC0_BASE、0、3、ADC_CTL_CH1);//PotB ADCSequenceStepConfigure (ADC0_BASE、0.4、ADC_CTL_TS);//传感器 ADCSequenceStepConfigure (ADC0_BASE、0、5、ADC_CTL_TS);//传感器 ADCSequenceStepConfigure (ADC0_BASE、0、6、ADC_CTL_TS);//传感器 ADCSequenceStepConfigure (ADC0_BASE、0、7、ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);//传感器 ADCSequenceEnable (ADC0_BASE、0); ADCIntEnable (ADC0_BASE、0); ADCIntRegister (ADC0_BASE、0、ObtMuestra); IntEnable (INT_ADC0SS0); IntMasterEnable(); } int main (void){ SysCtlClockSet (SYSCTL_XTAL_16MHz|SYSCTL_SYSDIV_5);//40MHz TimerTemp(); TimerPot (); ADCconfig(); } void ObtMuestra (){ 无符号长整型 ulADC0Value[8]; ADCIntClear (ADC0_BASE、0); ADCSequenceDataGet (ADC0_BASE、0、ulADC0Value); POT_A = conv*(ulADC0Value[0]+ulADC0Value[1])/2; POT_B = conv*(ulADC0Value[2]+ulADC0Value[3])/2; avgTemp =(ulADC0Value[4]+ ulADC0Value[5]+ ulADC0Value[6]+ ulADC0Value[7])/4; 温度 C =(1475 -(2475*avgTemp)/4096)/10; TempF =(9*TempC)/5+32; }
每个电位计需要2个样本、温度传感器需要4个样本、我的问题是变量 ulADC0Value 的 DataGet 中存在:
两个 Pot 位于0v 中、传感器的样本为2000 (例如)、因此第一个中断中的数组为:[0、0、0、200、200、200、200、200、000、2000 ]、当我恢复下一个中断时、我会得到数组中的值、如: [2000、200、0、0、0、200、2000]在每个中断中、我都得到值在数组中移动、因此 PoT_A、PoT_B、TempC 和 TempF 值的转换会发生根本变化。 发生什么事了?
我认为数组的[0]和[1]分配给了通道2中的值。 [2]和[3]连接到通道1,[4]…… [7]的值。
每次 ADC 转换需要1uS。 您正在进行8次转换、也就是8us。 您需要一些时间来读取结果、但会以125KHz 或恰好每8uS 再次触发 ADC。 因此、您正在尝试在下一次转换已经开始时读取 FIFO。 降低计时器频率或减少序列中的转换次数。