大家帮忙看看程序这样写可以达到采集多通道
数据吗?
#include "includes.h"
#include
#include
#include
#include "hw_memmap.h"
#include "hw_types.h"
#include "adc.h"
#include "gpio.h"
#include "sysctl.h"
#include "timer.h"
#include "hw_ints.h"
extern unsigned long ulStatus;
tBoolean tADCEndFlag = false; // 定义ADC转换结束的标志
//unsigned long b=0;
unsigned char ucChoiceFlag=0;
// Timer初始化
void timerInit(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // 使能Timer模块
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER); // 配置Timer为32位周期定时
TimerControlTrigger(TIMER0_BASE, TIMER_A, true); // 使能内部触发脉冲的产生
TimerControlStall(TIMER0_BASE, TIMER_A, true); // 调试时暂停计数(必要!)
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000); // 设置Timer初值
TimerEnable(TIMER0_BASE, TIMER_A); // 使能Timer计数
}
// ADC初始化
void vADCInit(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC); // 使能ADC模块
SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 设置ADC采样率
ADCSequenceDisable(ADC0_BASE, 0); // 禁止采样序列
ADCSequenceDisable(ADC0_BASE, 1); // 禁止采样序列
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
// 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.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7);//AIN0
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_6);//AIN1
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);//AIN2
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4);//AIN3
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_7);//AIN4
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_6);//AIN5
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_5);//AIN6
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_4);//AIN7
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);//AIN8
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);//AIN9
GPIOPinTypeADC(GPIO_PORTB_BASE, GPIO_PIN_4);//AIN10
// 采样序列配置:ADC基址,采样序列0,定时器触发,采样优先级0
ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_TIMER, 0);
// 采样序列配置:ADC基址,采样序列1,定时器触发,采样优先级1
ADCSequenceConfigure(ADC_BASE, 1, ADC_TRIGGER_TIMER, 1);
//ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
if(ucChoiceFlag==0)
{
// 采样步进设置:ADC基址,采样序列0,步值0,采样ADC0后停止并申请中断
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3);
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH5);
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH6);
ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH7|ADC_CTL_END |ADC_CTL_IE);
}
else
{
// 采样步进设置:ADC基址,采样序列1,步值0,采样ADC0后停止并申请中断
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH8);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH9);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_CH10 |ADC_CTL_END |ADC_CTL_IE);
}
ADCIntEnable(ADC_BASE, 0); // 使能ADC中断
IntEnable(INT_ADC0); // 使能ADC采样序列中断
IntMasterEnable( ); // 使能处理器中断
ADCSequenceEnable(ADC_BASE, 0); // 使能采样序列
ADCSequenceEnable(ADC_BASE, 1); // 使能采样序列
}
// ADC采样
unsigned long ulADCSample(unsigned long ulValue[])
{
while (!tADCEndFlag); // 等待采样结束
tADCEndFlag = false; // 清除ADC采样结束标志
if(ucChoiceFlag==0)
{
ADCSequenceDataGet(ADC_BASE,0, ulValue); // 读取ADC0 0序列转换结果
}
else
{
ADCSequenceDataGet(ADC_BASE,1, ulValue); // 读取ADC0 1序列转换结果
}
//return(ulValue[]);
}
// ADC采样序列0的中断
void ADC0Sequence0ISR(void)
{
unsigned long ulADCSequ0Value[8];
unsigned long v0;
unsigned char i0;
unsigned long ulADC0Sequ1Value[3];
unsigned long v1;
unsigned char i1;
unsigned long ulStatus;
// int i;
ulStatus = ADCIntStatus(ADC_BASE, 0, true); // 读取中断状态
ADCIntClear(ADC_BASE, 0); // 清除中断状态,重要
ADCSequenceDisable(ADC_BASE, 0);
if (ulStatus != 0) // 如果中断状态有效
{
tADCEndFlag = true; // 置位ADC采样结束标志
//tADCEndFlag = false;
ADCSequenceEnable(ADC_BASE, 0); // 使能采样序列
}
if(ucChoiceFlag==0)
{
ulADCSample(ulADCSequ0Value); // ADC0 序列0采样
for (i0 = 0; i0 < 8; i0++)
{
v0 = (ulADCSequ0Value[i0] * 3000) / 1024; // 转换成电压值
}
ucChoiceFlag=1;
}
else
{
ulADCSample(ulADC0Sequ1Value); // ADC0 序列1采样
for (i1 = 0; i1 < 3; i1++)
{
v1 = (ulADC0Sequ1Value[i1] * 3000) / 1024; // 转换成电压值
}
ucChoiceFlag=0;
}
// b++;
}