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.

CCTIMER1 to count clock cycles?

Other Parts Discussed in Thread: MSP430F5510

I'm using a MSP430F5510. Basically, at a certain point of my program I have an interrupt function executed with a frequency of 1.5MHz (the interrupt is on the rising edge of an external clock with this frequency). The microcontroller runs at 24MHz, so it has 16 clock cycles to execute it, right? The function is the following:

#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
  P2IFG &= ~BIT0;
  buffer[cnt] = P1IN;
  cnt--;
  if (!cnt)
    P2IE &= ~BIT0;
}

'buffer' and 'cnt' are global variables defined in RAM memory. I read from other threads to watch the CCTIMER1 while debugging to estimate the number of clock cycles. I do it while debugging with the FET debugger, but I don't understand how it counts. If I debug line by line, it counts 16 clock cycles. If I put a breakpoint at the beginning of the function and one at the end of the function, and I let it run, it counts 21 clock cycles. I know that it is not so accurate, but which one of the two cases is more "real"?

  • Number of CPU cycles needed depends on how the c-compiler optimize the execution speed. But there is no way the CPU can finish that ISR within 16 MCLK cycles.

  • I see... also because I don't take into account the 6 clock cycles needed to enter the interrupt function. I check the assembly code of the function, it is always the same either with the compiler optimizations enabled or disabled, it's too simple to be optimized. Maybe is it better to use a faster microcontroller (like ARM)?

    EDIT: is it possible to increase the frequency of the MSP430 up to 48MHz, using an external oscillator?

  • The DCO can oscillate much faster than 24 MHz, but the CPU cannot run faster than 25 MHz.

    You may consider use the CPU to handle the Timer exclusively to capturing the incoming edges until the buffer in RAM is full. After that, you can use the CPU to analyze and dispose the data in the buffer for next round of capturing.

    Without using interrupts, the CPU is capable of handling each capture within 16 CPU cycles if optimized.

  • How can I use a timer to fill the buffer?

    I try to follow your suggestion, I don't use interrupts and I just put the data capture in the main:

    register unsigned char *ptr;
    ....
    ptr = buffer;
    do
    {
      while(!(P2IN & BIT0));
      *ptr = P1IN;
      ptr++;
    } while((*ptr)); // buffer is initialized with all 1 and end with a 0

    now it is much faster than before, also because I store the pointer in a register instead of memory, but I don't know if it is enough (I count 13/15 clock cycles for the entire loop while debugging, an there are no additional clock cycles for entering the interrupt function like before)

**Attention** This is a public forum