Other Parts Discussed in Thread: CONTROLSUITE, TMS320F2802, TMS320F28035
Hello,
I'm trying to generate a 3-phase Sinusoidal PWM signals for an ACIM control. I'm requested to use a potentiometer to variate the output voltage (from 0 to 3V) and the frequency (from 1 to 60 Hz) to satisfy the V/f equation for speed control; when the voltage increases, the frequency must increase as well. So far, I've managed to modify the output voltage using the PWM chopping sub-module and reading the potentiometer values with the ADC module, but I still can't control de frequency values because I haven't found which PWM parameter I should modify. I've attached the code that has worked to me so far, in which I succesfuly change the output voltage values for PWM1 with the potentiometer but haven't figured out yet how to do it with the output frequency. I would really appreciate it if someone could give me hand on this! Thanks in advance.
void InitEPwm1()
{
EPwm1Regs.PCCTL.bit.CHPFREQ = 1;
EPwm1Regs.PCCTL.bit.CHPEN = 1;
EPwm1Regs.TBPRD = TB_PRD; // Set timer period
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBCTL.bit.HSPCLKDIV = HSPCLK_DIV; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = CLK_DIV;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //Generar una señal cuando CTR = 0. Esto hace al PWM1 como el maestro.
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Load registers every ZERO
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm1Regs.CMPA.half.CMPA = TB_PRD;
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on Zero
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Set PWM1A on Zero
EPwm1Regs.AQCTLB.bit.CAD = AQ_SET;
// Active Low PWMs - Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = DEAD_BAND;
EPwm1Regs.DBFED = DEAD_BAND;
EPwm1Regs.ETSEL.bit.INTEN = 1; // Habilitar interrupción por evento.
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTRD_CMPA;
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; //Interrupt on first event.
}
interrupt void adc_isr(void)
{
Duty = (0.001481481*AdcResult.ADCRESULT0);
EPwm1Regs.PCCTL.bit.CHPDUTY = Duty;
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
Jorge Flores