Practical_Electronics-May_2019

([email protected]) #1

 512 words of code, 24 bytes of RAM
 An internal oscillator calibrated to 1%
 8-bit timer
 4 I/O pins
 Wake on pin change
 SPI interface
 I^2 C interface
 UART interface
 1-wire interface
 Very low power consumption.


This now makes the processor a very
capable device – so long as your actual
requirements on what the device does
with those capabilities are not too de-
manding. Needless to say, you are not
going to be able to drive an LCD dis-
play with a parallel interface. But you
could drive a display equipped with a
serial interface, so long as you do not
need to display lots of text. All of that
text has to be stored in memory, and we
have just 512 bytes for Flash memory
storage. A serial LCD showing the time,
or perhaps the ambient temperature, is
probably feasible. Offering both? Perhaps
not – but half the fun is experimenting
and squeezing the maximum capability
from limited resources!
The memory layout of the device is
shown in Fig.2. Along with the gen-
eral-purpose registers – our available
RAM for program variables – there
are just eight special function regis-
ters. Here lies the PIC10F’s attraction
for other reasons – it is a very simple
device, and therefore makes an ideal
basis for learning the complexities
of a microcontroller. Other systems,
even the venerable Arduino processor,
contain far more registers, which may
overwhelm a student when trying to
master the lower levels of microcon-
troller systems. The PIC10F makes an
ideal entry point.
The pin-out of the fi rst device we
will be using is shown in Fig.3. This
variant is a dual-in-line plastic DIP
package, which is easy to solder to Ver-
oboard, or plug into a breadboard. The


pin-out shows how several functions
are mapped to the I/O pins.

Possibilities
So, what can you actually do with a
processor that is so limited, and with
so little memory?
First, remember that it is a very small
device – as can be seen in Fig.1. This
means it can be retrofi tted into an ex-
isting device or be used to create a tiny
functional product.
So what kind of projects are possible?
Here are some examples that spring
to mind that we believe are possible.

Smart bike light
Fitted with an accelerometer IC, the
PIC10F could be used to sense sudden
deceleration, and fl ash the brake light
automatically. A safety feature perhaps?

Disco lights
A string of RGB LEDs that change colour
depending on motion detected by an
acceleration IC. Could be fun on the
dance floor when mounted on your
best dancing shoes!

Logic probe
An improvement on an old classic –
a probe that can indicate when high,
low or pulses are detected on a wire.
Combined with an RGB LED for a more
modern approach to indicating the state.
We could program green for low, red
for high and blue for pulse.

Temperature warning
A small device that can be placed in
the refrigerator and warn when the
temperature rises too high. With some
additional components it should be
possible to detect a low-battery con-
dition too, and provide an additional
warning. A circuit like this could run
from a coin cell battery and be realised
in a very small enclosure.

Knock-knock switch
Making use of a simple piezo buzzer to
act as a vibration sensor, create a device
that will toggle a relay when a ‘knock-
knock’ physical signal is detected on a
surface. Ideal for turning desk lights on
and off, or as a general novelty switch.

Smart switch
A relay-controlled power source that
is controlled by a push switch. The
switch is de-bounced for a period of
time before turning on. While on, a long
press of the button will fl ash an LED
as a warning, and then power the relay
off if continued to be held. If a latching
relay is used, this circuit will consume
virtually no power, making it an ideal
way of controlling battery-powered

devices. It could also have a timer for
‘auto power-off’ functionality.
In this series of articles we will ex-
plore several of these ideas, and other
if suggested by readers – just pop your
thoughts into the magazine chat forum
at: http://www.eeweb.com/forum/category/
epe-magazine
We will explore circuits from
breadboard through to surface-mount
PCB designs to show the range of
applications.
Although these devices have at a
maximum only 512 words of program
memory, each of these words is 12-bits
long and can hold a complete assembly
level instruction, including any data
associated with it. All instructions oper-
ate in a single instruction cycle (except
when the instruction causes a branch
or a jump in the program, in which
case it takes two cycles). An instruc-
tion cycle takes 1μs, so that’s a million
instructions executed every second –
fast enough for the simple functions
that we might put this device to.
The trick with using such a limit-
ed device is applying it to projects
that can accommodate it – if you fi nd
yourself having to add many external
components (or more expensive com-
ponents) to circumvent the processor’s
limitations, then you will probably be
better off choosing a more powerful
processor. We will choose our projects
carefully to be relevant to a processor
of this size.
The next challenge is what can I do
with just 512 program instructions? A
surprising amount, as it turns out. Even
more surprising is that you do not have
to revert to programming the chip in as-
sembly language – we can write in the
‘C’ high-level language in many cases.
There are some subtleties required in
setting up the project code build fi les,
but we will explain these issues and
how to avoid them next month.

Software set-up
If you wish to follow along at home and
build these circuits, you will need to
download the software development
tools from Microchip. We will be using
the MPLAB X IDE, and the MPLAB XC
Compilers. Both of these are provided
for free by Microchip. MPLAB X IDE
can be downloaded from here: http://
bit.ly/pe-may19-mc1

INDF

Data memory Code memory
00h
01h TMR0
02h PCL
03h STATUS
04h FSR
05h OSCCAL
06h GPIO
CMCON0

General-
purpose
registers

07h
08h

1Fh

000h Reset vector

User code space

Oscillator
1FFhcalibration value

1
2
3
4

8
7
6
5

NC
(positive supply) VDD
GP2/T0CKI/FOSC4
GP1/ICSPCLK

GP3MCLR/VPP
VSS (negative supply)
NC
GP0/ICSPDAT

IC1PIC10F202

Fig.2. PIC10F202 memory layout


Fig.3. PIC10F202 pinout
Free download pdf