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.

CCS/TMS320F280049C: interrupt based timer program to toggle the led

Part Number: TMS320F280049C
Other Parts Discussed in Thread: LAUNCHXL-F280049C

Tool/software: Code Composer Studio

Hello team,

we are using  LAUNCHXL-F280049C card, we need to combine the both LED blink example and cpu timer example which provided in c2000 ware.i need to toggle led based  interrupt  timer , toggle the led for every 1/2 seconds.

thank you

  • Raja,

    Are you encountering any issue in combining the example? You can start with CPU timer example, and add the GPIO toggle functionality in that.

  • Hi, thanks for the reply, i added the led blink code to cpu timer example, but i didn't get any result, i  attached my code below

    //#############################################################################
    //
    // FILE: timer_ex1_cputimers.c
    //
    // TITLE: CPU Timers Example
    //
    //! \addtogroup bitfield_example_list
    //! <h1> CPU Timers </h1>
    //!
    //! This example configures CPU Timer0, 1, and 2 and increments
    //! a counter each time the timer asserts an interrupt.
    //!
    //! \b External \b Connections \n
    //! - None
    //!
    //! \b Watch \b Variables \n
    //! - CpuTimer0.InterruptCount
    //! - CpuTimer1.InterruptCount
    //! - CpuTimer2.InterruptCount
    //!
    //
    //#############################################################################
    // $TI Release: F28004x Support Library v1.10.00.00 $
    // $Release Date: Tue May 26 17:06:03 IST 2020 $
    // $Copyright:
    // Copyright (C) 2020 Texas Instruments Incorporated - http://www.ti.com/
    //
    // Redistribution and use in source and binary forms, with or without
    // modification, are permitted provided that the following conditions
    // are met:
    //
    // Redistributions of source code must retain the above copyright
    // notice, this list of conditions and the following disclaimer.
    //
    // Redistributions in binary form must reproduce the above copyright
    // notice, this list of conditions and the following disclaimer in the
    // documentation and/or other materials provided with the
    // distribution.
    //
    // Neither the name of Texas Instruments Incorporated nor the names of
    // its contributors may be used to endorse or promote products derived
    // from this software without specific prior written permission.
    //
    // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    // $
    //#############################################################################

    //
    // Included Files
    //
    #include "F28x_Project.h"

    //
    // Function Prototypes
    //
    __interrupt void cpuTimer0ISR(void);

    //__interrupt void cpuTimer1ISR(void);
    //__interrupt void cpuTimer2ISR(void);
    #define DEVICE_GPIO_PIN_LED1 23

    //
    // Main
    //
    void main(void)
    {
    //
    // Initialize device clock and peripherals
    //
    InitSysCtrl();

    //
    // Initialize GPIO

    //
    InitGpio();
    //GPIO_SetupPinMux(31U, GPIO_MUX_CPU1, 0);
    //GPIO_SetupPinOptions(31U, GPIO_OUTPUT, GPIO_PUSHPULL);
    GPIO_SetupPinMux(DEVICE_GPIO_PIN_LED1, GPIO_MUX_CPU1, 0);
    GPIO_SetupPinOptions(DEVICE_GPIO_PIN_LED1, GPIO_OUTPUT, GPIO_PUSHPULL);

    //
    // 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 the Device Peripheral. For this example, only initialize the
    // Cpu Timers.
    //
    InitCpuTimers();

    //
    // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
    // 100MHz CPU Freq, 1 second Period (in uSeconds)
    //
    ConfigCpuTimer(&CpuTimer0, 100, 1000000);

    //
    // 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, CPU int13
    // which is connected to CPU-Timer 1, and CPU int 14, which is connected
    // to CPU-Timer 2
    //
    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)
    {
    //led toggl
    if(CpuTimer0.InterruptCount==0)
    {
    GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 1);
    CpuTimer0Regs.TCR.bit.TSS=1;

    }
    CpuTimer0.InterruptCount++;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
    //
    // Acknowledge this interrupt to receive more interrupts from group 1
    //
    }

    //
    // cpuTimer1ISR - CPU Timer1 ISR with interrupt counter
    //
    /*__interrupt void cpuTimer1ISR(void)
    {
    //
    // The CPU acknowledges the interrupt
    //
    CpuTimer1.InterruptCount++;
    }

    //
    // cpuTimer2ISR CPU Timer2 ISR with interrupt counter
    //
    __interrupt void cpuTimer2ISR(void)
    {
    //
    // The CPU acknowledges the interrupt
    //
    CpuTimer2.InterruptCount++;
    }

    //
    // End of file
    //
    */

    thank you

  • What exactly is not working? Is CPU timer not working or LED toggle is not working?

    You can set the breakpoint in CPU-timer ISR and debug the LED toggle.

  • Hi, thanks for the reply,

    1.i attached above code for led toggle using timer,is that code is correct or wrong? if no what are the changes i need to do? 

    2. led toggle code  is not working, 

    3. below is code for led toggle,i need to set timer in place of delay how set it can you please help me

    for(;;)
    {
    // Turn on LED
    GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 0);

    // Delay for a bit.
    DELAY_US(500000);

    // Turn off LED

    GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 1);

    // Delay for a bit.
    DELAY_US(500000);
    }

    thank you

  • Raja,

    You just need to add one function call  in CPU timer ISR to toggle the GPIO line.

    __interrupt void
    cpuTimer0ISR(void)
    {
        cpuTimer0IntCount++;
    
        GPIO_togglePin(DEVICE_GPIO_PIN_LED1);
    
    
        //
        // Acknowledge this interrupt to receive more interrupts from group 1
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    }

  • Here is full project for your reference.

    0525.timer_ex1_cputimers.zip

  • Hi thanks for the reply...