Shop OBEX P1 Docs P2 Docs Learn Events
pasm question — Parallax Forums

pasm question

mikeamikea Posts: 283
edited 2013-03-03 16:20 in Propeller 1
I'm trying to ramp down a led as a pasm lesson, but can't seem to get it right. I've been copying examples from the manual and slightly changing them. I have a couple questions...
is... "delay long 0" near the bottom considered an unchangeable constant or is it just the starting point and will change if added to? If the "0" is left off is it assumed as a starting point and delay is more like a variable. The main problem here is i'm trying to increment delay with a limit of 80_000_000, so the rate of toggle slows to one second on one second off. Seems pretty straightforward, but it's not working.Any advice would be appreciated

{{ AssemblyToggle.spin }}
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB Main
{Launch cog to toggle P16 endlessly}
cognew(@Toggle, 0) 'Launch new cog
DAT
{Toggle P16}
org 0                         'Begin at Cog RAM addr 0
Toggle
 mov dira, Pin            'Set Pin to output
 mov Time, cnt           'Calculate delay time
 
:loop
 waitcnt time, Delay     'Wait
 xor outa, Pin              'Toggle Pin
 max Delay, #apex      'limit delay value to 80_000_000
 add Delay, #1             'increment delay value
 jmp #:loop 'Loop endlessly

 Pin long |< 16            'Pin number
 Delay long 0              'Clock cycles to delay
 apex long 80_000_000
 Time res 1                 'System Counter Workspace

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2013-03-03 13:14
    waitcnt time, delay

    would add delay to time and in the next Loop wait for that counter-value. But adding 0 means that you already missed the counter-value and that you have to wait for ~50 seconds until the counter passes the value again.
    So, in your code you also have a minimum delay which makes the code run as expected (not missing the counter value). This minimum value also depends on the runtime of instructions after the waitcnt,

    Delay is a variable which is initialized to be 0, but you can change it anywhere in your code!
  • Mark_TMark_T Posts: 1,981
    edited 2013-03-03 16:10
    The idiom in PASM is
                    mov     time, cnt
                    add     time, delay
                    waitcnt time, delay2  ' wait for delay
                    waitcnt time, delay3  ' wait for delay2
    
    In other words the delay in the instruction sets up the next waitcnt, not this one, so you need to have special case for the first use.

    The waitcnt instruction behaves like a wait, then an add.
  • kuronekokuroneko Posts: 3,623
    edited 2013-03-03 16:20
    Also, max Delay, #apex will limit the maximum to 9 (which is the current cog register location for apex). You want max Delay, apex instead and possibly move the add before the max. Minimum value for Delay will be 22 for the current setup (4*4+6).
    DAT             org     0
    
    Toggle          mov     dira, Pin
                    mov     Time, cnt
                    add     Time, #9        ' minimum delay to not block
    
    :loop           waitcnt time, Delay
                    xor     outa, Pin
                    add     Delay, #1
                    max     Delay, apex
                    jmp     #:loop
    
    Pin             long    |< 16
    Delay           long    22
    apex            long    80_000_000
    Time            res     1
    
                    fit
    
Sign In or Register to comment.