【DSP】TMS320F28035 ADC例程(軟體觸發+中斷)
阿新 • • 發佈:2019-02-11
#include "DSP28x_Project.h"
interrupt void adc_isr(void);
Uint16 ConversionCount;
Uint16 Voltage1[10];
Uint16 Voltage2[10];
main()
{
InitSysCtrl();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.ADCINT1 = &adc_isr; //對映ADC中斷
EDIS;
InitAdc();
PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //使能PIE級INT1.1中斷
IER |= M_INT1; //使能CPU級INT1中斷
EINT; //使能總中斷
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(;;)
{
}
}
interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = AdcResult.ADCRESULT0;
Voltage2[ConversionCount] = AdcResult.ADCRESULT1;
if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //清除EOC1訊號(ADCINT1)
AdcRegs.ADCSOCFRC1.all = 0x0003;//強制給通道0和1產生SOC訊號
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //寫1清0,寫0無效
}