// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.ADCINT = &adc_isr;
EDIS;
InitAdc(); // For this example, init the ADC
// Step 5. User specific code, enable interrupts:
// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
LoopCount = 0;
ConversionCount = 0;
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 1 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x7; // Setup ADCINA0 as 1st SEQ1 conv.
AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;// Enable SOCA from ePWM to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group ADC转换序列A启动使能位 1使能
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from from CPMA on upcount EPWMxSOCA脉冲生成选择位
//100:计数器增加时,TBCTR=CMPA
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event 该位决定发生多少个事件后产生EPWMxSOCA
EPwm1Regs.TBPRD = 0xFFFF; // Set period for ePWM1 确定定时器的周期,设置PWM的频率
//2^16=65536
//PWM的周期也就是采样周期为[1/(75*1000000)]*65536
EPwm1Regs.TBCTR=0X0000; //清除TB计数器
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start定时器计数模式 00:连续增模式
// Wait for ADC interrupt
for(;;)
{
LoopCount++;
}
// If 40 conversions have been logged, start over
if(ConversionCount == 9)
{
ConversionCount = 0;
}
else ConversionCount++;
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE