Hello everyone!
I am designing a Fuel Engine ECU (injection type) with this controller.
So far, so good, everythings works fine, but I came to a point where I could not do what I wanted. I am using ePWM1A, 2A, 3A and 4A to drive my injection circuitry which works great. I can control all of them easily in Duty Cycle and Period. But now I have to.. how to say this.. "position them in time". What I mean is that my pulses have to be at the exact moment I need them to be. I know when to generate my first one, but now I have to synchronize the others with this one, so I have 90 degrees between each ePWM's pulse. And then I have my Ignition signal which is also an ePWM and that needs to be generated a little before the first pulse..
Anyways, my point is, I am trying to find what values to put in the phase registers, because I can't get any consistent results.
Here is what I have so far.
PWM1A init:
usCount = (unsigned short) ((float)(ulPeriod / 7.6666666667));
// DutyCycle = DutyCycle(%) * Period = DutyCycle(%) * Count
usPWMDutyCycle = (ucDutyCycle * (usCount / 100)) ;
// Duty Cycle Register = Period Value - Duty Cycle value
usPWMDutyCycle = usCount - usPWMDutyCycle;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Set Compare A Descending to SET PWM ("ON" time)
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set Compare A Ascending to CLEAR PWM ("OFF" time)
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Time base counter counts up then down (permits symmetrical waveform)
EPwm1Regs.TBPRD = usCount; // Set time base period
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
#ifdef SYSCLK_100
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV2;
if(ulPeriod > 5200)
{
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 3; // Clock ratio to SYSCLKOUT (DIV by 6)
EPwm1Regs.TBCTL.bit.CLKDIV = 6; // div by 64
}
#endif
#ifdef SYSCLK_40
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
#endif
EPwm1Regs.CMPA.half.CMPA = usPWMDutyCycle; // Set compare A value
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0;
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;
EDIS;
PWM2A is initialized in the same fashion.
Then I set the phase relationship between the two:
// Phase shift in Counts = PhaseInDegrees/360 x PW1A_Period
EPwm2Regs.TBPHS.half.TBPHS = 1418; //(unsigned short) ((float)((usPhase / 360) * EPwm1Regs.TBPRD));
EPwm2Regs.TBPRD = EPwm1Regs.TBPRD;
EPwm2Regs.CMPA.half.CMPA = EPwm1Regs.CMPA.half.CMPA;
EPwm2Regs.TBCTL.bit.PHSEN = 1;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
So, I have usPhase equal to 180 and there is no phase shift. I put 360, I have 180 degrees phase shift. I put 540, still 180...
Is there something I have been missing.. ? Hope my question is clear.
Edit: To make it simple, i want, for example, ePWM5A's pulse to be 20 degrees before PWM1A's (that can vary a little, but something like that) . I also want PWM2-3-4A to be 90 spaced by 90 degrees.