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.

TMS320F28027: Programming Launchpad timers

Part Number: TMS320F28027
Other Parts Discussed in Thread: CONTROLSUITE

I'm puzzled about how to use CPU timer0.  I've looked at the example program included in controlSUITE but I find the comments very lacking.

The timer's ISR fires periodically but seems to take maybe 4-5 times longer between interrupts than it should.  For example a one-second delay results in interrupts every five seconds.

I thought that maybe CPU_RATE was set to a smaller value than it should be at 60 MHz (i.e., 16.6 ns) but it looks to be okay unless I'm missing some included location in the project.

Here's how I'm trying to program timer0 hardware:

#include "DSP28x_Project.h" // DSP28x header file
#include "f2802x_common/include/F2802x_SWPrioritizedIsrLevels.h"
#include "f2802x_common/include/cpu.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/adc.h"
#include "f2802x_common/include/clk.h"
#include "f2802x_common/include/gpio.h"
#include "f2802x_common/include/pie.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/timer.h"
#include "f2802x_common/include/pll.h"
#include "f2802x_common/include/sci.h"
#include "f2802x_common/include/sci_io.h"
#include "f2802x_common/include/wdog.h"



#ifdef _FLASH  // _FLASH is defined in the project properties
memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
#endif

// Select the internal oscillator 1 as the clock source.
CLK_setOscSrc(myClk, CLK_OscSrc_Internal);

// Set up the PLL for x12/2 which will yield 60 MHz (10 MHz*12/2).
PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);

...

...

...

TIMER_setPeriod(myTimer0, 60L*1000L);  // Sample rate

TIMER_setPreScaler(myTimer0, 0);

TIMER_reload(myTimer0);

TIMER_setEmulationMode(myTimer0, TIMER_EmulationMode_StopAfterNextDecrement);

TIMER_enableInt(myTimer0);

TIMER_start(myTimer0);

  • Mike,

    Please try changing:

    TIMER_setPeriod(myTimer0, 60L*1000L); // Sample rate

    to:

    TIMER_setPeriod(myTimer0, 60*1000000); // Sample rate

    Also, if running from flash, please check for proper wait-state settings.

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

    - Ken
  • Hi Ken:

    Probably a dumb question, but how do I check the wait-state settings? I am running this from flash.

    -- Mike
  • Mike,

    The flash settings can be found under \common\source\flash.c towards the bottom of the file. Also, in your project make sure that you are using the correct symbol for the conditional build. In CCS go to the project properties, then under C2000 Compiler see Predefined Symbols.

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

    - Ken
  • This is the code at the bottom of flash.c:

    // CAUTION

    //ONLY THE DEFAULT VALUE FOR THESE 2 REGISTERS SHOULD BE USED
    // FlashRegs.FSTDBYWAIT.bit.STDBYWAIT = 0x01FF;
    FLASH_setStandbyWaitCount(flashHandle, 0x01FF);
    // FlashRegs.FACTIVEWAIT.bit.ACTIVEWAIT = 0x01FF;
    FLASH_setActiveWaitCount(flashHandle, 0x01FF);

    I have the _FLASH, DEBUG, and LARGE_MODEL symbols defined for the project.  I don't see any place where wait states are set, so I guess these are set only in the source code?

    After copying the code section from flash to SARAM, should I be calling the function InitFlash();?

  • Mike,

    I was referring to 'towards the bottom' and not the very 'bottom'. Specifically, see the following in flash.c and notice the conditional build symbol:

    #if (CPU_FRQ_60MHZ)
    //
    // Set the Paged Waitstate for the Flash
    //
    FLASH_setNumPagedReadWaitStates(flashHandle, FLASH_NumPagedWaitStates_2);
    //FlashRegs.FBANKWAIT.bit.PAGEWAIT = 2;

    //
    // Set the Random Waitstate for the Flash
    //
    FLASH_setNumRandomReadWaitStates(flashHandle, FLASH_NumRandomWaitStates_2);
    //FlashRegs.FBANKWAIT.bit.RANDWAIT = 2;

    //
    // Set the Waitstate for the OTP
    //
    FLASH_setOtpWaitStates(flashHandle, FLASH_NumOtpWaitStates_3);
    //FlashRegs.FOTPWAIT.bit.OTPWAIT = 3;

    This will set the proper wait-states for 60 MHz. Somewhere in your project there is a symbol specifying the operating frequency is 60 MHz. You need to check on this.

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

    - Ken
  • Hi Ken:

    Okay, I checked the wait-state programming at the spot in flash.c where you indicated.  It is setting the number to FLASH_NumPagedWaitStates_2 for the paged, random, and OTP memories.  And the symbol CPU_FRQ_60MHZ is defined.

    With more testing, I've noticed that I can achieve a one-second timer tick using this code:  TIMER_setPeriod(MyTimer0, 60000/5).

    If TIMER_setPeriod takes the 'period' argument as milliseconds, this seems to show that the clock is running 5x slower than it should.  But I think it's supposed to take the argument as the number of microseconds, meaning it's running 5,000 times slower.

    Regarding the documentation, where can I find information about this and related functions?  In F2802x Peripheral Driver Library, the function description says this is an unsigned 32-bit integer value but the units are not supplied anywhere, unless I missed that.

    -- Mike

  • Sorry, Ken, operator error.

    I took another look at the code and there was a condition that was causing my non-interrupt time code, where I print debugging messages, to think that the timer was running much (4000 times!) slower than it really is. I hooked up a scope and using TIMER_setPeriod(MyTimer0, 60000L); I see a 1 ms tick as expected. Thanks for the help.
  • Mike,

    Thanks for letting me know.

    - Ken