Shop OBEX P1 Docs P2 Docs Learn Events
ASM: heartbeat (blinking led) — Parallax Forums

ASM: heartbeat (blinking led)

Robot FreakRobot Freak Posts: 168
edited 2008-04-15 11:15 in Propeller 1
Hello,

After programming a heartbeat (just a blinking led) in spin, I tried programming it in ASM.
But it isn't working smile.gif
Here is my program:
{{ heartbeat.spin }}

[b]CON[/b]
  [b]_clkmode[/b] = [b]xtal[/b]1 + [b]pll[/b]16x
  [b]_xinfreq[/b] = 5_000_000

[b]VAR[/b]
  [b]LONG[/b] stack[noparse][[/noparse]20]
  [b]BYTE[/b] id

[b]PUB[/b] start_asm
  id := [b]cognew[/b](@asm_start,0)

[b]PUB[/b] start
  id := [b]cognew[/b](beat,@stack)

[b]PUB[/b] stop
  [b]if[/b] id == -1
    [b]abort[/b]
  [b]cogstop[/b](id)
  id := -1

[b]PRI[/b] beat
  [b]repeat[/b]
    ![b]dira[/b][noparse][[/noparse]22]
    [b]waitcnt[/b](40_000_000 + [b]cnt[/b])

[b]DAT[/b]
              [b]org[/b] 0
asm_start
              [b]mov[/b] [b]dira[/b], pin_true                'Set pin 22 output
              [b]mov[/b] wait_var, [b]cnt[/b]                 'Set variable wait_var to cnt
              [b]add[/b] wait_var, delay_var           'Add delay_var to wait_var
:[b]repeat[/b]       [b]waitcnt[/b] wait_var, delay_var       'Wait 1/2 sec
              [b]mov[/b] [b]outa[/b], pin_false               'Set low
              [b]waitcnt[/b] wait_var, delay_var       'Wait 1/2 sec
              [b]mov[/b] [b]outa[/b], pin_true                'Set high
              [b]jmp[/b] :[b]repeat[/b]                      'Jump to repeat
              
pin_true      [b]long[/b] $1<<22
pin_false     [b]long[/b] $1<<22
delay_var     [b]long[/b] $28<<6
wait_var      [b]long[/b]
              [b]fit[/b] 496




It also contains the working one, in SPIN. (see PUB start)

Any idea how to fix this?
Kind regards,
Robot Freak

Post Edited (Robot Freak) : 4/14/2008 5:57:11 PM GMT

Comments

  • JavalinJavalin Posts: 892
    edited 2008-04-14 18:10
    You've got a few problems here:

    PRI beat
    dira[noparse][[/noparse]22]~~ ' make pin output
    repeat
    !outa[noparse][[/noparse]22] ' toggle HIGH and LOW states
    waitcnt(40_000_000 + cnt)

    and for the ASM - look at the ASM for beginners thread in one of the stickes - there is a post by me starting it, and Beau has an excellent post or two on setting pins...!

    James
  • Robot FreakRobot Freak Posts: 168
    edited 2008-04-14 18:26
    The "PRI beat" is working, but that has to be that my numeric-led-bar is connected in the unusual way.
    I'll try what your version does, and I'll search for the example.

    Thanks!
  • BaggersBaggers Posts: 3,019
    edited 2008-04-14 18:26
    Robot Freak,

    pin_true is 1<<22 and pin_false is also 1<<22, pin_false should be 0

    your jmp :repeat should also be jmp #:repeat

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • AleAle Posts: 2,363
    edited 2008-04-14 18:31
    And, besides what Baggers and javalin said, the delay increment should also be 40_000_000. for half a second. You can comfortably use the instruction xor two times instead of mov outa,something xor outa,something.
  • Robot FreakRobot Freak Posts: 168
    edited 2008-04-14 19:07
    Here is my working program:
    {{ heartbeat_asm.spin }}
     
    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    VAR
      BYTE id
    
    PUB start
      id := cognew(@Beat,0)
    
    PUB stop
      if id == -1
        abort
      cogstop(id)
      id := -1
      
    DAT
                org 0
    Beat    
                mov dira, Pin                       'Make Pin an output           
                mov Time, cnt                       'Move cnt value to variable Time
                add Time, Delay                     'Add Delay to variable Time
    
    :loop       waitcnt Time, Delay                 'Wait until cnt reaches Time,
                                                    '     then add Delay to variable Time                                          
                xor outa, Pin                       'Toggle the Pin state
                jmp #:loop                          'Jump to begin of loop
    
    Pin         long |< 22                          'Set bit 22 of Pin to logic true
    Delay       long 40_000_000                     'Set variable Delay to 40_000_000 (1/2 sec)
    Time        res 1                               'Reserve space for the variable Time
    
  • AleAle Posts: 2,363
    edited 2008-04-14 19:34
    Just one more piece of advice: Use a simulator. That really helps sometimes. I'd recommend mine (pPropellerSim at sourceforge), but you can also use Gear that is more complete in some areas than mine but lacking in others. OTOH there are a great deal of resources at the propeller wiki at propeller.wikispaces.com

    Edit: fixed link

    Post Edited (Ale) : 4/15/2008 8:46:53 AM GMT
  • JavalinJavalin Posts: 892
    edited 2008-04-15 09:45
    The benefit for XOR and OR,ANDN to toggle pin states allows you to change a single pin, the MOV INA,X changes ALL pins.

    Glad you got it working

    James
  • AleAle Posts: 2,363
    edited 2008-04-15 10:22
    Javalin: You can add that using those instructions you also use the same constant !
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-04-15 11:15
    But if the cog is only changing one pin and you set DIRA up properly than you can put whatever you want in the other pins and it won't matter. smile.gif
Sign In or Register to comment.