EmbeddedRelated.com
Forums

Software delay

Started by Pravin April 2, 2004
Hi friends,
I am new to MSP ,have been working on other controllers using
assembly launguage.
I have a doubt,
I want a delay of 1 sec wherein i am toggling the LED connected to
P6.3
i write a simple routine in C using ICC



I want to know with this value of "i" ,how much delay will be
generated.

Thanks,
Pravin

Beginning Microcontrollers with the MSP430

Some clues:

(a) you don't say what speed you run at.
(b) if you use the DCO, it drifts.
(c) best to use an ISR triggered off a timer to toggle the LED.
(d) put the processor into a low power mode rather than burning cycles.
(e) calculate the timer values from data sheets and crystal frequencies
(f) the result will be a program independent of compiler implementation

Best regards,

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for MSP430, ARM, and (soon) Atmel AVR processors
That depends on your clock speed.

You'd have to look at the assembler output and divide clock cycles for the
assembler takes into the clock speed.

Ralph Hilton
That totally depends upon the clock frequency of MCLK and the code
generated by the compiler. The actual loop will typically only take 2 or
3 clock cycles (assuming i is a register). Thus 150,000 clock cycles
would be my answer. there is a much better way of doing this that does
NOT hog the processor. Simply use one of the built in timer functions,
either Timer A or timer B. If you are running Timer A on a 32.768kHz
crystal 1 second is 32768 clock cycles, thuis set one of timer A's
compare registers to interrupt every 32768 cycles. If you only have a
fast crystal, say 8MHz, it is easier to use a timer to interrupt every
few milliseconds (tghis generates a timebase that could be very useful
for lots of things,I call this TICK or a heartbeat), I typically use 1
or 5ms. Then in the ISR, or TICK task I count the number of ticks for
whatever function I'm timing.

Al