Monthly Archives: September 2010

MSP430 delay function like the Arduino.

I did quite a bit of research on how to accurately delay the MSP430 devices like the Launchpad.

So, in the style of the arduino, I wrote one function that should help you:

It is important to know what your processor is currently running at with these.  It causes them to change based off what your clock is set to.

The MSP430′s have 4 calibrated values when they come to you.  Each chip is different and will have different values in these.  Fortunately, it is easy to set the clock with these two commands when you initialize the chip:

For 16Mhz set them as follows (Remember that the lower you can stand, the better for power).


For 8Mhz change the value to 8MHZ. You also have the option of 4MHZ and 1MHZ.

Keep in mind that 1MHZ is 1 clock cycle per every 1 microsecond.  So, you will not accurately get the delayMicroseconds to delay one clock cycle unless you direcly use the  __delay_cycles(1);  command under 1MHZ.  If you are running at 16Mhz, you would need __delay_cycles(16); for example.

// Delays by the specified Milliseconds

void delay(unsigned int ms)
while (ms–)
__delay_cycles(16000); // set for 16Mhz change it to 1000 for 1 Mhz

Delaying by a microsecond can be tricky.  The best way is to just use the __delay_cycles(x) command.  The problem with x is it has to be a constant.  So, if you want to delay by 1 microsecond put in __delay_cycles(1) for 1 MHZ and __delay_cycles(16) for 16MHZ.  Keep in mind that your microseconds will be ate up by every command you put in the program.  For instance a some simple division can eat up 100′s of clock cycles.