• TI Thinks Resolved

CCS/TMS320F2808: Problem with Timer0

Prodigy 120 points

Replies: 11

Views: 129

Part Number: TMS320F2808

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;
}

  • Frederic,

    I pasted your code verbatim into a CCS project and it ran correctly.  I placed a break-point on the first line of the ISR and it triggers each time.  When you say it's not triggering, how are you checking that?  Also, are building for flash or RAM?

    Regards,

    Richard 

  • In reply to Richard Poley:

    Hi Richard,
    I am building for flash memory. Could you share your clock and PLL settings with which you programmed? Thanks!

    Regards
    Frederic

  • In reply to Frederic Philips:

    Frederic,

    Sorry, I didn't know you were building for flash.  In that case I think you need to re-structure your code a little. 

    You'll need to set up the clocks first with InitSysCtrl(), then do the MemCopy(), then initialize the flash with InitFlash().  Attached is the main file from an older F2808 flash example.  I recommend following a similar initialization sequence.  The PLL settings used were:

    #define DSP28_CLKINDIV 0

    #define DSP28_PLLCR 10

    All I did was build and run your main file on an '069 (which I had to hand) to check whether the code was functionally OK.  It ran fine.

    Regards,

    Richard

    Example_280xFlash.c

  • In reply to Richard Poley:

    Hi Richard,

    The program was actually configured to build for RAM and not for flash. Sorry for the misinformation. Could you share the project with which you ran the code so that I can also test on my board? Thanks!

    Regards
    Frederic

  • In reply to Frederic Philips:

    Frederic,

    All I did was replace the main.c file in an F28069 example project with your code. If you download the latest C2000Ware, you can open up the CPU timer example for F28069, replace the main file in that project with the attachment (which is just your code), and it will work on an F28069. 

    I don't think this is going to run on an F2808, though.  If you have a TI example project for that device you should be able to do something similar.  Unfortunately, I'm not able to run F2808 on my machine at the moment.

    Regards,

    Richard

    forum.c

  • In reply to Richard Poley:

    Hi Richard,

    I compared the timer example for F28069 and tested it on my board. The result was the same and the Timer0 did not trigger. I also tired Timer1 and it doesn't seem to function either. I don't know what the issue is now and how to proceed from here on.

    Regards,

    Frederic

  • In reply to Frederic Philips:

    Frederic,

    I'm not sure either.  How are you testing to know whether the timer is triggering?  All I did was place a break-point on the first line of the ISR (line 87 in your program) and run the code.

    As a sanity check, and since you have an F28069 target, it would be worth running the CPU timer example in C2000Ware.  If you have the most recent C200Ware version installed in the default location, the example is at:

    C:\ti\c2000\C2000Ware_2_00_00_03\device_support\f2806x\examples\c28\cpu_timer

    Could you try that please and let me know?

    Regards,

    Richard

  • In reply to Richard Poley:

    Hi Richard,
    I am also testing using breakpoint exactly at the line you mentioned. BTW my target microcontroller is F2808 and not F28069. So, unfortunately, I don't have any C2000Ware examples to test.

    Regards
    Frederic

  • In reply to Frederic Philips:

    Hi Frederic,

    It's strange because I don't think the issue is in the code you posted. 

    Can you place a break-point at the first instruction after main() - line 26 above - and run the code?  Does it return there?  If so, I'm wondering if the watchdog it timing out before you get to enabling the interrupr.

    If not, run and then stop the code.  It should be in the while loop.  Open a Registers window and check that the timer0 registers have been configured correctly.  They are fine on my machine, I'm just looking for clues.

    Attached is the main file from an older F2808 CPU timer example which isn't being shipped any more.  If all else fails, you might like to try integrating this with your project to see if it works. 

    Regards,

    Richard

    Example_280xCpuTimer.c

  • In reply to Richard Poley:

    Frederic,

    Could you please let us know which target board (TI Experimenter Kit or Spectrum Digital eZdsp) you are using?  Also, please be sure that you are selecting the correct boot mode.  This may be related to your issue.

    I hope this helps. If this answers your question, please click the green "Verified Answer" button. Thanks.

    - Ken