William Wong
|
ED Online ID #13329 |
August 21, 2006
I found the PDT a bit confusing at first. This is because of the difference between the Propeller’s architecture and other microcontrollers as well as the syntactic and semantic nature of the .spin files. Parallax also tends to use their terminology. For example, building a project is done via Run/Compile Top/Update Status. Luckily the PDT is relatively simple and easy to use.
Lets start by looking at the organization of a .spin file in more detail. It is a text file and information is section dependent. Sections include CON (constants), VAR (class variables), OBJ (objects required by this object), PUB and PRIV (public and private Spin code) and DAT (cog code). There is also the hidden documentation section to complement the inline comments.
One thing to keep in mind is that indentation counts. For example, here is a simple SPIN program that toggles an LED attached to pin 16.
Spin code is very similar to Basic. I found it easy to read once I got used to the indentation requirements.
What was a little more difficult was learning how to multitask at the Spin and cog level. Multitasking at the Spin level is done by starting up another cog running the Spin interpreter. The cog is given a reference the Spin function to execute. There is no concept of yielding with Spin or cog code. In fact, there are no interrupts. Everything is designed to be polled although it is possible for cog code to wait for a change on the IO lines.