本程序采用EVA中断启动ADC转换,级联模式6通道顺序采样:
DSP28_Adc.c:
void InitAdc(void)
{
unsigned int i;
AdcRegs.ADCTRL1.bit.RESET=1;
asm(" RPT # 10 || NOP"); //等待12个周期,复位adc模块
AdcRegs.ADCTRL3.bit.ADCBGRFDN=3;
for(i=0;i<10000;i++) asm(" NOP"); // 能带隙和参考电路上电
AdcRegs.ADCTRL3.bit.ADCPWDN=1;
for(i=0;i<5000;i++) asm(" NOP"); // 内核内的模拟电路上电
AdcRegs.ADCTRL3.bit.ADCCLKPS=15; //核时钟分频器
AdcRegs.ADCTRL3.bit.SMODE_SEL=0; //顺序采样模式
AdcRegs.ADCTRL1.bit.RESET=0;
AdcRegs.ADCTRL1.bit.SUSMOD=3;//仿真挂起时,序列发生器和其他轮询程序逻辑立即停止
AdcRegs.ADCTRL1.bit.ACQ_PS=0; //控制SOC脉宽
AdcRegs.ADCTRL1.bit.CPS=0; //内核时钟预分频
AdcRegs.ADCTRL1.bit.CONT_RUN=0; //启动停止模式到达EOS后序列发生器停止
AdcRegs.ADCTRL1.bit.SEQ_CASC=1; //级联模式,SEQ1和SEQ2作为单个16状态序列发生器工作
AdcRegs.MAX_CONV.bit.MAX_CONV=0x0005;
AdcRegs.CHSELSEQ1.bit.CONV00=0x0;
AdcRegs.CHSELSEQ1.bit.CONV01=0x1;
AdcRegs.CHSELSEQ1.bit.CONV02=0x2;
AdcRegs.CHSELSEQ1.bit.CONV03=0x3;
AdcRegs.CHSELSEQ2.bit.CONV04=0x4;
AdcRegs.CHSELSEQ2.bit.CONV05=0x5;
AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ=0;
AdcRegs.ADCTRL2.bit.RST_SEQ1=0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1=1;
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ1=0;
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1=1;
AdcRegs.ADCTRL2.bit.EXT_SOC_SEQ1=0;
AdcRegs.ADCTRL2.bit.RST_SEQ2=0;
AdcRegs.ADCTRL2.bit.SOC_SEQ2=0;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ2=0;
AdcRegs.ADCTRL2.bit.INT_MOD_SEQ2=0;
AdcRegs.ADCTRL2.bit.EVB_SOC_SEQ2=0;
// AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
//使能ADC中断
PieCtrl.PIEIER1.bit.INTx6=1;
IER |= M_INT1;
}
AD.c文件:
#include "DSP28_Device.h"
unsigned int Send_Flag;
unsigned int i;
char *strg="abcd";
float ad[6]={0,1,2,3,4,5};
float adclo=0.0;
int ad_freq=0;
void DelayNmSec(int N)
{
unsigned int j;
while(N--)
for(j=0;j<65535;j++);
}
interrupt void T2PINT_ISR(void)
{
length=5;
length--;
Tx=(unsigned char*)strg;
if(length>0) SciaRegs.SCITXBUF=*Tx++;
else
{
length=0;
}
EvaRegs.EVAIMRB.bit.T2PINT=1;//中断允许
EvaRegs.EVAIFRB.bit.T2PINT=1;//清除中断标志
PieCtrl.PIEACK.bit.ACK3=1;//向cpu申请中断
}
interrupt void AD_ISR(void)
{
ad_freq++;
if(ad_freq==6)
{
ad[0]=((AdcRegs.RESULT0>>4)*3)/4095.0+adclo;
ad[1]=((AdcRegs.RESULT1>>4)*3)/4095.0+adclo;
ad[2]=((AdcRegs.RESULT2>>4)*3)/4095.0+adclo;
ad[3]=((AdcRegs.RESULT3>>4)*3)/4095.0+adclo;
ad[4]=((AdcRegs.RESULT4>>4)*3)/4095.0+adclo;
ad[5]=((AdcRegs.RESULT5>>4)*3)/4095.0+adclo;
ad_freq=0;
}
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1=1;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
PieCtrl.PIEACK.bit.ACK1=1;
}
void main(void)
{
/*初始化系统*/
InitSysCtrl();
/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE中断*/
InitPieCtrl();
/*初始化PIE中断矢量表*/
InitPieVectTable();
/*初始化SCIA寄存器*/
InitSci();
for(i = 0; i < 8; i++)
{
Sci_VarRx[i] = 0;
Sci_VarTx[i] = 0;
}
Rx=Sci_VarRx;
Tx=Sci_VarTx;
Send_Flag = 0;
rx_length=0;
add=0;
length=9;
// 初始化定时器2
/*
EvaRegs.GPTCONA.all=0;
EvaRegs.T2PR =0x1500; // 定时器2的周期为20k
EvaRegs.EVAIMRB.bit.T2PINT = 1;//定时器2周期中断允许
EvaRegs.EVAIFRB.bit.T2PINT = 1;//清除标志
EvaRegs.T2CNT =0x0000; // Timer2 counter
EvaRegs.T2CON.all =0x1440;//16分频,使能定时器操作,连续增模式
*/
/*初始化ADC寄存器*/
InitAdc();
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TXAINT = &SCITXINTA_ISR;
PieVectTable.RXAINT = &SCIRXINTA_ISR;
//PieVectTable.T2PINT = &T2PINT_ISR;
PieVectTable.ADCINT = &AD_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
//PieCtrl.PIEIER3.bit.INTx1=1;//T2pint中断
/*开中断*/
IER |= M_INT9;
//IER |= M_INT3; // t1pint enable
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
//配置时间管理器EVA time1
EvaRegs.T1PR=0x1500;
EvaRegs.GPTCONA.bit.T1TOADC=1;
EvaRegs.EVAIMRA.bit.T1PINT = 1;//定时器1周期中断允许
EvaRegs.EVAIFRA.bit.T1PINT = 1;//清除标志
EvaRegs.T1CNT =0x0000; // Timer1 counter
EvaRegs.T1CON.all=0x1040;
while(1)
{
}
}
//===========================================================================
// No more.
//===========================================================================
阅读(6633) | 评论(0) | 转发(0) |