Propeller Manual

Table Of Contents
2: Spin Language Reference – CTRA, CTRB
CTRA, CTRB
Register: Counter A and Counter B Control Registers.
((PUB PRI))
CTRA
((PUB PRI))
CTRB
Returns: Current value of Counter A or Counter B Control Register, if used as a source
variable.
Explanation
CTRA and CTRB are two of six registers (CTRA, CTRB, FRQA, FRQB, PHSA, and PHSB) that affect the
behavior of a cog’s Counter Modules. Each cog has two identical counter modules (A and B)
that can perform many repetitive tasks. The
CTRA and CTRB registers contain the
configuration settings of the Counter A and Counter B Modules, respectively.
The following discussion uses
CTRx, FRQx and PHSx to refer to both the A and B pairs of each
register.
Each of the two counter modules can control or monitor up to two I/O pins and perform
conditional 32-bit accumulation of the value in the FRQx register into the PHSx register on
every clock cycle. Each Counter Module has its own phase-locked loop (PLLx) which can be
used to synthesize frequencies from 64 MHz to 128 MHz.
With just a little configuration and in some cases a little maintenance from the cog, the
counter modules can be used for:
Frequency synthesis
Frequency measurement
Pulse counting
Pulse measurement
Multi-pin state measurement
Pulse-width modulation (PWM)
Duty-cycle measurement
Digital-to-analog conversion (DAC)
Analog-to-digital conversion (ADC)
And more.
For some of these operations the cog can set the counter’s configuration, via
CTRA or CTRB,
and it will perform its task completely independently. For others, the cog may use
WAITCNT to
time-align the counter’s reads and writes within a loop; creating the effect of a more complex
Propeller Manual v1.1 · Page 95