1
\$\begingroup\$

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
asked Nov 21, 2015 at 2:55
\$\endgroup\$
2
  • \$\begingroup\$ Depends on your clock speed. What did you try? \$\endgroup\$ Commented 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\$ Commented Nov 21, 2015 at 3:28

1 Answer 1

3
\$\begingroup\$

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
\$\endgroup\$
2
  • \$\begingroup\$ Is mixing a c style intrinsic with assembly good practice,or even valid? +1 though \$\endgroup\$ Commented Nov 21, 2015 at 10:56
  • 1
    \$\begingroup\$ The assembler wouldn't know about C intrinsics. That's why I wrote "compiler". \$\endgroup\$ Commented Nov 21, 2015 at 16:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.