一、主程序:
#include "DSP28_Device.h"
float ADResult;
unsigned int k=0;
float adclo;
interrupt void ADC_ISR(void);
void main(void)
{
InitSysCtrl(); //初始化系统
DINT; //关中断
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl(); //初始化PIE控制寄存器
InitPieVectTable(); //初始化PIE参数表
InitEv();
InitAdc(); //初始化ADC
adclo=0;
PieCtrl.PIEIER1.bit.INTx6=1;
EALLOW;
PieVectTable.ADCINT=&ADC_ISR;
EDIS;
IER |= M_INT1; // Enable INT14 which is connected to CPU-Timer 2:
EINT; // Enable INTM
ERTM; // Enable DBGM
EvaRegs.T1CON.bit.TENABLE=1;
for(;;)
{
}
}
interrupt void ADC_ISR(void)
{
ADResult=((AdcRegs.RESULT0>>4)*3)/4095.0+adclo;
PieCtrl.PIEACK.all=0x0001;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADCTRL2.bit.RST_SEQ1=1; //在这里设置断点
EINT;
}
二、ad初始化程序:
void InitAdc(void)
{
unsigned int i;
AdcRegs.ADCTRL1.bit.RESET=1;
NOP;
AdcRegs.ADCTRL1.bit.RESET=0;
AdcRegs.ADCTRL1.bit.SUSMOD=3;
AdcRegs.ADCTRL1.bit.ACQ_PS=0;
AdcRegs.ADCTRL1.bit.CPS=0;
AdcRegs.ADCTRL1.bit.CONT_RUN=0;
AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
AdcRegs.ADCTRL3.bit.ADCBGRFDN=3;
for(i=0;i<10000;i++) NOP;
AdcRegs.ADCTRL3.bit.ADCPWDN=1;
for(i=0;i<5000;i++) NOP;
AdcRegs.ADCTRL3.bit.ADCCLKPS=15;
AdcRegs.ADCTRL3.bit.SMODE_SEL=1;
AdcRegs.MAX_CONV.bit.MAX_CONV=7;//15;
AdcRegs.CHSELSEQ1.bit.CONV00=0;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ2_CLR=1;
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=0;
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=0;
}
三、EV初始化程序:
void InitEv(void)
{
EvaRegs.T1CON.bit.TMODE=2;
EvaRegs.T1CON.bit.TPS=1;
EvaRegs.T1CON.bit.TENABLE=0;
EvaRegs.T1CON.bit.TCLKS10=0;
EvaRegs.GPTCONA.bit.T1TOADC=2;
EvaRegs.EVAIMRA.bit.T1PINT=1;
EvaRegs.EVAIFRA.bit.T1PINT=1;
EvaRegs.T1PR=0x927B;//定时37499,周期1ms
EvaRegs.T1CNT=0;
}
此帖出自
小平头技术问答
EvaRegs.T1CON.bit.TENABLE=0; // 你没有启动定时器吧,应该使能定时器操作
EvaRegs.T1CON.bit.TCLKS10=0; // 那个TCLKS不是这样写的吧
一周热门 更多>