Shop OBEX P1 Docs P2 Docs Learn Events
SX/B and SXList sasmdel MACRO — Parallax Forums

SX/B and SXList sasmdel MACRO

PLJackPLJack Posts: 398
edited 2005-04-25 17:20 in General Discussion
I'm trying to use the SXList delay macro.
I don't seem to understand the syntax.

I keep getting the delayhelp "ERROR 'USAGE: delay value, [noparse][[/noparse]usec,msec,sec,cycles]'"
message or a "Files\test.SRC(251) Line 263, Warning 58, Pass 1: Division by zero"
error.

Could someone give me an example of a 1000 usec and 100 msec delay.

So, what am I doing wrong.


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
include         "sasmdel.src"

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

LED        VAR    RB.0            ' LED pin


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

OnDelay        CON    200            ' time LED is on
OffDelay    CON    200            ' time LED is off
CpuMhz          CON     4_000_000

' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  HIGH LED                    ' turn LED on
  \delay 100, msec
'  PAUSE OnDelay                ' delay
  LOW LED                    ' turn LED off
'  PAUSE OffDelay                ' delay
  \delay 100, msec
  GOTO Start                    ' repeat forever

Comments

  • KenMKenM Posts: 657
    edited 2005-04-16 15:26
    Does your delay have to be a macro?

    If not

    http://www.sxlist.com/cgi-bin/delay.exe

    You enter clock speed, requested delay and it spits out the code.
    ; Delay = 0.1 seconds; Clock frequency = 4 MHz; Actual delay = 0.1 seconds = 400000 cycles; Error = 0 %d1	DS	1d2	DS	1pt_one_sec:			;399992 cycles	mov	w, #$56	mov	d1, w	mov	w, #$E0	mov	d2, wpt_one_sec_0:	decsz	d1	jmp	$+2	decsz	d2	jmp	pt_one_sec_0			;2 cycles	nop	nop			;6 cycles (including call)	ret; Generated by [url=http://www.sxlist.com/cgi-bin/delay.exe][u][color=#800080]www.piclist.com/cgi-bin/delay.exe[/color][/u][/url] (January 1, 2002 version)
    ; Sat Apr 16 15:27:40 2005 GMT
    ; See also various delay routines at [url=http://www.sxlist.com/techref/ubicom/lib/flow/delays_sx.htm][u][color=#0000ff]http://www.sxlist.com/techref/ubicom/lib/flow/delays_sx.htm[/color][/u][/url] 
    

    and

    ; Delay = 0.001 seconds; Clock frequency = 4 MHz; Actual delay = 0.001 seconds = 4000 cycles; Error = 0 %d1	DS	1d2	DS	1pt_001_sec:			;3992 cycles	mov	w, #$3B	mov	d1, w	mov	w, #$03	mov	d2, wpt_001_sec_0:	decsz	d1	jmp	$+2	decsz	d2	jmp	pt_001_sec_0			;2 cycles	nop	nop			;6 cycles (including call)	ret; Generated by [url=http://www.sxlist.com/cgi-bin/delay.exe][u][color=#800080]www.piclist.com/cgi-bin/delay.exe[/color][/u][/url] (January 1, 2002 version)
    ; Sat Apr 16 15:29:30 2005 GMT
    
    ; See also various delay routines at [url=http://www.sxlist.com/techref/ubicom/lib/flow/delays_sx.htm][u][color=#0000ff]http://www.sxlist.com/techref/ubicom/lib/flow/delays_sx.htm[/color][/u][/url] 
    
    
    

    ·
  • PLJackPLJack Posts: 398
    edited 2005-04-17 14:32
    Delay.exe is a gem. Thanks ken.

    And for all of you just learning ASM, as I am, make sure you
    "call" the delay and not "jmp". [noparse]:)[/noparse]
    That will save you about an hour of watching the debug window.

    Jack
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-17 14:36
    SX/B has PAUSE and PAUSEUS fucntions built right in. Are these not helpful?....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • PLJackPLJack Posts: 398
    edited 2005-04-18 11:53
    Jon Williams said...
    SX/B has PAUSE and PAUSEUS fucntions built right in. Are these not helpful?....

    I knew that Pause would not have the resolution for microseconds.
    Forgot that I was dealing with Parallax, of course there is a microsecond
    version of pause for SX/B. What was I thinking. [noparse]:)[/noparse]

    Thanks Jon.

    Although I am having a love/hate good time learning ASM.
  • James NewtonJames Newton Posts: 329
    edited 2005-04-25 17:20
    Sorry to take so long to get to this... I was on a business trip.

    The CPUMHz that you set is interesting... How will you run your SX at 4,000,000 MHz? I could understand 4,000,000 Hz, but I usually set CPUMHz to just 4. Also, 4_000_000 is not a valid number as far as I know... It might work for the FREQ directive, but as an actual number SASM wants 4000000 for hertz and just 4 for MHz.

    That macro is also designed to work as a part of a template called sasmtemp.src. It sets up a few things that the delay macro needs to work. For delays of more than a few cycles, it expects an ISR that will increment a set of registers and clear a flag when they overflow. This is all setup in the sasmtemp.src file, but you can't use that in SX/B.

    I would probably be possible to come up with a version of the macro that could work in SX/B, but as others have mentioned, PAUSE and PAUSEUS are probably your best bet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ---
    James Newton, Host of SXList.com
    james@sxlist.com 1-619-652-0593 fax:1-208-279-8767
    SX FAQ / Code / Tutorials / Documentation:
    http://www.sxlist.com Pick faster!



Sign In or Register to comment.