This is only a preview of the June 2021 issue of Silicon Chip. You can view 37 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Advanced GPS Computer - Part 1":
Articles in this series:
Items relevant to "Recreating Arcade Pong":
Articles in this series:
Items relevant to "PIC Programming Helper":
Items relevant to "Programmable Hybrid Lab Supply with WiFi – Part 2":
Purchase a printed copy of this issue for $10.00. |
8-pin
14-pin
20-pin
PIC
PROGRAMMING
HELPER
It’s incredible what you can achieve with an 8-pin microcontroller. However,
programming and debugging these chips can be a challenge due to the need
to use the programming and reset pins for other purposes. This little board
makes working with these (and some larger) PICs much easier!
W
e include 8-pin PIC microcontrollers in many of our projects
because they are very handy for doing
certain jobs, and cheap to boot. Apart
from a handful of 6-pin parts, which
are only available in SMD packages,
they are some of the smallest microcontrollers around.
For example, we used a PIC12F1572
8-pin micro in our LED Christmas
Ornaments project (November 2020;
siliconchip.com.au/Article/14636).
In that case, despite only having eight
pins with two dedicated to power, it
was able to control twelve LEDs and
light them up in patterns.
We have also used parts like the
PIC12F617 in projects such as the Car
Radio Dimmer Adapter (August 2019;
siliconchip.com.au/Article/11773),
the MiniHeart heartbeat simulator
(January 2021; siliconchip.com.au/
Article/14706) and the Refined Fullwave Universal Motor Speed Controller (April 2021; siliconchip.com.au/
Article/14814).
If you only need five or six I/O pins,
then devices like these are handy and
compact, while still being computationally very capable. John Clarke
even used one to replace a hard-to-get
rotary switch with a potentiometer in
the Digital Effects Pedal from April
2021 (siliconchip.com.au/Series/361)
But consider that once you subtract
the power pins, you’re left with at most
six I/Os, and you usually need three of
64
Silicon Chip
these (MCLR, PG[E]D and PG[E]C) for
programming and debugging. Unless
your application only needs three I/
Os, you will inevitably end up sharing
some of these pins’ functions. These
shared connections can cause significant hassles.
This became apparent as we worked
on an upcoming project that pushes a
PIC12F1572 to its limits, using five I/O
pins and running the processor at its
highest operating frequency.
Some background
Microchip PIC microcontrollers
have long used a five-wire programming interface. The voltages and
protocol have varied over the years,
but these five wires have always performed broadly the same roles.
The PICkit 2 and PICkit 3 programmers both sport six-way headers;
the later PICkit 4 and Snap programmers have eight-way headers. This is
because these programmers now support Microchip parts that do not belong
to the PIC family, such as AVR and
SAM devices which came into Microchip’s stable with their 2016 purchase
of Atmel.
While the exact pin mapping of these
five wires varies between PIC families
and pin counts, the small number of
pins on the 8-pin parts means that
there are not many permutations.
By Tim Blythman
Australia’s electronics magazine
The purpose of the Helper device
we have developed is to switch the
function of some pins on your micro
between programming/debugging
and application-specific I/Os during
development. This will make your life
much easier.
While we can’t promise that this
Helper will work with all 8-pin PICs,
it should work with most. The main
exception we’re aware of is PIC10F
parts (some of which come in 8-pin
packages, but only six are connected).
Table.1 shows the five connections
used for PIC programming, their order
on the programming header and what
pins they connect to on an 8-pin PIC.
Note that the ground pin is located
in the centre of the group, reducing
the chance of damage if the header is
reversed.
One way to re-use pins 4, 6 & 7 on
an 8-pin PIC is to mount it in a socket
on the board, then when you need to
program it, unplug it and insert it into
a programming socket. After programming, it can be re-inserted into the
original socket on the board.
But this can quickly become tedious
as the chip is repeatedly moved
between the programming socket and
the test circuit. It also means you can’t
perform in-circuit debugging (ICD).
The alternative is so-called ICSP
(in-circuit serial programming),
which allows the chip to stay in place
and be programmed ‘in circuit’. But
siliconchip.com.au
Fig.1: most of the circuitry
is for switching the pin
connections for PIC chip
IC1 between the ICSP
header (CON3) and the
TGT PCB pads, which
plug into a development
board. S2 is used to
energise the relays. The
board can be split between
CON1 and CON2 to allow
some distance between the
circuits if necessary.
this might not be possible when pins
4, 6 or 7 need to be used for the project at hand, depending on how they
are used.
Pins 6 & 7 are usually fully featured;
in the case of the PIC12F1572, they can
be used as analog inputs to the ADC
(analog-to-digital converter), comparator or as PWM outputs. In most cases,
MCLR can also be used as an input,
if desired.
In our recent design using the
PIC12F1572, we used pins 6 & 7 as
analog inputs to sense the rotation
of potentiometers, so both are connected to a low-impedance analog
voltage source. This prevents successful in-circuit programming.
Also note that some programming
modes apply up to 13V to the MCLR
pin (pin 4). If this is being used as
an input, anything else connected to
it must handle this during in-circuit
programming.
A solution to this is that some PIC
parts are available with a so-called
debug header variant. This is a specialised part with extra pins to separate the programming and debug functions from the other pin functions. A
board fitted with jumpers often allows
the header to emulate different parts.
But these parts are much more
expensive than their off-the-shelf
counterparts, as might be expected for
something that sees very limited production. And they are not available to
suit all PIC parts.
An example is the AC244053,
which can emulate the PIC16F1454,
PIC16F1455 or PIC16F1459. This specialised chip is a 28-pin SOIC (SMD)
device, necessary to provide all 20 pins
of the PIC16F1459 plus the separate
debugging/programming pins.
You can purchase it from the
Digi-Key website for around $75:
www.digikey.com.au/products/en?
keywords=AC244053
Our solution
Header pin
Pin on PIC
Label
1
4
MCLR
Master clear and reset. It can also be used to
apply Vpp (above 5V) to enable programming
mode on the attached chip.
2
1
Vcc
Power, which could be provided by the
programmer or the connected circuit.
3
8
GND
Circuit ground
4
7
PGD
Programming data signal; driven by the
programmer during writes and driven by the chip
during reads.
5
6
PGC
Programming clock signal, usually driven by the
programmer.
For a slightly cheaper and more
generic solution, we’ve designed a tool
that works with most 8-pin PIC microcontrollers. We use a set of relays to
switch between the programmer and
the target PCB, ensuring only one is
connected at a time.
This removes conflicts, ensuring
that the pins are dedicated to only
one role at a time. So you can easily
switch between programming the chip
and testing its functions. Note, though,
that it might or might not allow you
to use in-circuit debugging; it depends
on whether your code will still work
with the debugging pins disconnected
from their other roles.
While debugging a semi-functional
circuit is annoying, we have done so in
the past and successfully fixed difficult
bugs in our code. You might need to
temporarily modify the code to ignore
the state of the dual-use pins; that’s
still better than not being able to use
in-circuit debugging at all!
Fig.1 shows the circuit diagram of
the Helper. In a similar vein to the
debug header, the Helper has a set of
Australia’s electronics magazine
June 2021 65
Table.1: PICkit programming header & 8-pin PIC pin mapping
siliconchip.com.au
Role
pins that slot into a DIL socket on the
target PCB, where the programmed
chip will go when development is
complete.
This header is marked TGT PCB,
and its pins run to the headers marked
CON1 and CON2. We’ll explain what
these are for shortly. Pins 1, 4, 6 and
7 of the TGT PCB header are wired to
the normally-closed contacts of 5V
DPDT miniature telecom relays RLY1
and RLY2.
The common contacts of RLY1 and
RLY2 are wired back to IC1, which is
where a real 8-pin PIC will be installed
during development. Pins 2, 3, 5 and
8 of the TGT PCB header are also
connected to the corresponding pins
of IC1.
This socket and header combination
is our ‘emulated’ chip. When RLY1 and
RLY2 are not energised, the target circuit will behave as though it has a PIC
chip directly plugged in.
The normally-open contacts of RLY1
and RLY2 are wired back to ICSP
header CON3 (along with the ground
connection, pin 8, from IC1). When the
relays are energised, IC1 is connected
to the ICSP header, allowing it to be
programmed.
Mini-USB socket CON4 and screw
terminal CON5 allow 5V to be provided, via S2, to the coils of RLY1
and RLY2 so that the switchover can
be effected by holding down pushbutton S2.
D1 is the back-EMF suppression
diode for the relay coils.
So far, we have described the critical parts of the Helper that provide
trouble-free programming. But since
we’ve gone to the trouble of designing a PCB, we thought we’d add a few
more features.
CON1 and CON2 are wired straight
through, and the PCB can be scored
between these connectors, allowing it to be broken apart and the two
parts wired together (eg, using a ribbon cable).
The need to have the two parts physically distant is handy, but we found a
degree of mechanical separation was
also very useful. The TGT PCB header
is a fair but not firm fit into a standard
IC socket, so having the flexible wire
connection allows some movement
of the main PCB without affecting the
seating of the emulated IC.
You could also use the pads of
CON1 or CON2 to wire directly to
your development system’s PCB if it
isn’t an 8-pin DIP part. For example,
enamelled copper wire could be soldered directly to the pads of a SOIC
(or smaller) IC footprint.
Both CON1 and CON2 have their
pins arranged to match the standard
numbering used on 8-pin chips for
simplicity.
If bridged, JP1 and JP2 connect the
relay power circuit (CON4 and CON5)
to the target circuit. We joined these to
allow the relay to be powered by our
These photos show the construction we used for our first project using the
Helper. Both CON4 and CON5 are unused, as we can provide power from our
modified Snap programmer.
66
Silicon Chip
Australia’s electronics magazine
siliconchip.com.au
Fig.2: many larger (14-pin and 20-pin) PICs have the
same configuration on their top 8 pins as an 8-pin PIC. By
expanding the number of lines, we can make a board that
will work with those chips too. Just make sure to check your
PIC’s pinout before connecting it up; if it is one of the recent
‘enhanced’ 14-pin or 20-pin chips, chances are it will work.
programmer, so we don’t need to supply power via CON4 or CON5. Note
that this requires JP4 (see below) to
be closed too.
JP3 is connected across S2’s contacts, so it provides a slightly more permanent way of setting the relays to the
programming position. You could also
use this to connect an external toggle
switch if you prefer something with a
non-momentary action.
JP4-JP7 can bridge the relay contacts
of the Vcc, MCLR, PGC or PGD lines,
respectively. We jumpered out Vcc in
our rig to prevent the IC from losing
power as the relay contacts change
over. Still, you might prefer to leave
it open to allow any other circuitry
to fully reset after a programming
sequence.
S1 simply connects the MCLR pin
to GND, resetting the microcontroller
under normal conditions. It shouldn’t
be pressed while S2 is active (and the
programmer is driving the MCLR line),
but it’s often handy to reset the microcontroller while testing.
We’ve also provided a position
(marked C1) for a bypass capacitor for
IC1. Since the target circuit will usually have provision for this, it is not
normally necessary. We didn’t populate it in our prototype.
siliconchip.com.au
Depending on the load incurred by
your circuit, this capacitor could be
used to maintain power to IC1 while
the relay contacts change over. The
capacitance needed for this to work
depends heavily on the circuit current
draw and switching time.
The specified relays are rated to
switch in about 4ms, so for example,
if your circuit (including the microcontroller) typically draws 20mA,
you would need 47μF to keep the
supply voltage from dropping below
4V during that 4ms period, or 22μF to
prevent it from falling below 3V. You
can scale the capacitor value proportionally for heavier or lighter loads.
Handling larger chips
Despite having more I/Os, larger
chips such as those with 14 or 20 pins
can still suffer from the same problems
as 8-pin chips. We tend to use all the
pins for something, regardless of how
many there are, which means that we
often have to be careful what we connect to the programming pins.
The good news is that many 14-pin
and 20-pin PICs use the same pinout
as the 8-pin types, just with more pins
added below. So all we have to do to
make the Helper usable with these
devices is to expand the PCB slightly,
Australia’s electronics magazine
adding extra pins on both the socket
for IC1 and the target chip header, as
shown in Fig.2.
CON1 and CON2 change to DIL
headers to accommodate the extra
pins, allowing a ribbon cable with
standard IDC inline sockets to join the
two boards if split apart.
Note that 18-pin parts like the
PIC16F88 that we’ve used for many
years (but no longer recommend for
new designs) has a different pinout
from the newer ‘enhanced’ range of
PICs, so it and similar chips will not
work with this project.
Most chips with more than 20 pins
use a different pinout too, and many
are also wider, so we didn’t think the
compromises necessary to make this
board support them were worthwhile.
Construction
The 8-pin PIC Programming Helper
is built on a double-sided PCB coded
24106211 which measures 37 x 72mm,
with a narrowed section at one end.
Refer to the PCB overlay diagram,
Fig.3, during construction.
The 14/20-pin version (which also
supports 8-pin PICs) uses a PCB coded
24106212 which is 37 x 105.5mm
(Fig.4). The assembly procedure for
the two boards is essentially the same.
June 2021 67
Fig.3: construction of this
8-pin version of the Helper is
straightforward, but we recommend
fitting a socket for IC1 so that you can
change it out for different parts in the
future. Also note that the pins fitted
to the TGT pads should be installed
underneath for the correct orientation
when plugged in.
Fig.4: building this version that suits
8, 14 & 20-pin PICs is almost the same
as the 8-pin only version. It just uses
larger sockets for IC1 and the TGT
connections, and larger headers for
CON1 and CON2 (if fitted).
68
Silicon Chip
If you intend to separate the PCB
between CON1 and CON2, do this now
so that no components are damaged.
Carefully score both sides of the
PCB to break the copper connections.
This will reduce the chance of tearing
them off the PCB.
Then, while firmly holding the
larger half of the PCB in a vice or pliers, flex the smaller (CON1) half of the
PCB with pliers along the line.
Once the PCB separates, you can
tidy up the rough edges with a file.
Take care to do this in a ventilated area
(such as outside) to minimise inhalation of the resulting glass fibre dust.
The first part to fit is the mini-USB
socket (CON4), as it’s the only surfacemounted part. Some flux paste is
handy, but since only the two outer
power pins need to be connected, you
could get away without it.
Apply flux to all the pads and slot
the connector into the holes in the
PCB. Solder the smaller pads to the
PCB. We’ve extended the two mandatory (power) pads to make this easier. If
you created any solder bridges, remove
them using solder wicking braid and
a bit more flux paste.
Then solder the four larger pads to
the PCB to mechanically secure the
part. Some time and heat may help
here due to the larger metal mass.
Clean up any excess flux at this point.
Fit diode D1 next, noting the location of the cathode band. Then install
the relays. They will have a stripe on
their body to indicate the pin 1 end,
or perhaps have a pin 1 dot like an IC.
This end goes nearest the diode, as
shown in Figs.3 & 4. Solder two leads
to secure the relays roughly in place
and adjust them to be flat against the
PCB one lead at a time. Finally, solder
the remaining pins.
We recommend using a socket for
IC1 so that the PIC chip can be changed
when necessary. Our photos show the
socket fitted with a PIC12F1572 for our
current project in progress. Use the
technique described above to ensure
that the socket is flat.
The seven jumpers (JP1-JP7) are
simply two-pin headers. These can
be easier to handle if fitted with the
jumper shunt first, as it provides plastic surfaces that won’t transfer heat as
quickly. Solder these in the positions
marked.
CON5 is intended to take a two-way
screw terminal, but you could solder
wires directly to the pads instead.
Australia’s electronics magazine
CON3 should ideally be a rightangled header to suit your programmer; our photos show the Helper connected to a low-cost Snap programmer,
but the PICkit series is also suitable.
You can temporarily fit the header to
your programmer to ensure it is correctly aligned while soldering.
Next, fit buttons S1 and S2, pressing
down firmly to snap them into place
before soldering.
For the TGT PCB pad, we simply
soldered header pins to the underside
of the PCB. We aligned them by slotting them into an 8-pin DIL IC socket
during soldering.
If you are using machined-pin IC
sockets, you should solder machined
pins to the Helper, or else they will not
plug in properly. Test fit them before
soldering to ensure that they will be
held securely in the socket.
The advantage of using standard
square header pins is that your prototype board (that the TGT PCB will
plug into) could be fitted with socket
strips during the testing phase, making
plugging and unplugging this board
very easy. They will also fit standard
dual-wipe sockets, although they are
a tight fit.
Regardless, as you can see from our
photos, these pins are fitted to the
underside of the PCB to maintain the
correct pinout.
If you have broken the PCB between
CON1 and CON2, use a ribbon cable to
bridge the gap. For the 8-pin version,
simply wire pin 1 to pin 1 through to
pin 8 to pin 8. You could also fit header
pins to both ends and use jumper wires
to join them.
For the 14-pin/20-pin version,
you’re better off fitting 2x10-pin headers to the boards at both ends, then
using a length of 20-way ribbon cable
fitted with IDC line sockets at either
end. Make sure when you plug it in
that the pin 1 stripe is at the pin 1 end
of both headers.
Testing
Apply 5V power via CON4 or CON5
and press S2; you should hear the relays
clicking. If not, then the relays or diode
D1 might be reversed. You should get a
similar result by shorting JP3.
Another simple test is to use any circuit that has a socketed 8-pin PIC (or
14-pin or 20-pin if you built the larger
version). Remove the PIC from the
socket and place it in IC1’s socket, then
fit the TGT PCB pins into the vacated
siliconchip.com.au
Usage
See the separate panel at right for
information about how we modified
our Snap programmer to provide 3.3V
or 5V power to the target circuit. With
this modification, we’re able to use the
much cheaper Snap in a wider variety of roles.
Since this modification provides
adequate USB power when set to 5V,
it can easily power the relays, and we
don’t need to supply any other power
to the Helper; JP1 and JP2 just need to
be shorted.
Other programmers (such as the
PICkit 2, PICkit 3 or PICkit 4) can be
used with this arrangement, although
these programmers might only be able
to source a limited amount of current.
Our experience is that they can supply
a fair bit beyond what a PIC needs, but
if it is not sufficient, power the relays
on the Helper via CON4 after removing shunts from JP1 and JP2.
In our setup, we’ve also fitted JP4 to
provide 5V to the programming target.
Our project is intended to be powered
externally, but this means we don’t
have to make a separate power connection to our breadboard prototype.
Plug your development PIC into the
onboard socket, then connect the TGT
PCB header to your custom PCB’s IC
socket to complete the ‘emulation’.
At this stage, the breadboard project is in normal operating mode and
can be powered up. To reprogram
IC1, press and hold S2 (or toggle a
switch attached to JP3), then start
the programming process. Once it is
complete, release S2 (or re-toggle the
switch across JP3).
If necessary, press S1 momentarily
to reset your target PIC, and it will be
back in the normal operating mode.
Summary
While we had a specific use case
in mind when designing this project,
it is generally useful while working
with most 8, 14 or 20-pin PIC microcontrollers.
The various jumpers provide the
means to set up different combinations
of connections, including powering it
from various sources.
We hope it will become a handy tool
in your development and prototyping
toolkit, as it has for us.
SC
siliconchip.com.au
Modifying the Snap programmer to provide power
The Snap programmer is great value, packing many of the same features as
the PICkit 4 for around a third of the price. But two features it lacks are the
ability to provide power to a target chip, and providing the higher Vpp voltage
needed to use high-voltage programming mode.
Luckily, the second aspect is becoming less important. Practically all newer
PICs support low-voltage programming for most cases. Where the MCLR pin is
not needed as an input, it’s likely that high-voltage programming is not required,
except for a few older PICs.
If we can use the Snap to provide power to its ICSP header, then it can come
very close to supplanting the PICkit 4.
In a stroke of luck (or was it by design?), there are a pair of test pads on the
Snap which provide both 5V and 3.3V power. These are located adjacent to
U5, a 3.3V MCP1727 linear regulator capable of delivering up to 1.5A.
Our update is to solder a 3-pin socket header to these pins. They are spaced
around 6mm apart, so this can be done reasonably elegantly with a 0.1in
(2.54mm) pitch header simply using the outside pins. The photo below should
make this fairly clear.
Start with a 3-way female socket and trim the middle pin close to the plastic shroud. Solder one pin to
the pad marked 5V0 and the second pin to the pad
marked 3V3.
To connect power to the ICSP header, we used
half a jumper wire soldered to pin 2 of the ICSP
header.
You can plug this into the left-hand socket
for 5V, the right-hand socket for 3.3V (which is
necessary for most PIC32 parts) or the centre
socket to provide no power. Just make sure
that the shortened middle pin isn’t contacting anything on the board.
With this simple addition, we are now
using the Snap for practically all our development work. Note that it doesn’t have the
current limiting that a PICkit 4 would provide.
►
socket. If all the pins are connected
correctly, then the circuit should work
as designed.
The added header has been tilted to prevent it from being too bulky, and to
allow the flying lead to enter at a comfortable angle.
Parts List - PIC Programming Helper
1 double-sided PCB coded 24106211 measuring 37 x 72mm, for 8-pin PICs
only, OR
1 double-sided PCB coded 24106212 measuring 37 x 105.5mm, for 8, 14 or
20-pin PICs
2 compact 5V DIL telecom relays (10-pin DIP, eg, TQ2-5V or EA2-5NU)
[Silicon Chip Online Shop Cat SC4159 or SC4158]
7 2-way male pin headers and jumper shunts (JP1-JP7)
2 4-way male pin headers OR
2 10-way male pin headers (to connect to TGT PCB; see text)
1 5-way male right-angle pin header (CON3, ICSP)
1 8-pin, 14-pin or 20-pin DIL socket (for IC1)
1 2-way mini screw terminal block (CON4)
1 mini Type-B USB socket (CON5)
1 1N4004 1A diode (D1)
2 tactile switches (S1, S2)
Optional parts to split 8-pin version
1 10cm length of 8-way ribbon cable
Optional parts to split 8/14/20-pin version
1 10cm length of 20-way ribbon cable
2 20-pin IDC line sockets
2 10x2 pin headers
Australia’s electronics magazine
June 2021 69
|