August
2004, Issue 169
PSoC
101
APPLYING
PSoC SKILLS
My
PSoC Dawg demo board is really just a larger version
of the PSoC Pup that is assembled on a large solderless
breadboard. As you can see in Photo 4, my Dawg has a
couple of LEDs, a potentiometer, and a 2 × 16 LCD module.
|

(Click
here to enlarge)
|
Photo
4—At this point, I wasn’t really ready to commit
to having a Dawg PCB fabricated. I figured that
by using a solderless breadboard, I could add any
peripheral stuff I needed as I learned more about
the PSoC system. This was a good idea because I
learned that I could place the PSoC pins in places
that allowed me to keep the wire runs pretty. |
The
CY8C27XXX emulator pod is attached to the Dawg using
a 28-pin DIP foot, which is keyed to the emulator pod
using a 28-pin mask. The mask is just a guide that allows
the right number of pins to be exposed to the foot,
which in this case is a special 28-pin DIP header.
Differing
masks allow the CY8C27XXX emulator pod to support special
feet that emulate TQFP, SOIC, SSOP, and DIP PSoC packages.
If the Dawg were a PCB, I would have plugged my CY8C27443
emulator pod/mask/foot assembly into a standard 28-pin
DIP socket.
Let’s
put together a simple PSoC device. Using an input voltage,
it determines whether to blink the Dawg’s LEDs with
a couple of 16-bit counter user modules that get their
blink rates from the incoming voltage or to buzz the
LEDs from the output of a couple of PWM user modules
that also get their LED blink duty cycle from an A/D
converter digital result. In addition, the mode will
be displayed on the Dawg’s LCD. Just for fun, let’s
add another set of preset 16-bit counters/LED blinkers
that get kicked off between the transition from 16-bit
counter blink mode and PWM blink mode.
We’ll
begin our little PSoC odyssey by defining and connecting
the LED I/O pins, placing the PGA, placing the 12-bit
A/D converter, and placing the pair of PWM user modules
in Photo 5. The LCD is not a placeable user module like
the PWM and PGA user modules. Instead, the LCD user
module is selected and enabled on the port of your choice
using the LCD user module Parameters window. As you
can see in Photo 5, I’ve chosen Port_2 as the LCD I/O
port.
|

(Click
here to enlarge)
|
Photo
5—This configuration (Dawg) is loaded at power-up.
I eliminated the Global Resources and user module
Parameter windows so you can get a better view of
the graphical design windows. I named the CY8C27443
pins using a window in the PSoC Designer IDE. Using
that same window, I can select the pin drive and
enable or disable the pin’s interrupt. Clicking
on the pin also allows the global in/out connection
of the pin to be set (green vertical bus lines to
PSoC I/O pins), and you can set the pin’s drive
and interrupt status. |
Notice
that the 12-bit A/D converter user module takes two
PSoC digital function blocks as well as an analog one.
If you refer back to Photo 1, you’ll see that a 16-bit
counter requires two PSoC digital function blocks. From
the looks of Photo 5, you can squeeze two more 16-bit
counters into the PSoC mix, but you still have the PWM/counter
transition 16-bit counter to place, and you’re flat
out of digital function blocks. Even if you could add
three 16-bit counters to the Photo 5 configuration,
how would you multiplex the modules so that they all
use the common set of LED I/O pins and the output of
the PGA/analog-to-digital converter combination?
No
problem. Really. The PSoC can be dynamically reconfigured.
That means you can chop your project up into reconfigurable
modules that you can load and unload on the fly.
Photo
5 is the PWM LED driver module called Dawg. In Photo
6, the song remains the same in the PSoC analog function
block area, but I’ve moved things around in the PSoC
digital block area to accommodate a pair of 16-bit counters.
Photo
6 is the 16-bit counter/LED flasher PSoC module called
analog. The preset pair of 16-bit transition counters
is placed in Photo 7 sans the PGA and 12-bit A/D converter;
it’s called “counter.” Note that in all of the configurations,
the LED I/O assignments, the PGA 12-bit A/D converter
I/O assignments, and the LCD I/O assignments are common
across each of the configurations that employ them.
|

(Click
here to enlarge)
|
Photo
6—This is the analog configuration. Note that the
PSoC I/O pin connections to the global in/out bus
did not change. However, because I had to fit some
16-bit counter user modules into different digital
function blocks, I was forced to rely on the other
output muxes (small blue boxes) to attach the new
user module configuration to the PSoC I/O pins that
are already attached to the LEDs. |
I’ve
been wrapped up in PSoC user modules for most of this
column. Don’t forget that the PSoC has a pretty good
microcontroller embedded with all of the analog and
digital user module stuff. I used its services in this
application.
The
code for my PSoC project is shown in Listing
1. I used the Global Resources window in the PSoC
Designer IDE to set the 12-bit A/D converter to output
0x000 with 2.5 V (VCC/2) in. The PSoC 12-bit A/D converter
provides digital results in two’s complement form. So,
all A/D converter inputs above VCC/2 provide positive
numbers as A/D converter outputs. All A/D converter
inputs below VCC/2 result in negative numbers being
output by the A/D converter. By simply turning the potentiometer
attached to the PSoC PGA_IN pin to either side of 2.5
V, I can move between the Dawg configuration and the
analog configuration by way of the counter configuration.