Shop OBEX P1 Docs P2 Docs Learn Events
Pause-loop calculator — Parallax Forums

Pause-loop calculator

Joel FriendJoel Friend Posts: 4
edited 2009-11-01 17:55 in General Discussion
Nearly all code that interacts with real-world entities has a loop that does nothing but kills time (switch de-bouncing, blinking LEDs, etc.).

Does anyone know if there is a simple calculator that figures out what values to use for the timer variable in these loops (using assembly language)? Something where you enter your clock speed and desired pause in seconds, and it would give you the values to use plus any remaining cycles to kill.

Example: pause for 1/4000 second at a clock of 4MHz

PAUSE
mov timer, #250
:LOOP
djnz timer, :LOOP
nop
nop
;pause completed, code here

I want to give this calculator the speed of 4MHz and .00025 seconds, and it should tell me variable #1 = 250, 2 leftover cycles.

Comments

  • Sens-a-DatSens-a-Dat Posts: 44
    edited 2009-10-31 20:24
    Joel,

    I use this link to determine the variables in obtaining any desired delay loop at any clock speed: www.sxlist.com/cgi-bin/delay.exe

    Gary
  • pjvpjv Posts: 1,903
    edited 2009-11-01 17:55
    Joel;

    Take a peek at the 2004/5 contest entry I submitted titled "Preemptive Real-Time Multi Tasking Operating System (RTOS)".

    It takes care of all the scheduling and timing details of running multiple tasks on an SX. The description and the code should be all you need to time things, all without any concern about counting loops or cycles.

    Cheers,

    Peter (pjv)
Sign In or Register to comment.