Shop OBEX P1 Docs P2 Docs Learn Events
Basic LED asm program — Parallax Forums

Basic LED asm program

RsadeikaRsadeika Posts: 3,837
edited 2011-03-03 14:59 in Propeller 1
I started to play around with asm, again. The program below, which is run on the demo board, works, but it seems like led 23 is also turning on with led 24. It does not happen with led 17, and 16. I cannot figure out why led 23 is turning on.

The second question I have is, how could I call led1, and led2 from PUB Main? I guess what I am really after is, coding some "sub-routines" in asm, and calling them from the PUB Main part of the program.

Thanks

Ray
'TestAsm2.spin

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000


PUB Main


  cognew(@Toggle,0)


DAT
          ORG  0
Toggle

loop

call  #led1
waitcnt  Time,Delay1
call  #led2
'waitcnt  Time,Delay2
        jmp loop

''''''''
led1
          mov  dira,Pin1 
          mov  Time,cnt
          add  Time,#9

          waitcnt  Time,Delay1
          xor  outa,Pin1
          
led1_ret  ret
''''''
led2
          mov  dira,Pin2
          ''mov  Time,cnt
          ''add  Time,#9
          
          waitcnt  Time,Delay2
          xor  outa,Pin2

led2_ret  ret
'''''''''

Pin1    long  |< 17
'Pin2    long  |< 24
Pin2    long  %00000000_10000000_00000000_00000000
Delay1  long  6_000_000
Delay2  long  12_000_000
Time         res  1

Comments

  • BeanBean Posts: 8,129
    edited 2011-03-03 13:58
    It is because of the VGA resistors.
    The pins used for the LEDs are also used for the VGA output.

    Any LED pins that are inputs will light if the next pin is connected to it via a VGA resistor.

    Bean
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-03-03 14:32
    Thanks Bean. Now, anybody have any suggestions for the second question? Maybe I am not looking at this correctly, is there an advantage to calling "sub-routines", in assembly format, from PUB Main? Asm code is supposed to run faster than Spin code, correct?
  • Mike GreenMike Green Posts: 23,101
    edited 2011-03-03 14:46
    You can't really "call" subroutines from Spin. The only thing you can do is to start up the PASM routine in its own cog and the Spin main program can interact with the routine via shared hub memory locations (or shared I/O pins ... rarely used). There's quite a bit of overhead in getting a PASM routine started (about 100us), so a PASM routine is often set up as a kind of interpreter where, once it's started, it fetches some kind of command from shared hub memory, does what's called for, then waits for another command. In your case, there'd probably be a pin number, an LED on time, an LED off time, and a count of the number of blinks to be done. This would all fit in one long so the PASM routine could fetch all the data at one time. It would make an entry in a table in cog memory for that I/O pin, then store a zero in the command long location to tell the other cogs that another command can be sent. The rest of the time, the cog can go through its table, figure out what has to be done at any given time and do it (turn an LED on or off). If you want to get fancy, the cog routine can also figure out how long it can wait until it has to do something and do a WAITCNT until then.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-03-03 14:59
    Attached is a template I use for calling PASM simple subroutines -- it works as Mike describes above.
Sign In or Register to comment.