Simple assembly language LED toggle problem ?
Bill Baird
Posts: 23
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
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
Your program looks correct, but in order to run an Assembly program it needs to be launched from Spin.
If you want to specify the Pin and Delay, you could do something like this....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
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?
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.
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?
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. )
····································
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. )
····································