Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

__no_operation() and _delay_cycles()

Is there a difference between what the MSP does when you call __no_operation() and _delay_cycles? Is a single cycle delay the same length as the __no_operation()?

  • Victor,

    __delay_cycles(xxx) is an intrinsic function that creates code that takes exactly xxx cycles to execute. For a single cycle delay, it would be identical to __no_operation(). You can do a quick test in either IAR or CCS with different values of xxx to see the actual code being created by the __delay_cycles() function. For example:
    __delay_cycles(1) creates NOP
    __delay_cycles(2) creates JMP  #Next_Address_In_Flash
    __delay_cycles(1) creates RLAM.W #3,R15
    ....

    If you only need a single cycle delay, you can stick with __no_operation().

    Regards,

    Dung

     

     

     

  • hi,

    i think __no_operation(); is more better than __delay_cycles(1);

  • Basically, __no_operation inserts an instruction that is one word sized, takes one cycle to execute and doesn’t change system state. See here:
    http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/257361.aspx

    __delay_cycles generates unspecified code that takes the given number of cycles to execute. Its size may vary depending on the parameter, the instructions used may change, and it may change the system state (which is unimportant because the status register content is no longer required after the end of each C statement). It may even use registers and therefore reduce effectiveness of code optimization, even though the compiler will hopefully pick a register that doesn’t cause too much impact.
    However, the final code generated by __delay_cycles is unknown and may change depending on the surrounding code or with the next compiler version. It is only known that its execution will take the give number of clock cycles. (and if interrupted by interrupts, the delay may be longer than expected)

    Using timers is to be preferred, as a tierm delay isn't prolonged by interrupts durign the delay (only by interrupts that begin before and end after the delay), its length can be determined at runtime and the cofde size is the same (in case of a delay funciton, the code is only added once, independent of th enubme rof delays)

**Attention** This is a public forum