DSP

【DSP】TMS320F28035 ADC例程(ePWM+中断)

2019-07-13 10:59发布

#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 = 5; //ePWM1A触发SOC0 AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5; //ePWM1A触发SOC1 AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //设置窗口采样次数 AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; //设置窗口采样次数 EDIS; //还没开始研究ePWM EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1 EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start 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) PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //写1清0,写0无效 }