|
|
|
@ -1,10 +1,11 @@
|
|
|
|
/* Gerardo Marx
|
|
|
|
/* Gerardo Marx
|
|
|
|
21/Oct/2026
|
|
|
|
21/Oct/2026
|
|
|
|
Objective:
|
|
|
|
Objective:
|
|
|
|
- ePWM1 (ePWM1A and ePWM1A) and ePWM2 will be controlled CPU1
|
|
|
|
- ePWM1 (ePWM1A and ePWM1B) and ePWM2 will be controlled CPU1
|
|
|
|
- ePWM4 and ePWM5 will be controlled CPU2
|
|
|
|
- ePWM4 and ePWM5 will be controlled CPU2
|
|
|
|
- CPU1: ePWM1 (GPIO0 and GPIO1 outputs), up-count, 10KHz, and D=0.4
|
|
|
|
- CPU1: ePWM1 (GPIO0 and GPIO1 outputs), up-count, 10KHz, and D=0.4
|
|
|
|
- CPU1: ePWM2 (GPIO2 and GPIO3), up-down, 5KHz, and m=-0.3
|
|
|
|
- CPU1: ePWM2 (GPIO2 and GPIO3), up-down, 5KHz, and m=-0.3
|
|
|
|
|
|
|
|
|
|
|
|
- CPU2: ePWM4 (GPIO6 and GPIO7), up-count, 15KHz, and D=0.6
|
|
|
|
- CPU2: ePWM4 (GPIO6 and GPIO7), up-count, 15KHz, and D=0.6
|
|
|
|
- CPU2: ePWM5 (GPIO8 and GPIO8), up-down, 4KHz, and m=+0.7
|
|
|
|
- CPU2: ePWM5 (GPIO8 and GPIO8), up-down, 4KHz, and m=+0.7
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -72,26 +73,63 @@ void main(void)
|
|
|
|
EPwm1Regs.TBPRD = 5000-1; // 10KHz sawtooth
|
|
|
|
EPwm1Regs.TBPRD = 5000-1; // 10KHz sawtooth
|
|
|
|
EPwm2Regs.TBPRD = 5000; // 5KHz triangular
|
|
|
|
EPwm2Regs.TBPRD = 5000; // 5KHz triangular
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Counter-compare submodules
|
|
|
|
|
|
|
|
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0; //shadow mode
|
|
|
|
|
|
|
|
EPwm1Regs.CMPCTL.bit.LOADAMODE = 0; //zero
|
|
|
|
|
|
|
|
EPwm1Regs.CMPA.bit.CMPA = 1999; // 0.4 of the duty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EPwm2Regs.CMPCTL.bit.SHDWAMODE = 0;
|
|
|
|
|
|
|
|
EPwm2Regs.CMPCTL.bit.LOADAMODE = 0;
|
|
|
|
|
|
|
|
EPwm2Regs.CMPA.bit.CMPA = (uint16_t)((-0.3+1)/2.0*5000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6. Configure AQ and dead band.
|
|
|
|
|
|
|
|
// Action qualifier submodule
|
|
|
|
|
|
|
|
// ePWM1 - A output to be fed to the upper device of a leg
|
|
|
|
|
|
|
|
// ePWM1 - B output to be feb to the lower device
|
|
|
|
|
|
|
|
// TBCTR = 0 -> A = 1 and B = 0 (ZRO and AQCTLA/B)
|
|
|
|
|
|
|
|
EPwm1Regs.AQCTLA.bit.ZRO = 2; // A = 1 @ 0x00
|
|
|
|
|
|
|
|
EPwm1Regs.AQCTLB.bit.ZRO = 1; // B = 0 @ 0x00
|
|
|
|
|
|
|
|
// TBCTR = CMPA -> A = 0 and B = 1 (CAU - AQCTLA/B)
|
|
|
|
|
|
|
|
EPwm1Regs.AQCTLA.bit.CAU = 1; // A = 0 @ TBCTR = CMPA up count
|
|
|
|
|
|
|
|
EPwm1Regs.AQCTLB.bit.CAU = 2; // B = 1 @ TBCTR = CMPA up count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ePWM2 - A output to be fed to the upper device of a leg
|
|
|
|
|
|
|
|
// ePWM2 - B output to be feb to the lower device
|
|
|
|
|
|
|
|
// TBCTR = CMPA first -> A = 1 and B = 0 (CAU and AQCTLA/B)
|
|
|
|
|
|
|
|
EPwm2Regs.AQCTLA.bit.CAU = 2; //A = 1: TBCTR = CMPA up count
|
|
|
|
|
|
|
|
EPwm2Regs.AQCTLB.bit.CAU = 1; //B = 0: TBCTR = CMPA up count
|
|
|
|
|
|
|
|
// TBCTR = CMPA second -> A = 0 and B = 1 (CAD and AQCTLA/B)
|
|
|
|
|
|
|
|
EPwm2Regs.AQCTLA.bit.CAD = 1; //A = 0: TBCTR = CMPA down count
|
|
|
|
|
|
|
|
EPwm2Regs.AQCTLB.bit.CAD = 2; //B = 1: TBCTR = CMPA down count
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 7. Configure event trigger and trip-zones.
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 8. Register and enable interrupts.
|
|
|
|
|
|
|
|
// NA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 9. Configure PWM GPIOs, diagnostic pin, and X-BAR
|
|
|
|
|
|
|
|
EALLOW;
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAGMUX1.bit.GPIO0 = 0;
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; // epwm1A
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAGMUX1.bit.GPIO1 = 0;
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1; // epwm1B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAGMUX1.bit.GPIO2 = 0;
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1; // epwm2A
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAGMUX1.bit.GPIO3 = 0;
|
|
|
|
|
|
|
|
GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1; // epwm2B
|
|
|
|
|
|
|
|
EDIS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 6. Configure AQ and dead band.
|
|
|
|
|
|
|
|
// 7. Configure event trigger and trip-zones.
|
|
|
|
|
|
|
|
// 8. Register and enable interrupts.
|
|
|
|
|
|
|
|
// 9. Configure PWM GPIOs, diagnostic pin, and X-BAR
|
|
|
|
|
|
|
|
// 10. Confirm fault condition and syncronize startup.
|
|
|
|
// 10. Confirm fault condition and syncronize startup.
|
|
|
|
|
|
|
|
// Start the timer counters for ePWM 1 and 2
|
|
|
|
|
|
|
|
EALLOW;
|
|
|
|
|
|
|
|
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
|
|
|
|
|
|
|
|
EDIS;
|
|
|
|
|
|
|
|
|
|
|
|
for(;;) { }
|
|
|
|
for(;;) { }
|
|
|
|
|
|
|
|
|
|
|
|
|