Shop OBEX P1 Docs P2 Docs Learn Events
Loops and Delays — Parallax Forums

Loops and Delays

jbumataijbumatai Posts: 26
edited 2007-09-26 04:10 in General Discussion
I am looking for good samples of Loops and Delays for SX Assembly. I have read the pdfs and looked the code. I have a few but I would like to see some explicit examples of the right way to do a Loop and Delay as far as a starting point. Can I get a super simple example?

TIA
JBuma

Comments

  • BeanBean Posts: 8,129
    edited 2007-09-25 18:52
    One way is to use PAUSE in SX/B, then look at the generated code with RUN->View List.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I know what I know, don't confuse me with the facts...
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • David BDavid B Posts: 592
    edited 2007-09-25 19:20
    I can show you some samples of loops and delays, but I can't say they're good examples, or the right way to do it. But these work.

    A good test is to run this in SxSim, put breakpoints in the NOPs, stop at the first, zero the microsecond time counter, run the enclosed delay routine to the second breakpoint, then see how many microseconds have passed.

    These make no attempt to be really accurate but they're pretty good for general purpose delays.

    If interrupts are enabled then they'll steal cycles from these, reducing their accuracy even more, but if the ISR is short I've had decent results even in that case.

    David

    ;

    device SX28, OSCHS, TURBO, STACKX, OPTIONX
    IRC_CAL IRC_FAST
    freq 20_000_000
    reset start_point

    org $F0
    bank_assorted = $

    t1 ds 1
    t2 ds 1
    t3 ds 1
    t4 ds 1

    ;
    ; main program
    ;

    start_point


    :here
    nop
    call @delay1ms
    nop
    jmp @:here

    ;
    ; Jump table
    ;
    org $600

    delay1ms jmp @_delay1ms
    delay10ms jmp @_delay10ms
    delay100ms jmp @_delay100ms
    delay1s jmp @_delay1s

    ;**************************************************************************
    ; delay functions

    _delay1s
    bank bank_assorted
    mov t4, #100
    :l1 call @delay10ms
    djnz t4, @:l1
    retp

    _delay100ms
    bank bank_assorted
    mov t4, #100
    :l1 call @delay1ms
    djnz t4, @:l1
    retp

    _delay10ms
    bank bank_assorted
    mov t3, #10
    :l1 call @delay1ms
    djnz t3, @:l1
    retp

    _delay1ms ; delay 19304 cycles with "15" loop =~ 1 ms @ 20 mHz
    bank bank_assorted
    mov t2, #15
    :l2 mov t1, #0
    :l1 djnz t1, @:l1
    djnz t2, @:l2
    retp


    ;---the end
  • jbumataijbumatai Posts: 26
    edited 2007-09-25 22:27
    Bean (Hitt Consulting) said...
    One way is to use PAUSE in SX/B, then look at the generated code with RUN->View List.

    Bean.

    Hello Bean, I never used SX/B so I do not know to run the code. Wierd, I know but I have only done the Assembly examples so far.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-09-25 22:48
    There are many ways to create delays in assembly.
    Take a look at this page:
    http://www.sxlist.com/techref/ubicom/lib/flow/delays_sx.htm
    Or use the delay code generator
    http://www.sxlist.com/techref/piclist/codegen/delay.htm

    regards peter
  • jbumataijbumatai Posts: 26
    edited 2007-09-26 00:06
    David B said...
    I can show you some samples of loops and delays, but I can't say they're good examples, or the right way to do it. But these work.

    A good test is to run this in SxSim, put breakpoints in the NOPs, stop at the first, zero the microsecond time counter, run the enclosed delay routine to the second breakpoint, then see how many microseconds have passed.
    ;

    start_point


    :here
    nop
    call @delay1ms
    nop
    jmp @:here

    I am checking it. My only question is about the NOP: is that for testing only as you mention the breakpoints?

    The code looks well thought out to me.

    Thanks David.

    Thanks Peter, I will check them out asap.

    Post Edited (jbumatai) : 9/26/2007 12:55:01 AM GMT

  • David BDavid B Posts: 592
    edited 2007-09-26 04:10
    The only reason for the NOPs in the main loop was to make a convenient place to checkmark the breakpoints in SxSim.
Sign In or Register to comment.