//编译前确保CPU时钟频率在DSP281x_Examples.h 中正确定义
#include "DSP281x_Device.h"
#include "DSP281x_Examples.h"
interrupt void adc_isr(void);
//全局变量定义
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Voltage1[3];
Uint16 Voltage2[3];
main()
{
InitSysCtrl();
//高速外围时钟定标寄存器,配置:系统时钟/6=25Mhz (系统时钟150Mhz)
EALLOW;
SysCtrlRegs.HISPCP.all = 0x3; //外围高速时钟HSPCLK = 系统时钟/(2*HISPCP)
EDIS;
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.ADCINT = &adc_isr;
EDIS;
InitAdc(); //初始化ADC
//在PIE中使能ADCINT
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; //使能CPU中断1
EINT; //使能全局中断INTM
ERTM; //使能全局实时中断 DBGM
LoopCount = 0;
ConversionCount = 0;
//配置ADC
AdcRegs.ADCMAXCONV.all = 0x0008; //最大转换通道寄存器
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; //输入通道选择排序寄存器
// AdcRegs.ADCCHSELSEQ1.all = 0x1110; //输入通道选择排序寄存器
// AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x2; //输入通道选择排序寄存器
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; //使能 EVASOC 启动 SEQ1
//AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1; //软件启动 SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; //使能 SEQ1 中断
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; //级联排序器操作,双(0)单(1)
//配置EVA
EvaRegs.T1CMPR = 0x0f00; //Timer1比较寄存器(当前的比较值)
EvaRegs.T1PR = 0xFFFF; //Timer1周期寄存器(当前的周期值)
EvaRegs.GPTCONA.bit.T1TOADC = 1; //使能 EVASOC in EVA
EvaRegs.T1CON.all = 0x1042; //Timer1控制寄存器;TMODE 连续增;Timer 使能;Timer 比较使能
//等待ADC中断
while(1)
{
LoopCount++;
}
}
interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4;
Voltage2[ConversionCount] = AdcRegs.ADCRESULT1 >>4;
if(ConversionCount == 2)
{
ConversionCount = 0;
}
else ConversionCount++;
//重新初始化,等待下一个 ADC 结果
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; //重启 SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; //清除 INT SEQ1 位
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //允许 PIE 中断
return;
}