Neat, right? With nearly no fuss, we have a free-running counter that gives us milliseconds, and since it’s a
global variable, we can read it or write it from any Spin
cog. Here’s the rub: We’re using a whole cog to increment
ADVENTURES IN PROPELLER PROGRAMMING
Post comments on this article and find any associated files and/or downloads at
Tool and like some of its editor features. To get around it
only supporting one template, I preface the name of my
Propeller Tool template files with two underscore characters
— this forces them to be sorted to the top in the file window
of the IDE (see Figure 1). Using this strategy, though, means
I have to do an Open/Save-As sequence so that I don’t
overwrite my template.
The Propeller IDE has a neat new template feature
that Brett Weir has been working on. Inside your library
folder you can create a folder called templates. Inside this
folder is where you can drop your template files, as well as
an icon (PNG graphic for it).
■ FIGURE 2. Propeller IDE
If you’re using the Prop IDE, let me suggest that you
create your own library folder in your documents folder
instead of using the default location. The Propeller IDE
installs as a 32-bit app in 64-bit Windows systems, which
means the installation folders are protected. The Prop IDE
lets you select the library folder, so put this in a place
where you can easily move files (not the case with
protected x86 folders in 64-bit Windows systems).
open from template.
Okay, enough road-warrior philosophizing. Let me show
you some of the things I’ve done over time to help myself
with my programs.
Drop your template files into the library\templates
folder, and if you really want to fancy it up, you can also
add a PNG graphic with the same name as a template.
Propeller Tool will scale these for the window, so size isn’t
critical. I chose to go with 128x128 PNG files with an alpha
channel. In Figure 2, you can see that I have three
templates in the IDE; one for the Propeller Activity board
(my go-to for experimenting), and two for the EFX-TEK HC-
8+ — one of which is set up specifically for my customers in
the escape room business.
I will provide you with copies of my basic templates (go
to the article link), but I am begging you to write your own.
Why? Because I’m just a joker for Los Angeles, and my
templates may not be to your liking or be suitable for the
kinds of projects that excite you. Is it work? You’re darn
right it is, and you should do it. Besides, it’s fun!
I was having coffee one morning with John Barrowman
(my partner at EFX-TEK), telling him about my conversation
with Rick and my thoughts for this column. He made a
really great point: Why would anyone deny themselves the
pleasure of creation? Yes, you can find lots of code on the
Internet (including mine), but you’ll learn more if you create
your own code. It’s probably a patience thing and,
interestingly, the one area of my life where I am patient. To
me, coding is a lot like sculpting: You rough out the form,
then — little by little — smooth out the details until it’s just
right. The rub is that simplicity and elegance take time,
which is why I always encourage friends to spend a bit of
time each day programming.
As you know, the Propeller doesn’t have traditional
hardware peripherals like UARTs, etc.; hence, we create them
virtually by launching a cog to handle those duties. The upside is that we can customize to our liking. For example,
there is a four-port serial object; yes, if you need
simultaneous serial streams to/from four different sources,
you can have them. Remember, though, that things don’t
have to be this complicated to be useful. I’m not a big fan of
the Arduino, but I have learned to program it so that I can
help my friends. One of the things I do like about the
Arduino is the millis() function. It returns the number of
milliseconds since the last reset and is very useful for
differential timing. Sure, we have the cnt register in the
Propeller but — at 80 MHz — that rolls over in under a
minute; for standardized timing, milliseconds are more useful.
Quick review: In the Propeller, we can create a
synchronized loop using the cnt register and the waitcnt
command. If we wanted to simulate the millis() function
from the Arduino, we could create a little method like this:
pri background | t
t := cnt
waitcnt(t += MS_001)
As we spend the time (when we have it), we’re able to
whittle away the fat of a program, or make it smarter or
more efficient. There’s a great quote from Blaise Pascal that
speaks to this: I have made this letter longer than usual,
only because I have not had the time to make it shorter.
We would, of course, launch this method into its own
cog, and declare millis in the global variable space so that
any Spin cog could access it.
May 2016 59