cancel
Showing results for 
Search instead for 
Did you mean: 

One second delay routine

c239955_stm1
Associate II
Posted on October 06, 2003 at 05:24

One second delay routine

2 REPLIES 2
c239955_stm1
Associate II
Posted on October 03, 2003 at 06:21

Hi all,

as you maybe guess from my post, I'm a novice in ST programming.

Can someone help me in writing a routine that generates 1 second delay with a ST6230?

Thank you in advance

Claudio
vikas2
Associate II
Posted on October 06, 2003 at 05:24

You can write delay routine by making a loop in which the controller does nothing and remain in loop for the specified time.

e.g. In the following examle,you can load values in Variables(Temp1 and Temp2) and make a delay accoding to your need.

delay: ldi X, TEMP1 ;delay=[6+{TEMP1*(6*TEMP2+10)}]*13/fosc

LOOP1:ldi A, TEMP2 ; Includes the call instruction time

LOOP2:dec A

jrnz LOOP2

dec X

jrnz LOOP1

ret

The formula delay=[6+{TEMP1*(6*TEMP2+10)}]*13/Fosc is expained below:

first digit ''6'' : no of clock cycles for call(4) and ret(2) instruction for the delay routine.

Second ''6'' in formula : no of clock cycles for Dec A(4) and jrnz LOOP2(2) instrucions.This is multiplied by TEMP2 because these two instrucions are executed TEMP2 times.

Digit ''10'' : Sum of no of clock cycles for dec X(4),jrnz LOOP1(2) and ldi A,TEMP2(4) instrucion execution.

(6*TEMP2+10) is multiplied by TEMP1,because LOOP2 is executed until TEMP1 becomes Zero.

The number of clock cycles(6+{TEMP1*(6*TEMP2+10)}) is multiplied by 13/fosc (because core frequency =crystal frequency divided by 13) to calculate the time period.

If you want delay more than possilbe with this example program(using maximum values for TEMP1 and TEMP2) then you can repeat the LOOP1(same as LOOP2) by adding one more varialbe TEMP3 and fill a value in it accordingly.

You can also see the exact time taken by delay routine on RIDE virtual machine(simulator).