Hello everyone,
I'm currently trying to do the following :
The point is I want to always have a 1ms high-level output after the counter reached the period and that period is variable.
I tried to set the ePWM period (TBPRD) equal to the period of Timer2 which is set up to produce the desired frequency :
void tim2_init(int regime)
{
float period;
static int initialized = 0;
if (regime < 300)
{
initialized = 0; // Initialisation � faire
CpuTimer2Regs.TCR.bit.TSS = 1; // Stop le timer 2
}
else
{
period = 120*(1000000/(float)regime);
// Lance le timer en mode auto-reload
if(initialized == 0)
{
// Configure CPU-Timer 0 to interrupt every (period/1000000) second:
// 80MHz CPU Freq, period (in uSeconds)
ConfigCpuTimer(&CpuTimer2, 80, period);
// Initialize the EPWM module :
InitEPwmTimer();
initialized = 1;
}
Freq_ind = 1000000/period;
}
}
void InitEPwmTimer(void)
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;
// Setup Sync
EPwm8Regs.TBCTL.bit.SYNCOSEL = 0; // Pass through
// Allow each timer to be sync'ed
// EPwm8Regs.TBCTL.bit.PHSEN = 1;
// EPwm8Regs.TBPHS.half.TBPHS = 200;
EPwm8Regs.TBPRD = CpuTimer2Regs.PRD.all; // P�riode de l'ePWM = p�riode du Timer 2
EPwm8Regs.TBCTL.bit.CTRMODE = 0; // Count up
// EPwm8Regs.ETSEL.bit.INTSEL = 1; // Enable INT on Zero event
// EPwm8Regs.ETSEL.bit.INTEN = 1; // Enable INT
// EPwm8Regs.ETPS.bit.INTPRD = 1; // Generate INT on 1st event
EPwm8Regs.AQCTLA.bit.PRD = 2; // Set output high when counter equals period
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;
}
But I don't know how to configure epWM registers to do what I want (as you can see, I didn't try many things, just picking some parts from an example).
Do you have any idea how to do this ?
Or better ideas about how to obtain the desired result ?
Thanks,
Alex