This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: how to program a INTERRUPT BASED TIMER PROGRAM TO TOGGLE THE LED

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE

CONTROLLER -TMS320F28388D

DOCKING STATION-TMDSHSECDOCK

PLZ TELL ME THE PROGRAMMING CODE FOR MAKING A INTERRUPT BASED TIMER PROGRAM TO TOGGLE THE LED EVERY 1/2 SECONDS

  • Hi Abhishek,

    Have you seen the examples in C2000WARE?

    There is an LED example (C:\ti\c2000\C2000Ware_x\device_support\f2838x\examples\cpu1\led) and an example of doing a timer interrupt (C:\ti\c2000\C2000Ware_x\device_support\f2838x\examples\cpu1\timer)

    The two examples can be combined with slight modifications to do what you need.

    Best Regards,

    Marlyn

  • hii marlyn,

    this is the code of TIMER which i got from library.i understood the code of LED but didn't got TIMER code and that's why couldn't merge the two codes for making the program. Can you help me in xplaination of this code or if will be better if u tell me how to merge the two codes..THANKS IN ADVANCE

  • Hi Abhishek,

    To learn how to properly configure an interrupt refer to the 'Peripheral Interrupt' section of the Technical Reference Manual.

    All of the configuration for the timer can stay the same expect changing the period from one second to 1/2 second; that is changed in the ConfigCpuTimer() function. Make sure to add the configuration for the GPIO pin in main() as well.

    Every time .5 seconds has elapsed the interrupt will occur. Within the interrupt service routine (ISR) you can change the status of the LED (I have marked where below). I would suggest just toggling the LED value so that every time the ISR executes the status of the LED will change.

    Please let me know if this is still not clear, or if you have any specific questions and I'll be happy to help futher.

    // You likely only need one timer interrupt so I kept Timer 0
    
    //
    // Function Prototype- This declares the function that will be used for the interrupt 
    //
    __interrupt void cpuTimer0ISR(void);
    
    
    //
    // Main
    //
    void main(void)
    {
        //
        // Initialize device clock and peripherals
        //
        InitSysCtrl();
    
        //
        // Disable CPU interrupts
        //
        DINT;
    
        //
        // Initialize the 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)
        //
        InitPieVectTable();
    
        //
        // Map ISR functions
        //
        EALLOW;
        PieVectTable.TIMER0_INT = &cpuTimer0ISR;
        EDIS;
    
        //Initialize/Configure the GPIO pin Here
    
        //
        // Initialize the Device Peripheral. For this example, only initialize the
        // Cpu Timers.
        //
        InitCpuTimers();
    
        //
        // Configure CPU-Timer 0 to interrupt every 1/2 second:
        // 200MHz: CPU Freq, Period: In uSeconds)
        //
        ConfigCpuTimer(&CpuTimer0, 200, 500000);
    
        //
        // To ensure precise timing, use write-only instructions to write to the
        // entire register. Therefore, if any of the configuration bits are changed
        // in ConfigCpuTimer and InitCpuTimers, the below settings must also be
        // be updated.
        //
        CpuTimer0Regs.TCR.all = 0x4000;
    
        //
        // Enable CPU int1 which is connected to CPU-Timer 0
        //
        IER |= M_INT1;
    
        //
        // Enable TINT0 in the PIE: Group 1 interrupt 7
        //
        PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
    
        //
        // Enable global Interrupts and higher priority real-time debug events
        //
        EINT;
        ERTM;
    
        //
        // IDLE loop. Just sit and loop forever (optional).
        //
        while(1)
        {
    
        }
    }
    
    //
    // cpuTimer0ISR - CPU Timer0 ISR with interrupt counter
    //
    __interrupt void cpuTimer0ISR(void)
    {
        //Toggle the value of the LED here 
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 1
        //
        PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    }
    
    //
    // End of file
    //

    Best Regards,

    Marlyn