Tool/software: Code Composer Studio
hello,
I am currently working over pwm using adc with voltage control loop. I have given a command in my loop that my pulse should shut off if my ADC input is greater than 2.5 v. I have activated ePWM1.
But what happening is ePWM1A is getting shut but ePWM1B is not shutting down. I am including piece of my program..please help
/configure ADCINA4
ADC_setIntPulseGenMode(myAdc1, ADC_IntPulseGenMode_Prior);
ADC_enableInt(myAdc1, ADC_IntNumber_1);
ADC_setIntMode(myAdc1, ADC_IntNumber_1, ADC_IntMode_ClearFlag);//ADCINT1 trips after AdcResults latch
ADC_setIntSrc(myAdc1, ADC_IntNumber_1, ADC_IntSrc_EOC2); //setup EOC2 to trigger ADCINT1 to fire
ADC_setSocChanNumber (myAdc1, ADC_SocNumber_0, ADC_SocChanNumber_A4); //set SOC0 channel select to ADCINA4
ADC_setSocChanNumber (myAdc1, ADC_SocNumber_1, ADC_SocChanNumber_A4); //set SOC1 channel select to ADCINA4
ADC_setSocChanNumber (myAdc1, ADC_SocNumber_2, ADC_SocChanNumber_A4); //set SOC2 channel select to ADCINA2
ADC_setSocTrigSrc(myAdc1, ADC_SocNumber_0, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
ADC_setSocTrigSrc(myAdc1, ADC_SocNumber_1, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1
ADC_setSocTrigSrc(myAdc1, ADC_SocNumber_2, ADC_SocTrigSrc_EPWM1_ADCSOCA); //set SOC2 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1, then SOC2
ADC_setSocSampleWindow(myAdc1, ADC_SocNumber_0, ADC_SocSampleWindow_7_cycles); //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
ADC_setSocSampleWindow(myAdc1, ADC_SocNumber_1, ADC_SocSampleWindow_7_cycles); //set SOC1 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1)
ADC_setSocSampleWindow(myAdc1, ADC_SocNumber_2, ADC_SocSampleWindow_7_cycles);
PWM_enableSocAPulse(myPwm1);
// Enable SOC on A group
// PWM_setSocBPulseSrc(myPwm2, PWM_SocPulseSrc_CounterEqualCmpAIncr);
PWM_setSocAPulseSrc(myPwm1, PWM_SocPulseSrc_CounterEqualCmpAIncr);// Select SOC from from CPMA on upcount
//PWM_setSocBPeriod(myPwm2, PWM_SocPeriod_FirstEvent);
PWM_setSocAPeriod(myPwm1, PWM_SocPeriod_FirstEvent); // Generate pulse on 1st event
//PWM_setCmpA(myPwm2, 0x0000); // Set compare A value
//PWM_setPeriod(myPwm2, 0x05DC);
PWM_setPeriod(myPwm1, 2500); // Period = 1500 for 20Khz Sampling Frequency
// PWM_setCounterMode(myPwm2, PWM_CounterMode_Up);
PWM_setCounterMode(myPwm1, PWM_CounterMode_Up);
CLK_enableTbClockSync(myClk);
for(;;)
PWM_setCmpA(myPwm1,Vpi_5);
void InitEPwm1()
{
CLK_disableTbClockSync(myClk);
CLK_enablePwmClock(myClk, PWM_Number_1);
GPIO_setPullUp(myGpio, GPIO_Number_0, GPIO_PullUp_Disable);
GPIO_setPullUp(myGpio, GPIO_Number_1, GPIO_PullUp_Disable);
GPIO_setMode(myGpio, GPIO_Number_0, GPIO_0_Mode_EPWM1A);
GPIO_setMode(myGpio, GPIO_Number_1, GPIO_1_Mode_EPWM1B);
// Setup Sync
PWM_setSyncMode(myPwm1, PWM_SyncMode_EPWMxSYNC);
// PWM_setSyncMode(myPwm2, PWM_SyncMode_EPWMxSYNC);
// Allow each timer to be sync'ed
PWM_enableCounterLoad(myPwm1);
PWM_setPeriod(myPwm1, PWM1_TIMER_TBPRD);
PWM_setCounterMode(myPwm1, PWM_CounterMode_Up); // Count up
PWM_setIntMode(myPwm1, PWM_IntMode_CounterEqualZero); // Select INT on Zero event
PWM_enableInt(myPwm1); // Enable INT
PWM_setIntPeriod(myPwm1, PWM_IntPeriod_FirstEvent); // Generate INT on 1st event
PWM_setActionQual_Period_PwmA(myPwm1, PWM_ActionQual_Set);
PWM_setActionQual_CntUp_CmpA_PwmA(myPwm1, PWM_ActionQual_Clear);
PWM_setActionQual_Period_PwmB(myPwm1, PWM_ActionQual_Clear);
PWM_setActionQual_CntUp_CmpA_PwmB(myPwm1, PWM_ActionQual_Set);
CLK_enableTbClockSync(myClk);
}
__interrupt void adc_isr(void)
{
Voltage1[ConversionCount] = ADC_readResult(myAdc1, ADC_ResultNumber_1);
//Voltage2[ConversionCount] = ADC_readResult(myAdc2, ADC_ResultNumber_2);
sum1 += Voltage1[ConversionCount];
//sum2 += Voltage2[ConversionCount];
if(ConversionCount == 40)
{
Vout_count1= sum1/ConversionCount;
Va1 = (Vout_count1 * 3.3)/(4096); // sensed voltage in 3.3V format
err_5 = 3.15 - Va1;
A_5 = (err_5 * Kp); // kp b
B_5 = (err_5 * Ki); // Ki multiplication
v_5 = k_5 + (B_5 + in_A);
if (v_5 >= 1200) v_5 = 1200; // maximum duty cycle limit
if (v_5 <= 10) v_5 = 10;
k_5 = v_5;
in_A = B_5;
Vpi_5 = A_5 + v_5;
if (Vpi_5 >= 1200) Vpi_5 = 1200;// maximum duty cycle limit
if (Vpi_5 <= 10) Vpi_5 = 10;
if (Va1 > 2.50) Vpi_5 = 0;// minimum duty cycle limit
ConversionCount = 0;
sum1=0;
}
else ConversionCount++;
// Clear ADCINT1 flag reinitialize for next SOC
ADC_clearIntFlag(myAdc1, ADC_IntNumber_1);
// Acknowledge interrupt to PIE
PIE_clearInt(myPie, PIE_GroupNumber_10);
}