operation, programmable access to two I/O pins, and a
bunch of other stuff that we’ll ignore for now. (See the
Parallax app note for a detailed diagram of the counter —
it’s genius.) My names for the three registers are the
control register (CTRx), the accumulator (PHSx), and the
value-to-add register (FRQx).
Basically, the counter works by adding the value in
FRQx to PHSx on those clock cycles when the
accumulate condition is true, outputting the results to the
selected pin(s) in the process. The CTRMODE field in
CTRx defines the accumulate condition and the
input/output relationship of the I/O pin(s) selected in the
APIN and BPIN fields.
In Color BASIC, read/write access to these three
registers (CTRx, PHSx, and FRQx) is available for the two
counters on one Propeller cog (counter A and counter B),
using the commands shown in Figure 7.
This next code snippet (available in the downloads as
COUNTERS.BAS) sets up counter A as a numerically
controlled oscillator that sends a tone through the audio
section of your Amigo. Give it a try as an introduction to
this powerful capability of your Mentor’s Friend!
FIGURE 6: One cog counter configured as a
numerically controlled oscillator. The PHSx register
accumulates the value in FRQx every clock cycle and
places bit 31 on APIN. CTRx CTRMODE must be set to
%00100 to enable this mode of operation.
15 OUTA [p]=1
20 FRQA = 24365
25 CTRA = %00100 SHL 26 + p
30 OUTA [p]=0
35 IF INKEY =0 THEN GOTO 35
40 FOR n = 24365 TO 48730 STEP 25
45 FRQA = n
50 NEXT n
55 PAUSE 1000
60 CTRA = 0
I tried extensively commenting this code to explain
mode of operation which follows.
If you’re intrigued by this powerful capability of your
Amigo, check out the excellent Parallax application note
downloads/AN001-P8X32ACounters-v2.0.pdf. You’ll find
a superb introduction to using the Propeller cog counters
in a variety of applications, including RF carrier synthesis,
pulse width modulation, digital-to-analog conversion,
frequency measurement, and many others.
Provides read/write access to the Control
Register in counter A or counter B.
CTRA / CTRB
CTRMODE (Bits 26.. 30) selects the counter
mode of operation. PLLDIV (bits 23.. 25) sets
the PLL division factor for PLL modes. APIN
(bits 0.. 5) and BPIN (bits 9.. 14) select the I/O
pin(s) used for that mode of operation.
We’ll just introduce the Color BASIC counter
commands and what they do, and then use those
commands to create a numerically controlled oscillator
(Both counter A and counter B have an APIN
and a BPIN.)
(NCO) that generates a tone through the audio section of
PHSA / PHSB
Provides read/write access to the
accumulator register in counter A or counter
Figure 6 shows a block diagram of a cog counter
configured as a numerically controlled oscillator. It’s a
good place to begin our explanation of the counters and
how to use them with Color BASIC.
FRQA / FRQB Provides read/write access to the value-to- add register in counter A or counter B.
Each counter contains three registers that control its
FIGURE 7: The Color BASIC 2.2L counter commands
give you access to two powerful configurable state
machines on one cog of the Propeller.
54 July/August 2018