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.

MSP430 Cycle Counting--Too Many and Too Few

Other Parts Discussed in Thread: MSP430F2274

I am using Tom Baugh's MSP430F2274 board and software in a class.  We are also using IAR Kickstart.

In his second lab exercise, BetterNextProject, we see various timing interrupt methods and LPM3 to reduce the number of cycles and power consumed.  Each time the LED output, P1.0, toggles due to a timer firing its interrupt, the SMCLK can be seen making a burst of 28 cycles of running in active mode.  Analyzing the disassembly code and reading the Family User's Guide (slau144j) and MSP430 Family Mixed-Signal Microcontroller Application Reports (slaa024), I can only account for 26 cycles.

Here are the details:

Action/Instruction (in execution order)    Cycles (from Tables 3-14 & 16 in the Family User's Guide)

Interrupt Accepted                           8     // 6 from Table 3-14 plus 2 from last sentence of slaa024 since                                                    //interrupted in LPM3. This includes the long cycle of SMCLK which                                                    //ends with the falling edge of a long period of it idling high.
008094  bic.w #0xF0, 0x0(SP)                 5     // First line of WatchdogTimer_ISR.  All low-power modes cleared.
00809A  reti                                 5
008050  xor.b #0x1,&P1OUT                    4     // Constant Generator register source to absolute destination. 
                                                   // This toggles the LED.
008054  jmp 0x804C                           2     // End of While Loop.
00804C  bis.w #0xD8,SR                       2     // Beginning of While Loop.  Start LPM3.  Instruction immediately
                                           ___     //before the XOR.
Total                                       26 cycles
 
When I monitor SMCLK on P2.1 on an oscilloscope, it idles high and has 28 falling edges.  Modifying the code by inserting LED-toggling eXclusive ORs wherever possible to isolate the actions/instructions, the extra two cycles come after the BIt Set instruction that starts LPM3. 

While testing, I commented out the BIt Clear instruction that clears all low power modes while retaining the inserted eXclusive ORs.  It then shows the RETI is only 4 cycles long.

So, what is happening?

Thanks,

Emmett Redd

  • The CPU has an execution pipeline, which means that the documented cycle counts are not the entire truth. The execution of the previous instruction overlaps with the fetching of the next instruction, so the last instruction will need at least an extra cycle before it is flushed out of the pipeline.

    Section 5.2.8 of the Family User's Guide describes what happens when clock sources are switched. It's possible that something similar happens when a clock source starts up or shuts down, i.e., one cycle might be needed to synchronize to the clock.

    As for the RETI needing only 4 cycles: it appears there are some corner cases that are not documented.

**Attention** This is a public forum