Other Parts Discussed in Thread: C2000WARE
Tool/software: Code Composer Studio
Hi,
I am trying to program the Timer 0 module in TMS320F2808. The Timer doesn't seem to be triggering at all. Could you guide me in the right direction? Thanks!
Regards,
Frederic
Here is the source code:
/* * TMS320F2808_GPIO_TIMER.c * * Created on: 14.10.2019 * Author: Frederic Leo */ #include "DSP280x_Device.h" // DSP280x Header file Include File #include "DSP280x_GlobalPrototypes.h" #include "DSP280x_Examples.h" // DSP280x Examples Include File void Init_Timer0(void); __interrupt void cpu_timer0_isr(void); void main() { // WARNING: Always ensure you call memcpy before running any functions from RAM // InitSysCtrl includes a call to a RAM based function and without a call to // memcpy first, the processor will go "into the weeds" #ifdef _FLASH memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize); #endif // Step 1. Initialize System Control: // PLL, WatchDog, enable Peripheral Clocks InitSysCtrl(); // Step 2. Initialize GPIO: InitGpio(); // Step 3. Clear all interrupts and initialize PIE vector table: // Disable CPU interrupts DINT; // Initialize PIE control registers to their default state. // The default state is all PIE interrupts disabled and flags // are cleared. InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; // Initialize the PIE vector table with pointers to the shell Interrupt // Service Routines (ISR). // This will populate the entire table, even if the interrupt // is not used in this example. This is useful for debug purposes. InitPieVectTable(); // Disable Protection EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &cpu_timer0_isr; EDIS; // This is needed to disable write to EALLOW protected registers EALLOW; // This is needed to write to EALLOW protected registers GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 0; // Set as GPIO GpioCtrlRegs.GPADIR.bit.GPIO14 = 1; // GPIO14 is output GpioCtrlRegs.GPAPUD.bit.GPIO14 = 1; // Disable pull-up on GPIO14 EDIS; // This is needed to disable write to EALLOW protected registers Init_Timer0(); for(;;) { //Run Forever } } void Init_Timer0(void) { InitCpuTimers(); // Only initialize the Cpu Timers ConfigCpuTimer(&CpuTimer0, 60, 500000); CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0 IER |= M_INT1; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // Enable TINT0 in the PIE: Group 1 interrupt 7 EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM } __interrupt void cpu_timer0_isr(void) { CpuTimer0.InterruptCount++; GpioDataRegs.GPATOGGLE.bit.GPIO14 = 1; // Toggle the state of GPIO14 // Acknowledge this interrupt to receive more interrupts from group 1 PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; }