2844 views|0 replies
- Last login
- 2023-11-15
- Online Time
- 196 hours
- Prestige
- 1018 points
- Points
- 641 points
|
【DSP】TMS320F28035 ADC routine (ePWM+interrupt)
[Copy link]
#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; //Map ADC interrupt EDIS; InitAdc(); PieCtrlRegs.PIEIER1.bit.INTx1 = 1; //Enable PIE level INT1.1 interrupt IER |= M_INT1; //Enable CPU level INT1 interrupt EINT; //Enable total interrupt ConversionCount = 0; EALLOW; AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //Generate EOC one ADC clock cycle before conversion is completed AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enable ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Turn off continuous mode AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //Map ADCINT1 to EOC1 AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; //Map ADCINA0 to channel 0 AdcRegs.ADCSOC1CTL.bit.CHSEL = 1; //Map ADCINA1 to channel 1 AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //ePWM1A triggers SOC0 AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5; //ePWM1A triggers SOC1 AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; //Set window sampling times AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; //Set window sampling times EDIS; //Haven’t started studying ePWM EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on group A 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; //Clear EOC1 signal (ADCINT1) PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //Write 1 to clear 0, write 0 is invalid }
|
|