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.

A doing nothing code



Hi all:

 

    I need a "wasting of time" code for my application. I am writing in C, using EZ430 RF2500 development kit. Anyone know a "doing nothing" just waste a few clock cycle code?

 

Thanks

  • In the "intrinsics.h" file there is a delay cycle function that can just add delay. If you add the following line it adds 200 CPU cycles of delay.
    __delay_cycles(200);        // Normal delay between bytes

    The other alternative is using a bunch of NOPs:
    __no_operation();

    May be the community has more tricks to share :)

  • Does anyone know if this code could do the trick?

    void inline micro_delay(register unsigned int n)
    {
        __asm__ __volatile__ (
            "1: \n"
            " dec %[n] \n"
            " jne 1b \n"
            : [n] "+r"(n));
    }

  • seadreamer said:
    Does anyone know if this code could do the trick?


    Yes, why not? It is more or less an empty "for"-loop, but since it is done as volatile asm, it is not subject to optimization or dead-code-checking and therefore will work.
    (I see, you're an mspgcc user like myself)

    But a better way is to have a timer running at a known frequency (e.g. 1MHz) in continuous mode. Then set a CCR register (e.g. TACCR2) to TAR+delay and wait for the CCRIFG flag being set. This allows an exact delay of 'delay' microseconds. And as long as the init code ensure that the tiemr runs at 1MHz (even if the core or crystal frequency might be different), the code using this type of delay will work the same on all projects. No need to adjust it then depending on the current MCLK.

**Attention** This is a public forum