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.

这是我改的一个接收4路数据的代码,给帮忙看看

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);
InitConsole();

//
// Display the setup on the console.
//
UARTprintf("ADC ->\n");
UARTprintf(" Type: Internal Temperature Sensor\n");
UARTprintf(" Samples: One\n");
UARTprintf(" Update Rate: 250ms\n");
UARTprintf(" Input Pin: Internal temperature sensor\n\n");
//5??,??PLL,????16M,system????? main osc?????40MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//??ADC0
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_5);

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_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH2);
//Configure steps 0 - 2 on sequencer 1 to sample the temperature sensor (ADC_CTL_TS).
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH8|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 1
while(1)
{
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
//trigger the ADC conversion with software
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
//wait for the conversion to complete
ADCSequenceDataGet(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.3V
// ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
UARTprintf("Temperature = %d %d %d %d\r\n", ui32ADC0Value[0],
ui32ADC0Value[1],ui32ADC0Value[2],ui32ADC0Value[3]);
//F = ( C * 9)/5 +32
}
}

我自己尝试了一下,收到的数据会出现0或4095这两个数,还有就是结算公式是不是和内部温度传感器的结算方法相同,谢谢指点

  • 传感器是个地磁传感器,传感器的电压是5V

  • 1.首先是算法,肯定是不一样的,不一样的传感器算法不一样,要根据你的传感器来具体计算。

    2.其实是电压,TM4C123x是3.3V供电,你传感器是5V供电,那么进去ad的电压最大也是5V,很可能就烧坏芯片的。要保证进去的电压不能超过VDDA。

    3.出现0是说明你输入的电压就是0V,出现4095说明ad输入的电压超过或者等于3.3V,ad饱和了。

    4.你对你做的实验的流程和原理还是不熟悉,这么蛮干,肯定是进度慢,建议你多看看相关的论文,弄清楚原理。知道和弄懂你想要什么

  • f非常感谢指点,我在问一下,第一,我的四路采集的代码有没有错误,第二,ad没有转换关系吗,他只是采集数据,而不是讲传感器的输出量转化为ad内的数输出来吗,第三个就是关于sequence,先前我在使用内部温度传感器的时候,使用过sequence1和3,但是两种情况下,温度的值不同,差异还比较大,这是什么愿意呀,

  • 1.这个没有测试,不过大致应该是没问题的。你可以自己测试,分别1,2,3,4l路接不同的电压进去,看看串口打印值的变化就知道了。

    2.ad有转换关系的,输进去0V,输出的数字在0左右。输进去电压3.3V,输出的数字在4096左右,仅此而已。至于要和你实际的传感器对上,要看你传感器和输出电压的对应关系的。这个和内部的温度传感器是不同的。

    3.至于3,肯定应该是一样的,估计还是你代码配置不对吧。

  • n你好,今天我测试了一下这个程序,用一个16位的DA发送4个电压0.1   0.8   1.5  3.0但是第一路也就是0.1V这个输出的值还有0出现,不是一个稳定的值,这是怎么回事呀