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.

MSP430F2274 Timer Module Hangs when running at 16MHz

Hi,

I have been struggling with this issue for some time now and I thought I had found the solution, but I upgraded to CCS V5 from CCS V4 and the problem is back.

The problem is that when I run the project at 16MHz the project loops in a timer_delay function. If I revert back to 8 or 12 MHz the issue is no longer a problem. In CCS V4 I found the problem to be related to the optimization level of the compiler, the default was set as 0 and I selected the blank option. This solved my problem. Now though in CCS V5 I have performed the same optimization procedure and I am having no success getting the project to run past the timer delay function.

I read the device errata and implemented the work around for the dead DCO problem, but this had no affect. Any ideas?

Thanks

These are the two function that the code is hanging in (which by the way work fine under slower frequencies):

USHORT Timer_GetTime(void)
{
   USHORT usTime;

   // read a stable value from timer A register
  do
  {
      usTime = TIMER_A_TAR;
   }
  while (usTime != TIMER_A_TAR);

   return (usTime);                                      // return the current time
}

void Timer_DelayTime(unsigned long usTimein10us)
{
 USHORT usTime;

   while (usTimein10us)                                 // wait for given time
   {
      usTime = Timer_GetTime();

      while(Timer_GetTime() - usTime < DELAY_10us);
      usTimein10us--;
   }

 

  • Under CCSv5.1 optimizations are always enabled to a level of -o0, to disable this you have to go to the advanced optimization options in the project properties and check "disable all high level optimizations".

    Though I have to say that a code that requires it to be built without any optimization is error prone as it could change it's behaviour with every small patch applied to the compiler. Often it helps to throw a volatile here and there but the use of volatile should actually be limited to points where it really makes sense. I could imagine that if you say volatile USHORT usTime in the Timer_DelayTime() it might work also.

    I actually don't understand the implementation of the Timer_GetTime() function, but maybe I must know more about the actual setup especially frequencies involved to get a better idea on why this might work in the first place, and why it wouldn't work with 16 MHz then.

  • Thanks for the fast response. I added volatile to the usTime variables and that did the trick.

    Thank you,

    Cody

**Attention** This is a public forum