#include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include // Prototype statements for functions found within this file. interrupt void adc_isr(void); void Adc_Config(void); // Global variables used in this example: Uint16 LoopCount; Uint16 ConversionCount; int Voltage2[1400]; main() { InitSysCtrl(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EALLOW; // This is needed to write to EALLOW protected register PieVectTable.ADCINT1 = &adc_isr; EDIS; // This is needed to disable write to EALLOW protected registers InitAdc(); // For this example, init the ADC // Enable ADCINT1 in PIE PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE IER |= M_INT1; // Enable CPU Interrupt 1 EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM LoopCount = 0; ConversionCount = 0; // Configure ADC EALLOW; AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; //ADCINT1 trips after AdcResults latch AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 1; //Disable ADCINT1 Continuous mode AdcRegs.INTSEL1N2.bit.INT1SEL = 2; //setup EOC2 to trigger ADCINT1 to fire AdcRegs.ADCSOC2CTL.bit.CHSEL = 4; //set SOC2 channel select to ADCINA2 AdcRegs.ADCSOC2CTL.bit.TRIGSEL = 5; //set SOC2 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1, then SOC2 AdcRegs.ADCSOC2CTL.bit.ACQPS = 6; //set SOC2 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) AdcRegs.ADCINTSOCSEL1.bit.SOC2 = 0; // No ADCINT triggers SOC2. TRIGSEL field determines trigger. AdcRegs.ADCCTL1.bit.ADCENABLE = 1; // Enable the ADC EDIS; // Assumes ePWM1 clock is already enabled in InitSysCtrl(); EPwm2Regs.TBCTL.bit.CTRMODE = 0x3; // Disable the timer EPwm2Regs.TBCTL.all = 0xC033; // Configure timer control register EPwm2Regs.TBCTR = 0x0000; // Clear timer counter EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group EPwm1Regs.ETSEL.bit.SOCASEL = 2; // Select SOC from from CPMA on upcount EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event EPwm1Regs.TBPRD = 600; // Set period for ePWM1 EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start // Wait for ADC interrupt for(;;) { LoopCount++; } } interrupt void adc_isr(void) { Voltage2[ConversionCount] = AdcResult.ADCRESULT2; if(ConversionCount == 1400) { ConversionCount = 0; } else { ConversionCount++; AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE } return; }