Hello,
In my motion control project, I would like to use the Cpu-Timer0 in order to generate an interrupt every 200us which launch an interrupt service routine "ISRKernel". This interrupt service routine is used to compute the current and the speed control of the AC motor.
So, I need to initialize, configurate, start the Cpu-Timer0 and associate to it the ISRKernel . I got some help from controlSuite example files.
Here is the way I initialize, configurate and start the Cpu-Timer0 is developed below :
In the file "cpu_timer.c"
struct CPUTIMER_VARS CpuTimer0;
//=====================================
// InitCpuTimers: Initialize specified Cpu Timer :
//-------------------------------------
// This function initializes all three CPU timers to a known state.
//=====================================
void InitCpuTimers(void)
{
// CPU Timer 0
// Initialize address pointers to respective timer registers:
CpuTimer0.RegsAddr = &CpuTimer0Regs;
// Initialize timer period to maximum:
CpuTimer0Regs.PRD.all = 0xFFFFFFFF;
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
CpuTimer0Regs.TPR.all = 0;
CpuTimer0Regs.TPRH.all = 0;
// Make sure timer is stopped:
CpuTimer0Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
CpuTimer0Regs.TCR.bit.TRB = 1;
// Reset interrupt counters:
CpuTimer0.InterruptCount = 0;
}
//=====================================
// ConfigCpuTimer: Configure Cpu Timer :
//-------------------------------------
// This function initializes the selected timer to the period specified
// by the "Freq" and "Period" parameters. The "Freq" is entered as "MHz"
// and the period in "uSeconds". The timer is held in the stopped state
// after configuration.
//=====================================
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
{
Uint32 temp;
// Initialize timer period:
Timer->CPUFreqInMHz = Freq;
Timer->PeriodInUSec = Period;
temp = (long) (Freq * Period);
Timer->RegsAddr->PRD.all = temp;
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
Timer->RegsAddr->TPR.all = 0;
Timer->RegsAddr->TPRH.all = 0;
// Initialize timer control register:
Timer->RegsAddr->TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart Timer
Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer
Timer->RegsAddr->TCR.bit.SOFT = 1;
Timer->RegsAddr->TCR.bit.FREE = 1; // Timer Free Run
Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
// Reset interrupt counter:
Timer->InterruptCount = 0;
}
In the "main function"in the file "imvf28.c" :
// Configure CPU-Timer 0 to interrupt every second : 150MHz CPU Freq, 200 usecond Period
InitCpuTimers(); // Init CPU-Timer0
ConfigCpuTimer(&CpuTimer0, 150, 200); // Config the Cpu-Timer0
StartCpuTimer0(); // CpuTimer0Regs.TCR.bit.TSS = 0 : start the Cpu-Timer 0
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
In the function "InitKernel" in the file "kernel.c" :
EALLOW; // Enable write to EALLOW protected registers
PieVectTable.TINT0 = &ISRKernel; // used to associate "IsrKernel" to CPU-Timer0
EDIS; // Disable write to EALLOW protected registers
// Enable TINT0 in the PIE: Group 1 interrupt 7 :
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
IER |= M_INT1;
// Enable EPWM1 INT in the PIE: Group 3 interrupt 1 // The original program used EPWM1 timer for this ISR
//PieCtrlRegs.PIEIER3.bit.INTx1 = 1; // The original program used EPWM1 timer for this ISR
//IER |= M_INT3; // Enable CPU INT3 for EPWM1 INT // The original program used EPWM1 timer for this ISR
Since my project is still not working correctly, I would be grateful if you could provide me with some tips to make my interrupt service routine work properly with the Cpu-Timer0.
Thank you in advance for your help in this matter.
Malory