I'm using a msp430g2553
and setting the clock to 1Mhz:
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
I've timed a 5 million cycles and it unexpectedly takes around 6 seconds (I was expecting 5). The loop I've used is:
int i;
for(i=0;i<5000;i++)
__delay_cycles(1000);
I've read about using interrupts (probably based on Timer_A, etc) but I'd like to avoid that for now.
So my question is: how can I implement a constant argument sleep
based on __delay_cycles?
Later edit
Assembly for:
void delay1000() {
__delay_cycles(1000);
}
is:
delay1000:
0c3b4: 04 12 PUSH R4
0c3b6: 04 41 MOV SP, R4
0c3b8: 24 53 INCD R4
0c3ba: 3f 40 4c 01 MOV #0x014c, R15 // 332 decimal (1000/3 -> DEC, TST and JNZ)
0c3be: 1f 83 DEC R15
0c3c0: 0f 93 TST R15
0c3c2: fd 23 JNZ delay1000+0xa
0c3c4: 03 43 NOP
0c3c6: 03 43 NOP
0c3c8: 34 41 POP R4
0c3ca: 30 41 RET