i want a program to generate delay in msecs by using timer for msp430g2211
where in i can call that function like delay(ms).
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.
i want a program to generate delay in msecs by using timer for msp430g2211
where in i can call that function like delay(ms).
Time is relative. The MSP does not knwo about absolute timing.
SInce the MSP has no realtime clock like PCs do (doesn't mean you cannot provide one externally), 'time' on the MSP passes relative to a provided clock.
e.g. a delay by a loop is based on the main clock speed (MCLK). 1000 cycles when the processor runs on 1MHz are 1ms. But only 125µs if the processor runs on 8MHz.
The MSP cannot tell the difference. For this reason, a delay(ms) function is meaningless.
There is a __delay_cycles(x) function that exactly consumes the given number of CPU clock cycles (power-ineffective busy-waiting loop), but the 'real world' duraiton of this delay still depends on the current MCLK speed.
Same is true for the timers. They too count only ticks from a clock.
A clock might be the internal DCO (which is quite unprecise) or an external crystal or reference clock. However, only you knwo what speed this clock has,. The MSP has no way to determine this.
So if you know the clock speed, you can set up a timer to count these clock ticks and provide an interrupt after a given number of ticks. If the clock frequency is what you think it is, then the interrupt will be generated after the time you want. If you make a msitake, the timing is different.
In short: you'll have to write your own delay(ms) function, based on the exact hardware (especially the clock speed) you have.
**Attention** This is a public forum