ADVENTURES IN PROPELLER PROGRAMMING
■ BY JON WILLIAMS
FROM SPIN TO PASM AND
For those of us that started with the BASIC Stamp and then (perhaps)
migrated to the SX via SX/B, there can be a bit of a learning curve moving to
the Propeller and its native language, Spin. Personally, I like programming in
Spin and I think my exposure to other programming languages allowed me
to pick it up and adopt it pretty quickly. Like anyone, though, it took a few
programs before the "Aha!" moment revealed itself. In working with friends,
I got the idea that sharing variables and the cog-to-cog connection is a real
challenge. So, let's start the new year with a tutorial of sorts so that we can
get a really firm grip on these processes. Once you have your own "Aha!"
moment, a whole new world of programming fun opens up for you.
Iknow what you’re thinking: “He mentioned PASM – man, I don’t want to learn Assembly!” With the speed
improvement of the Propeller over the BASIC Stamp, you
don’t have to for everything, but there will be times when
using PASM over Spin is required, and other times when it
would just be nice in terms of performance improvement.
For example: If you want to create a 1-Wire driver, it is
my opinion that it must be done in PASM. The timing
requirements of that protocol are very strict (it’s
asynchronous, so they have to be) and the 5
microseconds time per Spin instruction is just too coarse.
In the “nice to have” category, you can find floating point
math objects in the Object Exchange (ObEx) that are
written in Spin and PASM — the latter being much faster.
In applications like real-time process control that require
floating point math, speed is important and PASM is a big
help. Thankfully, as with the floating point libraries, there
are a lot of great PASM objects available for us to use.
There is no person in their right mind that would
accuse me of being the brightest bulb in the box and yet I
have been able to write PASM code for many applications.
I find PASM far friendlier than other flavors of Assembly
and am getting better all the time. You will, too — once
you dig in.
That said, I’m getting ahead of myself, and this article
is not about PASM programming but how to share
variables in a complex project, such as how to connect
Spin code to PASM code when that need arises. Again,
this seems to be a stumbling point for many Propeller
14 January 2011
newcomers and it is my hope to put a “regular guy” spin
(pun intended) on the process to help you create cooler
Propeller programs. As with many programming
languages, Spin has features that protect the casual
programmer, while giving the advanced programmer the
tools for creating code as he or she desires.
SCOPING THINGS OUT
Before we get to the Spin-to-PASM connection, it’s
probably a good idea to talk about variable scope as this
will answer the “Why do we have to do it that way?”
question before we get there.
Let’s start with a very simple program; this will print a
random number of stars (asterisk character) on a terminal
every 500 mS:
term : “fullduplexserial”
pub main | lottery, idx
term.start(RX1, TX1, %0000, 115_200)