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.
我想配置一个PE4,PE5两通道采样,配置采样率500k是先使能在配置,还是其他?
在获得数据的时候只有一个函数ADCSequenceDataGet();会不会两通道的数据获得重合?怎样才能精确的获得2通道数据?
void ADC0_init(void)
{
// Enable GPIO for ADC
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_500KSPS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);// Enable pin PE4_AIN9
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);// Enable pinPE5 _AIN8
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH8|ADC_CTL_CH9| ADC_CTL_IE |ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
ADCIntClear(ADC0_BASE, 1);//
// ADCIntRegister(ADC0_BASE,1,ADC0IntHandler);//
ADCIntEnable(ADC0_BASE,1);//
}
默认的采样速度1M就ok。
设置采样PE4,PE5两个通道时,按照楼主的配置,采样结束后,可以从fifo中读出2个数据,那么第一个数据对应的就是CH8的,第二个就是CH9的。
谢谢回复,你的意思是说比如我设置一个数组unsigned long ulADC0_Value[2];那我用函数才回来的值 ADCSequenceDataGet(ADC0_BASE, 1, ulADC0_Value); ulADC0_Value[0]放的CH8,ulADC0_Value[1]放的CH9是这样的嘛?;;还有这个主要涉及到一个闭环系统,采样过快调节不过来,所以我这样设置采样率对嘛
是这样理解。关于采样率设置,我记得早的TivaWare的库函数有点问题,后来我改成直接操作寄存器的了。把这个代码分享给您吧。
这里采样的是ADC的CH0~CH7,使能了中断,在中断中就可以直接读出8个数据,对应0~7通道的。
采样率的设置和查询我自己写的函数。
上代码:
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_adc.h"
//*****************************************************************************
//
//! \addtogroup adc_examples_list
//! <h1>Single Ended ADC (single_ended)</h1>
//!
//! This example shows how to setup ADC0 as a single ended input and take a
//! single sample on AIN0/PE7.
//!
//! This example uses the following peripherals and I/O signals. You must
//! review these and change as needed for your own board:
//! - ADC0 peripheral
//! - GPIO Port E peripheral (for AIN0 pin)
//! - AIN0 - PE7
//!
//! The following UART signals are configured only for displaying console
//! messages for this example. These are not required for operation of the
//! ADC.
//! - UART0 peripheral
//! - GPIO Port A peripheral (for UART0 pins)
//! - UART0RX - PA0
//! - UART0TX - PA1
//!
//! This example uses the following interrupt handlers. To use this example
//! in your own application you must add these interrupt handlers to your
//! vector table.
//! - None.
//
//*****************************************************************************
#define ADCSAMPLERATE_1MSPS 0x7 // 1,000,000 samples per second
#define ADCSAMPLERATE_500KSPS 0x5 // 500,000 samples per second
#define ADCSAMPLERATE_250KSPS 0x3 // 250,000 samples per second
#define ADCSAMPLERATE_125KSPS 0x1 // 125,000 samples per second
//*****************************************************************************
//
// This function sets up UART0 to be used for a console to display information
// as the example is running.
//
//*****************************************************************************
uint32_t pui32ADC0Value[8];
uint32_t Data[8]={0};
uint32_t TempVal = 0;
uint32_t TempVal2 = 0;
void ADCSampleRateSet(uint32_t ui32Speed)
{
//
// Set the ADC speed
//
HWREG(ADC0_BASE + ADC_O_PC) = (ui32Speed);
}
uint32_t ADCSampleRateGet(void)
{
//
// Return the current ADC speed.
//
return((HWREG(ADC0_BASE + ADC_O_PC) & 0x0f));
}
void
InitConsole(void)
{
//
// Enable GPIO port A which is used for UART0 pins.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//
// Enable UART0 so that we can configure the clock.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Select the alternate (UART) function for these pins.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}
void ADC0Sequence0Isr(void)
{
uint16_t i;
//
// Clear the ADC interrupt flag.
//
ADCIntClear(ADC0_BASE, 0);
//
// Read ADC Value.
//
ADCSequenceDataGet(ADC0_BASE, 0, pui32ADC0Value);
for(i = 0;i < 8;i ++)
{
Data[i] = pui32ADC0Value[i]*3300/4096;
}
SysCtlDelay(1);
}
//*****************************************************************************
//
// Configure ADC0 for a single-ended input and a single sample. Once the
// sample is ready, an interrupt flag will be set. Using a polling method,
// the data will be read then displayed on the console via UART0.
//
//*****************************************************************************
int
main(void)
{
//
// 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[8];
//uint32_t Data[8]={0};
//
// 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.
//
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Set up the serial console to use for displaying messages. This is
// just for this example program and is not needed for ADC operation.
//
InitConsole();
// //
// // 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/PE7\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_GPIOD);
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_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//set sample rate
ADCSampleRateSet(ADCSAMPLERATE_1MSPS);
//
// 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, 0, 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, 0, 0, ADC_CTL_CH0 );//PE3
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1 );//PE2
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2 );//PE1
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3 );//PE0
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH4 );//PD3
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH5 );//PD2
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH6 );//PD1
ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH7 | ADC_CTL_IE |ADC_CTL_END);
ADCIntEnable(ADC0_BASE, 0);
IntEnable(INT_ADC0SS0);
IntMasterEnable();
ADCIntClear(ADC0_BASE, 0);
//
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 0);
//
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
//
TempVal = ADCSampleRateGet();
//
// Sample AIN0 forever. Display the value on the console.
//
while(1)
{
//
// Trigger the ADC conversion.
//
ADCProcessorTrigger(ADC0_BASE, 0);
/*
//
// Wait for conversion to be completed.
//
while(!ADCIntStatus(ADC0_BASE, 0, false))
{
}
//
// Clear the ADC interrupt flag.
//
ADCIntClear(ADC0_BASE, 0);
//
// Read ADC Value.
//
ADCSequenceDataGet(ADC0_BASE, 0, pui32ADC0Value);
*/
/*
Data[0] = pui32ADC0Value[0]*3300/4096;
Data[1] = pui32ADC0Value[1]*3300/4096;
Data[2] = pui32ADC0Value[2]*3300/4096;
Data[3] = pui32ADC0Value[3]*3300/4096;
Data[4] = pui32ADC0Value[4]*3300/4096;
Data[5] = pui32ADC0Value[5]*3300/4096;
Data[6] = pui32ADC0Value[6]*3300/4096;
Data[7] = pui32ADC0Value[7]*3300/4096;
*/
//
// Display the AIN0 (PE7) digital value on the console.
//
// UARTprintf("AIN0 = %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.
//
SysCtlDelay(SysCtlClockGet() / 12);
}
}
1.我在代码中没看到有中断函数,请问中断内做了操作
2.ADC的中断触发配置为采样结束触发 ,应该怎么写?
在void ADCIntEnableEx(uint32_t ui32Base,uint32_t ui32IntFlags)
中:
ADC_INT_SS0 - interrupt due to ADC sample sequence 0.
ADC_INT_DMA_SS0 - interrupt due to DMA on ADC sample sequence 0.
ADC_INT_DCON_SS0 - interrupt due to digital comparator on ADC sample sequence 0.
这三个出发类型选择,分别是什么意思?
3.我在您的代码里没看到有配置触发方式的这一句,如果不配置,默认是什么方式触发?
您好,看见您的帖子很有收获。我有个关于ADC的问题,我用的CPUI是TM4C1294NCPDT,我需要用14个AI采集通道,根据您的程序,可以配置前8个通道,但是后面的6个通道怎样配置呢?谢谢
您好,我配制成4通道同时采集总是会出现固定的误差,比测试电压高300mV左右,目前就第一个通道有输入电压,其它几个通道悬空,这样其余通道也会出现挺大的电压数据,请问是怎么回事呢?
代码:
#define ADC_SSx 1 //采样序列定义
/*
================================================================================
描述 :
输入 :
输出 :
================================================================================
*/
void user_adcInit(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);//开启ADC时钟
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);//开启相应ADC引脚时钟
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0);//通道引脚初始化
ADCSequenceConfigure(ADC0_BASE, ADC_SSx, ADC_TRIGGER_PROCESSOR, 0);//ADC模式配置
ADCSequenceStepConfigure(ADC0_BASE, ADC_SSx, 0, ADC_CTL_CH0);//采样通道配置
ADCSequenceStepConfigure(ADC0_BASE, ADC_SSx, 1, ADC_CTL_CH1);//采样通道配置
ADCSequenceStepConfigure(ADC0_BASE, ADC_SSx, 2, ADC_CTL_CH2);//采样通道配置
ADCSequenceStepConfigure(ADC0_BASE, ADC_SSx, 3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);//采样通道配置
ADCSequenceEnable(ADC0_BASE, ADC_SSx); //使能采样序列
ADCIntClear(ADC0_BASE, ADC_SSx); //清除中断标志
}
/*
================================================================================
描述 :主程序循环调用
输入 :
输出 :
================================================================================
*/
void ADC_Read(void)
{
uint32_t pui32ADC0Value[8];
u8 i;
memset(pui32ADC0Value, 0, sizeof(pui32ADC0Value));
ADCProcessorTrigger(ADC0_BASE, ADC_SSx);
while(!ADCIntStatus(ADC0_BASE, ADC_SSx, false));
ADCIntClear(ADC0_BASE, ADC_SSx);
ADCSequenceDataGet(ADC0_BASE, ADC_SSx, pui32ADC0Value);
for(i=0;i<4;i++)
{
UARTprintf("ADC Value%d=%dmV\n",i,pui32ADC0Value[i]*3300/4096);
}
UARTprintf("******************\n");
}
输出数据:
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
//*****************************************************************************
//
//! \addtogroup adc_examples_list
//! <h1>ADC Temperature Sensor (temperature_sensor)</h1>
//!
//! This example shows how to setup ADC0 to read the internal temperature
//! sensor.
//!
//! NOTE: The internal temperature sensor is not calibrated. This example
//! just takes the raw temperature sensor sample and converts it using the
//! equation found in the LM3S9B96 datasheet.
//!
//! This example uses the following peripherals and I/O signals. You must
//! review these and change as needed for your own board:
//! - ADC0 peripheral
//!
//! The following UART signals are configured only for displaying console
//! messages for this example. These are not required for operation of the
//! ADC.
//! - UART0 peripheral
//! - GPIO Port A peripheral (for UART0 pins)
//! - UART0RX - PA0
//! - UART0TX - PA1
//!
//! This example uses the following interrupt handlers. To use this example
//! in your own application you must add these interrupt handlers to your
//! vector table.
//! - None.
//
//*****************************************************************************
//*****************************************************************************
//
// This function sets up UART0 to be used for a console to display information
// as the example is running.
//
//*****************************************************************************
void
InitConsole(void)
{
//
// Enable GPIO port A which is used for UART0 pins.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
//
// Enable UART0 so that we can configure the clock.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Select the alternate (UART) function for these pins.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}
int main(void)
{
uint32_t ui32ADC0Value[4];
//volatile uint32_t ui32TempAvg;
//volatile uint32_t ui32TempValueC;
//volatile uint32_t ui32TempValueF;
SysCtlClockSet(SYSCTL_SYSDIV_10|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
//SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1000KSPS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);// Enable pin PE4_AIN0
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);// Enable pinPE5 _AIN1
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);// Enable pin PE4_AIN8
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);// Enable pinPE5 _AIN9
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,0,ADC_CTL_CH0|ADC_CTL_CH1|ADC_CTL_CH8|ADC_CTL_CH9|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("%d %d %d %d\r\n", ui32ADC0Value[0],ui32ADC0Value[1],ui32ADC0Value[2],
ui32ADC0Value[3] );
//F = ( C * 9)/5 +32
}
}
请问我这个代码哪里有错,我想接受4路数据,我使用一个16位的DA,分别发送0.5/1/2/3V四个电压,这是接收到的数据
3997 0 0 536871424
4033 0 0 536871424
4037 0 0 536871424
3997 0 0 536871424
4035 0 0 536871424
2758 0 0 536871424
2692 0 0 536871424
2708 0 0 536871424
2737 0 0 536871424
2717 0 0 536871424
3602 0 0 536871424
3953 0 0 536871424
3934 0 0 536871424
4028 0 0 536871424
3995 0 0 536871424
3237 0 0 536871424
2696 0 0 536871424
2707 0 0 536871424
2716 0 0 536871424
2750 0 0 536871424
2834 0 0 536871424
4031 0 0 536871424
4080 0 0 536871424
4004 0 0 536871424
4041 0 0 536871424
3934 0 0 536871424
2719 0 0 536871424
2691 0 0 536871424
2696 0 0 536871424
2725 0 0 536871424
2712 0 0 536871424
3858 0 0 536871424
4033 0 0 536871424
4036 0 0 536871424
4032 0 0 536871424
3975 0 0 536871424
3036 0 0 536871424
2714 0 0 536871424
2716 0 0 536871424
2757 0 0 536871424
2709 0 0 536871424
3012 0 0 536871424
4020 0 0 536871424
请帮忙看一下,谢谢
ADCSequenceStepConfigure(ADC0_BASE,1,0,ADC_CTL_CH0|ADC_CTL_CH1|ADC_CTL_CH8|ADC_CTL_CH9|ADC_CTL_IE|ADC_CTL_END);
明显你的ui32ADC0Value[3]的值溢出了,这么大。上面这个函数的第三个参数应该是3吧。
您好,听了你的建议我把0改成了三但是结果成了
0 0 0 2826
0 0 0 2777
471 464 448 3304
1173 1155 1189 4095
1151 1153 1162 4029
1241 1159 1171 4095
1239 1227 1242 4084
771 841 747 3700
0 0 0 2721
0 0 0 2686
0 0 0 2681
0 0 0 2688
0 0 0 2727
0 0 0 2759
0 0 0 2758
447 439 458 3318
1154 1187 1134 3926
1171 1239 1166 4034
1083 1123 1179 4012
995 1095 1200 3955
895 897 904 3751
0 0 0 2702
0 0 0 2690
0 0 0 2655
0 0 0 2691
2 0 0 2754
0 0 0 2724
0 0 0 2711
286 325 232 3246
1159 1129 1160 4001
1190 1178 1199 4070
1175 1132 1100 4017
1139 1155 1148 4075
939 868 852 3775
输入是稳定的,用万用表测过了
这一句一个个来,
ADCSequenceStepConfigure(ADC0_BASE,1,0,ADC_CTL_CH0|ADC_CTL_CH1|ADC_CTL_CH8|ADC_CTL_CH9|ADC_CTL_IE|ADC_CTL_END);
换成这样:
ADCSequenceStepConfigure(ADC0_BASE,1,0,ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,1,1,ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE,1,2,ADC_CTL_CH8);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH9|ADC_CTL_IE|ADC_CTL_END);
您好,我改了,现在的代码是这个样子的
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
//SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1000KSPS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);// Enable pin PE4_AIN0
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);// Enable pinPE5 _AIN1
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);// Enable pin PE4_AIN8
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);// Enable pinPE5 _AIN9
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_CH8);
//Configure steps 0 - 2 on sequencer 1 to sample the temperature sensor (ADC_CTL_TS).
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH9|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("%d %d %d %d\r\n", ui32ADC0Value[0], ui32ADC0Value[1], ui32ADC0Value[2],
ui32ADC0Value[3]);
//F = ( C * 9)/5 +32
}
}
输入没有变化,结果却是
395 895 2118 3266
1193 1717 2790 4095
1088 1797 2970 4095
1098 1729 2848 4031
1231 1774 2970 4095
723 1371 2529 3779
0 283 1384 2821
0 303 1471 2633
0 317 1493 2765
0 391 1593 2742
0 329 1474 2714
291 909 2048 3286
1106 1819 2956 4095
1190 1707 2811 4095
1115 1827 2940 4095
1186 1755 2917 4070
726 1321 2446 3641
0 465 1490 2731
0 343 1546 2742
0 435 1492 2750
0 355 1516 2731
0 407 1578 2850
186 815 2066 3230
1242 1787 2962 4095
1091 1773 2974 4095
1143 1723 2975 4095
1142 1745 2938 4095
806 1369 2600 3714
0 401 1572 2781
0 347 1482 2726
0 619 1574 2786
0 341 1535 2732
0 365 1592 2755
343 928 2068 3311
1131 1725 2912 4095
1287 1827 2932 4095
1167 1749 2862 4016
1215 1772 2949 4095
743 1367 2498 3743
0 389 1486 2751
0 340 1560 2741
87 515 1578 2768
0 336 1485 2683
0 337 1595 2804
366 969 2157 3288
1057 1712 2867 4043
1159 1772 2818 3999
1151 1793 2932 4095
1271 1838 2978 4095
758 1299 2460 3762
0 433 1531 2732
0 369 1641 2803
0 388 1584 2756
0 309 1532 2738
0 359 1536 2740
但是我把PE4引脚和VCC接到一起,结果是这样的
939 1575 2831 4095
915 1581 2834 4095
927 1581 2833 4095
932 1573 2825 4095
917 1569 2836 4095
914 1571 2831 4095
915 1567 2835 4095
918 1573 2825 4095
924 1573 2833 4095
915 1573 2844 4095
914 1571 2832 4095
927 1575 2834 4095
915 1575 2831 4095
925 1585 2833 4095
921 1575 2820 4095
918 1563 2825 4095
911 1575 2828 4095
939 1583 2833 4095
922 1579 2829 4095
935 1577 2834 4094
924 1571 2821 4095
931 1571 2832 4095
911 1595 2822 4095
920 1569 2828 4095
927 1571 2828 4095
923 1580 2832 4095
942 1577 2833 4095
918 1587 2842 4095
935 1575 2840 4095
918 1569 2828 4095
899 1567 2824 4095
910 1579 2828 4095
926 1575 2828 4095
923 1581 2832 4095
918 1569 2830 4095
929 1575 2829 4095
918 1571 2834 4095
922 1568 2817 4095
915 1567 2827 4095
919 1577 2832 4095
923 1573 2831 4095
903 1571 2828 4095
927 1582 2832 4095
932 1584 2825 4095
927 1568 2825 4095
924 1563 2829 4095
911 1579 2834 4095
925 1571 2826 4095
921 1568 2812 4095
921 1569 2828 4095
908 1561 2825 4095
941 1578 2830 4095
926 1579 2828 4095
919 1571 2831 4095
907 1565 2831 4095
915 1571 2814 4095
923 1571 2832 4095
907 1579 2837 4095
927 1569 2824 4095
931 1593 2846 4095
925 1575 2826 4095
926 1581 2833 4095
923 1577 2829 4095
926 1576 2830 4095
927 1576 2828 4095
909 1568 2814 4095
926 1569 2831 4095
922 1575 2827 4095
926 1570 2829 4095
918 1575 2837 4095
915 1577 2833 4095
919 1581 2832 4095
923 1575 2836 4095
917 1579 2830 4095
930 1575 2830 4095
911 1573 2831 4095
926 1573 2826 4095
926 1583 2831 4095
929 1587 2828 4095
932 1579 2831 4095
922 1568 2830 4088
932 1579 2847 4095
911 1571 2828 4095
918 1571 2828 4095
928 1579 2829 4095
923 1583 2830 4095
923 1587 2833 4095
918 1566 2827 4095
919 1571 2827 4095
919 1570 2827 4095
915 1543 2834 4095
899 1571 2827 4095
927 1557 2826 4095
915 1577 2829 4095
923 1583 2828 4095
920 1573 2824 4095
919 1568 2824 4095
919 1577 2836 4095
923 1573 2833 4095
916 1571 2834 4095
915 1571 2833 4095
915 1575 2829 4095
919 1567 2824 4095
921 1569 2826 4095
923 1575 2825 4095
931 1577 2833 4095
919 1574 2827 4095
923 1579 2825 4095
935 1569 2854 4095
925 1571 2822 4095
916 1575 2820 4095
923 1583 2828 4095
914 1553 2814 4095
919 1567 2830 4095
919 1573 2834 4095
927 15 79 2810 4095
918 1575 2834 4095
926 1571 2831 4095
918 1581 2824 4087
923 1577 2834 4095
923 1575 2830 4095
933 1576 2833 4095
931 1581 2830 4095
927 1585 2828 4094
911 1571 2836 4095
923 1575 2828 4095
919 1577 2830 4095
929 1581 2817 4095
933 1575 2832 4095
919 1583 2828 4095
927 1578 2833 4095
931 1580 2828 4095
930 1577 2826 4095
928 1577 2831 4095
925 1569 2827 4095
931 1581 2830 4095
917 1571 2833 4095
您好,我改了,现在的代码是这个样子的
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
//SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1000KSPS);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);// Enable pin PE4_AIN0
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);// Enable pinPE5 _AIN1
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);// Enable pin PE4_AIN8
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);// Enable pinPE5 _AIN9
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_CH8);
//Configure steps 0 - 2 on sequencer 1 to sample the temperature sensor (ADC_CTL_TS).
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH9|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("%d %d %d %d\r\n", ui32ADC0Value[0], ui32ADC0Value[1], ui32ADC0Value[2],
ui32ADC0Value[3]);
//F = ( C * 9)/5 +32
}
}
输入没有变化,结果却是
395 895 2118 3266
1193 1717 2790 4095
1088 1797 2970 4095
1098 1729 2848 4031
1231 1774 2970 4095
723 1371 2529 3779
0 283 1384 2821
0 303 1471 2633
0 317 1493 2765
0 391 1593 2742
0 329 1474 2714
291 909 2048 3286
1106 1819 2956 4095
1190 1707 2811 4095
1115 1827 2940 4095
1186 1755 2917 4070
726 1321 2446 3641
0 465 1490 2731
0 343 1546 2742
0 435 1492 2750
0 355 1516 2731
0 407 1578 2850
186 815 2066 3230
1242 1787 2962 4095
1091 1773 2974 4095
1143 1723 2975 4095
1142 1745 2938 4095
806 1369 2600 3714
0 401 1572 2781
0 347 1482 2726
0 619 1574 2786
0 341 1535 2732
0 365 1592 2755
343 928 2068 3311
1131 1725 2912 4095
1287 1827 2932 4095
1167 1749 2862 4016
1215 1772 2949 4095
743 1367 2498 3743
0 389 1486 2751
0 340 1560 2741
87 515 1578 2768
0 336 1485 2683
0 337 1595 2804
366 969 2157 3288
1057 1712 2867 4043
1159 1772 2818 3999
1151 1793 2932 4095
1271 1838 2978 4095
758 1299 2460 3762
0 433 1531 2732
0 369 1641 2803
0 388 1584 2756
0 309 1532 2738
0 359 1536 2740
但是我把PE4引脚和VCC接到一起,结果是这样的
939 1575 2831 4095
915 1581 2834 4095
927 1581 2833 4095
932 1573 2825 4095
917 1569 2836 4095
914 1571 2831 4095
915 1567 2835 4095
918 1573 2825 4095
924 1573 2833 4095
915 1573 2844 4095
914 1571 2832 4095
927 1575 2834 4095
915 1575 2831 4095
925 1585 2833 4095
921 1575 2820 4095
918 1563 2825 4095
911 1575 2828 4095
939 1583 2833 4095
922 1579 2829 4095
935 1577 2834 4094
924 1571 2821 4095
931 1571 2832 4095
911 1595 2822 4095
920 1569 2828 4095
927 1571 2828 4095
923 1580 2832 4095
942 1577 2833 4095
918 1587 2842 4095
935 1575 2840 4095
918 1569 2828 4095
899 1567 2824 4095
910 1579 2828 4095
926 1575 2828 4095
923 1581 2832 4095
918 1569 2830 4095
929 1575 2829 4095
918 1571 2834 4095
922 1568 2817 4095
915 1567 2827 4095
919 1577 2832 4095
923 1573 2831 4095
903 1571 2828 4095
927 1582 2832 4095
932 1584 2825 4095
927 1568 2825 4095
924 1563 2829 4095
911 1579 2834 4095
925 1571 2826 4095
921 1568 2812 4095
921 1569 2828 4095
908 1561 2825 4095
941 1578 2830 4095
926 1579 2828 4095
919 1571 2831 4095
907 1565 2831 4095
915 1571 2814 4095
923 1571 2832 4095
907 1579 2837 4095
927 1569 2824 4095
931 1593 2846 4095
925 1575 2826 4095
926 1581 2833 4095
923 1577 2829 4095
926 1576 2830 4095
927 1576 2828 4095
909 1568 2814 4095
926 1569 2831 4095
922 1575 2827 4095
926 1570 2829 4095
918 1575 2837 4095
915 1577 2833 4095
919 1581 2832 4095
923 1575 2836 4095
917 1579 2830 4095
930 1575 2830 4095
911 1573 2831 4095
926 1573 2826 4095
926 1583 2831 4095
929 1587 2828 4095
932 1579 2831 4095
922 1568 2830 4088
932 1579 2847 4095
911 1571 2828 4095
918 1571 2828 4095
928 1579 2829 4095
923 1583 2830 4095
923 1587 2833 4095
918 1566 2827 4095
919 1571 2827 4095
919 1570 2827 4095
915 1543 2834 4095
899 1571 2827 4095
927 1557 2826 4095
915 1577 2829 4095
923 1583 2828 4095
920 1573 2824 4095
919 1568 2824 4095
919 1577 2836 4095
923 1573 2833 4095
916 1571 2834 4095
915 1571 2833 4095
915 1575 2829 4095
919 1567 2824 4095
921 1569 2826 4095
923 1575 2825 4095
931 1577 2833 4095
919 1574 2827 4095
923 1579 2825 4095
935 1569 2854 4095
925 1571 2822 4095
916 1575 2820 4095
923 1583 2828 4095
914 1553 2814 4095
919 1567 2830 4095
919 1573 2834 4095
927 15 79 2810 4095
918 1575 2834 4095
926 1571 2831 4095
918 1581 2824 4087
923 1577 2834 4095
923 1575 2830 4095
933 1576 2833 4095
931 1581 2830 4095
927 1585 2828 4094
911 1571 2836 4095
923 1575 2828 4095
919 1577 2830 4095
929 1581 2817 4095
933 1575 2832 4095
919 1583 2828 4095
927 1578 2833 4095
931 1580 2828 4095
930 1577 2826 4095
928 1577 2831 4095
925 1569 2827 4095
931 1581 2830 4095
917 1571 2833 4095
还有接线的时候不是直接PE3、PE2、PE5/PE4吗,谢谢您
把PE4引脚和VCC接到一起 后的数据应该是正常的吧,你的输入电压是 0.5/1/2/3.3V,根据转换结果来看跟我的一样,总是比输入电压高 0.2到0.3V,怎么变高的我也不清楚,还没解决。 至于你前面数据为什么会不正确,可以先检查硬件有没有问题;还有就是在while(1)之前的初始化加入这一句试试:ADCIntClear(ADC0_BASE, 1); //清除中断标志