int
main(void)
{
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
uint32_t ui32SysClock;
#endif
//
// This array is used for storing the data read from the ADC FIFO. It
// must be as large as the FIFO for the sequencer in use. This example
// uses sequence 3 which has a FIFO depth of 1. If another sequence
// was used with a deeper FIFO, then the array size must be changed.
//
uint32_t pui32ADC0Value[1];
//
// Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL. When
// using the ADC, you must either use the PLL or supply a 16 MHz clock
// source.
// TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
// crystal on your board.
//
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 20000000);
#else
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
#endif
//
// Set up the serial console to use for displaying messages. This is
// just for this example program and is not needed for ADC operation.
//
configureUART();
//
// Display the setup on the console.
//
UARTprintf("ADC ->\n");
UARTprintf(" Type: Single Ended\n");
UARTprintf(" Samples: One\n");
UARTprintf(" Update Rate: 250ms\n");
UARTprintf(" Input Pin: AIN0/PE3\n\n");
//
// The ADC0 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
//
// For this example ADC0 is used with AIN0 on port E7.
// The actual port and pins used may be different on your part, consult
// the data sheet for more information. GPIO port E needs to be enabled
// so these pins can be used.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//
// Select the analog ADC function for these pins.
// Consult the data sheet to see which functions are allocated per pin.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3| GPIO_PIN_2| GPIO_PIN_1| GPIO_PIN_5);
//
// Enable sample sequence 3 with a processor signal trigger. Sequence 3
// will do a single sample when the processor sends a signal to start the
// conversion. Each ADC module has 4 programmable sequences, sequence 0
// to sequence 3. This example is arbitrarily using sequence 3.
//
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
//
// Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in
// single-ended mode (default) and configure the interrupt flag
// (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic
// that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence
// 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and
// sequence 0 has 8 programmable steps. Since we are only doing a single
// conversion using sequence 3 we will only configure step 0. For more
// information on the ADC sequences and steps, reference the datasheet.
//
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);
//
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 3);
//
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
//
ADCIntClear(ADC0_BASE, 3);
//
// Sample AIN0 forever. Display the value on the console.
//
while(1)
{
//
// Trigger the ADC conversion.
//
ADCProcessorTrigger(ADC0_BASE, 3);
//
// Wait for conversion to be completed.
//
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
//
// Clear the ADC interrupt flag.
//
ADCIntClear(ADC0_BASE, 3);
//
// Read ADC Value.
//
ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value);
//
// Display the AIN0 (PE3) digital value on the console.
//
UARTprintf("AIN0 = %4d\r or AIN1 = %4d\r or AIN2 = %4d\r or AIN3= %4d\r", pui32ADC0Value[0]);
// This function provides a means of generating a constant length
// delay. The function delay (in cycles) = 3 * parameter. Delay
// 250ms arbitrarily.
//
#if defined(TARGET_IS_TM4C129_RA0) || \
defined(TARGET_IS_TM4C129_RA1) || \
defined(TARGET_IS_TM4C129_RA2)
SysCtlDelay(ui32SysClock / 12);
#else
SysCtlDelay(SysCtlClockGet() / 12);
#endif
}
}
黄色部分是我改正后的,请各位大神帮忙指正一下,谢谢能否正确采集四路数据
xyz549040622:
没法给你测,只能自己实测找问题了。注意通道的切换,主函数中其他通道的读函数在哪呢?只读取了一个通道呀。
chang liu11:
回复 xyz549040622:
k可否指出来,示例一下,对于通道不理解,难道需要4个通道吗
chang liu11:
回复 xyz549040622:
实际上可以接收四路数据的,但是有两路数据一模一样,把传感器拔掉后,依然有数据出现,还有如何把接收到的数据,换算成实际的,板子的换算关系在哪呢
xyz549040622:
回复 chang liu11:
我看了看数据手册的ad部分,我理解的也是有误差的,重新更正如下
1.TM4C123x其实只有两个ad模块,但是有24个ad通道。
明天继续写。
chang liu11:
回复 xyz549040622:
实际上可以接收四路数据的,但是有两路数据一模一样,把传感器拔掉后,依然有数据出现,还有如何把接收到的数据,换算成实际的,板子的换算关系在哪呢。还有对于通道不理解,能否指点一下,4路数据需要几个通道,
chang liu11:
回复 xyz549040622:
实际上可以接收四路数据的,但是有两路数据一模一样,把传感器拔掉后,依然有数据出现,还有如何把接收到的数据,换算成实际的,板子的换算关系在哪呢。还有对于通道不理解,能否指点一下,4路数据需要几个通道,