TMS320F28069 PWM触发ADC中断,在ADC中断更改PWM的占空比,但是发现在更改占空比的过程中PWM的频率会发生变化。下面是程序的配置,请大牛帮忙看下,哪里配置出问题


// Configure ADC
EALLOW;
AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1; // Enable non-overlap mode
AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; // ADCINT1 trips after AdcResults latch
AdcRegs.INTSEL1N2.bit.INT1E = 1; // Enabled ADCINT1
AdcRegs.INTSEL1N2.bit.INT1CONT = 0; // Disable ADCINT1 Continuous mode
AdcRegs.INTSEL1N2.bit.INT1SEL = 1; // setup EOC1 to trigger ADCINT1 to fire
AdcRegs.ADCSOC0CTL.bit.CHSEL = 8; // set SOC0 channel select to ADCINA4
AdcRegs.ADCSOC1CTL.bit.CHSEL = 9; // set SOC1 channel select to ADCINA2
AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 17; // set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 17; // set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; // set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; // set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)

//PWM配置

void InitEPwm7Example()
{

EPwm7Regs.TBPRD = 767; // Set timer period 6000 408
EPwm7Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm7Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm7Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm7Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm7Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm7Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TB_DIV4 = 0x02
EPwm7Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm7Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm7Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
// EPwm7Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm7Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
// EPwm7Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm7Regs.CMPA.half.CMPA = 384; //3000
// Set actions
EPwm7Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on CAD
EPwm7Regs.AQCTLA.bit.PRD = AQ_CLEAR;
EPwm7Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group
EPwm7Regs.ETSEL.bit.SOCASEL = 1; // Select SOC from CMPA on upcount
EPwm7Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event
}

__interrupt void adc_isr(void)
{

Voltage1[ConversionCount] = AdcResult.ADCRESULT0;
Voltage2[ConversionCount] = AdcResult.ADCRESULT1;
GpioDataRegs.GPADAT.bit.GPIO3 = Led;
Led = !Led;
EPwm7Regs.CMPA.half.CMPA =PwmFreq[ConversionCount];
// If 20 conversions have been logged, start over
if(ConversionCount == 11)
{
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;
}

4 个回复