DSP

【DSP】TMS320F28035 ADC例程(软件触发+查询)

2019-07-13 10:34发布

#include "DSP28x_Project.h" Uint16 ConversionCount; Uint16 Voltage1[10]; Uint16 Voltage2[10]; main() { InitSysCtrl(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); InitAdc(); ConversionCount = 0; EALLOW; AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //转换完成前一个ADC时钟周期产生EOC AdcRegs.INTSEL1N2.bit.INT1E = 1; //使能ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //关闭连续模式 AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //将ADCINT1映射到EOC1 AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; //将ADCINA0映射到通道0 AdcRegs.ADCSOC1CTL.bit.CHSEL = 1; //将ADCINA1映射到通道1 AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 0; //软件触发SOC0 AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 0; //软件触发SOC1 AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //设置窗口采样次数 AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; //设置窗口采样次数 EDIS; AdcRegs.ADCSOCFRC1.all = 0x0003;//强制给通道0和1产生SOC信号 for(;;) { while(AdcRegs.ADCINTFLG.bit.ADCINT1 == 0){} //等待EOC1信号(ADCINT1) AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //清除EOC1信号(ADCINT1) AdcRegs.ADCSOCFRC1.all = 0x0003;//强制给通道0和1产生SOC信号 if(ConversionCount == 9) { ConversionCount = 0; } else ConversionCount++; Voltage1[ConversionCount] = AdcResult.ADCRESULT0; Voltage2[ConversionCount] = AdcResult.ADCRESULT1; } }