写了一个定时中断函数,将AD采样写在定时中断中,结果不能得到正确的AD值,定时时间为0.1ms,
采用dsp2806,系统时钟为50MHz,外部引脚ADCIN已经连接到1.6V直流电压,为什么我的AD值却总是零呢?
请高手帮帮忙!!
void ADC_Init(void)
{
AdcRegs.ADCTRL1.bit.RESET = 1; //Reset ADC module
asm(" RPT #20||NOP");
AdcRegs.ADCTRL3.all = 0x00E2; // Power up bandgap/reference/ADC circuits
AdcRegs.ADCTRL1.bit.RESET = 0;
AdcRegs.ADCTRL1.bit.SUSMOD = 1; // 模式3
AdcRegs.ADCTRL1.bit.ACQ_PS = 0x4; // SOC脉宽
AdcRegs.ADCTRL1.bit.CPS = 1; // ADCCLK=FCLK/2
AdcRegs.ADCTRL1.bit.CONT_RUN =0; // ???
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 0;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // cascade mode
AdcRegs.ADCMAXCONV.all = 0x07;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA0 as 1st SEQ1 conv
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x0; // Setup ADCINB0 as 2nd SEQ1 conv
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x8;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x8;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x1;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x1;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x9; // Setup ADCINA1 as 3st SEQ1 conv
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x9; // Setup ADCINB1 as 4st SEQ1 conv
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 0; // disable SEQ1 interrupt (every EOS)
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 0;// disable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;
asm(" RPT #4||NOP");
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;
}
interrupt void TINT0_ISR(void) // CPU-Timer 0 P=0.1ms
{
i= AdcRegs.ADCRESULT0;
result[0]=i>>4;
i= AdcRegs.ADCRESULT1;
result[1]=i>>4;
i= AdcRegs.ADCRESULT2;
result[2]=i>>4;
i= AdcRegs.ADCRESULT3;
result[3]=i>>4;
i= AdcRegs.ADCRESULT4;
result[4]=i>>4;
i= AdcRegs.ADCRESULT5;
result[5]=i>>4;
i= AdcRegs.ADCRESULT6;
result[6]=i>>4;
i= AdcRegs.ADCRESULT7;
result[7]=i>>4;
i=result[0]+result[1]+result[2]+result[3];
i=i>>2;
g_uSample[g_uNum]=i;
i=result[4]+result[5]+result[6]+result[7];
i=i>>2;
g_uSample1[g_uNum]=i;
g_uNum++;
if(g_uNum>255) g_uNum=0;
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; //Restart the ADC
asm(" RPT #4||NOP");
CpuTimer0Regs.TCR.bit.TIF=1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
AdcRegs.ADCTRL2.bit.SOC_SEQ1 = 1;
EINT;
}
void main(void)
{
InitSysCtrl();
Config_Gpio();
ADC_Init();
GPIO_Init();
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
InitCpuTimers(); //Initialize the Cpu Timers
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //Timer0
IER |= M_INT1; //Timer0 1.7
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
ConfigCpuTimer(&CpuTimer0, 50, 100000);
StartCpuTimer0();
for(;;)
{
}
}
此帖出自
小平头技术问答
一周热门 更多>