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 cpu cycles



I am working with assembly codes using Code Composer Studio v5.5.0 for MSP430. When I enable the clock I get the CPU cycles as 1,900,612. It means that it should take around 1.9 seconds to execute( MSP Frequency is 1Mhz), but when I compared it with my watch it took around 6 seconds. Can anyone please tell me if the relation of CPU cycles and CPU seconds? Is it cycles/frequency or is there any other relation with other parameters like machine cycles.

  • Are you joking?

    R4, your loop index, is preloaded with 6 and then decremented, so you will get exactly 6 iterations of a loop containing 4 machine instruction, surely less than one hundred cycles (not millions). It seems your tool is completely broken.

    Regards,

    P.

  • Piergiuseppe Tundo said:
    It seems your tool is completely broken.

    And the long execution time is because the tool does single-stepping to determine the cycles.
    If the code were free-running, with a port toggle at beginning and end and an external counter/timer attached, the execution time would be in the range of far below a millisecond.

  • Hello Anirudh,

    I updated your code a little to demonstrate what the above posts explained (code below). I started Timer_A right before your code begins, so it will increment at every rising edge of the clock. Setting a breakpoint at “label” and running to this point will reveal how many clock cycles the program will take. You can see the value in Timer_A by using the memory browser at address 0x0170, or using the register view. After running your code Timer_A had the value 0x003D in it, so that’s 61 cycles. For more info on the timer please see the user guide (http://www.ti.com/lit/ug/slau144j/slau144j.pdf pg 355 I’m currently using the G2553).

    Regarding CPU seconds, you are correct in your calculation: CPU seconds = CPU cycles/CPU CLK Frequency. So with 61 cycles, that’s about 61 us. Jen-Michael explained why this can be longer while using the debug tool.

     

    Here’s the code:

    ;-------------------------------------------------------------------------------
    ; MSP430 Assembler Code Template for use with TI Code Composer Studio
    ;
    ;
    ;-------------------------------------------------------------------------------
                .cdecls C,LIST,"msp430.h"       ; Include device header file
    
    ;-------------------------------------------------------------------------------
                .text                           ; Assemble into program memory
                .retain                         ; Override ELF conditional linking
                                                ; and retain current section
                .retainrefs                     ; Additionally retain any sections
                                                ; that have references to current
                                                ; section
    ;-------------------------------------------------------------------------------
    RESET       mov.w   #__STACK_END,SP         ; Initialize stackpointer
    StopWDT     mov.w   #WDTPW|WDTHOLD,&WDTCTL  ; Stop watchdog timer
    
    ;-------------------------------------------------------------------------------
    			mov.w	#0x0220,R7
    			BIS		R7,TACTL				; initilize timer_A (using SMCLK & continuous)
    
    			mov.w #06h,R4                                            ; Main loop here
    			mov.w #arr1,R5
    			mov.w #200h,R6
    
    HERE		mov.w @R5+, 0(R6)
    
    			incd.w 	R6
    			dec		R4
    			jnz		HERE
    
    label		jmp label
    
    arr1		.word 20,30,-1,2,50,4
    ;-------------------------------------------------------------------------------
    
    
    ;-------------------------------------------------------------------------------
    ;           Stack Pointer definition
    ;-------------------------------------------------------------------------------
                .global __STACK_END
                .sect 	.stack
    
    ;-------------------------------------------------------------------------------
    ;           Interrupt Vectors
    ;-------------------------------------------------------------------------------
                .sect   ".reset"                ; MSP430 RESET Vector
                .short  RESET
    

    Let us know if you have any other questions!

    -Nate

  • IAR have a nice simulation mode with trace, it shows that it take 74 cycles.

**Attention** This is a public forum