Shop OBEX P1 Docs P2 Docs Learn Events
Simple assembly language LED toggle problem ? — Parallax Forums

Simple assembly language LED toggle problem ?

Bill BairdBill Baird Posts: 23
edited 2006-07-20 14:12 in Propeller 1
I have stolen elementary assembly LED toggle code from places in the assembly reference section of the manual, but it does nothing at all and gives no assembly errors. Not even if I just set the outa pins high or low do I get any LED response.

Whereas the Spin toggle code of the tutorial does blink the LED - so hardware and IDE programming is OK.

I must be embedding the assembly wrong in the Spin object declaration ? or what ?


PUB Toggle

DAT
ORG 0

Cycle mov dira, Pin

:Loop mov outa, Pin
mov Time, cnt
add Time, Delay
waitcnt Time, Delay

mov outa, #0
mov Time, cnt
add Time, Delay
waitcnt Time, Delay
jmp #:Loop

Pin Long $FFFFFFFF ' 32 bits of all 1's
Delay Long 3_000_000
Time Res 1

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2006-07-19 17:03
    Bill,

    Your program looks correct, but in order to run an Assembly program it needs to be launched from Spin.



    [b]PUB[/b] Toggle
        [b]cognew[/b](@Cycle,0)
    
    [b]DAT[/b]
            [b]ORG[/b] 0
    
    Cycle   [b]mov[/b] [b]dira[/b], Pin
    
    :Loop   [b]mov[/b]             [b]outa[/b],   Pin
            [b]mov[/b]             Time,   [b]cnt[/b]
            [b]add[/b]             Time,   Delay
            [b]waitcnt[/b]         Time,   Delay
    
            [b]mov[/b]             [b]outa[/b],   #0
            [b]mov[/b]             Time,   [b]cnt[/b]
            [b]add[/b]             Time,   Delay
            [b]waitcnt[/b]         Time,   Delay
            [b]jmp[/b]             #:Loop
    
    Pin     [b]Long[/b]  $FFFFFFFF                         ' 32 bits of all 1's
    Delay   [b]Long[/b]  3_000_000
    Time    [b]Res[/b] 1
    
    
    




    If you want to specify the Pin and Delay, you could do something like this....


    [b]PUB[/b] Start
        Toggle(16,3_000_000)
        [b]repeat[/b]
    
    [b]PUB[/b] Toggle(P,D)
        Pin := 1 << P
        Delay := D
        [b]cognew[/b](@Cycle,0)
    
    [b]DAT[/b]
            [b]ORG[/b] 0
    
    Cycle   [b]mov[/b] [b]dira[/b], Pin
    
    :Loop   [b]mov[/b]             [b]outa[/b],   Pin
            [b]mov[/b]             Time,   [b]cnt[/b]
            [b]add[/b]             Time,   Delay
            [b]waitcnt[/b]         Time,   Delay
    
            [b]mov[/b]             [b]outa[/b],   #0
            [b]mov[/b]             Time,   [b]cnt[/b]
            [b]add[/b]             Time,   Delay
            [b]waitcnt[/b]         Time,   Delay
            [b]jmp[/b]             #:Loop
    
    Pin     [b]Long[/b]  $FFFFFFFF                         ' 32 bits of all 1's
    Delay   [b]Long[/b]  3_000_000
    Time    [b]Res[/b] 1
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Bill BairdBill Baird Posts: 23
    edited 2006-07-19 22:48
    Oh Yess, That's my man. Now it's cookin.

    Thanks for the quick fix - I thought it might be something simple I didn't know about the Spin set up for assembly code.

    And thanks for the suggestions on further Spin usage. At the moment I am trying to write a fast assembly core of code to run entirely on one cog for hi speed output. Then I figure I will get to learning and using Spin running on cog 0 to set up and load this pure assembly output cog and feed it data from another fast assembly input cog.

    My best understanding at this point is that I might want to avoid loading the Spin interpreter at all on the pure assembly cogs to preserve memory space and speed. But I may well be wrong about this view? The thought of a single Spin instruction translating into some 120 assembly instructions in certain cases is very scarey.

    There must be at least an off chip compiler to interpret Spin so that real time interpretation could be avoided. Or perhaps I am wrong about the magnitude of slow down from Spin interpretation?
  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-19 23:11
    The SPIN interpreter is stored in ROM on the Propellor chip. When it is needed, it is copied from ROM to the memory of a cog and started, just like any other assembly program. The SPIN interpretive code (byte code) is fetched from the hub memory a byte at a time and all operands (constants, variables) are read and written to hub memory. Accessing hub memory takes time (an average of 10 clock cycles per access) and this is part of the speed penalty of the SPIN interpreter. The flip side of this is that the SPIN interpretive code is very powerful and allows you to write very simply many things that can't be done easily in one or two instructions. Multiplication and division are simple operators in SPIN, but have to be done by subroutine in assembly.

    SPIN is more than fast enough to do most I/O. Exceptions include high speed serial (including I2C, SPI) and video. There are a few other exceptions like floating point arithmetic, A/D conversion, and digital scope sampling, but really most things work really well in SPIN. Standard I2C works fine in SPIN. The interpreter is a marvel fitting into less than 500 instructions.

    There is no off-chip interpreter. The compiler translates SPIN and assembly source into interpretive code and binary instructions respectively, eliminates redundant and unused code, and packages everything into a memory image ready for loading. Someone is working on a Propellor instruction interpreter for debugging purposes. The internals of the SPIN interpretive code are currently proprietary to Parallax so I doubt we'll see any desktop interpreter any time soon.

    With the Propellor able to generate video and VGA with minimal external parts (a few resistors), it's very easy to do debugging on the Propellor. I always include the tv_text object when I'm working on a new program and toss in debug statements so I can follow the logic. With assembly language, I've used the LEDs built-in to the VGA circuitry on the demo board for debugging.

    Even when you plan to have an assembly routine in finished code, I strongly suggest you do the initial development in SPIN, then translate your tested logic to assembly. It makes it much easier to debug.
  • Bill BairdBill Baird Posts: 23
    edited 2006-07-20 11:05
    Great. Thank you for the clarification on the operation, power, and proprietary nature of the Spin interpreter and the suggestions for debugging.

    If I understand you right you are saying that the Spin interpreter is of necessity loaded into every active cog even if it is just to load and start assembly code. After the assembly takes over however it is completely in control without Spin assistance. Is that right?
  • KenBashKenBash Posts: 68
    edited 2006-07-20 13:23
    Hi Bill (and Beau)
    I downloaded this code last night and tried to get it working in a seperate Cog with some of my other code.

    ( this is my first attempt at writing assembly for the Propeller )

    These functions work fine by themselves, but as soon as I try to run it from another program ( in a seperate Cog ) my other code stops working.

    I have a couple of Spin co-processes runing in seperate Cogs but I can't seem to get this assembly code launched.

    What is the correct way to launch a simple assembly function like this from another spin program?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    " Anything worth doing... is worth overdoing. "

    ··············································· ( R.A.H. )
    ····································
  • KenBashKenBash Posts: 68
    edited 2006-07-20 14:12
    Oops... sorry, got it.

    I was trying to initiate using cognew from my main program, which in turn called cognew in the blink program.

    Thanks guys.

    K.B.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    " Anything worth doing... is worth overdoing. "

    ··············································· ( R.A.H. )
    ····································
Sign In or Register to comment.