刚学习dsp,编写了一个AD程序。程序的意图是想通过CPU定时器0触发AD采样,通道为ADCINA0-2,每通道采三次,然后取平均。连接
电路时将ADCLO与GND连一块接到干电池的负极,ADCINA连接电池正极。下面是我编写的采样程序,编译没有问题,就是观察不到电压AD0-AD2的变化,他们总是0。
#include "DSP2833x_Project.h"
int AD0=0,AD1=0,AD2=0,AD_FLAG=0;
void adc_init(void);
interrupt void adc_isr();
interrupt void cpu_
timer0_isr();
void main()
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER=0x0000;
IFR=0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.TINT0=&cpu_timer0_isr;
PieVectTable.SEQ1INT=&adc_isr;
EDIS;
InitCpuTimers();
#if(CPU_FRQ_150MHZ)
ConfigCpuTimer(&CpuTimer0,150,1000000);
#endif
#if(CPU_FRQ_100MHZ)
ConfigCpuTimer(&CpuTimer0,100,1000000);
#endif
CpuTimer0Regs.TCR.all=0x4001;
IER|=M_INT1;
PieCtrlRegs.PIEIER1.bit.INTx7=1;
PieCtrlRegs.PIEIER1.bit.INTx1=1;
EINT;
ERTM;
InitAdc();
while(1)
{
adc_init();
}
}
void adc_init(void)
{
AdcRegs.ADCTRL3.bit.ADCBGRFDN=0x3;
DELAY_US(5000L);
AdcRegs.ADCTRL3.bit.ADCPWDN=1;
DELAY_US(20L);
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;
AdcRegs.ADCTRL1.bit.SEQ_CASC=1;
AdcRegs.ADCMAXCONV.all=0x08;
AdcRegs.ADCCHSELSEQ1.bit.CONV00=0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01=0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV02=0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV03=0x1;
AdcRegs.ADCCHSELSEQ2.bit.CONV04=0x1;
AdcRegs.ADCCHSELSEQ2.bit.CONV05=0x1;
AdcRegs.ADCCHSELSEQ2.bit.CONV06=0x2;
AdcRegs.ADCCHSELSEQ2.bit.CONV07=0x2;
AdcRegs.ADCCHSELSEQ3.bit.CONV08=0x2;
AdcRegs.ADCTRL2.bit.SOC_SEQ1=AD_FLAG;
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1=1;
AdcRegs.ADCTRL1.bit.ACQ_PS=5;
AdcRegs.ADCTRL1.bit.CPS=0;
AdcRegs.ADCTRL3.bit.ADCCLKPS=5;
}
interrupt void adc_isr(void)
{
AD0=AdcRegs.ADCRESULT0>>4;
AD0+=AdcRegs.ADCRESULT1>>4;
AD0+=AdcRegs.ADCRESULT2>>4;
AD0=AD0/3;
AD1=AdcRegs.ADCRESULT3>>4;
AD1+=AdcRegs.ADCRESULT4>>4;
AD1+=AdcRegs.ADCRESULT5>>4;
AD1=AD1/3;
AD2=AdcRegs.ADCRESULT6>>4;
AD2+=AdcRegs.ADCRESULT7>>4;
AD2+=AdcRegs.ADCRESULT8>>4;
AD2=AD2/3;
AdcRegs.ADCTRL2.bit.RST_SEQ1=1;
AdcRegs.ADCST.bit.INT_SEQ1_CLR=1;
PieCtrlRegs.PIEACK.all=1;
AD_FLAG=0;
}
interrupt void cpu_timer0_isr(void)
{
AD_FLAG=1;
PieCtrlRegs.PIEACK.all=1;
}
学习学习,谢谢分享!
一周热门 更多>