\$\begingroup\$
\$\endgroup\$
2
I am writing a delay subroutine in assembly language for the MSP430. I want to know how to calculate the number that have to put in Register R10 in order to achieve a 20ms delay. Thanks
Delay mov #Number,R10 ;20 ms delay
L1 dec R10
jnz L1
ret
-
\$\begingroup\$ Depends on your clock speed. What did you try? \$\endgroup\$Passerby– Passerby2015年11月21日 03:26:55 +00:00Commented Nov 21, 2015 at 3:26
-
\$\begingroup\$ The clock speed is at 1Mhz. I am using the MSP430 g2553. I found a formula for the number: Number = (time/4*period) - 1, but i dont know if that is correct. \$\endgroup\$EMPV– EMPV2015年11月21日 03:28:50 +00:00Commented Nov 21, 2015 at 3:28
1 Answer 1
\$\begingroup\$
\$\endgroup\$
2
Have a look into section 3.4.4 (Instruction Cycles and Lengths) of the 2xx Family User's Guide (SLAU144):
CALL Delay 5 cycles MOV #x, R10 2 cycles DEC R10 x*1 cycles JNZ L1 x*2 cycles RET 3 cycles (Format-I instruction: MOV @SP+,PC)For 20 ms at 1 MHz, you want 20,000 cycles. Do the math.
Or just let the compiler do the work:
__delay_cycles(20000);
answered Nov 21, 2015 at 10:44
-
\$\begingroup\$ Is mixing a c style intrinsic with assembly good practice,or even valid? +1 though \$\endgroup\$Passerby– Passerby2015年11月21日 10:56:49 +00:00Commented Nov 21, 2015 at 10:56
-
1\$\begingroup\$ The assembler wouldn't know about C intrinsics. That's why I wrote "compiler". \$\endgroup\$CL.– CL.2015年11月21日 16:12:00 +00:00Commented Nov 21, 2015 at 16:12
default