You are on page 1of 100

The fully autonomous XENO FX sUAS easily and capably navigates aerial mapping missions

using a state-of-the-art flight control system and flexible interchangeable payload


modules. Our proprietary Mission Control software precisely controls and records flight
profiles and preprocesses your imagery for rapid data processing and evaluation.

• Durable, Robust, Elapor ® Foam Airframe • Fast & Easy Data Extraction
• Onboard Image Preprocessing • Modular Payload System Allows
for Future Sensor Integration
• Up to 60 Minute Flight Times
• Available with Parrot ® Sequoia or
• Up to 675 Acres per Flight (2.73 km2) @ 400’ AGL MAPIR ® Survey3 & Kernel ® Sensors
• SAFE LAUNCH - Propeller Starts Spinning After
Parrot® is a trademark or registered trademark of Parrot SA.
Hand Launch MAPIR® is a brand and dba for Peau Productions, Inc.

Agriculture Construction Energy Engineering Mining & Public


& Excavation & Gas & Surveying Aggregates Safety

HITEC COMMERCIAL SOLUTIONS, LLC


9320 Hazard Way, Suite D, San Diego, CA 92123
858.737.9220 | www.hitecnology.com

Full Page Ad.indd 2 6/12/2018 6:32:02 PM


DO YOU WANT THE BEST
ELECTRONICS DESIGN SOFTWARE?

FEATURES
• Schematic Capture
• PCB Layout
• Gridless Autorouting
• 3D Visualization
• M-CAD Integration
• SPICE Simulation
• MCU Co-simulation
• Built in IDE
• Visual Programming

Toll Free: +1 866 499 8184


Direct: 905 898 0665
Email: don.jackson@labcenter.com

Full Page.indd 3 4/9/2018 3:19:35 PM


TOC - Jul-Aug 18_TOC NV Mar 15.qxd 6/12/2018 3:50 PM Page 4

July-August 2018
Columns
08 TechKnowledgey 2018 85 Open Communication
Events, Advances, and News The Latest in Networking and
Read about these cool topics: Wireless Technologies
• Say No More Killer Wi-Fi Now Available
• Messin’ with Brain Cells Do you really need even better wireless service, and what
• Low-End 2-in-1 is its future? This article is an update on Wi-Fi, a closer
• A Beast of a Box look at the latest version, a summary of the problems, and
• Adaptive USB a look at what’s in store for you.
• Garmin for Golf
• A Blast of Sound
• Yodel-Ay-Eee-Ooh! Page 85
• Twitter Twaddle

12 Q&A
Reader Questions Answered Here
Topics discussed this time:
• High Voltage, Low Cost
• N, P, or What?

16 The Ham’s Wireless


Workbench
Practical Technology from the Ham World
Filter Basics
A casual observer might think that wireless systems
consist primarily of filters connected by the occasional bit
of circuit. Block diagrams of transceivers often include as
many filters as any other function. This is true at the
system level, just as it is at the circuit level — and many
circuits behave in a filter-like way, whether intended to be
a filter or not! That makes understanding filter basics
important for wireless success.

78 The Design Cycle 92 Near Space


Advanced Techniques for Design Engineers Approaching the Final Frontier
Go PICBASIC PRO with C Raspberry Pi Zero Flight Computer — Part 2
If you think you can’t code in C because your first The RaspPi Zero has turned into a really different
language is BASIC, you are dead wrong. In reality, experience for me (I’m accustomed to using the PICAXE
PICBASIC PRO and C are very much alike from a and BASIC Stamp). After a month, I’ve written complete
programmer’s view. In this edition of Design Cycle, I’ll flight code and even designed a camera system for the Pi.
show you how easy it is to port the LCD portion of the So, this month, I’ll fill you in on how I got the Raspberry
Explorer 8 Development Board example code for the Pi flight computer to where I can start planning to build an
PIC16F1719 from C to PICBASIC PRO. We’ll also take a airframe. Next stop, near space!
look at how the MPLAB Code Configurator can help you
Nuts & Volts (ISSN 1528-9885/CDN Pub Agree #40702530) is published bi-monthly for $26.95 per year
code PICBASIC PRO programs. by T & L Publications, Inc., 430 Princeland Court, Corona, CA 92879. PERIODICALS POSTAGE PAID AT
CORONA, CA AND AT ADDITIONAL MAILING OFFICES. POSTMASTER: Send address changes to
Nuts & Volts, P.O. Box 15277, North Hollywood, CA 91615 or Station A, P.O. Box 54, Windsor
ON N9A 6J5; cpcreturns@nutsvolts.com.

4 July/August 2018
TOC - Jul-Aug 18_TOC NV Mar 15.qxd 6/12/2018 3:50 PM Page 5

Subscription Information
Nuts & Volts — PO Box 15277

06 DEVELOPING
Departments 90 TECH FORUM
North Hollywood, CA 91615-9218
Call 877-525-2539 or go to www.nutsvolts.com
Subscribe • Gift • Renewal • Change of Info
PERSPECTIVES 95 CLASSIFIEDS For more details on subscribing, see our ad on Page 91.
Electronics as a Portal 95 ELECTRO-NET
to Other Hobbies 95 AD INDEX
22
77
NEW PRODUCTS
SHOWCASE
96 NV WEBSTORE
Projects & Features
24 Build a MIDI Lyre 49 VINTAGE COMPUTING:
When you think of MIDI controllers, you
probably think of a keyboard. However, Amigo Color BASIC — The
there are many reasons to have MIDI
controllers in other form factors, not the Missing Manual
least of which is fun! In this article, we will The original documentation for the Amigo
make a MIDI lyre version. retro computer was intended to help
■ By Jim Arlow readers mentor youngsters on computer
programming fundamentals. It also
included an “overview of most Color BASIC
34 Build Your Own Funky commands.” A couple of astute readers
working beyond introductory mentoring
Steampunk Display have asked me about the full command
I use LCD displays in almost every project. set. This article covers those “missing”
However, in this modern age of steampunk, commands, plus a couple of tips and tricks
I stumbled on something much cooler. I that Amigo owners may find helpful.
found these 1” high seven-segment ■ By Dane Weston
electromechanical displays (EMDs) that go
clickity, click. I embarked on an ambitious
project that featured five 1941 vintage 58 A Digital Analog –
rotary phone step-by-step (SXS) switches. I
thought these EMDs would be the perfect Part 5
match to display the dialed digits. So, I This final article in our series will examine
ordered a dozen and the rest is history. those circuits from the “555 Timer IC
■ By David Goodsell Circuits” by Forrest Mims which were not
covered in any of the preceding four
articles. As in the other installments, some
42 Build a USB Cable will use the PIC replacement from the first
part, while others will develop specific
Continuity Test Jig programs using a PIC to emulate a
If you’re like me, you likely have a drawer Page 24 particular implementation of a 555.
or shoebox stuffed with assorted USB ■ By Larry Cicchinelli
cables that are used to either charge or program a USB
device. The problem often is that some cables may only
be useful for charging, and which only have the +Vcc and 66 Get ASCII Data from PS-2
ground wires intact with one or both data wires either
broken or not connected in the first place. Here’s a simple Keyboards
test jig to help you tell what’s what. You can buy inexpensive PS-2 keyboards, but they don't
■ By Don Dorward VA3DDN produce ASCII values many applications need. To further
complicate things, these keyboards have their own code-
transmission protocol. I'll show you how to use a system-
44 Does Inductor Winding Have on-a-chip and a bit of software to convert PS-2 key codes
to corresponding ASCII values.
You Tied Up in Knots? ■ By Jonathan A. Titus
While resistors and capacitors
are easily procured and stocked,
most radio frequency circuits 72 Practical Ideas for Portable
require inductors in a wide range
of very specific values. In most Magnetic
cases, you need to create these
yourself, by winding wire on Loop
ferrite rods or toroids of specific
types and sizes. Is it possible to Antennas
substitute another ferrite piece at With the popularity of
hand and still get the right magnetic loop
inductance value? How can a antennas growing
hobbyist measure inductance these days, I thought
without buying an expensive I’d share how I
instrument? This article describes designed a
the principle behind inductance and presents some tricks convenient setup for
that I’ve used to make my own inductors. myself.
■ By Dev Gualtieri ■ By Jim Ford N6JF

July/August 2018 5
Bergeron - Developing Perspectives - Jul-Aug 18_Dev Perspectives - ReadFeed Feb15.qxd 6/12/2018 4:03 PM Page 6

DEVELOPING
PERSPECTIVES
by
Bryan
Bergeron,
Editor Published Bi-Monthly By
T & L Publications, Inc.
430 Princeland Court
Corona, CA 92879-1300
OFFICE: (951) 371-8497
FAX: (951) 371-3052
WEBSTORE: (800) 783-4624
Electronics as a Portal to www.nutsvolts.com

Other Hobbies SUBSCRIPTION


Toll Free: (877) 525-2539
watches on eBay can be had with Outside US: (818) 487-4545
E lectronics as a hobby is unique in
that it touches upon just about
every other technology or area of
glass backs as well as fronts.
As a result, any sort of optical
P.O. Box 15277
North Hollywood, CA 91615
subscribe@nutsvolts.com
potential interest, from photography monitoring of pulse or even
to cycling. oxygenation is possible with a few FOUNDER
Jack Lemieux
One electronics enthusiast might LEDs aimed at the wearer’s skin
be working on a throat microphone through the mineral glass case back. PUBLISHER
design for a helium diver while My latest work is trying to Larry Lemieux
leverage the solar watch faces I’ve publisher@nutsvolts.com
another is hard at work on an
Arduino-enabled bingo game display. reclaimed from Seiko watches to ASSOCIATE PUBLISHER/
Moreover, as you mature and power the electronics, simply ADVERTISING SALES
your life evolves, the focus of your because opening the case back every Robin Lemieux
robin@nutsvolts.com
electronics experimentation can co- week or two to change batteries is a
evolve. For example, you’re not stuck hassle. EXECUTIVE DIRECTOR/
with the turntable audio electronics As a result of my foray into PRODUCTION
Sean Lemieux
of your youth; you can move to RF watches, I’ve picked up a few dozen sean@nutsvolts.com
communications as you spend more tools and a handful of techniques
time on the road commuting to and useful for working in small confined EDITOR
from work. spaces not much larger than three or Bryan Bergeron
techedit-nutsvolts@yahoo.com
As such, I view electronics as a four stacked quarters.
portal to other hobbies and interests One of my most useful finds is CONTRIBUTING EDITORS
— often in a way that enhances and so-called “T” screwdriver blades. Fred Eady Kristen McIntyre
Lou Frenzel Ward Silver
renews the initial focus on Instead of a standard shaped blade Jeff Eckert Paul Verhage
electronics. that gradually narrows to an edge, Dane Weston Larry Cicchinelli
Dev Gualtieri Jim Ford
For example, I’ve been working “T” screwdriver blades are scooped Jim Arlow David Goodsell
with wearable computing for a while out, leaving a clean, nearly parallel Jon Titus Don Dorward
now, including a spine position blade that easily inserts into even the
SHOW COORDINATOR
sensor that enables the user to know finest head on a screw. Audrey Lemieux
the status of their posture. I’ve even gone as far as
When PDAs first became purchasing a screwdriver sharpener WEBSTORE MARKETING/
available, I strapped one on a belt, made for watchmakers so that I can COVER GRAPHICS
Brian Kirkpatrick
Batman style. Today, I get the same renew the T blades as I need them brian@nutsvolts.com
results with a miniature Bluetooth (for T blades, see Esslinger.com).
transmitter on the body and a remote Of course, I use these new ADMINISTRATIVE STAFF
Re Gandara
Mac/PC. screwdrivers and other tools on my re@nutsvolts.com
The appearance of more robotics experiments. No more
powerful and functional smart stripped screw heads because the Copyright © 2018 by T & L Publications, Inc.
All Rights Reserved
watches has encouraged me to look screwdriver blade is too thick. I’ve All advertising is subject to publisher’s approval. We
into small computing systems that fit also located sources for ultra- are not responsible for mistakes, misprints, or
typographical errors. Nuts & Volts Magazine assumes
in a watch case. miniature screws, pins, washers, no responsibility for the availability or condition of
For example, I’m a fan of the bearings, and the like. advertised items or for the honesty of the advertiser.
The publisher makes no claims for the legality of
Panerai watch clones because they’re Watch supply stores online are any item advertised in Nuts & Volts. This is the sole
big and thick — on the order of 45 one source for new parts, but I’ve responsibility of the advertiser. Advertisers and their
agencies agree to indemnify and protect the publisher
mm x 17 mm, depending on the had great luck tearing down broken from any and all claims, action, or expense arising from
model. That’s plenty of room for a watches that sell by the pound on advertising placed in Nuts & Volts. Please send all
editorial correspondence, UPS, overnight mail, and
project. The inexpensive mechanical eBay. artwork to: 430 Princeland Court, Corona, CA 92879.
6 July/August 2018
Bergeron - Developing Perspectives - Jul-Aug 18_Dev Perspectives - ReadFeed Feb15.qxd 6/12/2018 4:04 PM Page 7

There’s no way I can compete


with the likes of the Apple Watch or
a FitBit, but I don’t need to. I just
need the tools and some of the
know-how from the world of watches
to spice up my experimentation in
electronics. This is just one example.
Several years ago, I made a
similar foray into digital photography.
I picked up a few techniques and
tools that have improved my life
working with optical sensors.
In summary, the electronics
portal leads to many potential
adventures. Don’t feel you need to
stick with pure electronics.
Get out of your comfort zone
and explore some of the many
related technologies. You’ll be glad
you did. NV

July/August 2018 7
Eckert - TechKnowledgey - Jul-Aug 18_Eckert - TechKnowledgey - Feb 15.qxd 6/12/2018 4:10 PM Page 8

TECHKNOWLEDGEY 2018 ■ BY JEFF ECKERT

■ MIT’s AlterEgo device allows silent speech.


ADVANCED TECHNOLOGY
Say No More the signals with

Y ou may not have thought about it, but when engaged in


silent reading, you think the words as you read them and
hear them in your mind. This is known as “subvocalization,”
specific words. The
“AlterEgo” system
includes a pair of
and the phenomenon has been under consideration since bone-conduction
the mid 1800s. In 1899, a researcher named Curtis headphones that
concluded that silent reading was, in fact, the only mental transfer sound
activity that caused significant movements of the larynx. vibrations through the
Half a century later, A. W. Edfeldt devised an electrical face bones to the
instrument that could record this movement. His device was inner ear, bypassing
too primitive to correlate movements with specific words, the ear canal
but he did conclude that silent speech reinforces learning completely.
and is therefore a good thing. In one experiment, subjects used the system to report
Other researchers have come to the opposite opponents’ moves in a chess game and receive a
conclusion: that subvocalization should be minimized. After computer’s recommended moves, all soundlessly. In
all, if you have to subvocalize everything you read, you can’t another, 10 subjects used the system to execute
read any faster than you can speak (about 150 to 250 words computations, and it turned out to be about 92 percent
per minute). It’s therefore widely considered to be a accurate. Accuracy should improve as data about more
hindrance to learning, and speed readers are trained to complicated conversations is collected.
avoid it as much as possible. Researchers speculate that the system could be valuable
Researchers at the MIT Media Lab in both extremely noisy environments and one where
(www.media.mit.edu) have now created a wearable device silence is mandatory (e.g., special ops). It could also allow
that picks up neuromuscular signals in the face and jaw and disabled people who can’t speak normally to communicate
feeds them to a machine-learning system that can associate with others. ▲

Messin’ with Brain Cells imaging — showed responses similar to those of a normal
or decades, sci-fi movies and TV shows have portrayed sensory stimulus. The researchers speculated, “the laser
F characters whose brains have been erased or
reprogrammed by evil-doers. This fictitious process is so
holography setup could eventually be miniaturized to fit
in a backpack a person could haul around.” Goody for
common that it doesn’t particularly terrify most of us the FBI (Federal Brain Investigators).
anymore. Maybe it should now, because UC Berkeley So, how long until they are able to work with live
(www.berkeley.edu) neuroscientists are getting closer to human brains? Who knows? Maybe they already can.
making it a reality. Maybe they already have.
Under development is a system that uses holographic Are you absolutely certain you were at the Snake Pit
projection to activate or deactivate brain activity, thereby Bar and Grill last night? ▲
allowing it to “edit the sensations we feel, paste in our
brain pictures that we never saw, cut out unwanted pain,
or insert nonexistent scents into memory.”
Recently, a chunk of mouse brain was treated with a
protein that when hit with a flash of light turns the cell on
and creates a spike of activity. To function properly, the
system needs enough accuracy to “shoot the very
specific sets of neurons you want to activate and do it at
the characteristic scale and the speed at which they
normally work.” Apparently, they have achieved that.
The researchers have already tested the prototype on
mice as they walk on a treadmill, acting on the touch,
vision, and motor areas of the brain. Access to the brains
was enabled through an installed clear window. Brain
activity — as measured in real time with two-photon ■ A sample hologram with 50 randomly distributed
neuron targets.

8 July/August 2018
Eckert - TechKnowledgey - Jul-Aug 18_Eckert - TechKnowledgey - Feb 15.qxd 6/12/2018 4:10 PM Page 9

EVENTS, ADVANCES, AND NEWS

COMPUTERS and NETWORKING


Low-End 2-in-1
f you’re looking for a modestly priced laptop and don’t need a
I ton of processing power, you might want to put on your yoga
pants and a Yogi Bear T-shirt, open a cup of yogurt, and check out
one of the Yoga Books from Lenovo (www.lenovo.com).
The CPU in this 2-in-1 is an Intel Atom x5-Z8550: a power-
efficient quad-core chip that is robust enough for everyday tasks
such as Internet or Office, but not ideal for highly complex
software or games. On the positive side, it’s very thin (9.6 mm,
0.38 in) and light (0.69 kg, 1.52 lb), and it has a 10.1 in 1,920 x
1,200 screen.
The unit features a Halo keyboard, which is a full backlit
virtual version with a “Create Pad” for pen writing and drawing.
Other features include Dolby sound, an 8 MP rear camera and a
■ Lenovo’s Yoga Book 2-in-1.
2 MP front one, and the other usual tablet features.
As of this writing, you have a choice of Android or Windows operating systems. The Android version can
be had for around $300; with Windows 10, it goes for closer to $400. ▲

A Beast of a Box
designed to be the ultimate super-
o, you’ve decided to build your tower case. The dramatic look comes
S own computer using selected off-
the-shelf parts. Maybe you want to
from four smoked tempered glass
panels and brushed aluminum, and
put together the world’s most the triple-chamber, dual-system layout
powerful game computer or allows for installation of both a full E-
something that can be used for ATX and a mini-ITX system.
worldwide weather forecasting. If You can mount eight 120 mm
you’re like most of us, you’ll fans to the front, three 140 mm fans
probably house it in the cheapest in the roof, and two 120/140 fans to
box you can find. However, if you’re the rear, or you can install liquid-
willing to shell out some extra bucks, cooling radiators. Included are a
you can go the other way and put it CORSAIR Commander PRO digital
into something that’s impressive in ■ The Corsair Obsidian 1000D. RGB lighting and fan speed
and of itself. controller and three removable dust filters. The only bad
In that case, take a look at the Corsair Obsidian news is that we’re looking at a list price of $499, and the
1000D. Over two years in development, this box is street price seems to be the same. ▲

Adaptive USB
the Trinity: a 3-in-1 adaptive USB
n all likelihood, your computer Flash drive. It features USB Type-A,
I has a few large Type-A USB
ports, and your tablet and phone
Type-C, and micro-B connectors —
all in a single housing. These are
have micro-B connections. So, three of the most common USB
how can you move files from one formats, so you can use it with a
to the other? Sure, you can go range of devices. In addition, the
scrounging around in that big box Trinity supports OTG (on-the-go)
of tangled-up cables to find one ■ Patriot’s Trinity
for Android devices, which allows
with the right end connectors, but Flash drive. users to access it with any of their
wouldn’t it be easier if you could Android devices without
just use the same Flash drive with both? downloading any external drivers or software. The drives
Well, that’s what the folks at Patriot are available with capacities of 32, 64, and 128 GB,
(www.patriotmemory.com) thought, so they designed priced at (respectively) $27.99, $38.99, and $69.99. ▲

July/August 2018 9
Eckert - TechKnowledgey - Jul-Aug 18_Eckert - TechKnowledgey - Feb 15.qxd 6/12/2018 4:10 PM Page 10

Post comments on this article at www.nutsvolts.com/magazine/issue/2018/07.

CIRCUITS and DEVICES


Garmin for Golf
Based on GPS location, the
ith all the cheap and even Approach S10 will automatically
W free GPS apps available for
phones and tablets, we might
select the course and provide
distances to the front, back, and
imagine that companies like middle of the green for each hole.
Garmin International It also displays distances to
(www.garmin.com) would be hazards, doglegs, and layups.
having a hard time. However, they As the game progresses, the
have adapted to changing times watch automatically transitions to
with a variety of specialty products the next hole, and players can
such as GPS wristwatches, a enter in their score on the watch.
satellite communicator with GPS, After every game, the Approach
and sports and fitness items such S10 shows the total distance
as the Approach S10 for golfers. traveled, the total time played, and
This unit comes loaded with the score for that round. It’s okay
maps for more than 41,000 to swim, shower, or stumble into a
courses worldwide. It has a 1.3 water hazard while wearing it, as it
inch, high-res, sunlight readable is rated to five atmospheres.
screen that provides a clear and Battery life is rated at up to 12
crisp display even in direct hours. You can buy one online for
sunlight. ■ Garmin’s S10 GPS for golfers. about $130. ▲

A Blast of Sound
ack in the good ol’ days, an audio mixer was a huge console with many knobs, sliders, meters, and so
B on. It would usually be hooked up to a PA system or 10.5 inch multi-track tape recorder. These days,
however, your desktop computer, tablet, or phone can perform the same and many other functions, so
maybe you can replace the old-style mixing board with something like the Sound Blaster K3+ from
Creative Labs (www.creative.com).
The K3+ is an external sound mixer
module with hardware processing including
nine reverb effects, autotune (in case you’re
a really awful singer), and voice morphing
effects. It has multiple input types, supports
48V phantom-powered condenser mikes,
and offers individual I/O gain control. With
no necessary driver installation, it connects
to PCs and Macs via a simple USB cable
and can also be connected using a four-pole
3.5 mm jack. A built-in processor offers 24-
bit 48 kHz recording and 24-bit 98 kHz
playback.
Also included are six sound effects that
can be triggered at any time, including VIP
entrance, cheers, baby laughter, audience
laughter, gunshots, and crow caws. (No, I
don’t know why.) They are available at
Amazon, Newegg, and Fry’s for $129.99. ▲

■ The Sound Blaster K3+.

10 July/August 2018
Eckert - TechKnowledgey - Jul-Aug 18_Eckert - TechKnowledgey - Feb 15.qxd 6/12/2018 4:10 PM Page 11

Yodel-Ay-Eee-Ooh!
his month’s “How Did I Live Without It?” award goes
T to the Electronic Yodelling Pickle, magnanimously
provided to the world by Archie McPhee (mcphee.com),
which also sells rubber chickens, tinfoil hats for both cats
and humans, and a range of other not-so-serious products.
McPhee also maintains the Rubber Chicken Museum at its
Seattle store.
No doubt you are now thinking, “Wow. I gotta get me
a yodeling pickle.” Luckily, you don’t have to go to Seattle
to pick one up; they’re available from Amazon for a mere
$10.61. Oddly enough, the item shows 638 customer
reviews — 82 percent of which give it five or four stars.
One reviewer said it helped his uncle deal with
Alzheimer’s, and another indicated that it’s good for
calming crying babies.
One reviewer gave it only two stars, noting, “The
Yodelling Pickle in my house appears to be possessed.
Whenever I put it away in the kitchen cupboard, it
mysteriously appears in the top drawer of my wife’s
■ The Yodelling Pickle you’ve always wanted.
bedside table.” ▲

INDUSTRY and the PROFESSION


Twitter Twaddle
t isn’t exactly news that social media
I contains misinformation and outright lies. A
study conducted by Jun Zhuang, PhD
University of Buffalo, examined how more
than 20,000 tweets presented the facts after
Hurricane Sandy and the Boston Marathon
bombing. His article, published in Natural
Hazards, revealed that:

• Eighty-six to 91 percent spread false


news, either by retweeting or liking
the original post.
• Five to nine percent tried to confirm ■ Don’t believe
the false news, usually by retweeting everything little birdies
tell you.
and asking for verification.
• Only one to nine percent expressed
doubt.

Perhaps even more surprising is that Prof. Zhuang was Foundation to conduct additional studies. Nice work if
recently awarded $392,000 from the National Science you can get it. ▲

July/August 2018 11
n WITH KRISTEN A. McINTYRE
Q&A
In this column, Kristen answers questions about all aspects of electronics, including
computer hardware, software, circuits, electronic theory, troubleshooting, and anything
else of interest to the hobbyist. Feel free to participate with your questions, comments, or
suggestions. Send all questions and comments to: Q&A@nutsvolts.com.

a time-varying voltage produce a time-varying magnetic


• High Voltage, Low Cost flux and vice versa. Magnetic flux is the magnetic field
that passes through a given surface; for instance, the
• N, P, or What? surface covering a loop or loops of wire. If, for example,
that magnetic flux is changing with time, then we get a
corresponding voltage around the loop. Conversely, if
High Voltage, Low Cost we have a time-varying voltage, we can “induce” a time-
varying magnetic flux. Our job is to exploit this property.

Q
: I’m running an experiment for my high school The number of wire turns that are around the surface
science project that requires a 5,000V power through which the magnetic field passes are additive. In
supply. The commercial supplies are crazy other words, the more turns, the more voltage. If we have
expensive. Is there an inexpensive DIY way to a turns ratio of, say, 10 to 1, then the voltage on one turn n
generate a few thousand volts at only a few microamps? on what we often call the primary of a transformer will be
Greta Chivers multiplied by 10 and appear on the secondary. w
Boca Raton, FL Of course, there’s no free lunch, so the current will in
be reduced by a factor of 10 (at least) on the secondary

A
: Before we start on this question, I want to so that energy is conserved. So, Pin >= Pout. Another way to th
mention that 5KV — even at microamps — can think of that is: a
be dangerous. Please be cautious when dealing tr
with high voltage in any form. Keeping the Iin • Vin >= Iout • Vout
current limited to a few microamps is difficult at all points ra
in a circuit like this, so it’s possible to induce a fairly high The voltages that appear on these wire turns are not tu
voltage across your body if you touch the wrong thing. referenced to anything except themselves. This means that o
There are a few different approaches one could take we get to choose the reference by what we connect those th
to such a design, but all the ones that are relatively easy wires to. For this circuit, we’ll choose to reverse the voltage tu
involve an oscillator that is based on positive feedback by connecting one secondary up ‘backwards,’ reversing th
through a transformer. This serves the dual purpose of the voltage.
providing an easy feedback path that is naturally oscillatory, Note also that we can have multiple secondaries. Any w
plus gives us an opportunity to c
get some immediate voltage J1 o
multiplication through the turns 12V TR1 1500 turns e
1 12 J2
D112V
D4

ratio of the transformer. AC HV 1 m


S2

Let’s take a quick look at how 11 o


SpiceOrder 2

PRI

8
transformers work. One warning, J3 a
SpiceOrder 1
1K
R2

S1

though: I’m going to play fast and 6 7 AC HV 2


loose with causality for the sake of Q2 10 turns a
50 turns
clarity in this particular discussion. c
10K
Transformers work on the v
~10pF

principle of Faraday’s Law of R1 tr


C1
D3

Induction and Ampere’s Law from 1uF It


SpiceOrder 2
D2

2V

Maxwell’s Equations. We can have c


C2
SpiceOrder 1

n FIGURE 1. Example AC high n


voltage generator. 3
0V
12 July/August 2018

McIntyre - Q&A - Jul-Aug 18.indd 12 6/12/2018 11:59:07 AM


QUESTIONS and ANSWERS
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

Let’s use another technique instead:


C1

C3
J1 a capacitive voltage multiplier stack.
AC HV 1 A voltage multiplier exploits the AC
D1

D3
SpiceOrder 2
signal to progressively charge capacitors

SpiceOrder 1

SpiceOrder 2

SpiceOrder 1
that are at higher and higher voltages,
SpiceOrder 1

SpiceOrder 2

SpiceOrder 1

SpiceOrder 2
connected in series. The biggest

D2

D4
advantage is that each multiplier stage
C2

C4
J2 J3
only has to withstand voltage at that
AC HV 2 HV+
stage — if operating properly. This means
C5

C7
we can use more ordinary diodes and
capacitors.
See Figure 2 for a double
D5

D7
SpiceOrder 2

SpiceOrder 1

SpiceOrder 2

SpiceOrder 1
multiplier that gives us a factor of 8.
The components all need to be able
SpiceOrder 1

SpiceOrder 2

SpiceOrder 1

SpiceOrder 2
D6

D8
to handle about 1 KV max. It may take
C6

C8

J4 some time for this to charge up, but


HV- then it will be able to supply a little
current.
n FIGURE 2. Voltage doublers for a factor of 8 increase. The voltage might not be exactly right given the
numbers I’ve guessed at. It can be adjusted by changing
wire loop that experiences magnetic flux will see a voltage the supply voltage or the turns ratio. It’s prudent to add a
induced. As always, though, energy will be conserved. current-limiting resistor for safety.
Take a look at Figure 1 for an example of an oscillator To get a 10 microamp limit at 5 KV, a 500K resistor
that generates a somewhat high voltage. This oscillator uses will work. The capacitors in the multiplier stack will supply
a single transistor whose collector drives the primary of the considerably more current instantaneously. Make sure
transformer. everything can handle the voltage too and be careful!
A winding that reduces the voltage (using the turns
ratio) is used to turn the transistor off which, in turn, N, P, or What?
turns it on again in a positive feedback loop. This is our

Q
oscillator. Another secondary multiplies the voltage from : I’m confused about when to use N-channel vs.
the collector by roughly a factor of 30; again, using the P-channel MOSFETs for voltage regulation. Is
e turns ratio. That gives us some AC high voltage that’s on one optimized for positive regulation and one
the order of 600V for 12V input. for negative regulation?
This is not the kind of transformer you can just buy. It Terry Warden
will probably have to be hand-wound on a toroidal ferrite Downers Grove, IL
core or circular ferrite ‘pot’ core. I prefer the latter for ease

A
of winding and magnetic field confinement. You’ll need : I think we can clear up your confusion by
enough turns to get some inductance to exploit; the ferrite looking at how we model MOSFETs. It’s similar
mix is important too. Those choices are beyond the scope to what we do to understand regular bipolar
of this particular column, but perhaps we can cover them transistors. We’ll use a simplified model that
another time.
We could simply rectify and filter that
and be done, but we need more voltage. We
could also increase the turns ratio to get more
voltage, but then we might get arcing inside the
transformer without special insulating material.
It’s also going to be hard to find diodes and
capacitors to rectify and filter that voltage.

n FIGURE 3. MOSFET construction - CC BY-SA


3.0 Olivier Deleage and Peter Scott.

July/August 2018 13

McIntyre - Q&A - Jul-Aug 18.indd 13 6/12/2018 11:59:23 AM


QUESTIONS and ANSWERS

Drain Source Source

Gate

+
+
gm•Vgs Vgs
Vgs gm•Vgs
-
-
Gate

Source Source Drain

n FIGURE 4. N-channel MOSFET simple model. n FIGURE 5. P-channel MOSFET simple model.
doesn’t account for the AC characteristics very well, but is gate voltage controls the current flow, and it is positive
accurate enough to understand the difference between N- relative to the source. The important thing, though, is that
and P-channels. the current can only flow in one direction. If we look at
First, why do we call them N and P channels? If we Figure 5, we see that the current direction and gate voltage
take a look at Figure 3, we can see a rough outline of the is reversed. It flows from source to drain, plus the control
structure of a MOSFET. MOSFET stands for Metal Oxide voltage at the gate is reversed.
Semiconductor Field Effect Transistor, and the key feature So, which one should you use? Use the one that lets
is a gate that is insulated from the “channel” between the the current flow in the direction that is convenient for what
source and drain. you want to do. If it’s voltage regulation, chances are that
The transistor operates based on the electric field an N-channel MOSFET will be best suited to a positive
induced between the gate and the source. This field shifts regulated voltage. That’s because we expect the current to
the balance of charge carriers in that region, reducing flow from the positive to the negative voltages (see Figure
the size of the depletion layer. The depletion layer does 6 for a simplified example). If it’s a negative supply, then
not conduct, so we can change the amount of current that’s all reversed and we expect the currents to flow the
that flows between the drain and source by changing the other way. NV
depletion layer size and replacing it with a charge carrying
layer. J1
The type of material used for the source, drain, and V+
channel defines the type of device. An N-channel uses
IC2A
a material with an excess of negative charge carriers Q1
(electrons) for the source and drain, and forms an 3
N-channel when on. A P-channel uses a material with an 1
2
excess of positive charge carriers (holes) for the source and
drain, and forms a P-channel when on.
This doesn’t explain how they are different in a circuit,
however. I think the easiest way to see it is to look at the
models. Figure 4 is the N-channel model and Figure 5
is the P-channel model. Both are drawn so that positive
Load
R2

voltage is at the top of the diagram, while negative is at the


bottom.
When you look at the N-channel model, you can see
the direction of current flow is from drain to source. The
n FIGURE 6. Example positive linear power supply, N-channel
MOSFET. 0V
14 July/August 2018

McIntyre - Q&A - Jul-Aug 18.indd 14 6/12/2018 11:59:48 AM


Pico2204A SSA3021X
10MHz 2-Ch Oscilloscope Spectrum Analyzer

Passport-sized 2-ch PC-based 9 kHz – 2.1 GHz range and measures


scope. Compact alternative the magnitude of an input signal
to benchtop instruments. versus frequency over the full
100MSa/s in your laptop bag, frequency range of the instrument.
traveling toolkit, or for demos. Light weight and small size (15.5”
Built-in AWG, serial decoders & x 8.2” x 4.6”), with a user friendly
$ 139 two X1/X10 passive probes. $ 1,395 interface on a large 10.1” TFT LCD.
Free Shipping Free Shipping

IkaScope WS200 GPS Series


30MHz Wireless Oscilloscope Linear DC Power Supplies
WiFi-connected 30MHz scope-in-a- High quality linear DC power
probe for isolated measurements supplies with digital display meter
on tablets, smartphones and PCs. and remote control. Low ripple/
200MSa/s sampling rate, maximum noise, overload and reverse polarity
input +/-40Vpp. Turns on when protection. 18V/5A to 30V/3A
probe touches circuit. Weighs 2 oz. versions. Features constant voltage
299.95
Starting at
$
Free Shipping
For Windows, Mac, Linux. $ 199 and constant current operation.
Free Shipping

DS 1054Z SDS 1202X-E


50MHz 4-Channel Oscilloscope 200MHz 2 Ch Oscilloscope
High quality 4-channel 50MHz Excellent 200MHz Oscilloscope.
Oscilloscope. 1GSa/s + 30,000 wfms/s. 1GSa/s + 100,000wfms/s. 14Mpt
Innovative technology hits a new price memory for zooming on fast
point for reliable four-channel scopes. glitches. Very low-noise front-end.
12 Mpt memory for zooming on fast Common adjustments quickly
glitches. Large 7” TFT color display is accessible with single-button
$ 349 very easy to read. FREE carry bag! $ 379 control. Free serial decoders!
Free Shipping Free Shipping

CircuitGear Mini “I founded Saelig in 1988 to search the


CGM-101 Oscilloscope world for unique electronic control
components and test & measurement
Combination oscilloscope/waveform
equipment, including: economical
generator/digital I-O in one small, low oscilloscopes, PC and RF spectrum
cost unit. 2MSa/s dual channel, 200 kHz analyzers, USB and logic analyzers,
11-bit oscilloscope, DDS AWG, 8-ch I/O. Alan Lowne, CEO AWGs, pure RF sources, DMMs,
dataloggers, SPI/I2C controllers, high-reliability industrial and panel PCs,
USB powered, no AC adaptor required.
EMI enclosures, USB serial converter cables and lots more. ‘Saelig’ is an
Open source software for Windows, Olde English word meaning ‘happy, prosperous, and blessed’.
$ 99.95 Linux and Mac. That is what we wish for our customers!”
Free Shipping
What makes Saelig different? Take a look at our website’s
‘Values’ statement - www.saelig.com/values.htm
• Saelig Company, Inc. • www.saelig.com • sales@saelig.com • 1-888-7SAELIG
(1-888-772-3544)

Full Page Ad.indd 15 6/12/2018 6:35:44 PM


THE HAM‘S WIRELESS WORKBENCH n BY WARD SILVER N0AX
hwardsil@gmail.com

Filter Basics
Stop, Block, and Roll(off)
A casual observer might think that wireless systems consist
primarily of filters connected by the occasional bit of circuit!
Block diagrams of transceivers often include as many filters as any
other function. This is true at the system level, just as it is at the
circuit level — and many circuits behave in a filter-like way, whether
intended to be a filter or not! That makes understanding filter basics
important for wireless success.

What is a Filter? shows an example of each type of filter circuit.


A digital filter requires analog signals to be digitized,
Looking up “filter” generates a lot of entries! Along creating a stream of digital data representing the original
with the electrical definitions, there are adaptive filters signal. Once digitized, any mathematical operation can
and image filters and so forth, as well. The general idea, be performed on the data. If the result is to be viewed or
though, is to operate on an input signal (or data) so that listened to by a human, the digital data is converted back
the output is modified based on some pre-defined quality to an analog signal. Processing and converter electronics re
of the input signal. With respect to electrical signals, a filter are now inexpensive enough to implement that digital re
is a circuit or function with an effect that varies with the filters (and many other signal-processing functions) are th
input signal’s frequency, wavelength, or phase. All three of taking over from analog in ham radio. This column will re
those characteristics are basically the same thing: a regular stick with the traditional analog circuits, but the general sc
variation in time. definitions and specifications for how the filter behaves
apply to all filters. re
Analog and Digital Filters 2

As with just about everything else in ham radio, filters


Common Filter Types p
w
can be analog or digital. The common passive (unpowered) Nearly all electrical filters (assume we are talking about m
analog filter consists of familiar inductor-capacitor (LC) or electrical filters from this point on) are described and o
resistor-capacitor (RC) circuits. If some kind of amplifier is specified by their effect on the amplitude or magnitude of
used, the circuit becomes an active filter. Most active filters signals having different frequencies. (The phase response
use op-amps in a variety of feedback circuits. Figure 1 is also important in many applications.) This is the filter’s
frequency response and because it
describes signal amplitude, it is a
A magnitude response. Several types of

n FIGURE 1. Filter A is a passive high-pass LC filter used for rejecting AM


broadcast band signals. Filter B is an active low-pass op-amp filter typically
used for audio signals. B
16 July/August 2018

Silver - Hams Wireless Workbench - Jul 18.indd 16 6/12/2018 4:07:16 PM


PRACTICAL TECHNOLOGY FROM THE HAM WORLD
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

n FIGURE 2. Four different types of filter


responses: low-pass (A); high-pass (B);
band-pass (C); and notch or band-stop (D).
(Figure courtesy of the American Radio
Relay League.)

Filter Specifications
Before using or selecting filters, you’ll
have to know how they are specified.
Beyond just the broad high- or low-
s pass type, you’ll have to be able to give
specific frequencies and specific levels
of attenuation. Each of these parameters
has a name and precise definition. Figure
3 shows a high-pass filter’s magnitude
response. Drawing the gray boxes on a
response graph establishes the filter’s basic
behavior.
• Cutoff Frequency: The
frequency, ƒC, at which the output signal
responses are shown in Figure 2. Filters also have a phase has one-half the power of the input signal. This is useful
response that describes the phase relationship between in specifying where the pass-band ends and where the
the input and output signals. (There is also a time-domain stop-band begins. The cutoff frequency is also referred
response such as you would see on an oscilloscope to as the –3 dB frequency because –3 dB is equivalent
screen.) to a power ratio of one half.
Figures 2A and 2B show the high-pass and low-pass • Bandwidth: If a filter passes or rejects only a range of
responses. Figure 2C is a band-pass response and Figure frequencies acting like both a high-pass and a low-pass
2D is a band-stop or notch response. Each response has a filter, there will be two cutoff frequencies. The higher
pass-band (where signals aren’t attenuated) and a stop-band one is ƒH and the lower is ƒL. In Figure 2C, the two
where signals are rejected. All have many uses in radio, cutoff frequencies are approximately 2 kHz and 4 kHz,
ut mostly in attenuating unwanted signals. We’ll discuss some so that filter has a bandwidth of 4 – 2 = 2 kHz.
of these uses later in the article. • Ripple: This is the variation in attenuation, specified
in dB, of the input signal in the filter’s
pass-band or stop-band. Figure 3 shows
a filter with about 1.5 dB of ripple in the
pass-band. Variation in the stop-band is
also called ripple.
• Rolloff: The slope of the filter’s
response in the transition region between
the pass-band and stop-band. Rolloff
is given in dB/octave (a doubling of
frequency) or dB/decade (ten times
the frequency). If the response changes
rapidly with frequency, that rolloff is
termed steep.
• Insertion Loss (IL): The minimum

n FIGURE 3. A filter’s key specifications


for its amplitude response. The gray
boxes establish the basic performance
(see text).
July/August 2018 17

Silver - Hams Wireless Workbench - Jul 18.indd 17 6/12/2018 4:07:24 PM


PRACTICAL TECHNOLOGY FROM THE HAM WORLD

attenuation in the filter’s pass-band. A perfect filter bands and the steepness of the rolloff vary quite a bit. (The n
would have no insertion loss at all, but all practical filter’s phase responses are also quite different.) o
filters have some insertion loss. The filter in Figure 3 For example, compare the Chebyshev and Butterworth ro
has an IL of about 1 dB. low-pass filter response curves in Figure 4. Both are a
in
• Stop-band Attenuation and Notch Depth: In the low-pass filters with a cutoff frequency of 1,000 Hz. The
stop-band, a minimum amount of attenuation is curves have very different shapes, though. The Butterworth
required of the filter. If the filter rejects a narrow has a very smooth response with no ripple at all —
range of frequencies with a stop-band in between two Butterworth filters are often referred to as maximally-flat
pass-bands, notch depth is the maximum attenuation for that reason — but the rolloff is smooth and gradual,
between those two pass-bands. Both of these as well. The Chebyshev filter trades a smooth response
parameters are specified in dB. for steeper rolloff by allowing various amounts of ripple.
• Input and Output Impedance: Filters have a The filter response in Figure 4 is known as a “1 dB ripple
characteristic impedance that affects how a signal Chebyshev.”
source or load will perform when connected to the Depending on what you’re using the filter for, ripple
filter. For the filter to have only the desired effect, it’s or gradual rolloff might be okay. The different filter families
impedance should match the impedance of whatever offer choices about how the filter will perform and what
it is connected to: a signal generator, a microphone, effects they have on the signals. For example, hams trying

Attenuation - Is it Positive or
Negative?
If an output signal is smaller than the input signal, the ratio in dB d
will be negative. For example, if the output is five times less powerful
than the input to a filter, that is a power ratio of -7 dB with the minus
b
sign indicating a ratio less than 1. That represents an attenuation or
loss of 7 dB, with no minus sign. a
The rule is that power ratios in dB have a positive or negative n
value, while loss or attenuation are given without the minus sign. o
The -7 dB power ratio is a loss or attenuation of 7 dB. Similarly, if the
output was five times greater than the input, that would be a gain of 7
dB. n FIGURE 4. Filter responses for a Butterworth
and a Chebyshev low-pass filter. Both have
The minus sign isn’t used if the name of the parameter implies the same cutoff frequency of 1,000 Hz but have
whether it is present or not. significant differences in rolloff and ripple in the
passband. (Figure courtesy of the American Radio
Relay League.)

a transmission line, or an amplifier. If the impedances to design an audio filter for receiving the single tones of
don’t match, filter performance may not be as Morse code (CW) find that a lot of ripple means distortion
expected. and smearing of the carefully shaped dits and dahs. At high
speeds, that can make the code “tough copy.” In that case,
Filter Families and Orders it’s worth allowing a more gradual rolloff so you hear some
of the adjacent signals in order for the Morse elements
Looking through websites and books of filter designs, to be reproduced clearly. Each application is a little bit
you’ll notice that along with the type of frequency
response, there are other categories: Butterworth, Brick-wall or Ideal Filters
Chebyshev, Bessel, Elliptical, and more. These are known
as filter families. Many of the families are named for the The filter responses in Figure 2 vary smoothly between
designer who worked out the equations describing them. the pass-band and the stop-band. This is the way a real
(Elliptical filters are so-named because the solutions to filter behaves. Nevertheless, you will encounter references
functions describing them form an ellipse in Cartesian to “ideal” or “brick-wall” filters for which the pass-band
coordinates.) Each set of equations has different solutions and stop-band responses are completely uniform or “flat.”
The transition region for such a filter is a vertical line on the nF
that translate into different component values.
response graph with an infinite rolloff. Needless to say, these app
Each family of filters has a different frequency response filters can’t actually be built, although some sophisticated are
shape. They might all be designed to have the same cutoff digital filters get close. tran
frequency but the amount of ripple in the pass- and stop-
18 July/August 2018

Silver - Hams Wireless Workbench - Jul 18.indd 18 6/12/2018 4:07:35 PM


e n FIGURE 5. The effect of increasing a simple RC filter’s
Order describes the number of LC or RC pairs in a
order from 1 to 3. Note the increasing steepness of the filter’s passive filter, such as in Figure 1A which is a fifth-order
h rolloff at higher orders. (Graphic courtesy of Spinningspark filter. Figure 5 shows the effect of cascading three filter
at Wikipedia, CC BY-SA 3.0, https://en.wikipedia.org/w/ sections of Figure 1B’s active RC low-pass filter. You
index.php?curid=23488139.)
can see the rolloff of the filter increasing as order is
h increased.
In general, as order increases, performance can
more closely approach the ideal filter’s response. However,
filter complexity is increased, tuning is more critical,
and component variation and losses can have a more
pronounced effect on performance. We’ll cover order in
more detail next time.

s
Common Filter Applications
Let’s discuss a few applications for filters. Figure 6
is a block diagram showing where these filters are found
in typical ham radio transceivers and accessories. Signal-
processing filters are more and more likely to be performed
by software (DSP), but there are still many analog filter
circuits in radio.
• Audio Filters: Along with the CW band-pass filter
different in what is important. mentioned above, audio filters are also used to get
Once a filter family is selected, the next order of rid of hum (50 or 60 Hz signals caused by magnetic
business is to determine how many “sections” of filtering fields), buzz (caused by 120 Hz rectified AC and
are needed to meet the performance requirement. The ac neutral currents), and high-frequency hiss. FM
number of sections is the filter’s order — the higher the modulators and noise-reduction circuits also use pre-
order, the more filtering is applied to the input signal. emphasis (high-pass) and de-emphasis (low-pass) filters

n
h
,
e

n FIGURE 6. A transceiver block diagram showing typical


applications of filters for different functions. Filters
are used at frequencies from AC power through the
transmitted and received RF signals.

July/August 2018 19

Silver - Hams Wireless Workbench - Jul 18.indd 19 6/12/2018 4:07:49 PM


for good speech reproduction. spurious signals that might interfere with broadcast
• Noise Reduction: The ability of DSP to make decisions TV reception. (With TV stations having moved to UHF
“on the fly” about what signals are noise makes channels for DTV signals, TV interference is much less
it possible to create “smart speakers” and noise of a problem these days.)
reduction (NR) algorithms that remove undesired • AC Line Filter: Low-pass filters that attenuate RF
portions of the audio output of a receiver. Although signals on the hot and neutral lines of an appliance’s
they introduce some audible “artifacts,” the result is AC power connection. Line filters reduce both
much cleaner and easier to understand. on RF signals generated inside the appliance that
• Notch Filters: A type of band-stop filter, notch filters shouldn’t get out to be radiated and on RF signals
are designed to remove a very narrow range of signals picked up on the power wiring that might disrupt the
— often just a single-frequency tone caused by a appliance. These line filters usually do not filter the
spurious signal or an over-the-air carrier. Analog notch equipment ground (a.k.a., the third-wire or green-wire
filters require manual adjustment but DSP notch filters ground) conductor so additional filtering — such as
can automatically sense the presence of the interfering from a ferrite core — may be necessary. (See Ham’s
signal and “notch it out” — even for several signals at Wireless Workbench columns from the July 2015 and
once by using current technology. September 2015 issues on ferrite and RFI for more
• Anti-aliasing: When digitizing analog signals, it is information about this kind of filtering.)
necessary for the signals to contain
frequency components no higher
than one-half the sampling rate.
Filter Design Resources
Higher frequency signals will appear
Many books have “canned” filter designs for various common
in the digitized data as low frequency
spurious signals through a process
applications. If you are careful to use the same type of component and D
circuit layout, you’ll probably get acceptable results. Beginners should
known as aliasing. An anti-aliasing
start with pre-designed filters. As you progress, you’ll be presented
filter is a low-pass filter that removes
with the need to “roll your own” filter. Along with the Tonne Software
the undesired high frequency signals.
programs we’ll be using in the next column, there are some tried-and-
Similarly, when a digital signal is
true resources for the experimenter. For serious readers, the various
reconstituted as an analog signal, the
editions of Arthur Williams’ Filter Design Handbook are widely available
digital “stairstep” created in the output
as used copies.
waveform contains high frequency
If you’re looking for more of a “plug and chug” solution, the
signals that are removed by another
venerable Active Filter Cookbook by Don Lancaster in its various
low-pass smoothing filter.
printings will provide design formulas and examples for filters in the
• Preselector: Tunable analog LC
audio range. Finally, for RF filters, the ARRL Handbook’s chapter on
band-pass filters at the antenna input
Analog and Digital Filtering provides theory and projects through
that attenuate strong “out-of-band”
the microwave range with a long list of references and additional
signals that might overload a receiver,
supplemental information online.
causing it to produce spurious signals.
Preselectors are most often used on the HF amateur
bands which are shared with or adjacent to powerful
shortwave and military stations.
Do Filters Have to Be Circuits?
• Broadcast Reject: Instead of band-pass, “BC” reject Analog filters with Ls, Cs, and Rs are very common but
filters usually have a notch or band-stop response. they aren’t the only electronics that can perform filtering
They are used in the vicinity of strong fixed-frequency functions. Indeed, there are no perfect circuits for which
AM, FM, or TV stations. A similar filter can be used to frequency doesn’t matter, so technically, every circuit is a
attenuate commercial paging or repeater signals. filter! However, there are a few notable non-LCR filters you
• Harmonic-rejection Filter: FCC rules require the should be aware of:
spurious outputs from amateur transmitters to be at • Crystal and Mechanical Filters: Once the best
least 43 dB (20,000x) less powerful than the intended available passive filters for receiving RF signals, these
transmitter output. These low-pass filters are placed filters used quartz crystals and precisely machined
between the output of an RF amplifier and the mechanical resonators. A crystal roofing filter is still
antenna connection. The cutoff frequency of the filter used in many receiver designs to improve strong
is selected according to the operating band of the signals from interfering in crowded conditions.
transceiver. External low-pass filters are also used to • Stubs: Resonant sections of feed line can act as band-
provide additional attenuation of harmonics and other pass and band-reject filters. Books on transmission
20 July/August 2018

Silver - Hams Wireless Workbench - Jul 18.indd 20 6/12/2018 4:08:02 PM


PRACTICAL TECHNOLOGY FROM THE HAM WORLD

F
Why are Analog Filters Still Necessary?
While you’ll find digital filters taking over more and more filtering chores, analog filters are still the only
practical choice for many roles. Obviously, at high power levels — such as for transmitters and duplexers — low-
loss inductors (L) and capacitors (C) are required. The selection of appropriate components is an art in itself for
these circuits.
Less obviously, analog filters are also required at very low signal levels where a digital circuit may not have
enough resolution in bits to represent the signal, and at very high frequencies where the samples can’t be taken
fast enough. Digital filters also require a fair amount of supporting electronics and might be too expensive.
Analog filters will be with us for quite a while!

lines and antenna systems will explain how these work. you a better understanding of how filters behave and are
• Waveguides: Sections of waveguides with internal specified. It wouldn’t be very nice to leave you hanging
baffles or tuning screws can be very effective filters at without some practice, however. So, in the next column,
microwave frequencies. we’ll experiment with a very capable suite of filter design
• Antennas: Not only can antennas act as frequency- software.
dependent filters with preferred frequencies, but they ELSIE (a play on “LC”) is provided by Tonne Software
can act as spatial filters too! (Jim Tonne W4ENE is a long-time contributor to the ARRL
Handbook and other ham radio endeavors), along with
Designing Filters with ELSIE several filter design utilities.
You’ll find that filters are well within your ability to
In this column, I’ve presented some filter basics to give design and build! NV

July/August 2018 21

Silver - Hams Wireless Workbench - Jul 18.indd 21 6/13/2018 10:24:33 AM


NV New Products - Jul-Aug 18_Mar15 -NV - NewProducts.qxd 6/12/2018 5:57 PM Page 22

PRODUCTS
■ HARDWARE
■ SOFTWARE
■ GADGETS
NEW ■ TOOLS

IoT BUILDER DESIGN LeCroy HVD3000A high voltage even to very high frequencies, greatly
SOFTWARE differential probes, including the 1 kV
HVD310xA, the 2 kV HVD3206A,
improving measurement capability.
The high CMRR combined with low

L abcenter Electronics Ltd. has


announced the launch of its new
Internet of Things design software:
and the 6 kV HVD3605A. These
probes provide excellent CMRR
(common mode rejection ratio) over
probe noise and high offset
capability provides superior
measurement capabilities compared
IoT Builder. It’s based on Labcenter’s a broad frequency range to simplify to other HV differential probes.
renowned microcontroller simulation the measurement challenges found in The HVD3000A series covers a
tools and initially targets the Arduino noisy, high common-mode power broad range of applications, from
ecosystem. electronics environments. 120/240V switch-mode power
The product provides a unique The probe’s design makes it easy supplies through 600V class and 5 kV
agile workflow for the design of and safe to make precise high voltage class electrical apparatus. High-power
electronic appliances that can be floating measurements. Serving a DC-DC converters can operate at
controlled from a cellphone or tablet. wide range of power-electronics substantial voltages 500 VDC or
Users can design a ‘virtual front applications, they provide 1% gain higher.
panel’ in the IoT Builder editor and accuracy, a differential-voltage range The HVD310xA models provide
then program the interaction of the of up to 1,500V (DC + peak AC), and up to 1,000 VDC common-mode
front panel controls with the Arduino high offset ranges. (HVD3206A models provide up to
hardware using simple Visual The HVD3000A probes can 1500 VDC) and high precision (1%
Designer flowchart blocks. perform an AutoZero functionality gain accuracy) DC voltage
At any time during development, without having to first remove the measurements.
the entire system can be tested and probes from the device under test, Automatic switchable attenuation
debugged in the Proteus VSM ensuring consistent and efficient high keeps the probe in the optimum
simulation. This executes the same voltage testing. The AutoZero measurement range. Multiple probes
compiled hex file as the real capability ensures data precision by can be used to understand complex
hardware and will also simulate the allowing small offset drifts to be device switching performance. The
interaction of the front panel with the calibrated out of the measurements. HVD3000A high voltage differential
electronics. Additionally, the HVD3000A probes start at $1,535.
Once everything is working as probes automatically detect
expected, the firmware and front overloads of both differential- and For more information, contact:
panel can be deployed to the common-mode inputs, displaying the Saelig Company
Arduino hardware at the press of a overload condition on www.saelig.com
button. the oscilloscope’s
The final step is to point the screen. Designed to
target device at the remote hardware, work with Teledyne
watch it acquire the front panel over LeCroy’s oscilloscope
TCP/IP, and then control it from a cell range, all HVD3000A
phone, tablet, or PC. series probes connect
via the ProBus interface
For more information, contact: which brings power and
Labcenter Electronics communications,
www.labcenter.com eliminating the need for
a separate power supply
HIGH VOLTAGE or batteries. Attenuation
is automatically selected
DIFFERENTIAL based on the o’scope
PROBES gain range (V/div)
setting.

S aelig Company, Inc., announces


the availability of Teledyne
The CMRR for the
probes is exceptional
22 July/August 2018
NV New Products - Jul-Aug 18_Mar15 -NV - NewProducts.qxd 6/12/2018 5:57 PM Page 23

BETTER Count (HPC) development board


(DM164136) — a fully-integrated,
PERFORMANCE IN feature-rich rapid prototyping board
CLOSED-LOOP — can also be used to start
development with these MCUs.
CONTROL Rapid prototyping with the
APPS ATtiny1607 family is supported by
the ATmega4809 Xplained Pro

M icrochip Technology, Inc., has


introduced the new PIC18
Q10 and ATtiny1607 families,
(ATmega4809-XPRO) evaluation kit.
The USB-powered kit features touch
buttons, LEDs, and extension headers
featuring multiple intelligent Core for quick setup as well as an onboard
Independent Peripherals (CIPs) that programmer/debugger that
simplify development and enable seamlessly integrates with the Atmel
quick response time to system Studio 7 IDE and Atmel START (a free
events. online tool to configure peripherals
Ideal for applications that use CIPs such as these allow the and software that accelerates
closed-loop control, a key advantage CPU to execute more complex tasks, development).
of using the PIC18 Q10 and such as Human Machine Interface The PIC18 Q10 and ATtiny1607
ATtiny1607 MCUs are the CIPs that (HMI) controls, and remain in a low are available for sampling and in
independently manage tasks and power mode to conserve power until volume production.
reduce the amount of processing processing is required.
required from the CPU. All PIC18 Q10 products are For more information, contact:
System designers can also save supported by MPLAB® Code Microchip
time and simplify design efforts with Configurator (MCC), a free software www.microchip.com
the hardware-based CIPs, which plug-in that provides a graphical
significantly reduce the amount of interface to easily configure CHATTERBOX FOR
software required to write and peripherals and functions. MCC is
validate. Both families have features incorporated into Microchip’s PI COMPUTE
for functional safety and operate up
to 5V, increasing noise immunity and
providing compatibility with the
downloadable MPLAB X Integrated
Development Environment (IDE) and
the cloud-based MPLAB Xpress IDE,
D esigned by Gumstix in
Geppetto, and following the
Amazon AVS functional design guide,
majority of analog output and digital eliminating the need to download the Chatterbox for Raspberry Pi
sensors. software. The Curiosity High Pin Continued on page 77
Offered in a compact 3 x 3 mm
20-pin QFN package, the new
ATtiny1607 family is optimized for
space-constrained closed-loop control
systems. In addition to the integrated
high speed analog-to-digital converter
(ADC) that provides faster conversion
of analog signals resulting in
deterministic system response, the
devices provide improved oscillator
accuracy, allowing designers to
reduce external components and
save costs.
Among CIPs in the PIC18 Q10
family are the Complementary
Waveform Generator (CWG)
peripheral, which simplifies complex
switching designs, and an integrated
analog-to-digital converter with
computation (ADC2) that performs
advanced calculations and filtering of
data in hardware without any
intervention from the core.
July/August 2018 23
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 24

BUILD IT YOURSELF
By Jim Arlow

BUILD A
MIDI LYRE
When you think of MIDI controllers,

you probably think of a keyboard.

However, there are many reasons to

have MIDI controllers in other form

factors, not the least of which is fun!

Over the years, there have been

MIDI guitars, saxophones,

flute/clarinets, and even trumpets. In

this article, we will make a MIDI lyre.

lyre is a harp-like instrument that is small and


A
since the 1980s. Like the lyre, it has also stood the test of
portable, and has a relatively small number time (but not quite for so long!). You can find out all
of strings. It’s an ideal instrument to “MIDI- about MIDI at the MIDI Association (www.midi.org)
fy” because it’s already quite simple — and we will where there is a wealth of information.
make it even simpler. Lyres have been around for MIDI is ubiquitous, and you really have to try hard to
thousands of years, so it’s definitely a form factor find a modern synthesizer or electric piano that doesn’t
that has stood the test of time. support it. In fact, there are a wealth of MIDI instruments
As you will see, MIDI enabling a lyre creates a available, so you are really spoiled for choice.
simple elegant instrument that anyone can play. A MIDI controller is anything that can send MIDI
Also, the techniques presented here will allow you messages over one of the standard MIDI protocols to a
to create your own touch sensitive MIDI MIDI enabled instrument. The messages cause the
controllers in any form factor you can imagine. instrument to play notes, or otherwise modify its behavior
in some standard way.
The MIDI Interface Note that the MIDI controller itself doesn’t make any
sounds. All it does is command a MIDI instrument to
Before we can make a MIDI lyre, we need to know a make sounds. The MIDI lyre is a MIDI controller, so you
little about MIDI. MIDI stands for Musical Instrument will need to plug it into a MIDI instrument to hear
Digital Interface, and it’s a standard that has been around anything. It’s not a stand-alone instrument.
24 July/August 2018
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 25

Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

A MIDI controller can control any MIDI instrument by other plucked instrument), it goes something like this:
sending it MIDI messages over a standard transport
protocol. The original MIDI specification calls for a serial 1. Touch string.
protocol at 31250 baud sent through a five-pin DIN 2. Pull string from its equilibrium position.
connector. This is the protocol we will use here because 3. Release string.
it’s supported by the majority of MIDI instruments.
However, it is worth noting that there are other MIDI The release of the string causes it to start vibrating,
transport protocols in use; for example, MIDI over USB, and these vibrations are transmitted to a soundboard fixed
Firewire, and Bluetooth LE. It would be an interesting over a resonant cavity that amplifies the vibrations and
follow-up project to modify the MIDI lyre to support one creates the sound.
or more of these newer transport protocols. If we consider a touch event as a simple pulse (as
A MIDI message is made up of an eight-bit status byte shown in Figure 1), then a keyboard sends a Note On
optionally followed by one or two data bytes. There are a message on the rising edge of the pulse when a key is
large number of MIDI messages, but the only ones that pressed, and a plucked instrument sends a Note On
concern us for the lyre are the MIDI Note On and (for message on the falling edge of the pulse when a string is
completeness) Note Off messages. Note On causes the released. The keyboard also sends a Note Off message
MIDI instrument to play a particular note; Note Off causes when the key is released.
it to turn that note off. Does a plucked instrument ever send a Note Off
message? Not really. For most plucked instruments, the
Table 1 sound usually fades away naturally.
MIDI Message Status Byte Note Byte Velocity Byte Now that we understand a bit about lyres and MIDI,
let’s consider the construction of the instrument itself.
Note On 1001 nnnn 0kkkkkkk 0vvvvvvv
Note Off 1000 nnnn 0kkkkkkk 0vvvvvvv Building the MIDI Lyre
The On and Off messages are shown in Table 1. Each There are two aspects to building the MIDI lyre: the
message begins with a status byte where the most electronics and the touch sensors. We’ll start with the
significant four bits of each message (1001 and 1000, electronics.
respectively, in this case) indicate what the message The electronics are comprised of an Arduino Uno, an
means, and the least significant four bits specify the Adafruit MRP121 capacitive touch sensor breakout board,
channel. There is a total of 16 MIDI channels, and you can a female MIDI socket, a couple of resistors, and a couple
assign a different instrument to each one.
We will be sending on channel 0000, so the MIDI
status byte for Note On will be 10010000 (90
hexadecimal); for Note Off, it will be 10000000 (80
hexadecimal).
The next byte is the Note Byte which is a number
from 0 to 127. MIDI defines 128 possible notes such that
each increment by one represents a semitone increase in
pitch. Middle C is (usually) MIDI number 60 and middle
C# is (usually) MIDI number 61. We say “usually” because
how a particular MIDI instrument is tuned is up to the
instrument manufacturer.
The final byte in the Note On and Note Off messages
is the Velocity Byte, which is a number from 0 (silent) to
127 (maximum volume). The MIDI lyre will always send at
maximum volume (127) because it doesn’t have any touch
capability for volume control.
A MIDI keyboard controller works by sending a Note
On when a key is pressed and sending a Note Off when it
is released. Depending on the voice selected, the note will
stop immediately or decay at some preset rate when the
■ FIGURE 1. A touch shown as a simple pulse.
key is released. That’s fine for a keyboard, but how do we Keyboards send a Note On event on the rising edge
simulate a plucked instrument using MIDI? and a Note Off event on the falling edge. Plucked
If you consider the action of plucking a lyre (or any instruments send a Note On on the falling edge.
July/August 2018 25
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 26

■ FIGURE 2. Circuit diagram of the MIDI lyre.

DESCRIPTION QTY
Electronics
1/2 size solderless breadboard 1
Arduino Uno 1
Perspex carrier plate for Uno and breadboard (optional) 1
Adafruit 12-key capacitive touch sensor breakout - MPR121 (PRODUCT ID: 1982) 1
Tactile button (E Switch TL1100F160Q or similar) to fit breadboard 2
(SparkFun tactile button assortment 10302 is perfect)
Tactile button key caps (optional; included in SparkFun tactile button assortment) 2 PARTS
220R resistor
DIN 41524, 5/180º mini-DIN connector, right angle, PCB mounting,
2
1
LIST
(e.g,. CUI, Inc.; SDS-50J or SparkFun PRT-09536)
Dupont jumper wire connected 6 inch (approx) male to male (e.g., SparkFun PRT-12795) 1

Strings
2 mm diameter x 1 m length extruded carbon fiber rod 4
15A 12-way terminal barrier block (with screw fixings to take carbon fiber rod) 8 mm pitch 2
26 July/August 2018
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 27

of tactile switches. The circuit diagram is shown in Figure 2. The whole thing is
assembled on a half size breadboard as shown in the diagram in Figure 3. A
photo of the assembled board is shown in Figure 4.
The first thing to do is to add the headers to the Adafruit MPR121 board.
When you get the board, it comes with two headers that need to be soldered www.poscope.com
in place so that in can be inserted into a breadboard. You can find full details of
how to do this at https://learn.adafruit.com/adafruit-mpr121-12-key-
capacitive-touch-sensor-breakout-tutorial/assembly.
It’s very easy: Insert the long pins of both headers into the breadboard to

- USB #" 
- Ethernet - Encoders
- Web server - LCD
- Modbus #" "
- CNC (Mach3/4) #"" 
- IO

- up to 256 - up to 32
microsteps microsteps
- 50 V / 6 A - 30 V / 2.5 A
#"! ""
- Isolated

 ""
 ""

- up to 50MS/s
- resolution up to 12bit
- Lowest power consumption
#" ""
- 7 in 1: Oscilloscope, FFT, X/Y, Recorder,
"""  
" "
" """"
"

July/August 2018 27
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 28

hold them steady. Put the MPR121 board


down on top of them with its top surface
upwards so the pins go through the holes
in the board and solder the pins in place.
Make sure you have the board with its top
surface upwards, and you can’t go wrong.
Once the headers are soldered on,
insert the MPR121 into the half size
breadboard as shown back in Figure 2
and add the jumpers for VIN and GND.
The next step is to place the MIDI
socket on the breadboard. For
convenience, I used a PCB (printed circuit
board) compatible MIDI socket as shown
in Figure 5 that plugs directly into a
breadboard. However, you can also use a
socket with solder tags depending on how
you choose to construct your lyre.
■ FIGURE 3.
Fritzing The MIDI socket is a five-pin DIN
diagram socket, but there are three different flavors
showing of five-pin DIN with different
construction arrangements of pins. Make sure you get
of the MIDI the MIDI version which is DIN 41524,
lyre on a 5/180°. This means there are five pins
small
breadboard. with pins at 0°, 45°, 90°, 135°, and 180°.
Figure 6 shows a MIDI socket from the
back (the cable plugs into the other side),
so you can see exactly how to wire it up.
Notice that the pin numbering is not
consecutive!
Plug the socket into the breadboard,
then add the jumper between pin 2 and
GND; a 220R resistor between pin 4 and
+5V; and another 220R resistor on
pin 5 to a free row of contacts.
Next, you can add the octave up
and down pushbuttons. Any sort of
momentary action pushbutton will
do. I used tactile switches that are
compatible with the breadboard.
These are readily available from the
usual sources. One pole of each
switch goes to GND, and the other
will eventually go to a pin on the
Arduino. These pushbuttons are
optional; the lyre will work just fine
if you leave them out. However,
you will not be able to change the
octave.

■ FIGURE 4. Photo of the


finished MIDI lyre electronics.
Note the two six-way ribbon
cables that go from the MPR121
to the strings.
28 July/August 2018
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 29

Check all the connections on the


breadboard carefully. When you’re satisfied
they’re okay, you can attach the Arduino.
For convenience, I first attached the Uno
and breadboard to a small Perspex carrier plate.
You can see this in Figure 4. You can often buy
an Uno, half size breadboard, and plate as a kit.
Connect the Uno 5V pin to the 5V rail of
the breadboard, and the Uno GND pin to the
GND rail. Connect Uno pin 1 (TX0) to the
220R resistor that goes to pin 5 of the MIDI
socket. This is the serial transmit output from
the Uno, and it’s where we will output our
Note On events.
■ FIGURE 5. Photo of a female five-pin DIN MIDI socket suitable
I used Dupont male-to-male 10 cm jumper for mounting on a breadboard.
cables to connect the Uno to the breadboard.
Now, connect up the MPR121. This communicates simple kind of strip that has brass tubes in which the wires
with the Uno using the I2C serial protocol, so you only are secured with small bolts. Other fastenings are
need two wires. Connect Uno pin A4 to SDA (the data available, but they may not accept the 2 mm carbon fiber
line) and Uno pin 5 to SCL (the clock). rods.
That’s all the connections needed, and the electronics String spacing is not critical. It’s largely a matter of
are now complete. Now would be a good time to check personal preference and what terminal block spacings are
all the connections again! readily available. If the strings are too close together, it’s
hard to play individual notes. If the strings are too far
Mechanical Construction apart, it’s hard to strum the instrument.
I find that 12 mm is a decent compromise that allows
The MIDI lyre has 12 strings made of 2 mm carbon me to use off-the-shelf terminal blocks. Of course, if you
fiber rod. To make the strings, buy four pieces of 1 m break the terminal block up into individual terminals, you
long/2 mm diameter extruded carbon fiber rod. This is can have whatever string spacing you want! In fact, you
readily available for a few dollars in hobby shops or online can arrange the strings however you want, and make a
because it’s often used in RC planes, cars, and drones. whole range of other instruments! For the MIDI lyre, it’s
Cut each rod into three equal 333 mm lengths using a convenient to keep the blocks in one piece.
hacksaw or (if you have one) a bandsaw. I find it useful to Stringing the MIDI lyre involves fixing each carbon
tape all the rods together using masking tape and then fiber string between the bridge and neck terminal blocks.
mark and cut them all at once. The rod is surprisingly easy There is an easy way to do this and a hard way.
to cut even by hand. The hard way is (sadly) the more obvious way, so we
The length of the strings is not critical, so if you want need to discuss it so you don’t waste your time on it. This
to make them a bit shorter or longer, it should be no is to fix each string in the bridge terminal block and then
problem. In fact, 25 mm is also
a good length because you
can get four strings from a 1 m
rod.
In an acoustic lyre, the
strings are stretched over a
bridge to a neck where they
are tensioned by some sort of
tuning machines that are
usually simple pegs. To create
the bridge and the neck of the
lyre, use two 12-way terminal
barrier block strips with a 12
mm spacing between terminals
(this is usually the 15A rated
model). ■ FIGURE 6. Diagram to show correct wiring of a MIDI out socket. Note that the
Make sure you get the socket is viewed from the back so you can see exactly what pins to connect to.
July/August 2018 29
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 30

try to get the other ends of the strings into the neck block. If you need to replace a string (highly unlikely), loosen
This is surprisingly difficult and very, very fiddly because all the bolts holding it, slide it out of the top of the neck
the strings are already fixed at one end! block, and slide the new string in. It’s interesting to note
The easy way to string the lyre is as follows: that most string instruments have a preferred — and
sometimes necessary — way of being strung, and the MIDI
1. Loosen all the nuts on the neck terminal block so lyre happens to be no exception.
the holes are completely open. I remember spending an afternoon stringing a lute
2. Slide each string through the block to about its and getting halfway before I realized that I wasn’t going to
halfway point. get any further doing it that way.
3. Offer the end of each string up in turn to the A word of warning: Be careful when you tighten the
bridge terminal block and tighten in place. nuts in the terminal blocks. You need to just catch each
4. Slide the neck terminal block up to the opposite carbon fiber rod so that if you give it a little pull, it won’t
end of the strings and tighten everything. come out. Although carbon fiber rod is immensely strong,
it can be quite friable if crushed.
This is a very quick and easy method because you can Once you have fastened the strings in place, you need
move the strings independently. to mark some of the strings to give you an indication of

About the MPR121 Capacitive


Touch Sensor
The MIDI lyre uses the MPR121 touch sensor chip in
a convenient breakout board by Adafruit.
The MPR121 is a sophisticated device that has 12
independent electrode inputs for capacitive touch
sensing. It measures the total capacitance to ground, C,
on each of its 12 electrode sensing channels.
On each channel, this capacitance comprises the
background capacitance, Cb (usually about 10 pF or so)
and the finger touch capacitance, Cx (usually about 1 pF).
When the electrode is not touched, Cx is zero; when it is
touched, it’s about 1 pF or so.

C = Cb + Cx
■ FIGURE A. Output on one of the MPR121
The chip measures Cb and establishes the baseline electrodes with no touch.
capacitance which corresponds to no touch. This baseline
changes, so the chip dynamically recalibrates to
compensate for this. When an electrode is touched and
Cx is large enough, the chip registers a touch. When the
capacitance falls to the baseline again, it registers a
release.
It works by sequentially charging each electrode to a
peak voltage, V, by applying a constant current, I, for a
given time, T. It then measures V using a built-in 10-bit
ADC (analog-to-digital converter), then shorts the
electrode to ground ready for the next cycle.
Both I and T can be changed by altering the values of
internal registers, but for this application, the default
values seem to work well. We know that capacitance is
defined as:

C = Q/V

where Q = I T is the amount of charge. Therefore:


■ FIGURE B. Output on one of the MPR121
V = IT / C electrodes when touched. Notice the drop in peak
voltage compared to Figure 8.
So, the peak voltage, V, is inversely proportional to
the total capacitance of the electrode. You can see this
clearly in the oscilloscope traces in Figure A and Figure B. The difference between these two voltages, Vx – Vb,
Figure A shows the peak voltage, Vb, on an electrode determines if a touch (or release) event is generated.
when C = Cb, and Figure B shows the smaller voltage, Vx, Once a touch event is detected, it is published over an I2C
when the electrode is touched and C = Cb + Cx. serial interface.

30 July/August 2018
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 31

where particular notes can be found. Being a MIDI


Table 2
instrument, a small software change allows you to
tune the lyre however you want, and I will indicate MIDI Lyre Default Tuning
how to do this later. For now, I’ll describe the default String 0 1 2 3 4 5 6 7 8 9 10 11
tuning.
Note G A B C D E F G A B C D
The MIDI lyre is a diatonic instrument. It’s tuned
according to a C Major scale with no sharps or flats, Color Red Blue Red
i.e., the white notes on the piano keyboard. Diatonic
tuning is very common for both lyres and harps
and is particularly common for folk instruments. Table 3
Diatonic instruments are easy to play because it’s C Major starting on… Mode Scale
impossible to play a “wrong” note that is not in C Ionian CDEFGABC
whatever scale they are tuned to. The tuning of D Dorian DEFGABCD
the 12 strings of the MIDI lyre is shown in Table
E Phrygian EFGABCDE
2.
F Lydian FGABCDEF
String 0 is G and therefore a C Major scale
starts on string number 4 as shown in Table 2. G Mixolydian G A B C D E F G (the MIDI lyre)
For any musical theorists, this puts the MIDI lyre A Aeolian A BCDEFGA
in Mixolydian mode (like the mountain dulcimer) B Locrian BCDEFGAB
because although it is tuned to a C Major scale,
the strings actually start at G. One end of the wire is fastened in the terminal block
You get a mode by playing a C Major scale beginning and the other end plugs into the breadboard at the
on different white notes as shown in Table 3. The normal appropriate MPR121 pin. The MPR121 breakout board
C major scale happens to be Ionian mode. has 13 pins down one side. The first pin is GND (don’t
Now let’s mark some notes. Take some red insulating connect this to anything); then we have pins labelled 0 to
or masking tape and wrap it around the top and bottom 11 that are the touch sensor electrodes. Connect string 0
of strings 3 and 10. This marks the C notes. Next, take to pin 0 and so on.
some blue tape and wrap it around the Everything should now be
top and bottom of string 6. This marks connected correctly. A completed MIDI
F. lyre with electronics and strings is
This is a standard way of marking shown in Figure 7. Check your wiring
the strings of a harp or lyre because it again, and then you can program the
tells you where you can find lots of Arduino Uno.
useful notes:
Programming
1. The red strings are the tonic, C.
2. The string before the blue string the Uno
is the third, E. If you haven’t used an Arduino
3. The blue string is the fourth, F. before, I suggest you go to the Arduino
4. The string after the blue string is home page at https://www.arduino.cc
the fifth, G. and do a little reading. In particular,
take a look at “Resources/Getting
You can see that the thirds and Started” for instructions on how you
fifths are either side of the blue string; program the boards.
this makes it very easy to find the C Arduino boards are best
Major chord, CEGC. programmed using the new online web
Now that you have “strung” the editor. Connect the Uno to your
lyre, you can connect the strings to the computer via USB and go to the
MPR121. Arduino Home at
Connect each string to the https://create.arduino.cc. Select
appropriate pin of the MPR121 using “Arduino Web Editor.” The web editor
30 cm male-to-male Dupont jumper should open and automatically detect
wires. These usually come in ribbons of your board. If not, select it from the
40, and the best way is to break off two ■ FIGURE 7. The completed drop-down menu. Go to Examples/Built
ribbons with six wires in each. MIDI lyre. in/01 Basics and load and run Blink.
July/August 2018 31
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 32

This is like a “hello world” for the Arduino. scale or even a chromatic scale (after all, there are 12
If Blink runs okay, then you’re in business. If it doesn’t, strings!). The current limitations of the software are that
then there may be something wrong with your setup or there must be zero or more semitones between each
the Uno board. There is plenty of documentation and help string, and each semitone is of equal size according to
available on the website. normal Western tuning, which is 12-tone equal
You can find the software for the MIDI lyre with the temperament (i.e., 12 semitones in an octave where each
article downloads. Grab the file and import it into the web semitone is the same size).
editor using the Import button. From there, you can The software could easily be modified to play in
upload it to the Uno. Once it’s uploaded, connect the lyre different temperaments by sending MIDI pitch bend
to your MIDI instrument. If you touch and release a string, messages with each note. However, this is something for a
it should play something. follow-up project. If you’re interested in non-standard
temperaments, then you should check out Scala at
Warning: If you have your MIDI instrument connected www.huygens-fokker.org/scala.
while you are uploading the software, odd things will
happen! This is because on the Uno the same serial port Operation and Testing of
is used for MIDI and for USB. Therefore, to prevent
spurious MIDI messages, always turn off or disconnect the MIDI Lyre
your MIDI instrument before uploading software! When you power-up the lyre, the Uno’s built-in LED
will flash 25 times. Do not touch the strings during this
If you take a look at the software, you’ll see that there time because the MPR121 is calibrating itself against
are three global variables that you can customize. The first background capacitance (no touch)! If the LED never
variable is tonic. This sets the key in which the lyre is stops flashing, then you have an error communicating with
tuned, according to Table 4. the MPR121, and you should check all your wiring.
Once the LED has stopped flashing, you can connect
Table 4 your MIDI instrument if you have not already done so. If
Tonic 0 1 2 3 4 5 6 7 8 9 10 11 you touch and release a string, the instrument should play
C# D# F# G# A# a note.
Key C D E F G A B Remember that the MIDI lyre does not send Note Off
Db Eb Gb Ab Bb
messages. Therefore, if you select a voice that has infinite
The next variable is octave. As you might expect, this sustain, the note will just continue to play.
sets the octave in which the lyre will play. You can see The lyre only works with voices that die away
how it is manipulated by the Octave Up and Octave naturally, such as piano, guitar, any plucked instrument, or
Down buttons in the corresponding octaveUp( ) and tuned percussion such as tubular bells or gamelan.
octaveDown( ) functions. If you have installed the Octave Up and Octave Down
The default octave is 5, which is a nice treble range, buttons, pressing Octave Up will take the lyre up one
but, for example, you could instead default to a bass octave; pressing Octave Down will take it down one
instrument by setting the octave to 3 or 4. octave.
Finally, we have an integer array called There are two important points to note about this:
majorScaleOfsets[ ]. This controls the pitch of each string Firstly, not all voices work well at every octave; and
relative to the tonic. Each integer in this array is the secondly, changing the octave affects the next note to
number of semitones that a string differs from the tonic. In
the default tuning of the lyre, the tonic is C which is on
string number 4 (remember that the strings are numbered Resources
https://create.arduino.cc
from 0 to 11 to match the MPR121 electrodes). So, we The Arduino Web Editor.
www.midi.org
have: The MIDI Association.
Everything about MIDI. www.huygens-
majorScaleOfsets[ 3 ] = 0 fokker.org/scala
https://learn.adafruit.com/a Scala software for non-
dafruit-mpr121-12-key- standard temperaments.
String 0 is the first string; this is tuned to the G below capacitive-touch-sensor-
the tonic, so majorScaleOfsets[ 0 ] = -5, because G is five breakout-tutorial/assembly https://learn.adafruit.com/a
Details on the Adafruit dafruit-mpr121-12-key-
semitones below C. capacitive-touch-sensor-
MPR121 breakout board.
You should now be able to see that by changing the breakout-
values in majorscaleOffsets[ ], you can completely change https://www.arduino.cc tutorial/downloads
Everything about the Adafruit MPR121
the scale of the MIDI lyre. datasheet.
Arduino.
For example, you might change it to play in a minor
32 July/August 2018
Arlow - MIDI Lyre - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:22 PM Page 33

play, not the one that is currently package it all up in some way so
playing. that it’s easy to transport and play.
Playing the MIDI lyre is done There are any number of ways
with a plucking type of motion that you can do this, and provided you
is a quick touch and release. If you still have access to the strings,
touch a string, it will not sound until buttons, and ports, you can
you release it. Touch sensor package it as you choose.
reliability can depend quite strongly I like to make the instrument
on skin resistance, so if you have look like a lyre. The easiest way to
particularly dry skin, you might find achieve this is to mount the
that your touch is not always instrument on a U-shaped piece of
detected. MDF, Perspex, or ply as shown in
To solve this problem, you may Figure 7. I find 6 mm is a good
need to moisten your fingers thickness for the sheet material
slightly before playing. In fact, it’s because it’s rigid enough without
quite useful to keep a damp sponge being too heavy. My MIDI lyre is
or towel next to you while you play. shown in Figure 7.
You can play single notes or chords I call this a “skeleton lyre”
because the instrument is fully because I keep the electronics
polyphonic. exposed so I can easily experiment
The other way to play the lyre and make changes. For a more
is to strum it by dragging your robust instrument, you can cover
fingers across several strings. The the electronics apart from the
instrument works very well in this buttons and ports.
mode. (In a future article, I’ll The shape I have chosen is
describe a simple modification that ■ FIGURE 8. Plans for the MIDI lyre roughly based on the Saxon lyre
frame that are loosely based on the
turns the MIDI lyre into an Sutton Hoo Saxon version. from the seventh century C.E. that
autoharp for playing strummed was found in a burial site at Sutton
chords.) Hoo, England.
Figure 8 shows the plans for this instrument if you’d
Putting It All Together like to copy it. NV

Now that you have a working MIDI lyre, you need to

Your Single Source of Electronic Equipment, Tools, and Components

01DM820B 01DMMY64 01DMM9803R Sweep Function Generator


Digital Multimeter Digital Multimeter Bench DMM 3MHz, 6 Waveform Functions, Int/Ext Counter,
Super Economy 32 Ranges True RMS lin/log sweep
DMM - Volts, current, Including temperature, Auto and manual Model FG-30 $135
Resistance, Trransistor capacitance, frequency range, RS232C (no display)
and Diode Teest. and diode/transistor standard interface. Model FG-32
Includes Leads $7.50 testing Runs on DC or AC $139.95 $195
$29.95 (5 digit display)

01DS1102E 01SDS1052DL DC Power Supplies


100MHz Rigol Oscilloscope Siglent 50MHz DSO Model HY3003
Variable Output, 0-30VDC,
Features: 1 million points of 500MSa/s Sampling 0-3Amp. $95
deep memory, FFT, record 32K M
Memory
and replay, roll mode, alternate trigger mode, and 6 Digit
g Frequency
q Cou
Counter Model HY3003-3
I t face
USB Inter f Tw
wo 0-30VDC, 0-3Amp Variable
adjustable trigger sensitivity
$399 7” Color TFT T--LCD Screen $279 Outputs plus 5V 3A fixed. $195

Parallax Board of Education Full Kit BOE Full Kit $98.90 0603ZD98
48W Soldering Station
USB version with Stamp and USB Cable. Parallax 7.5V Power Supply $8.95 Temp.
em Controlled
e
310oF~840oF $15.25

1 (800) 972-2225 | http://www.elexp.com | contact@elexp.com


July/August 2018 33
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 34

BUILD IT YOURSELF
By David Goodsell

BUILD YOUR OWN


FUNKY STEAMPUNK

DISPLAY

I use LCD displays in almost every project. They are perfect for displaying data about
voltage, current, time, frequency, wind speed, rainfall, etc. However, in this modern
age of steampunk, I stumbled on something much cooler.
34 July/August 2018
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 35

Post comments on this article and find any associated files and/or
downloads at www.nutsvolts.com/magazine/issue/2018/07.

I found a number of vendors on eBay who were


selling surplus 1” high seven-segment
electromechanical displays (EMDs) that go clickity
click (see Figure 1). The segments appear and
disappear in the blink of an eye when the tiny coils
are pulsed. They aren’t quite as fast as LCDs, but
they can add a whole new dimension to your
project: sound! (Check out my YouTube video at
https://www.youtube.com/watch?v=inIxU27QgN0.)
Many months ago, I embarked on an ambitious
project that featured five 1941 vintage rotary
telephone step-by-step (SXS) switches. I thought
these little EMDs would be the perfect match to
display the dialed digits; refer to Figure 2. So, I
ordered a dozen from a guy in Hungary and the rest
is history. You can see nine of them mounted in a
line under the SXS switches.
■ FIGURE 1. The seven electromagnetic coils are driven by
25 ms bipolar pulses that flip the segments on or off.
Reinventing the Wheel
The displays didn’t come with drivers and I couldn’t I learned a few things along the way, and it was a
find a commercial source. I saw a reference to a 40-pin rewarding experience to design and build the PCB
FP2800A decoder/driver IC but it was no longer available, (printed circuit board) drivers using tiny SMD components.
so I decided to build my own. Maybe I missed something,
but it wouldn’t be the first time I set about reinventing the ■ FIGURE 2. My step-by-step vintage 1941 telephone
wheel. switch demonstrator uses nine displays to show the
numbers dialed.

July/August 2018 35
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 36

■ FIGURE 3. The
stack of boards
includes an
ATtiny2313 µC
and four TB6612
dual motor
drivers to decode
and flip segments
A-G.

cases. So, I made


each one an
independent unit
with three stacked
boards as shown
in Figure 3.
They also had
to be front-
mountable in
rectangular holes
Perhaps you can find an application for these funky little in a panel — much like mounting LCD displays.
displays and have as much fun building with them as I did. Lastly, they had to accept two types of inputs: a
totalizing pulse input (1-10 pulses) from a relay contact or
The Requirements telephone dial; and a daisy-chained SPI data/clock input
that was addressable from a host microcontroller.
My requirements were simple. Each display had to be The plan was to build a total of nine daisy-chained
a stand-alone unit with its own driver. I needed them to be displays for the telephone project. Figure 4 shows the
physically located at different positions in the telephone completed three-board assembly, with six daisy-chained
project, which didn’t lend itself to grouping them in most wires going in and out.

Let’s Get Started


This article will describe how I designed and built the
drivers and some of the problems I encountered.
The first task was locating a suitable bi-directional
driver for each segment, like an H-bridge. I found
references to a 40-pin FP2800A IC that could drive
multiple digits, but I never could find a source. Besides, I
really wanted something smaller since I wanted the digits
to be independent and compact.
If the displays were to be used for something else like
a clock, they could all be mounted on a longer PCB and
there would be plenty of room for an FP2800A (if you can
find one).
After more research, I finally settled on the Toshiba
TB6612 which contains two motor drivers and is normally
used to control small DC motors. However, I blanched
when I saw it only came in a tiny SSOP package. I had
used many SMD parts in the past but never any with a

The full link to eBay for the individual seven-segment


electromagnetic displays for $9 from Hungary is:
https://www.ebay.com/itm/7-segment-1-Ferranti-
■ FIGURE 4. Multiple displays can be daisy-chained Packard-electromechanical-
together to respond to SPI generated addresses and display/160945344354?epid=1848339022&hash=item257
digits. 9170f62:g:36cAAOSwzrxUtXEM
36 July/August 2018
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 37

0.025” pitch. All I could picture was a mess of


solder bridges!
Luckily, Adafruit carried TB6612 breakout
boards for $4.95 each, which I could use to
breadboard up the circuit. Figure 5 shows two of
the four boards I acquired.

Breadboard Stage
I like to start with a breadboard before I commit
to a PCB because of several painful experiences in
the past. The breadboard consisted of four TB6612s,
some inverters, and an ATtiny AVR chip to do the
decoding and pulsing. Figure 6 is the schematic of ■ FIGURE 5. I used four of the Adafruit TB6612 motor driver
the final unit, but the breadboard was very similar. boards for a breadboard before committing to a PCB.
Amazingly, it worked the first time. I had not
mis-wired a single segment. However, just as I was a 3K resistor and kept it low, except during the 25 ms
congratulating myself, I said “What’s that smell? pulses. Problem solved. Whew!
Something is burning! (BTW, in my video on YouTube I mentioned applying
The spec sheet for the displays emphasized that the a 250 ms pulse. Not so! 25 ms is the correct duration.)
segments should not be pulsed more frequently than 900
ms because the coils would overheat. I had programmed Counting Dial Pulses
the Tiny to wait the correct interval but as I moved several
wires on the breadboard (without turning off the power?), and SPI
I inadvertently let the TB6612 standby pins float high for a A properly adjusted normally-closed rotary dial
minute or so. Several coils got really hot and almost operates at 10 pulses per second (PPS), 60 ms open, 40
burned out. ms closed. Dialing “O” generates 10 pulses and would
From then on, I pulled the standby line to ground with display a zero. I set up the program to tally the pulses until

■ FIGURE 6. The schematic shows that each


assembly can accept pulses from an NC contact or
one byte (addr+data) via the daisy-chained SPI lines.

July/August 2018 37
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 38

the dial was done rotating, and after ■ FIGURE 7. I successfully soldered
detecting a “missing pulse” it would the SMD components with a chisel
send the total to the display. It took a tip iron, 0.015” solder, and flux pen.
whole day of hair-pulling to get this
supposedly simple routine to work
correctly. board, and MicroC board. They are
I also wanted the Telephone interconnected via headers, with a
System Processor (Arduino Mega little air space between them for
2560) to be able to talk to each cooling. I used ExpressPCB because
display via an SPI link (Data & Clk). their boards have been very accurate
The Mega would serially transmit in the past and cost-effective for small
eight bits over the daisy-chained lines jobs. The layout software was free and
to all nine displays. The high nib easy to use. The file for the boards is
would be the address (0 to 15) and with the article downloads.
the low nib would be the character to Regarding the layout, I was
display (0 to 9 and six special pleasantly surprised that the four
characters). driver chips would fit on one board.
Actually, it was super easy The chips have a ton of pins, but with
because both the Mega and Tiny had a two-sided board you can do
ready-to-use SPI routines. Although, I wonders. The design also required
had to slow down the Mega SPI seven inverters but the normal
transfer rate quite a bit to get reliable 74XX04 only had six.
data from the Mega port to the EMD So, I added a simple transistor
Tinys because the pulses had to go through buffers, high inverter on the breadboard. Just by luck I stumbled on to
speed opto-isolators, and 40” of twisted pair cable to get the perfect chip to replace the transistor in the final
to the farthest EMD. The received signal was a mess at the design. It was a 74HCT1G04, which had five pins and
higher rates and required a scope to track down a contained a single 74XX inverter. Six + one = seven. How
readable waveform. nifty! I happily added it to the back of the driver board
and ordered the first set of three PCBs.
PCB Design Two days later they arrived. SEMI-DISASTER! The new
single-inverter chip was left-right reversed on the board! I
I settled on three stacked PCBs: a coil board, driver had forgotten to reverse the pins when I mounted it on
the backside. I had to
ITEM DESCRIPTION DIGI-KEY laugh.
(unless noted otherwise) However, I saved
C1, C4-10, C13-15 0.1 μF, 25V, Capacitor, 0805 399-1168-1-ND the board by swapping
C2, C3
C11, C12
10 μF, 25V, Capacitor
0.47 μF, 16V, Capacitor, 0805
478-5257-1-ND
478-1403-1-ND
PARTS the inverter’s pins with
some wirewrap wire. I
R1, R4, R5, R7
R2, R3
10K, Resistor, 0805
3K, Resistor, 0805
311-10.0KCRCT-ND
311-3.0KARCT-ND
LIST corrected my mistake
R6, R8 470, Resistor, 0805 311-470ARCT-ND on the next order of
R9, R10 2K, Resistor, 0805 311-2.00KCRCT-ND boards.
D1, D2 1N4148, Diode, SOD23 1N4818WTPMSCT-ND
Q1 5V Regulator, 100 ma, SOT223 NCV4264-2ST50T3GOSCT-ND
U1 74HCT04, Hex Inverter, TSSOP 1727-4085-1-ND Drag
U2-U5
U6
TB6612, Dual Motor Driver, SSOP
74HCT14, Inverter, Schmitt, TSSOP
TB6612FNGC8ELCT-ND
296-8395-1-ND
Soldering
U7 ATtiny2313, MCU, 8-bit, SOIC ATTINY2313-20SURCT-ND A friend suggested
U8 74HCT1G04 Single Inverter, SSOP 1727-6051-1-ND a website that explained
LED1 LED, Red, 1206 1830-1092-1-ND
H1, H2, H3, H5, H6 Headers: 1,3,7,7,7 pins (25 pins total) S1232E-36-ND how to “drag-solder”
H4, H7, H8 Headers: 3,3,7,7 pins (20 pins total) 3M156862-36-ND fine-pitch ICs. The
PCB Printed Circuit Boards; set of 3 ExpressPCB, custom YouTube link is
DISP1 Seven-Segment Electromagnetic Display Ebay, see link in article 6PB0u8irn-4. I’m sure
SW1 Tactile Pushbutton, SPST, NO CKN10741-ND
TOOL1 Flux Pen KE-1803, Kester this technique is old hat
TOOL2 AVR Programmer/Debugger ATATMEL-ICE-BASIC-ND to lots of folks but it
or AVRISP mkII (Ebay) was new to me.
TOOL3 Atmel Studio 7 IDP Microchip Alas, there was
38 July/August 2018
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 39

hope of not botching the job. On the video, I also


learned about using flux pens which made the
solder flow perfectly.
As I soldered the driver ICs, I got better with
each chip but still had a long way to go to match
the finesse in the video. Figure 7 shows me
slaving over a hot iron, happy as a clam.
Additional closeup photographs of the fronts
and backs of the final populated PCBs are shown
in Figures 8 and 9.

Programming the
ATtiny2313
I chose to program the ATtiny2313 in
assembly using Atmel Studio because I had used
the same chip in another recent project. The only
tricky part was the “missed pulse” section that
■ FIGURE 8. Front view: The six-pin ISP programming
locked in the dial count when the rotary dial connector is in the upper right of the right MicroC board.
finished turning. The rest was easy.
Actually, if you just want to use SPI to talk to
the displays, a smaller chip could probably be
employed, including PICs. The assembly program
is available with the article downloads.
To program the µC, two different Atmel In-
System Programmers (ISP) are available. The
AVRISP mkII is obsolete but still available on eBay
for about $50. The current AVR
programmer/debugger from the manufacturer is
the ATATMEL-ICE for $91. In both cases, when the
chip is being programmed, it has to be powered-
up by a separate 5V supply.
That concludes my description of the design,
construction, programming, and operation of the
EMDs. However, I’d like to say a few more words
about my “ambitious” telephone project, in case
anyone is interested.
■ FIGURE 9. Rear view: The five-pin single inverter chip (U8) is
located on the back of the left driver board, in the lower right.
So, What’s this
Telephone Project electronic switching gradually took over. By the 1990s, the
all About? SXS switches were completely phased out.
In days gone by, telephone operators manually routed This brings us to my vintage step-by-step switching
the calls by using switchboards with plugs, jacks, lever system. I embarked on the project — called a Private
switches, and lots of wires. It was labor-intensive, but nice Branch Exchange (PBX) — because when I was a kid I
to hear the operator say “Number Please?” went on a field trip to the telephone company and the
In 1891, a man named Strowger envisioned an rows and rows of clicking SXS switches left a lasting
electromechanical system to replace the operators. The impression on me. With the advent of eBay, it’s much
end result was the rotary dial which selected the number easier to find old telephone equipment.
to call, and electromechanical step-by-step (SXS) switches I bought the five SXS switches from a guy on the east
to automatically route the calls. coast. I built a sturdy frame for them and added a ton of
Soon, the Central Offices were filled with thousands electronics, displays, relays, switches, lights, power
and thousands of clicking step-by-step switches, and supplies, and an Arduino Mega to make them do some
operators were only needed for long distance calls. Over fun things.
the years, improvements were made to the switches, but A photo of the backside of the PBX with its numerous
July/August 2018 39
Goodsell - Steampunk-Electromechanical Display - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 4:42 PM Page 40

■ FIGURE 10.
The back of the
telephone
demonstrator
contains
numerous
subassemblies,
relays, and a blue
Arduino Mega
2560 system
controller.

subassemblies is
shown in Figure
10.
In operation,
my PBX can pulse-
dial and ring the
touch-tone phone
(#54321).
It can connect
to an outside line
by dialing 9, then
dial up any
number in the
world, including cell phones. Plus, I used the Arduino
Mega to add a six-number auto-dial memory function
Introducing the much like modern phones.

NEW PV Jr.
Finally, it has a secret “Spirit of the Telephone” hidden
inside the circuitry that randomly replays Alexander
Graham Bell’s first call in 1876, and a comedic routine by
our favorite TV operator, Lily Tomlin.
Mini Circuit Board Holder I’m not alone in my fascination with old telephones.
There are two major groups — Antique Telephone
Collectors Association (ATCA) and Telephone Collectors
International (TCI) — whose members have constructed
DESIGNED much more elaborate (by a factor of 100) step-by-step
switching systems in their garages and basements. These
FOR OVER folks are really serious about vintage telephones and
telephone equipment.
THE EDGE
COMPONENT Afterthoughts
BOARDS Hopefully, other innovative experimenters will find
Model applications for these funky displays and devise alternate
220 schemes to drive groups of them, which may cut down on
the number of components.
In the meantime, just remember, steampunk rules!
NV
Innovative H olldi
o din
Holdingngg SSolutions
olutio
olutiio
ut ons
n

800-759-7535

40 July/August 2018
Romi
Versatile robot platform with
integrated battery compartment,
Balboa motors, and wheels; several
add-on board options available
Programmable balancing
robot kit that can stand
itself up and drive
around on two wheels

...and more
Everything from Zumo
mechanical parts and Complete integrated Mini
jumper wires to motor Sumo robot on a tracked
drivers and voltage chassis, featuring a
regulators variety of sensors

Finding the right parts for your robot can be difficult, but you also don’t want to spend all
your time reinventing the wheel (or motor controller). That’s where we come in: Pololu
has the unique products—from A-Stars to Zumos—that can help you take your robot from
idea to reality.

Find out more at www.pololu.com

Full Page.indd 41 4/9/2018 3:56:31 PM


Dorward - USB Cable Tester - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 5:28 PM Page 42

BUILD IT YOURSELF

BUILD A USB By Don Dorward VA3DDN


Post comments on this article and
find any associated files and/or

CABLE CONTINUITY
downloads at www.nutsvolts.com/
magazine/issue/2018/07.

TEST JIG
If you’re like me, you likely ■ FIGURE 1.
have a drawer or shoebox
stuffed with assorted USB
cables that are used to
either charge or program a
USB device. The problem
often is that some cables
may only be useful for
charging, and which only
have the +Vcc and ground
wires intact with one or
both data wires either
broken or not connected in
the first place.

How do you tell? B, and fastened them to a small piece of wood.)


Figure 1 shows a simple test jig that will make it easier Simply plug in your questionable cable to the
for you to quickly check the continuity of a four-conductor appropriate mating female connectors on the test jig as
USB cable. The only parts needed are two (or more) shown and use an ohmmeter to check continuity by
“breakout” boards with female USB receptacles to match probing matching pin numbers on each breakout board.
the ends of the USB cable you want to test and something You can also verify the interconnection of pins 4 and 5 on
to mount them on. an OTG cable (see sidebar).
(I used the USB type A, USB Micro-B, and USB Mini- As an after-thought, I added the simple LED continuity

What does OTC mean? ■ FIGURE 2.


OTC is short for “On-The-Go.”
OTC USB cables are made with five pins at the Micro or
Mini end instead of four. The extra pin (#4) is sensed by OTC
capable Android devices to allow them to communicate with
peripheral devices such as USB storage, keyboards, etc.
This pin is marked as “ID” on the breakout boards and is
usually connected directly to ground pin 5. This is easily
verified using the USB cable checker.
42 July/August 2018
Dorward - USB Cable Tester - Jul-Aug 18_Blank Project NV.qxd 6/12/2018 5:37 PM Page 43

checker shown at the top of Figure 1. It consists


of just a lithium-ion coin cell like a CR2032, a
blue LED from my junk box, and some jumper
wires. It’s much easier to use than a multimeter.
The schematic is shown in Figure 2. The
circuit can be built on a small piece of perfboard.
A strip board layout is shown in Figure 3.
A quick note on the coin-cell holder. I used a ■ FIGURE 3.
vertical holder because I had one. However,
horizontal mounted holders may be
more common, although they take

ALLELECTRONICS.com
up more space.
I hope you find this test jig
handy. NV
Surplus & New Parts & Supplies since 1967
Order Online or Toll Free 1-800-826-5432
The little breakout boards are
available from suppliers such as AC POWER CORD WITH 6 VDC, 25 RPM GEAR MOTOR
SparkFun. SparkFun part numbers
INLINE ROCKER SWITCH New gear head motor
prepped with an arm
are as follows: that rotates an offset axle
in a 1" circle. Motor is
• Type A USB: BOB-12700 1.45"D x 3.00"L. No-load specs: 25RPM @
6Vdc, 150mA. Prepped w/ wire leads and
• Micro-B USB: BOB-12035 70" power cord with on-off rocker switch
drive arm. Includes a custom mounting
mid-way. Black SPT-2 18 AWG zip cord
• Mini-B USB: BOB-09966 bracket and slotted metal link rod.
rated 300V, cULus. $
• Jumpers F/F: PRT-11710 or CAT# LCAC-456 250each
CAT# DCM-470
$ 75 10 for $4.25 each
12796 100 for $1.85 each 4 each 100 for $3.75 each

4MM BLUE OVAL LED 4-POSITION PC MOUNT


TERMINAL STRIP,
Connecting an LED Cree # C4SMK-BJF. Very pretty, high-
brightness oval LED. 4mm aqua-blue dif- NUMBERED 1-4
Directly to a Li-ion fused lens in off-state. Darker blue when
lit. Rated: 3.2V, 20ma. 390-1520 mcd.
Two interlocking 2-position blocks,
numbered 1-2, 3-4. PC mount screw-clamp
Coin Cell 470nm. Large quantity available.
CAT# LED-270
terminals on 5mm (0.197") centers. Accepts
up to 14 AWG wire. Rated 10 Amps, 300
At first glance, you may 100 for 5¢ each
wonder why the LED doesn’t burn 10 75¢ for 1000 for 3¢ each Volts. Side wire entry - 10mm (0.40") high.
CAT# TER-404 100 for 20¢ each
out when connected directly
45 ¢each 500 for 15¢ each
across a 3V coin cell battery 20 X 2 LCD 1000 for 12¢ each
without the usual series current- W/ WHITE LED
BACKLIGHT Reduced Price 2" ALLIGATOR CLIP
limiting resistor. The main reason
Optrex# C51505NFJ-SLW-AIN. WITH SCREW
is that coin cell batteries like the Solid, spring-action clip with screw. 5mm
Viewing area: 83.0 x 18.0 mm.
CR2032 already have a built-in Overall size: 116.0 x 37.0 x 15.6mm cable access hole can connect to banana
plug test lead.
$3.15 for $ 00
internal series resistance (IR). This
IR may range from 10 to 50 ohms
CAT# LCD-165
10 for $2.50 each
$ 85
2 each
CAT# ALG-M 5 1
or higher as the cell discharges. 100 for 17¢ each • 1000 for 15¢ each
Also note that blue or white SMART PHONE MICROSCOPE VOICE RECORD /
LEDs are a good match to the WITH 30X MAGNIFICATION PLAY MODULE
battery, with Vfs of approximately Attaches directly to your smart phone Multiple-message record /
2.9V at 10 mA. If you use a red, enabling close-up viewing of small playback device offers
green, or amber LED whose Vfs objects. Easy to use - simply voice recording, non-volatile storage, and
position microscope lens over your playback capability for 8-20 seconds.
are lower (around 1.8 to 2.0 volts),
camera lens, turn on your camera Features on-board microphone and internal
it would be good practice to add app, and you're ready. Includes three audio amplifier which can drive an 8 Ohm
an external series resistor of 68 replaceable, button-cell batteries. $ $ 00
ohms. CAT# CPM-1 799
each
0.5W speaker directly.
CAT# ME-63 6 each

July/August 2018 43
Gualtieri - Inductor Winding - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:50 PM Page 44

Does Inductor
Winding Have
You Tied in
Knots?

While resistors and capacitors are easily


procured and stocked, most radio
frequency circuits require inductors in a
wide range of very specific values. In
most cases, you need to create these
Introduction
yourself, by winding wire on ferrite rods
Resistors are the most common passive
or toroids of specific types and sizes. Is it component on any printed circuit board
possible to substitute another ferrite (PCB), so it’s good that they cost just a little
more than a penny each. Up in price an
piece at hand and still get the right order of magnitude from resistors are
inductance value? How can a hobbyist capacitors, which are generally larger. Rare
— except in radio frequency circuits — are
measure inductance without buying an inductors which are generally much larger
expensive instrument? This article than the capacitors, more expensive, and
very hard to source.
describes the principle behind Probably not a lot of folks have likely
inductance and presents some tricks that seen a memristor — the fourth passive
component that completes the passive
I have used to make my own inductors. component family, as seen in Figure 1.
44 July/August 2018
Gualtieri - Inductor Winding - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:50 PM Page 45

By Dev Gualtieri, Tikalon LLC To post comments on this article and find any associated files and/or
(gualtieri@ieee.org) downloads, go to www.nutsvolts.com/magazine/issue/2018/07.

FIGURE 2. A simple air-core solenoid with its


magnetic field lines shown.

winding will induce a current in another. Note the


FIGURE 1. The four members of the passive similarity between the words, “induce,” and “inductance.”
components family: the resistor R; capacitor C;
inductor L; and the memristor M. The component
values are determined by their response to
The Solenoid
current i, voltage v, charge q, and magnetic flux f. The simplest inductor is a solenoid coil, which is just a
helix of wire with no core (Figure 2). Passing a direct
Practical examples of the memristor have been current through a solenoid creates a magnetic force; a fact
developed only in the last decade. discovered in the early 19th century.
A solenoid essentially stores the electrical energy of
History of Inductors flowing current in a magnetic field. When the core of the
solenoid is empty, this energy is stored in the physical
The unit of inductance is the henry, named after the vacuum, also known as free space.
American scientist, Joseph Henry (1797–1878). Henry Since air has a low magnetic permeability, much of
was the first to wrap multiple coils of wire around a piece the magnetic field potential afforded by applied currents is
of iron to create an electromagnet that was more powerful lost, so the inductance is smaller than when a magnetic
than a solenoid coil with no iron core. core is introduced (see Figure 3).
English scientist, Michael Faraday (1791–1867) — for If our solenoid coil is very long, it’s inductance L is
whom the unit of capacitance, the farad, is named — did easily calculated:
similar experiments at about the same time. Faraday
discovered that an alternating current in one transformer L = N2µ0A/ℓ

FIGURE 3. A solenoid
coil wrapped on a
ferrite core.

July/August 2018 45
Gualtieri - Inductor Winding - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:50 PM Page 46

where L is the inductance in henrys, N is the number of magnetic core can be moved into and out of a coil to
turns, µ0 is the permeability of free space (4π x 10−7 H/m), make a variable inductor.
A is the cross-sectional area of the coil in square meters, As an example that multi-layer coils closely follow this
and ℓ is the length of the coil in meters. This formula same equation, I measured the inductance of the 52-turn
applies only to long single layer coils, but it’s generally coil shown in Figure 3 and got 93 mH. When I put a
close for shorter coils and most multi-layer coils, as I’ll second layer of 42 turns over this, the inductance was 315
show later. mH. Scaling by the ratio of the square of the turns gives
If we wind a coil on a magnetic material (such as a us a calculated inductance of 303 mH, which is just a few
ferrite rod), the inductance is greatly increased (Figure 3). percent less.
That’s because the permeability of the core is much
greater than the permeability of free space. The magnetic Toroid
core concentrates the magnetic field lines inside the coil
where they have the greatest effect. Magnetic flux “leaks” out of each end of a short
Depending on the core material, the inductance solenoid coil, and that’s why the inductance equations
increase can be much more than a thousand, although given above are specified for the ideal case of an infinite
common radio frequency values range from about 200 for length.
VHF to 1,000 for lower frequencies. A simple fix for such leakage is to join the ends
The magnetic permeability of ferrite is large, so the together to create a toroid, as shown in Figure 4.
magnetic field lines are concentrated in the coil, thereby The inductance of a single layer winding on a toroid is
increasing inductance by a large factor. given as:
The inductance equation for such a coil is the same as
for an air-core coil multiplied by the relative permeability L = N2Kµ0A/2pr
K of the magnetic core:
which is our familiar equation with the length replaced by
L = N2Kµ0A/ℓ the unwrapped length of the toroid; that is, its
circumference at the midpoint, with the distance from the
The relative permeability is the ratio of the center of the circle to the midpoint being the radius r.
permeability to the permeability of free space. The Toroids offer a slightly greater inductance than short
solenoids for the same number of turns, since the
magnetic field lines are all contained inside the
core.

Ferrite Materials
While iron is a magnetic material, it doesn’t
make a good inductor core. That’s because it’s also
an electrical conductor, and the alternating currents
applied to a surrounding coil will lose energy by
heating the iron through induced eddy currents.
Think in terms of not putting metal objects into a
microwave oven.
There’s also the problem that the iron will
“saturate;” that is, become so charged with a
magnetic field that it can’t be made to magnetize
further.
There are various ways around this problem;
one of which is to load the iron with silicon to form
a steel alloy that’s less conducting, and to form the
core from thin sheets that are insulated from each
other. This is the method used to make cores for
most low frequency transformers. Another is to
make the iron into a fine powder and encapsulate
each grain.
At radio frequencies, we need a better material
FIGURE 4. An inductor wound on a toroidal ferrite core. than iron or steel; one that won’t saturate and is an
46 July/August 2018
Gualtieri - Inductor Winding - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:50 PM Page 47

insulator. Fortunately, materials


scientists have discovered oxides of
iron and other metals that satisfy
these requirements. They are called
ferrites, since they are based on the
oxide, Fe3O4, called ferrite.
In most cases, some of the iron
(Fe) is replaced by other metals;
notably manganese, zinc, and
nickel.

Quality Factor
You can’t wire your house with FIGURE 5. An op-amp gyrator circuit. RC forms a phase-shifting
small diameter wire since the wire circuit, and the simulated inductance is proportional to this phase
shift. The resistor RL must generally be at least a few hundred ohms
resistance is too high; you’ll get a for most op-amps, so the inductor Q is limited.
voltage drop across that resistance.
Too small a diameter wire will
likewise diminish the effectiveness of an inductor, which only at low frequencies, so gyrator inductors will only
ideally should have zero resistance at low frequencies. work at low frequencies. As can be seen in Figure 5, the
The quality of an inductor — known as its Q — is a simulated inductance has one terminal grounded, so this
measure of how well it acts as a perfect inductor at a limits the types of circuits in which gyrator inductors can
given frequency F: be used.
Also, the inductor resistance RL must be reasonably
Q = XL/R = 2pFL/R large since op-amp inputs have limitations. RL must
generally be at least a few hundred ohms for most op-
where XL is called the inductive reactance (essentially, the amps, so the inductor Q is limited.
“AC resistance”) which is equal to 2pFL. The Q factor
effectively shows how much better an inductor is at Litz Wire
responding to alternating current than direct current. It
also shows how narrow a band-pass filter you can build The “skin effect” is the tendency for high frequency
from an inductor and capacitor. currents to preferentially flow near the surface of wire. In
effect, the middle portion of the wire is wasted conductor at
Gyrators high frequencies; when you’re winding an inductor, you end
up with a higher resistance for the same number of turns.
Inductors and capacitors are complementary devices. An easy way around this is to use Litz wire, which is a
Capacitors pass high frequencies while blocking low multi-stranded single-conductor wire. Litz wire allows a
frequencies. A capacitor’s ability to block direct current is parallel combination of smaller wires that mitigates the
one of its most important functions. skin effect.
An inductor quite differently
passes low frequencies and blocks
the high frequencies.
There’s an electrical circuit called
a gyrator that uses a capacitor to
make a simulated inductor. Gyrators
are built around an amplifier. They
can be implemented using active
components, including transistors,
but it’s most common to use an
operational amplifier (op-amp) as
shown in Figure 5. Gyrators can be
used to simulate huge values of
inductance, but they have a few FIGURE 6. A resonant parallel combination of an inductor and
limitations. capacitor driven by a signal generator and monitored by an
Op-amps generally work well oscilloscope.
July/August 2018 47
Gualtieri - Inductor Winding - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:50 PM Page 48

The resonance of the


parallel LC circuit will be
FIGURE 7. apparent by a peak in
Frequency response the voltage on the
of a resonant oscilloscope as the
parallel frequency is changed
combination of the
toroidal inductor (Figure 7).
shown in Figure 4 You don’t need to
and a 0.01 μF carefully graph the
capacitor. response (as in the
figure) if you’re just
interested in the
resonance frequency.
The capacitor had a
±5% tolerance, so the
calculated inductance
could be accurate only to
±5%. If you have access
to a capacitance meter,
you can do better.
To determine the
inductance, just parallel it
with a known
capacitance and plug the
values into the equation.
The one caveat here
is that capacitor values aren’t exact; they have a tolerance.
Measuring Inductance The 0.01 µF capacitor that I used in the measurement
shown in Figure 7 had a tolerance code J, which specified
Digital multimeters that measure resistance, voltage, a not-ideal ±5%, but better than most.
and current can be purchased at very low cost, and This means that the calculated inductance can’t be
hobbyists typically have at least one of these in their tool any better than this. Some common capacitor tolerance
chest. Inductance meters are more unusual and usually codes are shown in Table 1.
more expensive. Reworking the resonance equation to give inductance
I don’t have an inductance meter, but I do have a yields the following:
signal generator and oscilloscope (as most dedicated
hobbyists have), so I use a resonance technique to L = 1/(4p2L2F2)
measure inductance (Figure 6).
A parallel combination of an inductance and Based on the capacitor value of 0.01 µF and the
capacitance is often called a tank circuit by old-timers observed resonance frequency of 72 kHz, the inductance
since these circuits were often immersed in a tank of for the coil shown in Figure 4 was 492 µH.
insulating oil in high power transmitters. Plugging in values for the toroid relative permeability
Such a circuit will resonate at a characteristic of 1,000, its cross-sectional area, radius, and number of
frequency F given by: turns into the toroid inductance equation gives 476 µH, or
a deviation of about 3% — consistent with the capacitor
F = 1/(2p(LC)-1/2) tolerance.

Table 1: Capacitor Tolerance Codes.


Conclusion
F ±1%
G ±2% Winding inductors can be an easy task when you
know a few simple equations and measurement
J ±5%
techniques.
K ±10% Now that you know the basics, the Internet is a good
M ±20% resource for further information. NV
48 July/August 2018
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 49

Vintage Computing
Amigo Color BASIC —
The Missing Manual
By Dane Weston
The original online daneweston15@gmail.com

T
documentation for
the Amigo retro he commands not covered previously include Color BASIC bitwise operators,
computer was SRAM commands, access to the hardware counter registers on one Parallax
intended to help Propeller cog, and a few odds and ends. The tips include a map of screen
readers mentor memory that allows direct read or write access to the Amigo display, and how to
youngsters on build your own hardware “shields” for your Mentor’s Friend. I hope you and a
young protégé can use this additional data to add some zest to your Amigo
computer adventures!
programming
fundamentals. It also Bitwise Operators
included an
“overview of most Let’s begin with the bitwise operators. Color BASIC implements some of the
Color BASIC bitwise operators found in Propeller Assembler and Spin without elaboration or
complication, and you and your Amigo may find them useful in addressing some
commands.” A programming tasks.
couple of astute As shown in Figure 1, these bitwise operators include shift left (SHL), shift
readers working right (SHR), rotate left (ROL), rotate right (ROR), arithmetic shift right (SAR), bit
beyond introductory reverse (REV), bitwise logical and ( & ), and bitwise logical or ( | ).
mentoring have Depending on your background and experience, each of these operator’s
functions may or may not be intuitive. For me, the easiest way to understand
asked me about the them is just to try them out and see what happens. The code snippet that
full command set. follows (available with the downloads as BINARY.BAS) offers one way to do this,
This article covers and illustrates a couple of the bitwise operators in the process:
those “missing”
5 REM ——- BINARY.BAS ——-
commands, plus a
10 CLS
couple of tips and 20 PRINT “ “: INPUT “Expression to Convert to Binary? “;n
tricks that Amigo 25 PRINT “N = “;n
owners may find 30 PRINT “N = %”;
helpful. For 40 GOSUB 500
reference, you can 50 DISPLAY 13,13: PRINT “Again (Y/N)?”
60 a=INKEY
find the complete 70 IF a=0 THEN GOTO 60
Color BASIC 2.2L 80 IF a<>”N” AND a<>”n” THEN GOTO 20
command set with 90 PRINT “ “: PRINT “Bye!”
the article 100 END
downloads. 495 REM ——- Bit Mask / Print ——-

July/August 2018 49
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 50

Vintage Computing
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

500 m=1 SHL 31 REM <— Look at MSB First


505 FOR i=0 TO 31
510 r=m & n REM <— Apply Single Bit Mask
515 IF r THEN PRINT “1”;: GOTO 525
520 PRINT “0”;
525 m=m SHR 1 REM <— Slide Mask One Bit Right
530 NEXT i
535 RETURN

Operation Action Performed

Shift Left. Shifts each bit in a, b times to the


a SHL b left. Bit 31 (the most significant bit) is
discarded each shift, and bit 0 is set to zero.
Shift Right. Shifts each bit in a, b times to the
a SHR b right. Bit 0 (the least significant bit) is
discarded each shift, and bit 31 is set to zero.
Rotate Left. Shifts each bit in a, b times to the
a ROL b left. Bit 31 (the most significant bit) is moved FIGURE 2: Using BINARY.BAS to explore Color BASIC
to bit 0 (the least significant bit) each time. bitwise operators.
a ROR b Rotate Right. Shifts each bit in a, b times to
the right. Bit 0 is moved to bit 31 each time. the process for the remaining 31 bits of n.
Figure 2 shows BINARY.BAS in action; it should be
Arithmetic Shift Right. Shifts each bit in a, b
times to the right. Preserves the sign bit (bit easy to see the results of various bitwise operations.
a SAR b
31 keeps its original value); bit 0 is discarded Here’s a tip not mentioned in my original overview of
each shift. Color BASIC that may be helpful. Color BASIC implements
Bit Reverse. Reverses the order of b least both the % prefix for binary numbers and the $ prefix for
a REV b significant bits in a and sets the remaining hexadecimal ones. So, you can enter a specific bit pattern
bits to zero. into a variable with v = %1011001110001111, for
Bitwise logical “and.” Compares the values in instance, or print the decimal value of a hex number with
a and b bit-by-corresponding-bit and places a PRINT $FFCEB. Try including binary or hex values in the
a&b
1 in that bit of the result if the bits from a and input expression of BINARY.BAS and watch what happens.
b are both 1. Places a 0 in that bit otherwise.
Bitwise logical “or.” Compares the values in a
and b bit-by-corresponding-bit and places a 1
SRAM Commands
a|b in that bit of the result if either bit from a and
b (or both) is 1. Places a 0 in that bit Let’s look at the SRAM commands now. You may
otherwise. recall that the Amigo sports 32K of SRAM, but my
FIGURE 1: The Color BASIC 2.2L bitwise operators — introductory Color BASIC commands set offered no
more tools for your Amigo toolbox! commands to access that storage. (This was an oversight
on my part, and one for which I sincerely apologize.) As
A quick look at this code snippet should reveal no shown in Figure 3, there are only three SRAM commands
surprises until the subroutine in Lines 495-535, where we in Color BASIC, and they are easy to understand and use.
see a couple of bitwise operators at work: As you can see, Color BASIC uses the typical PEEK
<address> instruction to read from memory and POKE
• Line 500 uses SHL to initialize bit mask m, placing a <address>, <value> to write. For the Amigo SRAM, values
one in bit 31 and zeroes in bits 0 through 30 by left- read or written are eight-bit bytes, and they will remain in
shifting “1” 31 times. SRAM until power is removed, or a CLEAR or REBOOT
• Then, Line 510 conducts a bitwise logical & of this command is issued. This means you can use SRAM to
mask and n (the 32-bit signed integer) which results from
evaluation of the expression that was input in Line 20. Dane Weston’s book on Color BASIC for the
• If bit 31 of n is one, the result of m & n will be Pocket Mini Computer is available at
nonzero; the IF statement in Line 515 is TRUE and prints www.lulu.com/shop/display-product.ep?pID=4536358.
1. Otherwise, bit 31 is zero, and Line 520 prints 0. Application Note on Propeller Cog Counters is available at
• Then, Line 525 uses SHR to slide the 1 in bit 31 of the https://www.parallax.com/downloads/an001-propeller-
mask one bit to the right, and the FOR/NEXT loop repeats p8x23a-counters.
50 July/August 2018
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 51

Vintage Computing

pass data from one program to another.


Let’s give these commands a try. Enter the commands
that follow and confirm that your Amigo provides the
highlighted responses:

CLEAR
PRINT PEEK 0
0
POKE 0,100
PRINT PEEK 0
100
POKE 1,”A”
PRINT PEEK 1
65
DISPLAY PEEK 1
A
POKE 2,965
PRINT PEEK 2 FIGURE 4: Your Amigo can use SRAM to store 32-bit
197 integers and string data.
POKE 2,-965
PRINT PEEK 2 interesting possibilities to address Color BASIC’s lack of
59 strings and a DATA statement. It’s also easy to store 32-bit
CLEAR integers using four SRAM bytes. Here’s how.
PRINT PEEK 0, PEEK 1, PEEK 2 Enter the following code (or copy it from the article
0 0 0 downloads) and RUN it on your Amigo. As shown in
Figure 4, SRAM.BAS will prompt you to enter a number
These examples should give you a feel for the SRAM (any 32-bit integer) and then a string, store these in SRAM,
commands. and then retrieve and display them.
A couple of points are worth mentioning, even if they
seem obvious to you. The CLEAR command does zero-out 10 REM —- SRAM.BAS —-
all 32767 SRAM locations, and it takes several seconds to 15 COLOR 63,22
complete. You can only store one eight-bit byte in an 20 CLS
SRAM location, and if you try to write a number greater 25 LOCATE 10,0: PRINT “—- Exploring Amigo SRAM —
than 255 or less than zero, only the eight least significant -”
bits will be saved. 30 LOCATE 2,2: INPUT “Enter a number: “;n
An alphanumeric (or graphics) character can be saved 35 LOCATE 4,4: PRINT “Saving “;n;” to SRAM...”
and recalled with eight bits, which opens up some 40 a=100: GOSUB 200
45 LOCATE 2,10: PRINT “Enter a string: “;
Command Action Performed 50 x=4: y=12: LOCATE x,y REM <— COL,ROW of
String Start
55 L=INKEY : IF L=0 THEN GOTO 55
Reads data from SRAM. Returns the eight-bit
byte value stored at SRAM address a (0 to 60 IF L=13 THEN DISPLAY 5: GOTO 75
PEEK a
32767). Typically used on the right of the 65 IF L=200 THEN DISPLAY 8,32,8: GOTO 55
assignment operator, as in x = PEEK a. 70 IF L>12 THEN DISPLAY L: GOTO 55
75 a=200: GOSUB 400
100 LOCATE 2,22: PRINT “Press Any Key to
Writes to SRAM. Places the eight-bit byte
value v at SRAM address a. If v is less than 0 Retrieve Info...”
POKE a,v
or greater than 255, only the eight least 105 IF INKEY =0 THEN GOTO 105
significant digits will be saved. 110 a=100: GOSUB 300
115 LOCATE 4,6: PRINT “Retrieved Integer = “;n
Clears SRAM memory (0 to 32767) to zeros. 120 LOCATE 2,14: PRINT “Retrieved String:”
CLEAR Also occurs when the REBOOT command is 125 LOCATE 4,16
executed, but not when NEW or RUN is
issued. 130 a=200: GOSUB 500
FIGURE 3: The Color BASIC 2.2L SRAM commands 135 LOCATE 2,24: PRINT “Again (Y/N)?
manage your Amigo’s volatile storage. “

July/August 2018 51
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 52

Vintage Computing

140 L=INKEY terminator, and it seems to work just fine.


145 IF L=0 THEN GOTO 140 • Lines 200-230 save the 32-bit integer n to SRAM, with
150 IF L=”Y” OR L=”y” THEN GOTO 20 the least significant byte starting at address a. In each
155 IF L<>”N” AND L<>”n” THEN GOTO 140 iteration of the FOR/NEXT loop, the next eight-bit byte of
160 LOCATE 2,26: PRINT “Bye!” n is moved to bits 0-7 of the expression n SHR (8*i).
199 END These bits are then poked into the next SRAM address.
200 REM —- Save 32-Bit Integer —- • Lines 300-330 retrieve a 32-bit integer n from SRAM,
205 REM ... Expects Address in a, Integer in n starting with the most significant of the four bytes stored
210 FOR i=0 TO 3 at SRAM address a+3. Line 320 uses the SHL operator to
215 POKE a+i, n SHR (8*i) move each byte to the left in each iteration of the
220 NEXT i FOR/NEXT loop.
230 RETURN • Lines 400-435 copy a string of characters from the
300 REM —- Retrieve 32-Bit Integer —- screen location starting at column/row coordinates x,y to
305 REM ... Expects Address a, Returns Integer n SRAM, beginning at address a. I used ASCII character 5 as
310 n=0 the string terminator, but you can use any character that
315 FOR i=a+3 TO a STEP -1 prints in the next screen location.
320 n=n SHL 8 + PEEK i The “secret sauce” of this approach is the formula in
325 NEXT i Line 410, which maps the x,y coordinates of a cell on the
330 RETURN Amigo display to its location in Propeller main memory,
400 REM —- Save a String —- where its contents are available using the BYTE command.
405 REM ... Address in a, String Start in x,y (More on this trick shortly.)
410 s=2931-y*50-x REM <— Memory location of x,y So, 2931 is the top left corner of the screen; 2930 is
415 t=BYTE [s] one cell to the right; 1082 is the bottom right corner; and
420 POKE a,t so forth.
425 a=a+1: s=s-1 Line 410 places the starting point of the string (passed
430 IF t<>5 THEN GOTO 415 to the subroutine in x,y) in s, then Lines 415-430 get the
435 RETURN character at that location; POKE it to SRAM; increment
500 REM —- Retrieve a String —- the SRAM address and move to the next screen memory
505 REM ... Address in a, ASCII 5 as Terminator location; and repeat the process until the string terminator
510 t=PEEK a (ASCII 5) is found.
515 IF t=5 THEN RETURN • Lines 500-530 retrieve a string of characters from SRAM
520 DISPLAY t starting at address a and place them on the screen,
525 a=a+1 starting at the current cursor location and placing
530 GOTO 510 characters until a string terminator is found. Again, ASCII 5
is used as the string terminator, but in this case, it is not
Here’s what going on with this code: printed on the screen.

• Lines 10-199 provide the body of this little program, Our explanation of saving strings to SRAM touched
handling the user interface and calling subroutines to store on direct access to Amigo screen memory, so let’s discuss
and retrieve 32-bit integers and strings. Only two items that useful trick next.
here may need some explanation. Color BASIC uses over 5K of the 32K Propeller main
First, x and y in Line 50 save the column/row memory to support the 50x37 character video display,
coordinates of the first letter of the string being input. with three bytes of memory dedicated to each character
(We’ll use a trick to get the string characters from screen cell. These three bytes provide character, foreground color,
memory, and we’ll need these coordinates to do that.) and background color information about that specific cell
Second, Lines 55-70 place keystroke characters on the of the display, and their position on the memory map
screen, parsing them to exclude non-printable characters doesn’t change with a given Color BASIC binary.
(Line 70), provide a backspace capability (Line 65), and In other words, as long as you’re running the Color
identify the end-of-string (Line 60). BASIC 2.2L that ships with the Amigo, the screen memory
Note ASCII 13 <Enter> is used to stop placing map remains constant regardless of what your program or
characters on the screen. You can’t use it as the string your onboard experiment is doing.
terminator because it jumps to the beginning of the next With a little detective work, it’s possible to discover
line on the screen, and we need to use contiguous cells in this memory map and then use the BYTE command to
screen memory for SRAM input. read from or write to screen memory directly. Here are
I used the ASCII 5 graphics character as the string the formulas you can use to convert screen XY
52 July/August 2018
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 53

Vintage Computing

column/row coordinates to Propeller main memory values


you can use in your Color BASIC programs:

Cell Content = BYTE [2931 - Y*50 - X]


Foreground Color = BYTE [21449 + 2*X +100*Y] SHR 2
Background Color = BYTE [21448 + 2*X + 100*Y] SHR 2

Note that while cell content memory contains the


whole eight-bit byte representing the character in that cell,
foreground or background color information in the palette
cells is contained in bits 2 through 7. So, you have to do
some bit shifting when you read or write a color value.
Without getting too much into the weeds, the palette
cells for each screen location are consecutive, and each
contains the VGA red, green, and blue levels in bits 7..6,
5..4, and 3..2, respectively. Bits 1..0 are reserved for
horizontal and vertical sync of the video signal and are
provided by the PASM module in the Color BASIC code FIGURE 5: Cool trick: You can read and write to video
that manages the VGA interface. So, we have to shift the memory with the BYTE command.
six color bits two bits left to write our desired color to the
palette cells, and two bits to the right to read a color value 110 k=INKEY : IF k=0 THEN GOTO 110
from them. 115 IF k<>”N” AND k<>”n” THEN GOTO 20
Here’s a code snippet that demonstrates this trick. It’s 120 LOCATE 2,18: PRINT “Bye!”
fairly straightforward, and shows how to use the address 125 END
formulas above to move bytes to and from screen
memory. You can copy this code (SCRN-RW.BAS) from Controlling Hardware Counters
the downloads.
Figure 5 shows one example of this little program at Next, let’s look at the capability of your Amigo to
work. I hope you find this capability helpful! control the hardware counters on one cog of the amazing
Propeller chip. You may recall that the Propeller consists
10 REM —- SCRN-RW.BAS —- of eight identical processors (cogs), and Color BASIC uses
15 COLOR 63,22 those to provide a tinyBASIC interpreter and manage all
20 CLS the I/O of your Amigo: keyboard, monitor, SD card, audio,
25 LOCATE 8,0: PRINT “Reading / Writing the and so forth.
Amigo Screen” You may also recall that one of the key features of the
30 LOCATE 2,2: INPUT “Screen Cell Coordinates Propeller is that each of the eight cogs contains two
(X,Y)? “;x,y independent hardware counters — configurable state
35 IF x>49 THEN x=49 machines that can generate or sense signals as often as
40 IF y>36 THEN y=36 every clock cycle.
45 LOCATE 2,4: INPUT “Content, Foreground, You can configure these programmable hardware
Background? “;c,f,b counters with Spin or PASM for 32 different modes of
50 LOCATE 2,6: PRINT “Writing to Screen...” operation, and they will continue operating in that
55 PAUSE 1000 configuration without further software interaction or
60 BYTE [2931-50*y-x] = c overhead.
65 PAUSE 1000 This is a hugely powerful capability, and the “big
70 BYTE [21449+2*x+100*y] = f SHL 2 brains” who created Color BASIC had the wisdom to
75 PAUSE 1000 include access to two of these counters in your Color
80 BYTE [21448+2*x+100*y] = b SHL 2 BASIC toolkit. That means you can create a wide variety
85 LOCATE 2,8: PRINT “Reading from Screen...” of useful hardware projects with little or no actual
90 LOCATE 4,10: PRINT “c = “;BYTE [2931-50*y-x] hardware on the Amigo breadboard.
95 LOCATE 4,11: PRINT “f = “;BYTE A detailed explanation of these counters is beyond
[21449+2*x+100*y] SHR 2 the scope of this article, which intends just to introduce
100 LOCATE 4,12: PRINT “b = “;BYTE Color BASIC commands that were not listed in the original
[21448+2*x+100*y] SHR 2 Mentor’s Friend documentation. We can do that
105 LOCATE 2,16: PRINT “Again (Y/N)?” introduction with just one simple example of one counter
July/August 2018 53
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 54

Vintage Computing

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!

10 p=24
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
FIGURE 6: One cog counter configured as a
numerically controlled oscillator. The PHSx register 50 NEXT n
accumulates the value in FRQx every clock cycle and 55 PAUSE 1000
places bit 31 on APIN. CTRx CTRMODE must be set to 60 CTRA = 0
%00100 to enable this mode of operation.
I tried extensively commenting this code to explain
mode of operation which follows.
If you’re intrigued by this powerful capability of your Command Function
Amigo, check out the excellent Parallax application note
at https://www.parallax.com/sites/default/files/ Provides read/write access to the Control
downloads/AN001-P8X32ACounters-v2.0.pdf. You’ll find Register in counter A or counter B.
CTRMODE (Bits 26..30) selects the counter
a superb introduction to using the Propeller cog counters mode of operation. PLLDIV (bits 23..25) sets
in a variety of applications, including RF carrier synthesis, CTRA / CTRB the PLL division factor for PLL modes. APIN
pulse width modulation, digital-to-analog conversion, (bits 0..5) and BPIN (bits 9..14) select the I/O
pin(s) used for that mode of operation.
frequency measurement, and many others. (Both counter A and counter B have an APIN
We’ll just introduce the Color BASIC counter and a BPIN.)
commands and what they do, and then use those
commands to create a numerically controlled oscillator Provides read/write access to the
PHSA / PHSB accumulator register in counter A or counter
(NCO) that generates a tone through the audio section of B.
your Amigo.
Figure 6 shows a block diagram of a cog counter FRQA / FRQB Provides read/write access to the value-to-
add register in counter A or counter B.
configured as a numerically controlled oscillator. It’s a
good place to begin our explanation of the counters and FIGURE 7: The Color BASIC 2.2L counter commands
how to use them with Color BASIC. give you access to two powerful configurable state
Each counter contains three registers that control its machines on one cog of the Propeller.

54 July/August 2018
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:26 PM Page 55

Vintage Computing

how it works, but my comments just made things more 200


confusing. Here’s what’s going on, line by line: PRINT ASC “<F6>”
213
• Line 10 sets the Propeller I/O pin we’ll be using to 24, PRINT ASC “<left arrow>”
which is the left channel of the Amigo audio section. 192
• Line 15 sets the direction of our audio pin to output,
but for now masks the output with a 1. In the Propeller The FILE command can be used on either side of the
chip, a cog counter output bit is OR’d with the “equals sign” assignment operator to read or write the
corresponding bit of the output register, and AND’d with next byte of the currently open file. The code that follows
the corresponding bit of the direction register. (available to download) creates the file TEST.DAT on the
So, OUTA[p]=1 sets both output and direction SD card and then uses FILE to write the alphabet to it. It
registers to 1, creating a masked output on the pin. We’ll then reopens the file and uses FILE to read and print bytes
use OUTA[p]=0 to unmask the counter output pin in Line until it finds the end of file.
30. Note that Color BASIC adds a -1 as the end-of-file
• Line 20 sets the value-to-add register to 24365, which character on file closure, and that on opening, FILE points
for the Amigo is the FRQx for 130.8 Hz (one octave to the first record of the file.
below middle C). From the Parallax application note (you
really should take a look at it!), the NCO frequency is 5 REM —- FILE.BAS —-
given by: 10 CLS
15 OPEN “test.dat”,W
fhz = FRQx / 232 x System Frequency 20 PRINT “Writing alphabet to TEST.DAT...”
25 FOR n=65 TO 90
for values of FRQx between 0 and $8000_0000. For the 30 FILE = n
Amigo, with its 80 MHz clock, this arithmetic simplifies to 35 NEXT n
FRQx = 186.26 fhz. So, middle C (261.6 Hz) is FRQx = 40 PRINT “Closing file...”
48730; A4 (440 Hz) is FRQx = 81954; and so forth. 45 CLOSE
• Line 25 left shifts the value for Single-Ended NCO mode 50 DISPLAY 13,13: PRINT “Press a key to
(%00100) into the CTRMODE field of CTRA and then continue...”
adds 24 into the APIN field. The PLLDIV and BPIN fields 55 IF INKEY =0 THEN GOTO 55
are not used in this counter mode of operation. 60 DISPLAY 13,13: PRINT “Reading data from
At this point, the counter is now operating, but the TEST.DAT...”
output is being masked by the 1 we placed in the output 65 OPEN “test.dat”,R
register in Line 15.
• Line 30 places a 0 in the output register for pin 24, Command Action Performed
unmasking the APIN output from the counter and Returns the ASCII value of the single
ASC “n”
applying it to the Amigo left audio channel. character enclosed in quotes.
• Line 35 lets the counter run, applying a steady tone to Reads or writes the next byte in the
the audio channel until you press a key. currently open file on the SD card.
FILE VARIABLE = FILE reads a byte from a file
• Lines 40-55 adjust FRQA to slide the tone up an octave, open in the Read mode. FILE =
then hold it there for one second. <expression> writes a byte to a file in the
• Line 60 turns the counter off. Write or Append mode.
Like the BYTE command, but with a 16-bit
With our introduction of the counter commands value. Reads or writes a 16-bit value to the
Amigo main memory address specified,
complete, let’s finish up the remaining Color BASIC
WORD [nnnnn] where nnnnn is between 0 and 32767. The
commands that were not covered in the initial Mentor’s command can be used on either side of
Friend documentation. These are summarized in Figure 8, the “equals sign” assignment operator,
and the least significant bit of the address
and we’ll briefly cover each with an example. is ignored.
The ASC command is a convenient way to find the Like the WORD command, but with a 32-
ASCII code of a character or key on the keyboard. To LONG [nnnnn] bit value. The least significant two bits of
demonstrate this, type in the commands below, entering the address nnnnn are ignored.
the actual key in quotes instead of the label that I’ve used: CNT Reads (only) the value of the Propeller
system counter register.
PRINT ASC “A” FIGURE 8: The remaining “missing” commands. An
65 updated list of all Color BASIC 2.2L commands is
PRINT ASC “<backspace>” available in the downloads for this article.
July/August 2018 55
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 4:59 PM Page 56

Vintage Computing

70 n=FILE of the Propeller system counter register. For the 80 MHz


75 DISPLAY n system clock of the Amigo, each tick of the clock is close
80 IF n>-1 THEN GOTO 70 to 0.125 nanoseconds, so you can use CNT to perform
85 DISPLAY 13,13: PRINT “Closing file...” some timing tasks in your programs.
90 CLOSE It won’t be gnat’s eyebrow precise due to the double-
interpreted nature of Color BASIC, but may be close
WORD and LONG work just like the BYTE command, enough for some of your programming needs. This next
but with a two-byte or four-byte operand, respectively. Try code block (also in the downloads) creates a crude
these commands on the video section of the main stopwatch by counting clock ticks and doing some math:
memory. As expected, WORD ignores the top two bytes
of the 32-bit variable S, while LONG uses all four. You 10 REM —- TIMER.BAS —-
may find these two commands helpful for some tasks with 15 CLS : PRINT “Press any key to start...”
your Amigo. 20 IF INKEY =0 THEN GOTO 20
25 a = CNT
CLS 30 CLS : PRINT “Press any key to stop...”
S = “A” SHL 24 + “B” SHL 16 + “C” SHL 8 + “D” 35 LOCATE 15,15: PRINT “CNT = “;CNT
WORD [2850] = S CD 40 IF INKEY =0 THEN GOTO 35
LONG [2800] = S ABCD 45 b=CNT
PRINT WORD [2850] 50 CLS
16706 55 PRINT “Start CNT = “;a
PRINT WORD [2800] 60 PRINT “Stop CNT = “;b
538976288 65 PRINT “Difference = “;b-a
70 t=(b-a)/100000*125
The CNT command is read-only and returns the value 75 s=t/100000

ww
www.embeddedARM.com
w.embeddedARM.com
TS-4900
TS-4900
Computer
Computer on M
Module
odule
W
WiFi
iFi and Bluet
Bluetooth
ooth Enabled
1 GH
GHzz i.MX6 C
Computer
omputer M
Module
odule
Single or Q
Quad
uad Core
Core

TS-7970
TS-7970
Single Board
Board Computer
Computer
GHzz i.MX6 ARMCPU
1 GH
Single or QQuad
uad Core
Core
Up ttoo 2 GB DDR3 RRAM
AM
4 GB MLMLCC eMMC Flash
Flash
Choose your
your own
own adventure.
adventure. W
WiFi
iFi and Bluetooth
Bluetooth

BBoard Support Packages,


oard Support Packages,
SSource
ource C ode and TToolchains
Code ooolchains
AAvailable
vailable
56 July/August 2018
Weston - Missing Manual - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:26 PM Page 57

Vintage Computing

80 m=t//10
90 PRINT “Elapsed Time =
“;s;”.”;m;” sec”
100 DISPLAY 13,13: PRINT “Again
(Y/N)?”
110 k=INKEY : IF k=0 THEN GOTO 110
120 IF k<>”N” AND K<>”n” THEN GOTO
10
130 PRINT “Bye!”

Closing Odds and Ends


Let’s conclude with one other trick
for the Mentor’s Friend that you and
your protégé may find useful. Several
popular microcontroller boards can
accept “hats” or “shields” that extend
their functionality by plugging a
daughterboard into headers on the host FIGURE 9: Another trick for your Amigo: Using the Parallax
board. The Amigo Experimenter’s Section circuit overlay board to create hardware “shields.”
uses the same breadboard and header Shown here on the Experimenter’s section headers is a shield
placement as several popular boards containing four solid-state relays which is being used to hack a
toy RC car controller.
from Parallax, and they offer a little
through-hole kit that makes it easy to
convert breadboard circuits into permanent “shields.”
If you’re interested in converting your own world-
changing breadboard projects into permanent shields for
your Amigo, check out the Circuit Overlay Board from
Parallax (P/N 32999). Shield layout and construction are
really easy using the Parallax kit, and if you need plug-and-
play convenience (I do mini-Maker Faires with the Amigo,
for instance), shields are a great way to go.
Figure 9 shows a solid-state relay shield sitting
comfortably on my Amigo.

That completes this update of Amigo Color BASIC


2.2L commands. I hope these additional commands (plus
the tricks we discussed) will send you and a young helper
on another adventure with your Amigo. Have fun and be G
T IN
well! NV U V P R IN
F E R IN G
NOW OF
T PA N E L
Perhaps the easiest way to build your own Amigo is
FRON N E RI T
I G
from the kit available from the Nuts & Volts webstore,

D E S – WE MACHINE
which provides everything you need, including the circuit
board, all components (including an EEPROM pre-loaded

GN IT
with Color BASIC), and a 2GB SD card with sample
programs. If you already have a Propeller board with
connectors for a PS/2 keyboard, VGA monitor, and 2GB YOU DESI re s
lo s u
SD card, you can “roll your own” Amigo by downloading ls & E n c
C u s to m Pane
the Color BASIC source from the Nuts & Volts website, c tu ri n g
updating the I/O pin assignments to match your  a n u fa
tM w a re
A D S o ft
hardware, and then loading the compiled Color BASIC tF re e C
h ip p in g e n ts
binary to the EEPROM on your board. Or, if you are truly tF re e S e q u ir e m
ambitious, download the Amigo schematic from the Nuts im u m O rd e r R
tN o M in
& Volts website and build out the circuits using your 5 Days
favorite construction techniques, then download the tB u il t in
Color BASIC source or binary and Flash it to your www.frontpanelexpress.com
EEPROM.
July/August 2018 57
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 58

A Digital
Analog — Part 5
When a PIC can Replace a 555
This final article in our series will examine those circuits from the “555
Timer IC Circuits” by Forrest Mims which were not covered in any of
the preceding four articles. As in the other installments, some will use
the PIC replacement from the first installment (December 2016),
while others will develop specific programs using a PIC to emulate a
particular implementation of a 555.

By Larry Cicchinelli To post comments on this article and find any associated files and/or
downloads, go to www.nutsvolts.com/magazine/issue/2018/07.

Engineers Mini-Notebook 555 Circuits by Forrest M.


Mimms, III ©1984. Also see www.forrestmims.org.

low. The output of section 1 (normally low) is capacitively

J
ust as a quick review, that first article described a
general-purpose 555 replacement using a coupled to the trigger of section 2 which also has a
microprocessor: the PIC12F1572. The second article pullup.
(May 2017) reviewed the circuits and their PIC The operation is quite straightforward: The high to low
equivalents, which used the 555 basically as a mono- edge of the trigger signal causes section 1 to output a
stable multivibrator. Part 3 (December 2017) discussed positive pulse. At the end of the pulse, the low-going edge
the less complex audio oscillator circuits. The fourth article triggers section 2. The purpose of the circuit is to generate
(February 2018) covered the more complex audio an output that is delayed from the triggering pulse.
oscillator circuits.
Where I have modified component values SCHEMATIC 1. 556
in any circuits from the Mims book, I show the cascaded timer.
original values in parentheses. Also, those
components marked with an asterisk (*) are
additional components and are not in the
original.

Mims Circuit 6
Circuit 6 in Schematic 1 shows a 555 being
used as a cascaded timer. The output of the
first section is used as the trigger for the second
section. The trigger for section 1 is essentially
capacitively coupled to ensure that the input
pulse width is shorter than the output pulse
width. Resistor R5 is there to discharge C2; R2
is a pullup that keeps the trigger input high
except when the trigger signal transitions to
58 July/August 2018
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 59

If you need an operation such as


this, you can use the PIC replacement
in mode 1 (delayed one-shot) or
mode 3 (retriggered and delayed one-
shot; refer to Schematic 2).
I have also developed a program
(MSMVx2.asm) which simulates two
555s as shown in Schematic 3. Both
one-shots have been programmed to
trigger on a negative edge, but this is SCHEMATIC 2. PIC 555 replacement.
easily altered by changing either or
both of two definitions. It’s also
possible to enable the one-shots to
trigger on both edges, but the
program would need to be modified
a little bit. There are definitions that
enable the one-shots to be
retriggered.
Both monostable multivibrators
(one-shots) use one of the timers in
the PIC to determine the pulse width.
One-shot 1 uses Timer 0 and one-
shot 2 uses Timer 2.
Both one-shots have approximately a 1000:1 SCHEMATIC 3. PIC dual
pulse width span due to the 10-bit A/D (analog-to- 555 monostable.
digital) converter. There are definitions in the program
which enable you to change the resolution (also
changes the minimum and maximum widths) of the
pulses.

Mims Circuit 7
Circuit 7 (which is shown in Schematic 4) is titled
as an intervalometer. It’s simply a 556 with section 1
wired as an astable and section 2 as a monostable
driving a relay. The period of section 1 determines
how often the relay is activated, while the pulse width
of section 2 determines the length of time the relay is
activated.
The timing diagram in the book has the
output of section 1 inverted. The output SCHEMATIC 4. 556 intervalometer.
should be shown as high for most of the time
with a short low pulse. Also, the 555 (in
monostable mode) is triggered on a negative-
going edge which the diagram would show if
the upper trace was to be inverted.
The diodes are for protection against the
high voltage inductive kick which occurs
when the relay is turned off. D1 prevents it
from reaching the 555, while D2 should
prevent the voltage across the coil from
exceeding the reverse breakdown voltage of
the diode. I believe a better placement for D2
would be what’s shown by D3 in Schematic
4. This would clamp the high voltage to one
diode drop above the power supply.
July/August 2018 59
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 60

low level pulse. For any given range


determined by the capacitor, the output
pulse width will be fixed unless you vary the
value of R2. The following formulas apply:

LowPulseWidth = ln(2) x R2 x C1 = .693 x


R2 x C1

Period = ln(2) x (R1 + R7 + (2 x R2)) x C1

Due to component tolerances —


especially the capacitor — you can use
SCHEMATIC 5. PIC 555 replacement for the intervalometer. either 0.66 (2/3) or 0.7 instead of the
constant shown in the equations, which will
The operation of this circuit can easily be obtained get you close enough for the vast majority of applications.
using a 555 replacement in either mode 4 or mode 5. The values shown in the schematic are specifically for
Schematic 5 shows the wiring of the 555 replacement for FM-12, the pulse generator. For FM-22 (an LED flasher),
this equivalent circuit (the resistor values are for mode 5). R1 is 100K and C1 is 47 µF. The flash rate can be varied
Note that the PIC uses a transistor buffer to drive the between 0.2 Hz and 8.3 Hz. The 2N2222 inverts the
relay. signal and causes the LED to flash on for a short time
The PIC output current is limited to 20 mA, so a (when pin 5 is low) of approximately 32 ms.
buffer is going to be required for most relays. Select mode Since the 555 has plenty of drive capability that can
4 if you want to control the off-time of the relay and its easily handle an LED directly, it’s possible to get the same
on-time. Select mode 5 if you want to control the period results without a transistor using the alternate LED circuit
of the relay operation and its on-time. This is a subtle shown in the box. The value of R6 (as well as R4) should
difference but may be important depending on the be calculated based on the supply voltage and the current
application. required by the LED. The values shown for R6 cause about
Also, note that the 555 circuit uses +12V while the 5 mA through LED2 at the two voltage extremes.
PIC should use no more than +5V. A higher voltage relay Just as a note of interest, the original circuit with the
can be used if desired simply by connecting the “top” side transistor draws roughly the same amount of current
of the relay and cathode of the diode to the required independent of the state of the LED. The alternative circuit
voltage. (without the transistor) draws very little current when the
LED is off.
Mims Circuits 12, 22, and 23
The circuits in Schematic 6 use the 555 as a
simple pulse generator. For FM-22 and FM-23, the
only differences are the loads the 555 is driving
and the timing components.
Its astable operation has been discussed in
previous articles of this series, so I won’t repeat it
here. The frequency range of FM-12 is roughly
1.4 Hz to 300 kHz depending on the capacitor. I
have included a spreadsheet with the article
downloads (555 Astable.ods) which calculates the
time values based on the three timing
components. Keep in mind that as R1 becomes
small, the circuit will stop operating correctly (if
R7 = 0).
I found that with C1 = .01 µF or .1 µF, I
needed to make R7 about 390 ohms for the
circuit to work properly with R1 = 0 and VCC =
5V. Each capacitor value yields about a 400:1
frequency span.
SCHEMATIC 6. 555 pulse generator.
With this circuit, the output is a very narrow
60 July/August 2018
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 61

FM-23 is a power FET lamp dimmer (using R5,


Q2, and DS1) with R1 = 1K or 5K and C1 = .047 SCHEMATIC 8. 555
light/dark detector.
µF. Here again, the output low time (Q2 off) is
fixed; this time, at about 32 µs. This
implementation also has a fixed resistor of 390
ohms in series with the potentiometer allowing
the pot to be adjusted to zero ohms (without
damaging the 555 or causing the circuit to
malfunction). This will yield close to a 50% duty
cycle.
The frequency is high enough so that the
lamp appears to be on continuously at varying
levels of intensity. However, since the duty cycle
is limited to a minimum of 50%, you will not be
able to dim it to completely off. Strictly speaking,
R5 is not necessary, but I prefer to not have the
gate of an FET floating while the circuit is being
assembled.
In general, a PWM circuit operates with a
constant period while both the on-time and off-time motor. Schematic 7 shows the driver circuit I
changes. With this circuit, the off-time remains constant implemented.
while the on-time and period are changing so that longer I used the circuit of Schematic 2 and this driver to get
periods produce higher duty cycles. In both cases, it’s the a very smooth speed control. I set the PIC 555
duty cycle that is important. The higher the duty cycle replacement to mode 5 with a period of about 30 µs. The
(longer output high time), the brighter the bulb. reason for the relatively high frequency was due to the
The circuit of Schematic 2 can be used as the basis type of motor being used. Lower frequencies tended to
for all three of the above circuits using either mode 4 or 5. make the motor chatter.
It has the advantage of allowing independent modification The IXDD609 is a FET gate driver and is required to
of both the on-time and off-time (or period), and its duty overcome the gate capacitance of the FET. Without this
cycle can span 0.1% to 99.9%. The table in the schematic driver, the gate input rise and fall times were slow enough
shows the resistor values required for different ranges and that the FET turned on and off slowly and became quite
modes of operation. hot. With the driver, the FET doesn’t even get warm when
Just a note for the lamp dimmer: Frequencies above driving a five amp motor at full speed.
60 Hz are usually not noticeable by most people. There is one caution: The supply voltage to the IXDD
A recent project I did used PWM to drive a DC fan — or whatever FET driver you use — must not exceed the
maximum VGS of the FET (or the max voltage of the
driver IC), while still being high enough to ensure full turn-
on of the FET.
SCHEMATIC 7. I used a Schottky diode because they are faster than a
FET gate driver.
normal power diode and they have a lower forward
voltage drop yielding lower power dissipation. In this
application, the diode gets hotter than the FET. I put both
the diode and the FET on heatsinks.

Mims Circuit 24
The light/dark detector shown in Schematic 8 uses a
photoresistor connected to the Reset input as a gate for
the 555 wired as an astable multivibrator. The Reset input
has to be high in order for the 555 to oscillate. The
position of the switch determines whether the 555 is
enabled when light hits the photoresistor (lower resistance
when exposed to light) or does not hit it.
The threshold of the Reset input is about 1V but the
input resistance will be different depending on the
July/August 2018 61
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 62

Schematic 9A is an infrared security


alarm. U1 is configured as an astable
multivibrator with a frequency of about 6
Hz, period = 166 ms. The LED will be
turned on when the output is low; about
3.2 ms. U2 is configured as a monostable
multivibrator (one-shot) with an on-time of
almost 52 ms.
With the insert in place, Q1 will be
off which causes Q2 to be held off and
the trigger input of U2 is held high. With
the trigger high, the output will be low
keeping the buzzer turned off. When the
insert is removed, U2 will be triggered as
well as Q2 turning on synchronously with
the output of U1 causing the one-shot
(U2) output to go high.
Capacitor C2 will charge until it
reaches the threshold voltage at which
time the output will turn off and the
discharge circuit will turn on. The buzzer
in this circuit must be of the internally
driven type.
Since I was unsure of the function of
SCHEMATIC 9. 555 infrared security alarm. Q2, I tested the operation of this circuit
by driving the U2 trigger circuit directly
semiconductor process used for the part: MOS versus from a PIC 555 in mode 4, range 2, and off-time of about
bipolar. Using an MOS part (input current about 10 pa) 3 ms.
allows you to pick a photoresistor with higher on and off When the trigger goes low (simulating the insert being
resistances. If you are using a bipolar part, you will need a removed and LED1 turning on), U2 is triggered, Q2 turns
photoresistor with lower resistance values and you may on, the 555 discharge circuit turns off, and the buzzer
need to make R3 smaller. turns on for the duration of the C2 charge cycle.
You can use the circuit of Schematic 2 for this With the component values shown, the removal of
application as well, with either astable mode (4 or 5). The Q2 has no impact on the circuit. The output low time of
same photoresistor circuit can also be utilized to drive the U1 is short enough (3.3 ms) that Q2 does not affect the
gate/trigger (RA3) input. charging of C2. If the U1 output low time is increased to 6
ms or greater, then Q2 begins to have an effect on the
Mims Circuit 25 charge time of C2; see Picture 1.
The area circled in red shows the plateau caused by
Q2 which is clamping the capacitor to about 0.5V.
Since the plateau does not start until about 5 ms
after the trigger, it will not occur with a trigger
pulse width less than 5 ms.
Once the trigger is removed, Q2 will turn off
allowing C2 to finish charging to the threshold
voltage and turn off the output.
Schematic 9B shows another possible
implementation. This one is similar to FM-24 in that
the Reset input is used as a gate for the astable
multivibrator.
I also changed the operation such that the
frequency of the 555 is about 500 Hz so that the
buzzer needs to be of the externally driven type. In
this case, the buzzer will sound continuously when
PICTURE 1. 555 astable capacitor charge cycle. the insert is removed.
62 July/August 2018
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 63

If you want a pulsing sound, then you should


change the timing components (R8 = 47K, R9 = 15K,
C4 = 4.7 µf) and use an internally driven buzzer.
You can easily use the PIC 555 circuit of Schematic
2 for this application. Use the circuit shown in
Schematic 9C to drive the MCLR input and use mode
4. You can set the circuit to either have a continuous
tone or a pulsing tone just as described for the 555
implementation in the previous paragraph.

Mims Circuits 26 and 27


The two circuits shown in Schematic 10 are an
analog lightwave transmitter and receiver. The
transmitter circuit is a simple 555 astable multivibrator
whose output period varies with the value of R1. If you
use a photoresistor for R1, the frequency will vary with
the amount of light hitting it. The higher the light
intensity, the lower the resistance which yields higher
frequencies.
The 555 portion of the receiver is identical with a
few minor component value differences to the
frequency meter of FM-13 discussed in Part 2 of this
series. The op-amp is there to amplify the signal from SCHEMATIC 10. 555 analog lightwave transmitter and
the phototransistor so that relatively weak signals can receiver.
be handled. The op-amp circuit can be eliminated
if the transistor is close to the IR diode.
The operation of the circuit is such that the SCHEMATIC 11. Alternate op-amp buffer.
meter — when calibrated with R109 — will show
the frequency of the transmitter pulse stream.
R104 is used to adjust the trip point of 1458b
which is being used as a comparator.
There is one minor issue with the circuit: The
1458 specifications state that the minimum
voltage between the power pins is 10V. The
circuit will probably work at 9V, but it could be
marginal. The text in the book suggests that 741s
may be substituted for the 1458; however, the
741 specifies a minimum supply of ±10V or, if
used with a single supply, 20V.
Schematic 11 shows an alternate op-amp
circuit. The basic circuit is the same except that
the op-amp has been replaced with one of the
many rail-to-rail op-amps available today which
were not available when the Engineer’s Workbook
series was written.
This circuit has two additional features for section 2 of Resources
the op-amp: no potentiometer required for setting the trip
point; and some hysteresis (about 100 mV) for a little All schematics are drawn using DipTrace
www.diptrace.com
noise immunity. The op-amp shown has a maximum
supply voltage of 6V. However, there are many single All parts purchased are
voltage rail-to-rail op-amps that have a wider supply from Digi-Key
www.digikey.com
voltage range which will also work in this circuit.
Two PIC replacements can be used instead of the My website
555s. Use the table shown back in Schematic 2 to select www.qsl.net/k3pto

July/August 2018 63
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 64

the appropriate modes, range, period values, i.e., higher


and pulse characteristics. For frequencies.
the transmitter (as with the 555 Putting the positive terminal
implementation), the output of the cell on the +5V line will
period can be controlled by a cause the control voltage to
photoresistor as one leg of a decrease with higher light
voltage divider. intensity which will then yield
However, with this circuit, higher frequencies.
you can just as easily drive the Schematic 12B shows a
off-time input from a voltage similar circuit using the NCO
source. For instance, you could feature of a PIC18313. (See Part
use a photocell whose output 3 of this series for sample
voltage varies with light programs.) In this case,
intensity. however, higher voltages on the
Schematic 12A is an control input cause higher
example of the transmitter using frequencies on the output.
a PIC 555 replacement and a In both cases, you’ll want to
photocell. The circuit is make sure that the maximum
essentially a VCO with a 50% output voltage of the photocell
duty cycle. The placement of is less than 5V. Resistors R5 and
the photocell may look a little R8 are there to limit the current
strange, but keep in mind that to the inputs in case of
lower voltages on the control SCHEMATIC 12. PIC analog lightwave excessive photocell voltage.
inputs correspond to lower transmitters. For those of you who like a
programming challenge, you
can edit MSMVx2.asm and modify it
so that one section is an astable
multivibrator and use it to drive the
IR transmitter. The other section
would stay as a monostable to be
used as the receiver.

Mims Circuit 28
The last circuit in the book
(Schematic 13) is a DC-DC
converter. It uses a 555 in its astable
configuration at about 2.9 kHz with a
low pulse width of about 7 µs. This is
very close to a 98% duty cycle.
In my experimenting with the
circuit, I found that I could not even
get close to Mr. Mims results using
the values and configuration in his
schematic. I had to make some
changes to get nearly the same
results.
I used a different transformer
which would have affected my
results. Refer to Schematic 14 for my
final 555 circuit.
The first problem I found with
the original circuit was that the 555
was getting quite hot. I believe this
was due to the very high duty cycle
64 July/August 2018
Cicchinelli - A Digital-Analog Final Part 5 - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:05 PM Page 65

of the configuration and that the 555 output was


driving a transformer connected to ground. SCHEMATIC 13. 555
This meant that the 555 output was DC-DC converter.
essentially shorted to ground for 98% of the
time. I first simply moved one side of the
transformer to +V which corrected the heating
issue, but I still didn’t get as high a voltage.
The second change I made was to increase
the value of R2 to 10K. With the 1K in the
circuit, I measured about 50V across C2 (with
Vcc = 5V). With 10K, I measured about 80V.
The last changes were to insert a PNP buffer
between the 555 and transformer and then
insert a 100K potentiometer in series with R2.
These two changes allow me to adjust the
voltage from about 10V to over
100V with a 5V supply.
Replacing the 555 in
Schematic 14 with the PIC 555
will yield similar results. Use
mode 5 and range 0 with a fixed
frequency of about 2 kHz.
With a 100K load, a duty
cycle of 90% yields about 23V,
while a duty cycle of 50% yields
70V.
Lower duty cycles don’t give
much higher voltages. Keep in
mind that the PIC duty cycle is
based on the ratio of output on
(high) to period. With the PIC SCHEMATIC 14. Modified 555 DC-DC converter.
output on, the 2N3906 is off.

That’s a Wrap THE MOST COMPLETE PROGRAMMING TUTORIAL!


• Everything you need to learn to program PIC® micro-
I have enjoyed writing this series
controllers is included in this package
and would like to thank Nuts & Volts
for asking me to write it. I’ve learned • Learn the fundamental concepts of programming,
quite a bit about the 555 and its including program flow, loops, coding techniques, binary
many uses from reading and manipulation, device-to-device communication, user
implementing the circuits described interface design, in-circuit debugging, and more!
in 555 Timer IC Circuits by Mr. Mims
and hope that you have as well. • Includes all the necessary the software, compiler,
$99.99 trainer board, cable, tutorial with exercises and sample
If you have any questions about Academic and bulk pricing available
the PIC 555 replacement or any of code!
the examples in this series, feel free Check out our other popular products
to email me at k3pto@arrl.net. NV for PIC® developers including:
U2 Programmer

PBP3
PICBASIC PRO™ Compiler
PBP3 Compiler
Prototyping Boards
Experimenter Boards
www.melabs.com
Contact us at info@melabs.com

July/August 2018 65
Titus - ASCII data from PS-2 Keyboards - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:12 PM Page 66

Get ASCII Data


from PS-2
Keyboards

T
he PS-2 keyboard engineers assigned a respectively. A PS-2 keyboard does, however, transmit key
unique code to each key. So, for example, codes in a UART-type format: a start bit; eight data bits;
the W key produces 0x1D and the X key an odd-parity bit; and a stop bit (Figure 1). The least-
produces 0x22 (all values given in significant bit (LSB) of a key code gets shifted out first.
hexadecimal). These codes don’t directly You might think a UART could handle this serial
translate into ASCII values; 0x57 and 0x58, information, but keyboard clock frequencies can vary

FIGURE 1. A
PS-2 keyboard
transmits data
and clock
signals when I
press the W
key, which has
the assigned
code 0x1D
(MSB first).
66 July/August 2018
Titus - ASCII data from PS-2 Keyboards - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:12 PM Page 67

You can buy inexpensive PS-2 keyboards,


but they don't produce ASCII values many To post comments on this
applications need. To further complicate article and find any associated
files and/or downloads, go to
things, these keyboards have their own www.nutsvolts.com/magazine
/issue/2018/07.
code-transmission protocol. I'll show you
how to use a system-on-a-chip and a bit of
software to convert PS-2 key codes to
corresponding ASCII values.
Connect a PS-2
Keyboard to an
MCU
When you press the W
key, the keyboard transmits the
key code 0x1D. When you
release the W key, the
keyboard sends a key-release
code, 0xF0, followed by the W
key’s code, 0x1D (Figure 2).
The key-release code remains
the same (0xF0) for all keys.
This article covers the keys
in the large main alphanumeric
keyboard area. It does not
discuss auxiliary keys such as
Home, Page Up, and Page
Down, but you may easily
modify the software to include
them if you wish.

By Jonathan A. Titus
Use a System-
on-a-Chip (SoC)
For this project, I chose a
Cypress Semiconductor
CY8CKIT-059 5LP prototyping
kit (Figure 3) and the free
between 10 kHz and about 16 kHz, so a UART set for a Cypress PSoC™ Creator software you can download and
fixed bit rate might not work in all cases (Note 1). Many install on a host PC. Cypress sells the prototype kit for
MCUs include a serial-peripheral interface (SPI) port that $10. The board connects to a PC via a USB cable.
can operate as a slave device and receive serial data. In Print the documents, “PSoC 5LP Prototyping Kit
this mode, the keyboard can
supply the needed serial data
and clock signals. The MCU can
then process the information and
act accordingly.

FIGURE 2. The serial


transmission when I press
and release the W key.
Upon release, the
keyboard transmits the
key release code, followed
by the W key code.
July/August 2018 67
Titus - ASCII data from PS-2 Keyboards - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:12 PM Page 68

FIGURE 3. A CY8CKIT-059 5LP prototyping kit. The four block stays active at all times.
contacts on the left mate with a female USB connector. Like many other PSoC components, the SPI port
These signals communicate data and programs between
the PSoC chip and your host PC. Photo courtesy of Cypress requires an internal synchronizing clock. I chose a clock
Semiconductor Corp. from the list of blocks and set it for a 1 MHz output. The
documents mentioned earlier explain how to start a
Guide” and Cypress AN77759 “Getting Started with PSoC project like this, configure blocks, assign physical I/O pins
5LP,” and use them to get off to a quick and easy start. to signals, and build a project with the PSoC Creator
(Directions are included with the article downloads.) software. (I connected the MOSI to a PSoC output pin,
A Cypress 5LP PSoC (Programmable System-on-a- but this project does not use it.)
Chip) device includes many “building blocks” for functions A rapid double-click on the SPI slave block opens the
such as SPI, USB, and UART ports; EEPROM; clocks; SPIS_1 Configure window shown in Figure 5. Here, you
analog-to-digital converters (ADC); pulse-width modulators select one of four modes, and as you examine each, the
(PWM); and so on. timing diagram changes to illustrate the signals for that
Unlike other MCUs, the 5LP devices only implement mode. I chose the clock-phase (CPHA = 1) and the clock
(or “connect”) the blocks you want. You select a function, polarity (CPOL = 1) that match the keyboard clock and
drag its block into the PSoC Creator schematic drawing data signal levels and edges shown earlier (refer back to
area, and set parameters. Figure 1).
In most cases, you don’t need to set bits in registers. The PSoC SPI block works with from three to as many
Each block has its own datasheet, and example programs as 16 bits. I chose 11 bits to match the number of bits
give you a head start. When you “build” a project, the transmitted by a keyboard. I also chose LSB first as the
PSoC creates the APIs for you. The documentation for shift direction for incoming data to match the keyboard’s
each block lists the APIs and explains their uses. data format. This setting simplifies software for keyboard
decoding.
Configure an SPI Port for 11 The Advanced section of this window (Figure 6) lets
me select an external clock: the 1 MHz clock shown in
Bits Figure 4. This clock signal is external to the SPI block and
Figure 4 shows an SPI slave port as I configured it. used only within the PSoC to synchronize processor and
The MOSI (master-out, slave-in) pin connects to the logic activities. I also chose an SPI buffer memory size for
keyboard’s data-output signal. The keyboard clock four 11-bit values, and no interrupts. Anyone familiar with
connects to the SPI serial-clock input (sclk). I connected peripheral setup in a typical MCU will appreciate the ease
the slave-select input (ss) internally to a logic 0, so the SPI of SPI setup.
That simplicity applies to other blocks, too.
You don’t search through lists of registers to find
a bit that enables a peripheral and then tinker
with other bits to get the behavior you want. The
PSoC Creator handles those details. The software
does the same things for a UART in this project.
The UART sends ASCII values to a terminal
emulator on my PC.
A separate window lets you assign the
signals to physical I/O pins. In this project, the

FIGURE 4. My SPI port in the PSoC Creator schematic window.


You drag and drop an SPI and other building blocks into the
schematic area as needed and connect them with "wires." Later,
you assign signals to physical I/O pins. I used the default name
SPIS_1 for this block, but you can change it as you wish.
68 July/August 2018
Titus - ASCII data from PS-2 Keyboards - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:12 PM Page 69

FIGURE 5. This SPI_Slave Configure window


appears after a double-click on the SPI function FIGURE 6. The SPI advanced configuration window lets you set
shown in Figure 4. You may choose the type of the SPI buffer memory size, choose a clock, and set interrupts
signals for the SPI port, the number of data bits, if any. The clock refers to a PSoC internal synchronizing clock,
and whether the MSB or LSB shifts in first. not the clock signal from a PS-2 keyboard.

keyboard’s data output connects to port 3, bit 0 (noted as


P3.0) and the keyboard clock signal connects to port 3, bit
1 (P3.1). A UART output connects to port 12, bit 7
(P12.7), which routes the signal to another MCU on the
small programmer section of the prototyping board.
This MCU communicates with a host PC via the male
programming USB connector. I chose the Parallax Serial
Terminal (PST) software for debugging and testing.
A PS-2 keyboard has four connections with a
computer: two wires for +5V and ground; and two wires
to transmit a serial key code and a synchronizing clock
signal (Figure 7). This view looks into the pin (male) end FIGURE 7. The pin connections for a PS-2 keyboard.
of a PS-2 keyboard connector, or at the solder contacts on (Viewed looking into the male pins.)
a mating female connector. The PSoC 5LP Prototyping Kit
Guide includes a table of pin names, signals, and
descriptions for the PSoC board. Table 1 lists the and uses many files which at first can seem overwhelming.
keyboard-to-prototyping kit connections you need for this Figure 8 shows a portion of the Workspace Explorer area
project. on the left side of the PSoC Creator window. Because this
project does not use interrupts, all my software went into
Software Builds the Project and the main.c file. Before I wrote any code, I had to decide
how to process the keyboard data and how to handle the
Creates the Files key release code and the shift keys.
When the PSoC Creator “builds” a project, it creates

FIGURE 8. Don't
Table 1. Keyboard and PSoC Prototyping Kit Connections. let the list of PSoC
files and folders
Keyboard Signals PSoC Signals
intimidate you.
Name Connector Pin Name Signal Pin Name You'll only work
with the main.c
+5V In 4 VDD +5V Power J2_01 file unless you use
GND In 3 GND Ground J2_02 an SPI interrupt,
which would add
Clock Out 5 P3.1 GPIO J2_24 only one other file
for an ISR.
Keyboard Data Out 1 P3.0 GPIO J2_25
July/August 2018 69
Titus - ASCII data from PS-2 Keyboards - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:12 PM Page 70

Every Key has Its Code lock). Please refer to Figure 9 as I explain the software
operations. Suppose I press the letter G. The “Get Key
Because every key has a unique code, you might try Code” software section converts the 11-bit keyboard
to use that code as an index into an array of ASCII values; information into the eight-bit keyboard code
basically, a lookup table. That’s a good idea. You could (Keyboard_Data in the software). This keyboard value
create the array ASCII_Equivalent[ ] in which to store the equals the G key code, 0x34.
ASCII values. Then, the W key code 0x1D, for example, The next software section tests the value to determine
would direct software to array element if it equals the key-release code, 0xF0, or either shift key
ASCII_Equivalent[0x1D] that would hold the W key’s ASCII code, 0x12 or 0x59. In this case, the G key value matches
code. So, do we save the value for an uppercase or none of these three conditions. So, the program continues
lowercase W in the array? It depends. The software must and the value from some previously pressed key goes into
monitor codes from the two shift keys (one on the left and variable Old_Data; the G key value, 0x34, gets put into
one on the right of the keyboard) and decide which ASCII the New_Data variable.
value to retrieve. So, we create two arrays — LC_Array[ ] This process lets the software later determine if the
and UC_Array[ ] — for lowercase and uppercase ASCII key just released has the same code as the key pressed
values. earlier. It’s simply a way to detect an error, such as
Table 2 shows part of the information for each array. pressing two keys at once. More about this shortly.
The downloads for this article include the complete table, Next, the software tests the KeyRelease_flag, but
and the PSoC software includes both arrays and all PSoC because I haven’t released the G key this flag is false.
files. Gray rows in the table indicate an unused code or Then, based on the state of the Shift_ flag, the MCU
no value assigned for a key such as F1 or F2. decides whether to fetch the ASCII value for the
uppercase UC_Array[ ] or from the lowercase LC_Array[ ]. I
A Flowchart Maps Our Way haven’t touched a shift key, so the Shift_flag is false, and
the software gets the lowercase g ASCII value 0x67. The
The translation of key codes into ASCII values gets software then goes back to await arrival of a new key
more involved as shown in the software flowchart (Figure code. (In my software, the ASCII value goes to my host PC
9). This code runs in an infinite loop, but you could use it and the terminal displays “g.”)
as the basis for an interrupt-service routine (ISR). That When I release the G key, the software must
approach goes beyond the scope of this article. recognize the key release code and then ignore the key
The keyboard software has three main tasks. First, it code that closely follows (refer back to Figure 2). Without
waits for the SPI buffer memory to become “not empty,” this test, the software would sense two key codes from the
which signals new information has arrived in the SPI port. pressed and released key, and a terminal would display
Second, the software must properly detect the shift key’s “gg.” Here’s how the software avoids the “double g”
condition to choose an uppercase or lowercase ASCII problem.
value. Third, it must handle the key release code and the
key code that follows it to ensure we don’t get duplicate
characters when we release a key.
Detect a Key Release
The software uses two true-false flags: KeyRelease_flag, When I release the G key, the keyboard transmits the
which when true indicates the software has detected the key release code, 0xF0, which the software detects and
0xF0 key release code; and Shift_flag that gets set to true then sets the KeyRelease_flag to true. Next, the program
when the software senses a pressed shift key (but not caps goes back to wait for another value from the SPI port. In
this key release
Table 2. A portion of the lowercase and uppercase information for PS-2 keyboard-to-ASCII example, the
conversions. The keyboard does not assign codes 0x17 through 0x19 to any keys.
PS-2 Keyboard Scan Code Lower-Case Characters Upper-Case Characters
Note 1. A person
Decimal Hex LC Keyboard Char LC ASCII Value UC Keyboard Char UC ASCII Value in a support group
20 14 c 63 C 43 reported using a
UART with a
21 15 q 71 Q 51 12,000 bits per
22 16 1 31 ! 21 second (bps) clock.
23 17 0 0 Worth a try, but an
SPI port can better
24 18 0 0 handle clock
25 19 0 0 frequency changes
from keyboard to
26 1A z 7A Z 5A keyboard. My PS-2
27 1B s 73 S 53 keyboard produced
a clock signal
28 1C a 61 A 41
equivalent to
29 1D w 77 W 57 13,700 bits/sec.
70 July/August 2018
Titus - ASCII data from PS-2 Keyboards - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:12 PM Page 71

Cypress PSoC Creator 4.2 Bit-swap code is available


(free) at
www.cypress.com/products https://stackoverflow.com/q
/psoc-creator-integrated- uestions/2602823/in-c-c- When the SPI port receives the shift key code that
design-environment-ide whats-the-simplest-way-to-
reverse-the-order-of-bits-in- follows the release of a shift key, the software tests the
Parallax Serial Terminal a-byte. KeyRelease_flag. If it detects a set KeyRelease_flag, it clears
download (free) the KeyRelease_flag and the Shift_flag. (The software does
https://www.parallax.com/d not use the caps lock key, 0x58, which I despise and have
ownloads/parallax-serial- Resources
terminal removed from my keyboards because I hit it by accident
too often.)
keyboard again sends the value for the G key (0x34).
The program compares the final G key data with 0xF0
and with both shift key values. Again, the G key code
Time to Get Started
doesn’t match these values, so the software goes on to The article downloads contain all the software and
transfer the New_Data value (the G key data sent when I files needed for this project. If you choose to use a
pressed the G key) to Old_Data. The second G key value different processor, I have included the C language code
— sent after the key release code — gets saved in in a separate text file. I leave it to you to set up and create
New_Data. Thus, we have: code for your MCU’s SPI port. The PSoC project also
contains the C program in main.c. There’s a Get Started
• Old_Data = 0x34, G key code sent when key pressed guide (PDF format) that explains how to open this project
• New_Data = 0x34, G key code sent when key released in the PSoC Creator software. You can then examine the
“innards” of the project.
The software now “sees” the KeyRelease_flag as true, A second version (Bundle04) of the software is
so it compares Old_Data and New_Data. When they available to handle key rollover. The first version works but
match, all is well, and the software clears the it doesn't handle this; that is, several keys pressed at the
KeyRelease_flag and loops back to handle the code from same time. The second version does. Key rollover isn't a
the next key I press. problem for most typists, but it happens once in a while,
In this way, the software properly ignores the G key so people may use the second version if they wish. I hope
code sent right after the key release code. Plus, we don’t this information will be “key” to your success! NV
see “gg” on a terminal; only “g.” If the
Old_Data and New_Data values do not
match, a command turns on an “error”
LED on the PSoC board. You may add
error-handling software if you wish.

Shift Happens
The two shift keys operate the
same way as other keys. Each sends its
code when pressed and sends the key
release code and its shift key code
again when released. The flowchart in
Figure 9 shows how the shift key
affects the choice of ASCII value.
When I press the left shift key, the
software receives 0x12 and tests it for a
match with the key release code (no
match) and the code for each shift key.
The software detects a match with one
of the two shift key codes and branches
to test the KeyRelease_flag. If this flag is
false, the software sets the Shift_flag
and goes back to get the next code
from the SPI port.
As long as I press the shift key, the
Shift_flag remains set and the software
selects ASCII values from the uppercase
UC_ASCII array. When I release the FIGURE 9. Flowchart for the PS-2 keyboard code
shift key, it produces the key release code (0xF0) and that converter that produces corresponding ASCII
condition causes the software to set the KeyRelease_flag. values for shifted and unshifted keys.
July/August 2018 71
Ford - Magnetic Loop Antennas - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:23 PM Page 72

Antenna, tripod
without 40M fixed
capacitor.

72 July/August 2018
Ford - Magnetic Loop Antennas - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:23 PM Page 73

Practical Ideas for


Portable Magnetic
Loop Antennas By Jim Ford N6JF

Magnetic loop antennas are becoming even more popular these days
because they can be very efficient for their size, do not need radials
(even though most designs are vertically polarized), have useful takeoff
angles, and can be easily rotated to peak or null a signal. The cost of
this is small bandwidth, high voltage capacitors, and the necessity to
keep resistance losses very low.
y loop design presented here eliminates the use torch to get the extra heat works great. Fortunately, the

M of vacuum variable capacitors because of the


size, weight, and expense. Manual tuning is more
practical for portable operation. For me, that
meant it would be no more than 10 feet in circumference
to fit in my car’s trunk, but with 40M-10M capability at
learning curve is fast and no flux is needed.
I brazed them in the garage with the aid of a vice,
although a warm day with no wind outside might be
better. Using one inch copper tubing might be an option
for some, but bending is likely difficult for the less
100 watts. experienced.
I had a Johnson dual 200 pF/2 KV in stock that would The DC resistance of the loop measured about 1.4
tune 30M-10M if you put both sections in series to get milliohms. A good small transmitting loop calculator is at
100 pF/4 KV (use both ends and not the frame), thereby www.66pacific.com. Their calculator for 40M said I
avoiding wiper contact resistance. A less expensive fixed needed about 10-12 pF more. That might have been due
vacuum capacitor can be added in parallel (in my case, to stray capacitance in the construction, which turned out
140 pF/5 KV) to the variable for 40M. Two low loss to be good since I was able to tune down to 6.8 MHz
capacitors in parallel splits total current, which approaches with no problems.
40A at 100W. The fixed vacuum capacitor was only necessary on
I cut a 10 foot section of type M 3/4 inch copper 40M, which was an initial concern. The final design tuned
pipe into eight equal pieces (.875 OD) with the last piece from 6.8–28.7 MHz, although the upper end could easily
split and shortened by the
capacitor mount. Thicker pipe
adds weight, but no noticeably 15% silver brazing rods and
better performance. Eight 45 clamps for capacitors.
degree elbows join the sections.
I used 15% silver brazing rods
available on eBay for about $20
which is also 80% copper. Lead or
tin are not good choices for
conductivity. I used Silvaloy 15 but
other brands are similar. Six or
seven rods 20 inches in length
were used.
The joints need to be clean
and bright; brazing them with a
MAPP gas cylinder on a propane
July/August 2018 73
Ford - Magnetic Loop Antennas - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:23 PM Page 74

Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

Top mount detail.

Tripod overview.

be extended by bending or removing a variable capacitor other method.


plate. Modified copper pipe U hold-downs are strong and No RF on the feedline was verified by moving my
were used to mount the capacitors. hands up and down the coax line close to the connector
Homebrew high voltage capacitor ideas are in the with no changes in SWR, which should result in better
ARRL Antenna Book and on the Internet; just remember nulls. With the capacitor up higher, there is also less
for 100W about 4KV is needed. During initial testing at chance of detuning because of surrounding objects.
100W, the variable capacitor arced until I discovered a I got most of the parts from Home Depot, including
small leaf had fallen on it.
A popular way to match the antenna is with a small
1/5 diameter loop (eight inches of RG8X in this case).
Notes
K. Siwiak KE4PT, “RF Exposure Compliance Distances for
One end of the coax is soldered to the center and shell of Transmitting Loops, and Transmitting Loop Current” QST
the SO239 connector in the usual manner, but the other Technical Correspondence May 2017 pp 64-65.
end has the braid not connected with the center coax
K. Siwiak KE4PT, “Near Fields of an Electrically Small Loop
wire soldered to the outside shell making a DC short. Can Affect Direction Finding” QST July 2015 pp 63-64.
Some say this method is better because it provides an
improved electrostatic shield and better pattern. Jim Lux W6RMK in an extensive technical analysis letter to
The feed loop can be put on the top or bottom. Steve Ford on Nov 29, 2006 about RF compliance with
Mounting at the top makes the loop less top-heavy. loop antennas
However, RF is then coupled to the coax line hanging Table 17 in FCC OET65B; www.fcc.gov/general/oet-
down and needs to be choked off by toroids or some bulletins-line.
74 July/August 2018
Ford - Magnetic Loop Antennas - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:23 PM Page 75

the copper pipe U hold-downs which were


hammered and used to attach the capacitors.
Nuts were brazed on to the top section, so a
brass screw could attach the fixed capacitor for
40M. A switch would be far too lossy.
The three 22 1/2 degree 3/4 inch PVC
elbows used in the tripod are from
Pvcpipesupplies.com for just a few dollars.
Using PVC for a frame is better because
the less metal in the RF field, the better. Since
the first H frame mount tried was too unstable,
I tried the tripod mount with much better
results, with easy assembly and disassembly.
The tripod needed 22 1/2 degree elbows
because commonly-available 45 degree
versions made the legs spread out too fast. The
bottom portion of the tripod has a stop below
the shelf which stabilizes it and allows weights
on the bottom during windy conditions.
I used a 22-5/8 inch on a side 1/2 inch
plywood for the bottom shelf but would use
5/16 next time. The top triangle was 8-5/8 Tuning capacitor; copper straps across aluminum section for
inches on a side and was 3/4 inch thick pine lower resistance.
(hardwood next time). All PVC pieces are 3/4
inch except the four foot/one inch mast which
makes the tuning capacitor just reachable. The
total diagonal length above the bottom shelf is
30-5/8 inches including the coupler, whereas
the section below is 13 inches.
Painting the whole frame to reduce sun
damage is desirable. The two PVC pieces
attached to the mast are cut with an opening
of .89 inches. This allows strong snap
attachment but easy disassembly. The Y mount
PVC Ts must be attached to the loop before
brazing, using a wet rag to keep it cool. Next
time, three or four inches lower would make it
slightly less top heavy farther from the high
voltage area, possibly extending the 10M
upper frequency limit.
The SWR at resonance is 1.3 or less
except for 10M where it is 1.6. The loss
matching this low SWR with a tuner would
likely be more than extra loss caused by the Tuning capacitor; holes for 40M fixed capacitor shown.
SWR. Peaking on receive noise is easy since
it’s so sharp you might simplify operations by doing only compared to a commercial loop of the same size but
that. using aluminum tubing. Their 2:1 SWR bandwidth on 40M
The 2:1 SWR bandwidth is: was 27 kHz vs. 13 kHz, but their extra loss could be
heard by some comparing on the air signals. For about
40M 13 kHz two hours a couple of months ago on 40M, this resulted
30M 35 kHz in about 20 heard contacts from Alaska to New England
20M 48 kHz with 200 mW — which is a testament to both WSPR and
15M 80 kHz this antenna.
10M 83 kHz (Likely more bandwidth, RF exposure safety is a concern for small loop
but SWR starts at 1.6.) antennas. Using a low power SWR analyzer or peaking
receiver noise is a safe alternative to low power SWR
At a Quartzfest demonstration last year, the loop was tuning. Kai Siwiak KE4PT mentioned in QST Technical
July/August 2018 75
Ford - Magnetic Loop Antennas - Jul-Aug 18_Blank Rough NV.qxd 6/12/2018 5:23 PM Page 76

SWR on 40M. Tuning capacitor with 40M fixed capacitor attached.

Correspondence in May 2017 in part: aware user, and 2.1 meters (6.9 feet) for the general
public.”
“Additionally, for a one meter diameter loop operating Others have suggested even more distance (Notes 1,
at a continuous 10W, including ground reflection, 2, 3, and 4) certainly with 100W.
compliance distances are nearly constant over the 40-10
meter bands at less than 1.5 meters (4.9 feet) for the Have fun and be safe! NV

76 July/August 2018
NV New Products - Jul-Aug 18_Mar15 -NV - NewProducts.qxd 6/12/2018 5:50 PM Page 77

■ NEW PRODUCTS Continued from page 23

company, Würth Elektronik Depending on the application,


ICS for this innovative between 10 and 25 mating cycles are
product. REDFIT IDC is specified.
available in four-pin to 20- The plastic housing of the
pin versions and is suitable REDFIT IDC SKEDD WR-WST
for permanent use on PCBs connector family of products is made
(printed circuit boards) as of halogen-free LCP (liquid crystal
well as for temporary Continued on page 89
connections for
programming and
debugging purposes.
REDFIT IDC can be setting your ideas into
MOTION
manually mounted on the
plated-through holes of the
Compute provides a feature rich PCB, which eliminates the need for
development platform for Alexa extra sockets and any related Use Small Mechanical
Components from SDP/SI
Voice Service projects. soldering processes. It also requires
With a 2.5 watt speaker driver, no mating plug, therefore saving on START CREATING!
programmable pushbuttons, and a components and reducing assembly
built-in microphone, Chatterbox can and process costs.
be configured as a push- or hold-to- For miniaturized components in
talk, or hot-word-detect Alexa particular, the less space required
platform. and the lower the height needed for www.sdp-si.com 516-328-3300
Features such as a 15-pin CSI 2 any pin headers and other connector
camera connector, RGB LED, Wi-Fi, components, the better. REDFIT IDC
and Bluetooth, as well as a 20-pin SKEDD connectors only take up
GPIO header, make the Chatterbox room for the connector itself on the
Pi an ideal home assistant PCB. There is no need for extra
development board. space above the circuit board.
The Chatterbox W5G Wi- The SKEDD connector is
Fi/Bluetooth module provides the attached to the ribbon cable via
increased bandwidth of 5 GHz insulation displacement technology.
802.11b/g/n over the previous 2.4 The plastic guides on the underside
GHz model, as well as Bluetooth 4.2 of the housing are longer than the
and BLE. Retail price is around $116. contacts, thus preventing short
circuits on the board underneath.
For more information, contact: Different size thicknesses of the
Gumstix guiding pins provide reverse polarity
www.gumstix.com protection during the simple (and
tool-free) process of plugging and
SOLDERLESS/DIRECT unplugging the SKEDD connector.

PLUG-IN
CONNECTORS
W ürth Elektronik eiSos introduces
its new “REDFIT IDC SKEDD
WR-WST connectors” product family:
solderless, space-saving, and multi-
pluggable connectors for signal
transmission.
The electronics and
electromechanical components
manufacturer is using the patented
SKEDD technology from its sister
July/August 2018 77
THE DESIGN CYCLE n BY FRED EADY

Go PICBASIC PRO with C L


fi

P
I/
ICBASIC PRO version 3.1 is a very powerful programming tool. A quick outside view n
p
of the PICBASIC PRO command structure may lead one to believe that its programs can P

only consist of the calls listed in the User Guide. Not so! In fact, PICBASIC PRO logic is w
w
much like C language logic. With a few out-of-the-box programming techniques, just about re
lo
any C source file can be converted to PICBASIC PRO source.
S

In this installment of Design


Cycle, we’ll utilize the code S
generation prowess of
Microchip’s MPLAB Code
it
Configurator to lay down b
a path for PICBASIC PRO re
S
programming.
;
MPLAB X IDE (integrated development P
environment) and XC8 C compiler. The ;
idea is to build our project modules as S
C-language modules and then convert ;
them to PICBASIC PRO source. In the ;
process, we’ll also define our hardware ;
configuration using the MPLAB S
Code Configurator, which will be C
converted to PICBASIC PRO speak P
n PHOTO 1. Everything you need to develop with eight-bit PIC microcontrollers is as well. S
here. The Explorer 8 development board also supports PICtails, Digilent PMODs, Our preferred hardware platform R
and MikroElektronika click boards. for this project will be the Microchip O
Explorer 8 development board B
which is captured in Photo 1. The B
How Do We Start? Explorer 8 board supports the majority of eight-bit PIC ;
First, we’re going to throw away the PICBASIC PRO microcontrollers including the new enhanced PIC16F ;
User Guide. Well, not all of it. We’ll need to reference devices. We can also code for MikroElektronika click ;
the math operators and variable types sections, but we’re boards as the Explorer 8 dev board sports a pair of click W
going to pretty much ignore the built-in command area. board sockets. S
Second, we’re going to assume that we have This board is equipped with an LCD and a UART C
absolutely no idea of how to begin to write our PICBASIC port that can connect to the simple serial port terminal P
PRO code. Lastly, we’re going to depend on the C code that is part of the MPLAB X IDE. On the software side, S
generated by the MPLAB Code Configurator to pave the the Explorer 8 board is supported by some board-specific S
way to our PICBASIC PRO programming success. example code, which was generated using the MPLAB S
To begin, we’ll need to download and install the latest Code Configurator. S
78 July/August 2018

Eady - Design Cycle - Jul-Aug 18.indd 78 6/12/2018 11:31:47 AM


ADVANCED TECHNIQUES FOR DESIGN ENGINEERS
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

LCD
Now, we can set the WCOL bit within our PICBASIC
If you consult the Explorer 8 User’s Guide, you will PRO code like this:
find that the board’s LCD is driven by an MCP23S17
I/O expander. The MCP23S17 speaks SPI. There are no WCOL = 1
native PICBASIC PRO SPI functions. So, our first task is to
port the SPI driver contained in the development board’s The MCP23S17 is not required to return any data to
n PIC16F1719 example code package. the host PIC microcontroller using the SPI portal as it is
Let’s start our port with code that defines the bits only attached to the LCD. So, our SPI communications will
within the SPI engine’s register stack. We will be coding only have to flow from the host PIC to the MCP23S17.
with bits found within the SSP1STAT and SSP1CON1 Here is the basic SPI communications code the MPLAB
registers. The C source to set the SSP1CON1 WCOL bit Code Configurator generated:
looks like this:
uint8_t SPI_Exchange8bit(uint8_t data)
SSP1CON1bits.WCOL = 1; {
// Clear the Write Collision flag, to allow
Setting the WCOL bit in PICBASIC PRO looks like this: writing
SSP1CON1bits.WCOL = 0;
SSP1CON1.7 = 1 SSPBUF = data;
while(SSP1STATbits.BF == SPI_RX_IN_PROGRESS)
As you can see, the C source tends to self-document {
itself, while the identical operation in PICBASIC PRO is a }
bit cryptic. To make our ported PICBASIC PRO code more return (SSPBUF);
readable, we will plant some aliases on the bits within the }
SSP1STAT and SSP1CON1 registers:
The C implementation of the SPI_Exchange8bit
;*********************************************;* function simply clears the WCOL collision bit, stuffs the
PIR1 BITS data we want to send into the SSPBUF, and waits for the
e ;********************************************* SSPBUF to fill with incoming data from the slave device.
SSP1IF VAR PIR1.3 The incoming data is returned to the caller.
;************************************************ In our case, the slave device is the MCP23S17 and
;* SSP1STAT BITS no real data is clocked in as the MCP23S17’s SPI output
;************************************************ pin is not connected. Our PICBASIC PRO port of the SPI_
SMP VAR SSP1STAT.7
;SAMPLE BIT Exchange8bit function takes this form:
CKE VAR SSP1STAT.6
;SPI CLOCK SELECT BIT
P VAR SSP1STAT.4
;STOP STATUS BIT I2C ONLY ;************************************************
S VAR SSP1STAT.3
;START STATUS BIT I2C ONLY ;* GLOBAL VARIABLES
m RW VAR SSP1STAT.2
;TRANSMIT STATUS BIT I2C ;************************************************
p ONLY dataOut VAR BYTE
BF VAR SSP1STAT.0
;BUFFER FULL/EMPTY STATUS dataReturned VAR BYTE
BIT ;************************************************
;************************************************ ;* SSP1BUF/SPI CONSTANTS
;* SSP1CON1 BITS ;************************************************
;************************************************ EMPTY CON 0
WCOL VAR SSP1CON1.7
;COLLISION BIT FULL CON 1
SSPEN VAR SSP1CON1.5
;SPI ENABLE BIT SPI_RX_IN_PROGRESS CON 0
CKP VAR SSP1CON1.4 ;CLOCK NULL CON 0
POLARITY BIT ;************************************************
SSPM3 VAR SSP1CON1.3
;MODE SELECT BIT ;* SPI Exchange8bit
SSPM2 VAR SSP1CON1.2
;MODE SELECT BIT ;************************************************
SSPM1 VAR SSP1CON1.1
;MODE SELECT BIT SPI_Exchange8bit:
SSPM0 VAR SSP1CON1.0
;MODE SELECT BIT WCOL = 0
July/August 2018 79

Eady - Design Cycle - Jul-Aug 18.indd 79 6/12/2018 11:38:32 AM


ADVANCED TECHNIQUES FOR DESIGN ENGINEERS

SSPBUF = dataOut ;************************************************ ;


do while BF = SPI_RX_IN_PROGRESS IO_EXPD_ADDRESS CON $40 c
loop GPIO_A_ADDRESS CON $12 ;
dataReturned = SSPBUF GPIO_B_ADDRESS CON $13 ;
return IO_DIR_A_ADDRESS CON $00 ;
IO_DIR_B_ADDRESS CON $01 L
With our base PICBASIC PRO SPI communication r
function in place, we can now concentrate on porting We now have enough nails and glue to frame up our r
our base PICBASIC PRO LCD functions. Let’s bring up LCD_WriteIOExpander PICBASIC PRO subroutine. The c
the MCP23S17 I/O Expander first. The MPLAB Code variables regAddr and regData are preloaded before calling r
Configurator generated this C template for us: the LCD_WriteIOExpander subroutine: r
c
void LCD_WriteIOExpander(uint8_t reg, uint8_t ;************************************************ r
data) { ;* GLOBAL VARIABLES r
LCD_CHIP_SELECT_SetLow(); ;************************************************ c
SPI_Exchange8bit(IO_EXPD_ADDRESS); regData VAR BYTE ;spi data to send r
SPI_Exchange8bit(reg); regAddr VAR BYTE ;preloaded spi target
SPI_Exchange8bit(data); address
LCD_CHIP_SELECT_SetHigh(); ;************************************************ fu
} ;* LCD_WriteIOExpander in
;************************************************ a
The first order of business here is to figure out what LCD_WriteIOExpander:
PIC I/O pin the LCD chip select is assigned to. Then, lcdChipSelect = 0 #
we’ll hunt down the value of I/O_EXPD_ADDRESS. The dataOut = IO_EXPD_ADDRESS #
MPLAB Code Configurator placed the LCD chip select pin call SPI_Exchange8bit #
assignment in the pin_manager.h file: dataOut = regAddr #
call SPI_Exchange8bit #
#define LCD_CHIP_SELECT_LAT LATAbits.LATA2 dataOut = regData #
#define LCD_CHIP_SELECT_SetHigh() do { LATAbits. call SPI_Exchange8bit #
LATA2 = 1; } while(0) lcdChipSelect = 1 #
#define LCD_CHIP_SELECT_SetLow() do { LATAbits. return
LATA2 = 0; } while(0) v
Being able to control the MCP23S17 completes the
The I/O_EXPD_ADDRESS value is located in the lcd.h bridge between the host microcontroller and the LCD. D
file. Note that the MCP23S17 GPIO and port direction We can now send commands to the LCD via the PIC’s SPI
register address values were also found within lcd.h: portal. The next logical step is to port the C function that D
sends LCD commands:
#define IO_EXPD_ADDRESS 0x40 E
#define GPIO_A_ADDRESS 0x12 void LCD_WriteCommand(uint8_t cmd) {
#define GPIO_B_ADDRESS 0x13 LCD_WriteIOExpander(GPIO_A_ADDRESS, 0x60);
#define IO_DIR_A_ADDRESS 0x00 //RS LOW -- E HIGH -- LCD Enabled
#define IO_DIR_B_ADDRESS 0x01 LCD_WriteIOExpander(GPIO_B_ADDRESS, cmd);
//Write the command on PORT B
The PICBASIC PRO porting of the LCD chip select is LCD_WriteIOExpander(GPIO_A_ADDRESS, 0x20);
quick and easy: //RS LOW -- E LOW -- LCD Enabled
}
lcdChipSelect VAR PORTA.2
The ported LCD_WriteCommand function takes this
So is the PICBASIC PRO adaptation of the MCP23S17 form. The cmd variable must be preloaded before calling
address values: LCD_WriteCommand: }

;************************************************ ;************************************************
;* IO EXPANDER CONSTANTS ;* GLOBAL VARIABLES w
80 July/August 2018

Eady - Design Cycle - Jul-Aug 18.indd 80 6/12/2018 11:32:32 AM


* ;************************************************ a PICBASIC PRO delay routine, we’ll just reach into the
cmd VAR BYTE PICBASIC PRO bag of tricks and use the built-in PAUSE
;************************************************ function to port the C __delay_ms function:
;* LCD_WriteCommand
;************************************************ ;************************************************
LCD_WriteCommand: ;* LCD CONSTANTS
regAddr = GPIO_A_ADDRESS ;************************************************
regData = $60 LCD_CLEAR CON $01
call LCD_WriteIOExpander LCD_VDD_EN CON $20
g regAddr = GPIO_B_ADDRESS LCD_FUNCTION_SET CON $3C
regData = cmd LCD_SET_DISPLAY CON $0C
call LCD_WriteIOExpander LCD_SET_DDRAM_ADDRESS CON $80
* regAddr = GPIO_A_ADDRESS LINE1_START_ADDRESS CON $80
regData = $20 LINE2_START_ADDRESS CON $C0
* call LCD_WriteIOExpander OUTPUT_DIR CON $00
return ;************************************************
t ;* LCD_Initialize
As we continue to add to our base of LCD driver ;************************************************
* functions, the easier the porting becomes. The LCD LCD_Initialize:
initialize C function is based on the LCD_WriteIOExpander regAddr = IO_DIR_A_ADDRESS
* and LCD_WriteCommand functions: regData = OUTPUT_DIR
call LCD_WriteIOExpander
#define LCD_CLEAR 0x01 regAddr = IO_DIR_B_ADDRESS
#define LCD_VDD_EN 0x20 regData = OUTPUT_DIR
#define LCD_FUNCTION_SET 0x3C call LCD_WriteIOExpander
#define LCD_SET_DISPLAY 0x0C regAddr = GPIO_A_ADDRESS
#define LCD_SET_DDRAM_ADDRESS 0x80 regData = LCD_VDD_EN
#define LINE1_START_ADDRESS 0x80 call LCD_WriteIOExpander
#define LINE2_START_ADDRESS 0xC0 pause 10
#define OUTPUT_DIR 0x00 cmd = LCD_FUNCTION_SET
call LCD_WriteCommand
void LCD_Initialize(void) { pause 10
LCD_WriteIOExpander(IO_DIR_A_ADDRESS, OUTPUT_ cmd = LCD_SET_DISPLAY
DIR); call LCD_WriteCommand
LCD_WriteIOExpander(IO_DIR_B_ADDRESS, OUTPUT_ pause 10
DIR); cmd = LCD_CLEAR
LCD_WriteIOExpander(GPIO_A_ADDRESS, LCD_VDD_ call LCD_WriteCommand
EN); pause 10
__delay_ms(10); cmd = LCD_SET_DISPLAY
LCD_WriteCommand(LCD_FUNCTION_SET); call LCD_WriteCommand
__delay_ms(10); pause 130
LCD_WriteCommand(LCD_SET_DISPLAY); cmd = LCD_SET_DDRAM_ADDRESS
__delay_ms(10); call LCD_WriteCommand
LCD_WriteCommand(LCD_CLEAR); pause 1
__delay_ms(10); return
LCD_WriteCommand(LCD_SET_DISPLAY);
__delay_ms(130); The LCD is now under our control. All that’s left to
LCD_WriteCommand(LCD_SET_DDRAM_ADDRESS); do is port the C source that writes human-readable stuff
__delay_ms(1); to the display. There are four C functions we need to port.
} The first function writes a single byte to the LCD via the
MCP23S17:
* As long as you don’t have to constantly reinvent the
wheel, porting code is fun. So, instead of scratch-writing void LCD_WriteByte(uint8_t data) {
July/August 2018 81

Eady - Design Cycle - Jul-Aug 18.indd 81 6/12/2018 11:32:49 AM


LCD_WriteIOExpander(GPIO_A_ADDRESS, 0xE0); ;************************************************
//RS HIGH -- E HIGH -- LCD Enabled --> This is to lcdBuf VAR BYTE[17] d
choose the data register on the LCD i VAR BYTE
LCD_WriteIOExpander(GPIO_B_ADDRESS, data); ;************************************************ v
//Write the byte on PORT B ;* LCD_WriteString
LCD_WriteIOExpander(GPIO_A_ADDRESS, 0xA0); ;************************************************
//RS HIGH -- E LOW -- LCD enabled --> This is to LCD_WriteString: }
latch the data on the LCD i = 0
} do while lcdBuf[i] != 0
lcdBiteOut = lcdBuf[i] it
The ported version of LCD_WriteByte requires the call LCD_WriteByte n
user to preload the variable lcdBiteOut with the byte to be i = i + 1
displayed: loop ;
return ;
;************************************************ ;
;* GLOBAL VARIABLES The third display function is responsible for moving the c
;************************************************ LCD’s cursor to a desired position: c
lcdBiteOut VAR BYTE r
;************************************************ void LCD_GoTo(uint8_t row, uint8_t column) { c
;* LCD_WriteByte if (row < 2) { c
;************************************************ uint8_t pos = (row == 0) ? (LINE1_START_ r
LCD_WriteBYte: ADDRESS | column) : (LINE2_START_ADDRESS |
regAddr = GPIO_A_ADDRESS column);
regData = $E0 LCD_WriteCommand(pos);
A
call LCD_WriteIOExpander }
regAddr = GPIO_B_ADDRESS } to
regData = lcdBiteOut o
call LCD_WriteIOExpander The PICBASIC PRO port demystifies the C source line th
regAddr = GPIO_A_ADDRESS that contains the “?”. Again, preload the variables row and c
regData = $A0 col before calling LCD_GoTo: th
call LCD_WriteIOExpander
return ************************************************* #
;* GLOBAL VARIABLES
PICBASIC PRO isn’t very handy at string manipulation. ;************************************************ &
So, the second display function utilizes another built-in row VAR BYTE _
PICBASIC PRO function called ARRAYWRITE to assist in col VAR BYTE
writing a string of characters to the LCD. Here is the C pos VAR BYTE _
version of the string display function: ;************************************************ _
;* LCD_GoTo #
void LCD_WriteString(const char *data) { ;************************************************
uint8_t i = 0; LCD_GoTo:
while (data[i]) { if row < 2 then th
LCD_WriteByte(data[i++]); select case row
} case 0 /
} pos = LINE1_START_ADDRESS | col #
case 1 S
The ARRAYWRITE function is not part of the ported pos = LINE2_START_ADDRESS | col o
string function and is used to preload strings that are end select #
passed to the ported version of the LCD_WriteString cmd = pos E
function shown here: call LCD_WriteCommand #
endif E
;************************************************ return #
;* GLOBAL VARIABLES S
82 July/August 2018

Eady - Design Cycle - Jul-Aug 18.indd 82 6/12/2018 11:33:05 AM


ADVANCED TECHNIQUES FOR DESIGN ENGINEERS

* The fourth and final LCD function simply clears the #pragma config CP = OFF // Flash Program Memory
display and positions the cursor at the home position: Code Protection->Program memory code protection
is disabled
* void LCD_Clear(void) { #pragma config BOREN = ON // Brown-out Reset
LCD_WriteCommand(LCD_CLEAR); Enable->Brown-out Reset enabled
* LCD_GoTo(0, 0); #pragma config CLKOUTEN = OFF // Clock Out
} Enable->CLKOUT function is disabled. I/O or
oscillator function on the CLKOUT pin
The PICBASIC PRO port is almost not a port at all as
it consists of functions we have already ported. There is no // CONFIG2
need to preload the cmd, row, and col variables: #pragma config WRT = OFF // Flash Memory Self-
Write Protection->Write protection off
;************************************************ #pragma config PPS1WAY = ON // Peripheral Pin
;* LCD_Clear Select one-way control->The PPSLOCK bit cannot be
;************************************************ cleared once it is set by software
e cmd = LCD_CLEAR #pragma config ZCDDIS = ON // Zero-cross detect
call LCD_WriteCommand disable->Zero-cross detect circuit is disabled at
row = 0 POR
col = 0 #pragma config PLLEN = OFF // Phase Lock Loop
call LCD_Goto enable->4x PLL is enabled when software sets the
return SPLLEN bit
#pragma config STVREN = ON // Stack Overflow/
Underflow Reset Enable->Stack Overflow or Underflow
Almost There will cause a Reset
The SPI and LCD port are finished. However, we need #pragma config BORV = LO // Brown-out Reset
to take care of some other necessities before we can apply Voltage Selection->Brown-out Reset Voltage
our ported code. I relied on the configuration fuse settings (Vbor), low trip point selected.
that PICBASIC PRO set for the PIC16LF1708 with only a #pragma config LPBOR = OFF // Low-Power Brown
couple of exceptions. I turned off the watchdog timer and Out Reset->Low-Power BOR is disabled
the power-up timer: #pragma config LVP = OFF // Low-Voltage
Programming Enable->High-voltage on MCLR/VPP must
* #CONFIG be used for programming
__config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF
* & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _BOREN_ON & If you don’t have any special requirements, it’s much
_CLKOUTEN_OFF easier to use the PICBASIC PRO-supplied configuration
__config _CONFIG2, _WRT_OFF & _PPS1WAY_OFF & fuse data. The Code Configurator can also be used to
_ZCDDIS_ON & _PLLEN_OFF & _STVREN_ON & _BORV_LO & generate the system oscillator and watchdog configuration
* _LPBOR_OFF & _LVP_OFF values, which are directly portable. You need only replace
#ENDCONFIG the C hexadecimal notation “0x” with the PICBASIC PRO
* hexadecimal notation “$:”
You can also use the Code Configurator to generate
the configuration fuse settings. It will generate this: ;************************************************
;* INITIALIZE OSCILLATOR
// CONFIG1 ;************************************************
#pragma config FOSC = INTOSC // Oscillator OSCCON = $72 ;SCS INTOSC; SPLLEN disabled;
Selection Bits->INTOSC oscillator: I/O function IRCF 8MHz_HF;
on CLKIN pin OSCSTAT = $00 ;SOSCR disabled;
#pragma config WDTE = OFF // Watchdog Timer OSCTUNE = $00 ;TUN 0;
Enable->WDT disabled BORCON = $00 ;SBOREN disabled; BORFS disabled;
#pragma config PWRTE = OFF // Power-up Timer ;************************************************
Enable->PWRT disabled ;* INITIALIZE WATCHDOG TIMER
#pragma config MCLRE = ON // MCLR Pin Function ;************************************************
Select->MCLR/VPP pin function is MCLR WDTCON = $16 ;WDTPS 1:65536; SWDTEN OFF
July/August 2018 83

Eady - Design Cycle - Jul-Aug 18.indd 83 6/12/2018 11:40:50 AM


ADVANCED TECHNIQUES FOR DESIGN ENGINEERS

Then, write a string to lines 1 and 2 of the


LCD:

;************************************
************
;* GLOBAL VARIABLES
;************************************
************
lcdBuf
VAR BYTE[17]
;************************************
************
;* MAIN PROGRAM LOOP
;************************************
************
call SPI_Initialize
call LCD_Initialize
ARRAYWRITE lcdBuf,[“ DESIGN CYCLE”,0]
call LCD_WriteString
row = 1
col = 0
call LCD_GoTo
n PHOTO 2. It works. You didn’t have any doubts, did you? ARRAYWRITE lcdBuf,[“ PICBASIC
PRO”,0]
call LCD_WriteString
PICBASIC PRO has no built-in provisions for PPS DO
(Peripheral Pin Select). However, PPS is a walk in the park LOOP
to set up for the PIC16LF1708. We must assign I/O pins
to the PIC’s SPI portal. The Explorer 8 board schematic The zero behind the ASCII strings in the ARRAYWRITE
tells us that the PIC’s SDO pin is expected to be assigned lines of code produce a zero-terminated string, which
to RC5 and the SCK pin should be assigned to RC3. The our LCD_WriteString function is looking for as an ending
PIC16LF1708 datasheet tells us that loading registers character.
RC5PPS and RC3PPS with binary 10010 and 1000, I will leave you with Photo 2 and the full download of
respectively, will accomplish our SPI pin assignment task: the PICBASIC PRO source code for this article. You can
now add the Explorer 8 development board and the skill of
;************************************************ porting C to PICBASIC PRO to your Design Cycle. NV
;* INITIALIZE I/O
;************************************************
TRISA = %11111011
TRISB = %11110001
TRISC = %10010111 Explorer 8 Development
RC5PPS = $12 ;SDO Board
RC3PPS = $10 ;SCK
XC8 C Compiler
The TRISx values were copied from the development MPLAB X
board PIC16F1719 example code. The port being changed Microchip
is the C binary notation “0b” to the PICBASIC PRO binary
notation “%.” www.microchip.com
PICBASIC PRO 3
Smoke Test ME Labs
Well, it all compiles. However, that doesn’t mean it will www.melabs.com
work. So, the plan is to initialize the SPI portal and LCD.
84 July/August 2018

Eady - Design Cycle - Jul-Aug 18.indd 84 6/12/2018 11:33:38 AM


n BY LOU FRENZEL W5LEF OPEN COMMUNICATION

Killer Wi-Fi Now Available


Do you really need it and what is the
future of Wi-Fi?
Here is what you need to know about the wireless
technology we cannot do without.

W e are clearly blessed with so many good wireless services. We’re all addicted to
our 4G LTE smartphones for text, email, and even voice. And now, 5G is in the
works. Bluetooth wireless is everywhere in our hands-free auto audio, Bluetooth
speakers, and headphones, and dozens of other products. On top of that, our go-to
wireless is Wi-Fi. Our first question when we visit someone or set up in a new environment
is “what is the Wi-Fi password?” We take it for granted as we do electrical power service.
We only miss it when it goes away.

Wi-Fi is one of the most sorted out and Wi-Fi in Review


ship shape wireless technologies ever invented. Wi-Fi is just the trade name of this wireless standard.
Thanks to the Wi-Fi Alliance and its rigorous It’s based on the 802.11 standards of the Institute of
certification program, all Wi-Fi chips and Electrical and Electronic Engineers (IEEE). The standard
products must be tested and certified to meet has been around for over 20 years with the first successful
specifications and be fully interoperable with any version being 802.11b. It operated in the 2.4 GHz
other Wi-Fi device. Furthermore, this technology unlicensed band and could deliver up to 11 Mbps of data
has been on a steady upgrade path that has rate under ideal conditions.
given us not only continuously improved data Further versions came along such as 802.11g that
rates but better link reliability as well. There added OFDM modulation and bumped the data rate to 54
are all sorts of bells and whistles to use and Mbps. An OFDM 54 Mbps version 802.11a operating in
the 5 GHz unlicensed spectrum also emerged.
appreciate.
The biggest change was the introduction of 802.11n
that added MIMO and wider bandwidth to get well over
Wi-Fi is one of the most sorted out and 100 Mbps data rates. The 802.11n version was very
ship shape wireless technologies ever successful. Most of us probably still have an 802.11n
invented. router, and many public hot spots and company access
points still use it. It works and has good speed and
That’s the good news. The bad news is — if that’s coverage for almost all but the most demanding.
what it really is — that Wi-Fi is reaching a technology A newer standard is 802.11ac. It features larger
plateau where everything about it is peaking out. Industry MIMO configurations, wider bandwidths, and pushes the
is beginning to question where Wi-Fi is going. What’s the top single stream data rate capability past 1 Gbps. Most
next big thing for Wi-Fi? There are multiple answers to users are still upgrading from 11n to 11ac. If you plan to
that question. One thing we know for sure is that the next upgrade, an 11ac router is what you’ll probably get.
iteration of Wi-Fi is just now becoming available. That is the Here are the basic features and specs of 11ac:
version based on the IEEE 802.11ax standard. It’s faster and
better than ever. • Backwards compatible with 802.11n.
So, where do we go from here? This article is an • Wider bandwidths of 40, 80, and 160 MHz.
update on Wi-Fi, a closer look at the latest version, a • 5 GHz band only.
summary of the problems, and a look at what’s in store for • Modulation with 256QAM.
you. • 8 x 8 MIMO.
July/August 2018 85

Frenzel - Open Communication - Jul-Aug 18.indd 85 6/12/2018 11:47:14 AM


THE LATEST IN NETWORKING AND WIRELESS TECHNOLOGIES
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

• Using maximum features, peak ideal data rate is 6.93


Gbps.
• Typical configuration can produce data rates of over 1
WiGig
Gbps. WiGig is the trade name given to routers implemented
with the 802.11ad standard. WiGig operates in the 60 GHz
The 802.11ac routers are already becoming the unlicensed band. Using 2 GHz wide channels and OFDM
mainstream. While these routers will serve most consumers with 64QAM modulation, it can deliver 7 Gbps of data
adequately for years to come, new standards are in the speed up to about 10 meters max.
works. Figure 1 shows D-Links’ latest 802.11ac compatible Range is really limited by the high millimeter wave
router. The four MIMO antennas boost speed while signal, but by using agile beamforming and phased array
improving link reliability. antennas, the range is useable. The 11ad standard and
products have actually been around for several years now,
but have not gained traction in the marketplace. With sp
limited range and few access points to connect to, the th
standard has an uncertain future. is
One potential use is as wireless connections to virtual fa
Figure 1. D-Links’ AC1750 reality/augmented reality headsets. Competition from st
MU-MIMO router (DIR- another Wi-Fi standard may commit the 11ad standard to
867) can hit speeds up to oblivion. We shall see. D
1.75 Gb/s. 5
The Newest Standard: 11ax lin
M
The latest standard is 802.11ax. Chips are now
available from vendors like Broadcom and Quantenna that E
will power the forthcoming new routers. This new standard E
offers further improvements in speed and coverage. It a
operates in both the 2.4 and 5 GHz bands and features the a
same bandwidths to 160 MHz and 8x8 MIMO. It also adds
two key upgrades that will further improve performance. n
te
b
What Limits Your Data Rate? a
We all want downloads to be faster. Unfortunately, there appears to be a diminishing return. Beyond a certain p
point, humans cannot tell the difference between 10 Mb/s downloads or 50 Mb/s downloads for common uses like
email or Internet surfing. It is streaming video that demands the high rates. If the streaming video is not delayed, we
usually don’t care what the actual speed is.
Another key factor is the download speed capability of your Internet service provider (ISP) and what speed your
account permits. Home cable TV and DSL lines have definite upper limits, and lower than you realize. DSL lines rarely
go much beyond about 10 Mb/s. Cable connections can sometimes go up to 50 to 100 Mb/s, but that depends upon
what you want to pay for. That said, you should also realize that your actual potential rate is very dependent upon your
specific connection and could be lower than the peak promised.
For company APs and public hot spots, the connection is usually a 1 Gb/s Ethernet line. Some office APs may also
be on a 10 Gb/s Ethernet switch. A good rate is the usual result but heavy usage can overwhelm any AP.
The point is, you can buy a 1 Gb/s + capable Wi-Fi router but you are never going to see that rate if your ISP can’t
deliver it that fast. The weakest link in the data stream chain is the bottleneck. That means, getting a new 802.11ac or
802.11ax router will not in and of itself give you that rate if the ISP cannot match it.
Don’t let that stop you from upgrading as all the newer routers are backward-compatible with the previous 11n
standard. And, don’t forget that you need the latest standard like 11ac on both your Wi-Fi device as well as in the
router to get the full benefits of the latest standard.
Another good rationale for getting the newer and faster router is link reliability. Since the newer standards and
router products use lots of MIMO, the overall link is better, range is extended, and greater whole house coverage is F
(F
usually better. More users can get faster links and the overall connection is more reliable.
in

86 July/August 2018

Frenzel - Open Communication - Jul-Aug 18.indd 86 6/12/2018 11:47:35 AM


Ratification
IEEE Std. Band Technology Modulation Channel BW MIMO Max. Speed
Date
Up to
802.11n 2009 2.4 & 5 GHz OFDM 20, 40 MHz Up to 4x4 600 Mb/s
64QAM
d
Hz Up to 40, 80, 160
802.11ac 2013 5 GHz OFDM Up to 8x8 3 Gb/s+
256QAM MHz
2019 Up to 40, 80, 160 8x8 MU-
802.11ax 2.4 & 5 GHz OFDM Up to 7 Gb/s
expected 1024QAM MHz MIMO

Table 1. Summary of the Most Recent Wi-Fi Standards

These are 1024QAM modulation that will help deliver while before you see a critical mass of 11ax.
speeds up to 7 GB/s for a single user and multi-user MIMO Always go for the latest standard but relax knowing
that uses beamforming to target specific users. MU-MIMO that all these devices are backward-compatible to retain
is expected to boost data rates on crowded networks by a interoperability with older 11n and even 11g in some
factor up to four. Table 1 summarizes the three main Wi-Fi cases.
standards.
Routers are also available. Examples are those from
D-Link such as the AX6000 and AX11000 that work in the
Wi-Fi Issues
5 GHz band. Under the right conditions, they can produce Perhaps the biggest issue is the growing potential for
link speeds of 6 Gb/s or 11 Gb/s, respectively, using 4x4 interference. Wi-Fi does use the unlicensed 2.4 GHz and
MIMO. 5 GHz bands that are loaded with lots of other radios.
Figure 2 shows a front-end module (FEM) from The 2.4 GHz band is already shared with Bluetooth,
t Ethertronics that operates in the 5 GHz band. It includes ZigBee, 802.15.4 ISM band radios, and cordless phones.
d Ethertronics active antenna steering technology along with Furthermore, the allocated Wi-Fi bands are limited so there
a +18.5 dBm power amplifier that works with both 11ac is some contention for the channels that occurs in areas
e and 11ax in 80 and 160 MHz channels. where multiple Wi-Fi access points are closely adjacent.
ds Don’t forget! To receive the benefits of any of these On top of that, the growing adoption of the Internet
newer standards like 11ac and ax, you must have the same of Things (IoT) using Wi-Fi will potentially put thousands --
technologies on both ends of the link. To get full 11ac even millions -- of more devices in the same spectrum that
benefits, the router or AP must meet the standard as well will surely lead to even more interference.
as your laptop, iPad, or smartphone. Most of the newer Another issue that has risen over the years is more
phones and laptops incorporate 11ac. However, it will be a users per access point. Each AP can handle multiple
connections at a time, but it slows the data rate for each.
The newer standards have addressed this capacity problem
by using MIMO and boosting speed.
Another forthcoming problem is running out of
spectrum. Wi-Fi has only been allotted a certain amount
of space in the 2.4 and 5 GHz bands. With the new 11ac
and 11ax standards using ever wider channels (up to
160 MHz), the spectrum is used up quickly and capacity
limited. More spectrum is needed if the quest for ever
higher speeds continues.
One possibility is the 3.5 GHz band that may offer
some additional space. More of the 5 GHz band would
be ideal, but many others are seeking space in that band
as well. No one seems to know now where the extra
spectrum will be or when.
In case you didn’t know, the cellular carriers are all
using a part of the Wi-Fi 5 GHz spectrum for offloading
Figure 2. The Ethertronics EC714 front-end module some high speed data streams. Two technologies are used:
(FEM) operates in the 5 GHz band and is designed to be
one is called LTE Licensed Assisted Access (LAA), and
incorporated into 11ax and 11ac equipment.
LTE-U for unlicensed. When the cellular network is at its
July/August 2018 87

Frenzel - Open Communication - Jul-Aug 18.indd 87 6/12/2018 11:47:54 AM


THE LATEST IN NETWORKING AND WIRELESS TECHNOLOGIES

THE LATEST IN NETWORKING AND WIRELESS TECHNOLOGIES

peak in activity, it may not be able to deliver high speed Using 1, 2, 4, 8, or 16 MHz channels, it can achieve data
streaming to a customer. So, the cellular operator offloads rates up to about 100 kb/s. Speed is not usually needed
the data streaming to their Wi-Fi network. That works, but in most IoT uses, so it’s not a problem. The propagation
eats up spectrum that could otherwise be used by other capability in the 902-928 MHz band is excellent and
services. under good conditions like high antennas, range can be a
kilometer or more.
What’s Next? Neither 11af or 11ah have been widely adopted. Most
IoT applications today are the slower Wi-Fi standards,
The real question is where does Wi-Fi go from here? Bluetooth, ZigBee, Z-Wave, or some variation of the
Up to now, the IEEE 802.11 standard group has focused 802.15.4 standard like Thread. All of these with the
mainly on incremental boosts in data rate and capacity. At exception of the Z-Wave operate in the already crowded
this point, more speed may not be necessary. 2.4 GHz band.
For example, an upgrade of the 11ad 60 GHz standard Another emerging wireless technology is Li-Fi or Light
designated 11ay is in the works. It offers a channel Fidelity. It uses visible light as the data carrier. White LEDs
bandwidth of 8 GHz and a 4x4 MIMO configuration that illuminate spaces and are modulated by the data. High
can generate a max speed of up to 20 Gb/s. Do we need data rate downloads are easily accommodated. The range
it? is limited because of the direct line of sight (LOS) path light
Also consider that Wi-Fi has multiple offshoots that takes, but it could be useful in some office or industrial
have not been based on the speed/capacity upgrade settings as it is very secure. Li-Fi is not officially part of the
path. For example, a modified version of 802.11a called Wi-Fi family, but who knows what will happen?
802.11p has been proposed for vehicle-to-vehicle (V2V) Finally, the big question is how does the new fifth
communications systems that are planned to enhance the generation (5G) wireless network impact Wi-Fi? 5G
advanced driver assistance systems (ADAS) that are now will deliver Wi-Fi like speeds to homes and businesses.
being installed in most new cars. V2V allows cars to talk Theoretically, it should complement Wi-Fi but it may also
to one another so as to share location, speed, direction, replace Wi-Fi in some applications. We shall see. NV
stopped, or turning condition, and other data that can help If you want to dig into Wi-Fi in more detail, you can
avoid collisions.
start at these websites:
Then, there are the 802.11af and 802.11ah standards.
Both use a version of the Wi-Fi protocols but in different
frequency bands. Both target IoT applications. For
example, the 11af version uses the available “white space.”
White space is the empty 6 MHz wide VHF and UHF TV
channels commonly available in most areas. These lower Wi-Fi Alliance
frequencies in the 54 to 698 MHz range permit longer www.wi-fi.org
range communications of many kilometers. Traditional Wi-
Fi range is typically only up to about 100 meters. IEEE Working Group 802
As mentioned, the 11ah standard also targets IoT uses. www.eee802.org
It’s designed to use the 902-928 MHz ISM band in the US.

88 July/August 2018

Frenzel - Open Communication - Jul-Aug 18.indd 88 6/12/2018 11:54:40 AM


NV New Products - Jul-Aug 18_Mar15 -NV - NewProducts.qxd 6/12/2018 5:50 PM Page 89

■ NEW PRODUCTS Continued from page 77


If you have a new product
polymers) of flammability class UL94 board can be broken down into 32 that you would like us to
V0. The specified operating individual strips each containing four run in our New Products
temperature ranges from -25°C to holes, or can be kept whole. section, please email a
+105°C. The contact material (a The initial application of the
short description (300-500
copper alloy) is gold-plated on the board was to modify the size of
SKEDD site and tin-plated on the Schmartboard surface-mount to DIP words) and a photo of your
IDC. The SKEDD contacts on the adapter boards to fit into multiple DIP product to:
dual row plug connector are offset socket sizes. These boards can be newproducts@nutsvolts.com
with a 2.54 mm pitch. On the cable used to add power and ground strips
side, the AWG 28 ribbon cable is capabilities to a circuit and they work
connected with a 1.27 mm pitch. well with ribbon cables. You can recorder with the free DASLab
Other technical features include a connect exactly how many strips that software.
rated current of 1.0A per pin, an are needed to your cable. Price is $5. The DAS240-BAT comes
operating voltage of 100V, isolation standard with 20 universal analog
resistance of >1,000MΩ, voltage For more information, contact: channels including convenient screw
stability of 500 Vac/min, and contact Schmartboard input terminals, and is expandable up
resistance of max. 10 mΩ. http://schmartboard.com to 200 channels. The acquisition
The REDFIT IDC SKEDD system features 16-bit resolution and
connectors are immediately available MULTI-CHANNEL can record measurements with a
from stock with 4, 6, 8, 10, 12, 14, sampling rate up to 1 ms per
16, 18, or 20 pins, and in any RECORDER channel.
quantities. Free samples can be
requested. B &K Precision is now offering the
DAS240-BAT portable multi-
channel recorder. The instrument was
The intuitive user interface
features a wide 10 inch TFT color
touch screen with icon driven menus.
For more information, contact: developed by B&K Precision's Measurement results can be
Würth Elektronik eiSos subsidiary Sefram in France, which displayed in numerical and graphical
www.we-online.de specializes in the design and formats.
manufacture of recorders, field The DAS240-BAT offers a
NEW TYPE OF strength meters, and other test and number of notable advantages such
measurement solutions. as significantly longer battery life, a
THRU-HOLE This new recorder measures and larger touchscreen, larger standard
BOARD records voltage, temperature, current,
resistance, frequency, and pulse.
memory, and a longer warranty.
The multi-channel recorder is

S chmartboard is now offering the


Universal DIP Adapter Board. This
is a flexible board that allows you to
Measurement data can be saved to
the 32 GB internal hard drive or to
an external device such as a USB
ideal as a field tool, and comes with
a two year warranty. It has a list price
of $3,395.
creatively modify your circuits. The memory stick. The unit also includes
two USB host ports and an LAN For more information, contact:
interface that allows users to B&K Precision
remotely control and configure the www.bkprecision.com

July/August 2018 89
TECHFORUM READER - TO - READER

>>> QUESTIONS build that would be useful? Also, what Take your time in cleaning and
is the theory of how such a detector pasting — the leaked corrosion so
Smooth LEDs? would work? tends to be very tenacious, etc., and re
What makes some LED #7184 Denzel Meier sometimes difficult to remove. Be lo
replacement bulbs dimmable, Winnsboro, SC aware that you’ll use lots of Q-tips as Th
while others are not? Some of the you’ll want fresh ones when they get re
replacements I have purchased do not PCBs With PTHs dirty and ratty. re
dim very smoothly. They seem to dim Is there a hobbyist method for Ken Simmons dr
in steps and then just turn off before making circuit boards with plated Auburn, MI no
lowering to where I need them to be. through holes at home? Also curious
The previous incandesants dimmed by what is meant by multilayer #2 Baking soda is a good acid yo
much more smoothly down to a soft boards. I'm just getting started, so neutralizer. It will stop further lu
glow. Is there a different, (maybe forgive if this is an obvious newbie damage, but does nothing to restore ba
more expensive) type/technology question. damage done. The oxide already
that would more closely emulate Leonelo Márquez deposited will need to be removed
the incandesants? I'm using an X10 #7185 Maplewood, MN with a scraping tool of some kind, and
controller for the dimming, could this will, without doubt, reveal damage.
>>> ANSWERS
[#
be the problem? Bill van Dijk P
#7181 Everett Barham Canada
Elvaston, IL [#2184 - February 2018] ke
Neutralizing Battery Corrosion #3 If the watch is really expensive, I de
TV Image Capture What’s the best way to neutralize would bring it to a watch maker shop a
What’s the best way to capture battery corrosion? I inherited an old, and pay for the cleaning. At home, a
images from my TV? I’m looking to but expensive quartz watch from for my electronics, I use dish washing th
do something like a computer “print my grandfather and found a heavily liquid — pour a few drops onto the
screen.” corroded coin battery inside the corrosion and let it soak overnight.
#7182 Sharon Fitzgerald watch case. I need to neutralize the This usually dissolves the acidic ke
Chattanooga,TN corrosion without damaging the corrosion. You can still clean with a th
movement. Q-tip, then rinse and carefully dry the
Phone Line Intercom watch.
We use our cell phones as our #1 First, use a Q-tip and 90%+ Werner
main phone service, so our “land isopropyl alcohol to clean the via Internet
line” is no longer being used. Is there corrosion — do NOT immerse
a way to use the house phone wiring or flood the watch with alcohol! #4 Sorry, but I suspect this is going
along with the old phones as a whole When you’re done with this step, to be difficult to impossible. I have
house intercom system? I have a CAREFULLY use canned air to used white vinegar to neutralize and
detached garage/workshop away GENTLY dry the cleaned area. remove the deposits and corrosion
from the house where this would Then, apply a paste made from but:
be especially useful, not to mention baking soda and water to the cleaned 1. The corrosion/battery acid and
almost every room is wired. Would I areas and let it sit for 20-30 min. The possibly the addition of the vinegar
need to disconnect from the phone baking soda will stop any corrosive acid end up removing the coatings on
company "grid" to do this? action by any corrosion not removed metal parts which makes them less
#7183 Jay Bousquet by the first alcohol cleaning. robust.
Lexington, NC Finally, use a dry Q-tip to remove 2. A watch has extremely small
as much of the baking soda paste parts and the connections may be
Show Me The Power as possible, then finish cleaning any ruined already. You need to first take
When renovating houses residue with Q-tips and alcohol. Use the watch completely apart to see
as a hobby, I need to locate the canned air to dry the cleaned area the extent of the damage inside it. If
powerlines inside the walls and also and ensure you don’t get any of the the damage is confined to the battery
underground. What curcuit can I paste blown into the watch. port, you may be in luck.
90 July/August 2018

Tech Forum - Jul-Aug 18.indd 90 6/13/2018 9:30:24 AM


>>>YOUR ELECTRONICS QUESTIONS ANSWERED HERE BY N&V READERS

Send all questions and answers by email to forum@nutsvolts.com


or via the online form at www.nutsvolts.com/tech-forum

Use a Q-tip cotton swab with bits, or two eight-bit values in rapid you press the “A” key, for example,
some vinegar on it; place it on the succession. Not all microcontrollers the keyboard’s circuit produces the
residue/corrosion and keep it there can. (If you lack a good SPI port, hex code 1C. When you release the
long enough to soak into the residue. emulate it in software.) Use the MOSI A key, the keyboard transmits a key-
Then, twist the swab to remove the signal for the key-code transmissions release code F0, followed by the key’s
residue. If more removal is needed, and use the SCLK signal to emulate code again.
repeat this process. You can also use the keyboard’s clock output. The bits The shift key works the same
ns dry swabs to remove more residue if transmitted when you press a key way. To send an uppercase A your
MI no more vinegar is needed. look much like those put out by a microcontroller or processor board
Once all the residue is removed, standard UART: a start bit; eight data would send the SHIFT key code,
you should use a contact cleaner/ bits; an odd parity bit; and a stop bit. the A key code (then a short delay),
lubricator/protector fluid to coat the The keyboard’s clock output followed by the key release code and
battery contacts. produces a logic 1 in its idle state and the A key code again. Then, it would
Phil Karras creates a positive edge for each of send the key release code followed
via email the 11 bits. An SPI port configured by the shift key code.
d as CPOL=1, CPHA=1, provides Remember, your code must
[#5181 - May/June 2018] the proper timing. Note: The least- calculate an odd-parity bit and insert
k PS2 Emulation significant bit of an eight-bit key value it in the 11-bit value to send. You can
a My Sony CD changer has a PS2 gets sent first. My old PS-2 keyboard find parity generator code on the
keyboard port to enter the CD title, produces clock signals at 13.7 kHz. Internet. Also, ensure you send the
I details, etc. Instead of typing, is there That’s a good frequency to start with key and release values in bit-reversed
p a way to emulate a PS2 interface on for the SPI port. form. Thus, the 1C code (0001 1100)
a PC or processor board to automate A PS-2 keyboard assigns a for A must get transmitted as 0011
g the key presses? unique non-ASCII code to every 1000. You can simply set up your
key. Find a list of the keys and code so it uses the “reverse-bit”
Yes, you can emulate a PS-2 assigned codes here: https:// values to start with.
keyboard. An SPI master port will do techdocs.altium.com/display/FPGA/ Jon Titus
the job as long as it can handle 11 PS2+Keyboard+Scan+Codes. When Herriman, UT
e

er
et

July/August 2018 91

Tech Forum - Jul-Aug 18.indd 91 6/12/2018 11:16:05 AM


NEAR SPACE n BY L. PAUL VERHAGE

Raspberry Pi Zero Flight


Computer — Part 2
he Raspberry Pi Zero has turned into a really different experience for me (I’m

T accustomed to using the PICAXE and BASIC Stamp). After a month, I’ve written
complete flight code and even designed a camera system for the Pi. So, this month,
I’ll fill you in on how I got the Raspberry Pi flight computer to where I can start planning to
build an airframe. Next stop, near space!

On the left is a small Raspberry Pi Zero. I’ve connected it to the expansion c


board that I designed in Part 1 to create a RaspPi BalloonSat flight computer.
b

Nearly Flight Ready The PICAXE uses the BASIC code shown next to
digitize sensor voltages with 10 bits of resolution and to w
I’ve finally incorporated the following items into the store the results into the shared EEPROM. Note that pin
RaspPi Zero flight computer: a Geiger counter to measure C.3 connects the Pi to the PICAXE and is used to signal the a
cosmic rays; a weather station to measure air temperature, PICAXE to stop updating the EEPROM while the Pi reads its
pressure, and relative humidity; a GPS to measure time, 3D stored data.
location, speed, and heading; and a digital camera. That’s e
everything I need for a really neat near space mission. Plus, i2cslave %10100000,i2cfast,i2cword ‘ memory R
plenty of room remains on the flight computer for the speed: 400 kHz, 1 word records ge
additional experiments that I’ll dream up later. pause 1000
th
ADC:
Geiger Counter and Weather Data if pinC.3 = 0 then goto ADC ‘ wait until
to
th
The PICAXE on board the RaspPi flight computer RPi is not reading EEPROM re
collects sensor data using its built-in ADC (analog-to-digital readadc10 C.0,W0 ‘ digitize
converter). Afterwards, it stores that data into the shared voltage (repeat 3 times) ev
EEPROM for the Pi to read when it’s ready. count C.2,5000,W3 ‘ count geiger P
92 July/August 2018

Verhage - Near Space - July-Aug 18.indd 92 6/12/2018 3:46:46 PM


APPROACHING THE FINAL FRONTIER
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/magazine/issue/2018/07.

To test the Raspberry Pi


Zero near space flight
computer on the ground, I needed
to do two things. First, I had to
spoof it with a GPS simulator. The
circuit on the left generates the
GPS data typically seen during
a balloon ascent. Second, the
weather station needed a syringe,
so I could pull a vacuum to
simulate the air pressure changes
found during a balloon ascent.

next memory address. That automatic


advancing keeps the code short.

b0 = bus.read_byte(address)
# get the byte of data and
increment the address
:
:
b7 = bus.read_byte(address)
# get the next byte of data &
increment address

Reading GPS Sentences


on counter clicks My GPS receiver constantly produces about seven
ter. writei2c (1,B0) ‘ write first different sentences every second. Therefore, I have the Pi
byte of digitized voltage read the sentences as they arrive over its GPS port until it
pause 10 receives a sentence matching the format it’s looking for.
writei2c (2,B1) ‘ write second In this case, I want a sentence containing the time and
word of digitized voltage altitude data. So, I programmed the Pi to listen for the GGA
pause 10 ‘ (repeat for sentence. The code used to get the GPS sentence begins
e all data) by saving a bogus GPS sentence to the GPS variable
ts (GPSSentence) and then loops until the Pi receives the
Since the PICAXE digitizes its data at 10-bit resolution, desired GPS sentence:
each reading must be stored in two bytes. This is why the
Raspberry Pi reads the EEPROM a total of eight times to GPSSentence = ‘GPaaa’
get the four sensor values. while not GPSSentence.startswith(‘$GPGGA’):
Following are the Python commands used to retrieve GPSSentence =ser.readline()
this data. Occasionally, the EEPROM isn’t ready for the Pi
to read its contents (according to an error message from Since all the data is stored on a 32 Gb SD card,
the Pi). So, if there’s an EEPROM exception, I have the Pi there’s no need to save space by parsing out the GGA
read the EEPROM a second time. sentence for the information I want. Instead, the entire
The nice thing about these commands is that GGA sentence is written to the SD card with the rest of the
every time the Pi retrieves one byte from EEPROM, the analog data.
r Pi automatically advances its address pointer to the By the way, I had difficulty getting the Pi to pause five
July/August 2018 93

Verhage - Near Space - July-Aug 18.indd 93 6/12/2018 3:47:00 PM


APPROACHING THE FINAL FRONTIER

The RaspPi Zero is the warm blob


(yellow rectangle) on the right
side of the figure. The smaller warm blob at
the lower left I think is where I held the PCB
before taking this image. Seeing this makes
me wonder if the heat generated by the Pi
means batteries inside the airframe won’t
need a hand warmer.

The Raspberry Pi runs hotter than the rest of the flight computer PCB (printed circuit board) or
PICAXE. Based on a recommendation of one of my near space friends, Mark N9XTN, I took a thermal
image of the powered-up flight computer (Figure A).

seconds before reading another GPS sentence. As a result, executed once since there’s only one GPGGA sentence to
I programmed it to read the GPS every second and then store.
throw away four sequential sentences.
text = textcount+”,” # append a comma to
the end of the string
Storing Data text = text+textd0 # append the first
Analog sensor data is binary by its nature, but the GPS data to the record count
data is ASCII text. These data types must be converted into text = text+GPSSentence # append the GPGGA
the same format before they can be combined together sentence to the data to store
and stored in the SD card. Since I’ll use Excel to analyze
the data, I choose to convert all the data into ASCII. First, After creating the string of data that the Pi collected,
however, both bytes from the analog-to-digital conversion it’s time to write the text to the file stored on the SD card.
must be combined into a word before it can be converted The Python commands to open the file, append the new
into ASCII text (a string variable). The commands to do this data, and close the file look like this:
are:
file = open(Logfile,”a+”) # open the log file
d0 = (b1*256)+b0 # combine the two and append data
bytes to make a word of data file.write(text) # write the data into
textd0 = str(d0) # convert binary the log file
data into text file.close() # close the log file

After converting each analog voltage into text, it’s It’s taken me a good month to get to this point. I
1
time to concatenate them together along with the GPS think it’s worth it, however, even if just for the learning F
d
sentence. The commands to do that are shown next. Note opportunity. Next time, I’ll talk about the camera that I a
that the first line of code adds a comma to the string so found for the Raspberry Pi and how I plan to integrate it a
that Excel knows where to divide the text data into its into the flight computer.
proper fields (I store the flight computer’s data as a comma With any luck, my RaspPi flight computer will be taking
delimited file). a trip into near space this summer.
The second command gets repeated four times (once Onwards and Upwards,
for each analog measurement). The last line of code is Your Near Space Guide NV
94 July/August 2018

Verhage - Near Space - July-Aug 18.indd 94 6/12/2018 3:51:03 PM


ElectroNet - Classified Ads - Index - Jul-Aug 18_Mar15 -NV - NewProducts.qxd 6/12/2018 8:46 PM Page 95

ELECTRONET
For the ElectroNet online, go to
www.nutsvolts.com
click Electro-Net

USBUSB-FIFO
Add USB to your next project--
It's easier than you might think!
USB-UART USB/Microcontroller Boards
RFID Readers Design/Manufacturing Services Available
Absolutely NO driver software development required!
www.dlpdesign.com

LIGHTING HARDWARE
WANTED

DEC and VME


Equipment WANTED!
Digital Equipment Corp
and
Motorola MVME Systems
and Parts
Buy - Sell - Trade
Subscribe today! CALL KEYWAYS 937-847-2300
or email buyer@keyways.com

ADvertiser INDEX
■L O O K F O R ■S E A R C H F O R ■F I N D Find your favorite advertisers here! Accutrace .................................99
All Electronics Corp. ................43
ACTUATORS DEVELOPMENT Hitec Commercial Solutions
Hitec Commercial Solutions PLATFORMS/TOOLS Pololu Electronix Express ...................33
Technologic Systems SDP/SI
AUDIO/VIDEO ServoCity ExpressPCB ............................27
Zeppelin Design Labs EDUCATION Front Panel Express ................57
ME Labs SERVICES
BATTERIES/CHARGERS PoLabs Octopart Hammond Manufacturing ........76
Hitec Commercial Solutions
EMBEDDED SYSTEMS TEST EQUIPMENT Hitec Commercial Solutions ......2
BUYING ELECTRONIC Saelig Co. Inc. Electronix Express
SURPLUS Technologic Systems PoLabs Labcenter Electronics ................3
Saelig Co., Inc.
All Electronics Corp. SequimTek
ENCLOSURES Measurement Computing ......100
CIRCUIT BOARDS Front Panel Express
Hammond Manufacturing TOOLS ME Labs ..................................65
Accutrace PanaVise
ExpressPCB PoLabs Octopart .....................................7
PCB Fab Express KITS
Saelig Co., Inc. Zeppelin Design Labs PanaVise .................................40
TRANSFORMERS
Hammond Manufacturing
COMPONENTS LCDs/DISPLAYS PCB Fab Express ....................64
All Electronics Corp. Saelig Co., Inc.
Electronix Express WIRE, CABLE AND Pico Technology ......................21
Octopart MICROCONTROLLERS / CONNECTORS
Saelig Co., Inc. I/O BOARDS All Electronics Corp. PoLabs ....................................27
ME Labs Pololu .......................................41
DATA LOGGING Technologic Systems WIRELESS PRODUCTS
Measurement Computing Technologic Systems
Saelig Co., Inc. ........................15
Pico Technology MISC./SURPLUS
All Electronics Corp. SDP/SI .....................................77
DESIGN/ENGINEERING/
REPAIR SERVICES MOTORS / MOTOR SequimTek .................................7
Accutrace CONTROL
ExpressPCB ServoCity .................................98
Hitec Commercial Solutions
DESIGN SOFTWARE Technologic Systems ...............56
Labcenter Electronics ROBOTICS
Electronix Express Zeppelin Design Labs ..............23

July/August 2018 95
NV Webstore - Jul-Aug 18_NV Webstore June 2016 working.qxd 6/12/2018 8:31 PM Page 96

For comple t e pr oduct de t ails, visi t us online!!


The Nuts & Volts WEBSTORE
GREAT FOR DIYers!
Schaum's Outline of Electric Electronics Workshop Arduino and Raspberry Pi Sensor
Circuits, Seventh Edition Companion for Hobbyists Projects for the Evil Genius
by Stan Gibilisco by Robert Chin
by Mahmood In this practical Learn to quickly build
Nahvi & Joseph guide, electronics your own electronic
Edminister expert Stan gadgets that monitor,

the real world — with


Tough test Gibilisco shows you, measure, and react to
questions? Missed step by step, how to
lectures? Not set up a home no prior experience
enough time? workshop so you required! This easy-to-
Textbook too can invent, design, follow guide covers the
pricey? This all-in- build, test, and programming and
one package repair electronic electronics essentials
includes more than circuits and gadgets. needed to build fun and
500 fully-solved Electronics Workshop educational sensor-based projects with
problems, examples, and practice exercises Companion for Hobbyists both the Arduino and Raspberry Pi. Arduino
to sharpen your problem-solving skills. Plus, provides tips for constructing your and Raspberry Pi Sensor Projects for the Evil
you will have access to 25 detailed videos workbench and stocking it with the tools, Genius features step-by-step DIY projects
featuring math instructors who explain components, and test equipment you’ll that use inexpensive readily-available parts.
how to solve the most commonly tested need. Clear illustrations and interesting You will discover how to use touch,

motion sensors — even sensors that


problems — it's just like having your own do-it-yourself experiments are included temperature, moisture, light, sound, and
virtual tutor! throughout this hands-on resource.
$22.00 $25.00 detect the presence of a human! $24.00

Hacking Electronics: Learning Programming the Raspberry Pi, Beginner's Guide to Reading
Electronics with Arduino and Second Edition: Getting Started Schematics, 3E
Raspberry Pi, Second Edition with Python by Stan Gibilisco
by Simon Monk by Simon Monk
Navigate the roadmaps
Up-to-date hacks that An updated guide of simple electronic
will breathe life into to programming circuits and complex
your Arduino and your own RaspPi systems with help from
RaspPi creations! projects an experienced
This intuitive DIY engineer. With all-new
Learn to create inventive art and demo circuits
guide shows how to programs and fun games
wire, disassemble, you can build, this
on your powerful hands-on, illustrated
tweak, and re- Raspberry Pi with no
purpose household guide explains how to
programming experience understand and create
devices and required. This practical
integrate them with your RaspPi and high-precision
book has been revised to fully cover the electronics diagrams.
Arduino inventions. You’ll discover how to new Raspberry Pi 2, including upgrades to
build an Internet-controlled hacked electric Find out how to
the Raspbian operating system. DIY identify parts and connections, decipher
toy, ultrasonic rangefinder, remote- projects include a hangman game, RGB
controlled robotic rover, audio amp, slot element ratings, and apply diagram-based
LED controller, digital clock, and information in your own projects.
car brakes and headlights — even a smart RasPiRobot with an ultrasonic rangefinder.
card reader!
$30.00 $15.00 $25.00

How to Diagnose and Fix Programming PICs in Basic Programming Arduino


Everything Electronic by Chuck Hellebuyck Next Steps: Going Further
by Michael Jay Geier If you wanted to learn with Sketches
A Fully Revised how to program by Simon Monk
Guide to microcontrollers, then
you've found the right In this practical guide,
Electronics book! Microchip PIC electronics guru Simon
Repair all kinds of microcontrollers are Monk takes you under
electrical products, being designed into the hood of Arduino
from modern digital electronics throughout and reveals professional
gadgets to analog the world and none is programming secrets.
antiques, with help more popular than the Also shows you how
from this updated eight-pin version. Now to use interrupts,
book. The Second the home hobbyist can manage memory,
Edition offers expert create projects with these little program for the
insights, case studies, and step-by-step microcontrollers using a low cost Internet, maximize
instruction from a lifelong electronics guru. development tool called the CHIPAXE
system and the Basic software serial communications,
Discover how to assemble your workbench, perform digital signal
use the latest test equipment, zero in on and language.Chuck Hellebuyck introduces
how to use this development setup to processing, and much more. All of the 75+
replace dead components, and handle example sketches featured in the book are
build useful projects with an eight-pin
reassembly. $24.95 PIC12F683 microcontroller. $14.95 available for download. $20.00

96 July/August 2018
NV Webstore - Jul-Aug 18_NV Webstore June 2016 working.qxd 6/12/2018 8:32 PM Page 97

Order online @ store.nutsvolts.com


Or CALL 1-800-783-4624 today!

CD-ROM SPECIAL
EDUCATIONAL

July/August 2018 97
EXTREME
S E R V O G E A R B O X E S
BUILT FOR

A P P L I C A T I O N S

FEATURES...
32P GEARS: MULTIPLIES THE TORQUE BY UP TO 7x

EXTERNAL POTENTIOMETER: UNLOCKS UP TO


400° OF ROTATION

1/2‘’ SHAFT: ISOLATES THE LOAD FROM THE SERVO

6-32 THREADED HOLES: PROVIDE NUMEROUS


MOUNTING SOLUTIONS

- UTILIZING OUR PATENTED DESIGN


- FEATURING HITEC’S D485HW SERVO

AVAILABLE AT SERVOCITY.COM
sales@servocity.com • 620-221-0123

Full Page Ad.indd 98 6/12/2018 6:39:11 PM


ea ea ea

Our Full Service Capabilities:

(408)748-9600
ITAR I SO 9001:2008 UL Approved

Full Page.indd 99 4/9/2018 4:09:02 PM


Expand Your Data Acquisition
Options with Open Source Software
Measurement Computing now offers
Easy-to-use Python™ and C® Support
with Universal Library for Linux®
MCC is committed to the success of our customers on all platforms.
Due to the strength and growth of the Linux community, Measurement Computing provides Linux
support options for many of our data acquisition devices through the newly developed Universal
Library for Linux. UL for Linux is open source, with the source code available on GitHub for you to
compile on your distribution of Linux.

Unparalleled Linux Support


• Completely Open Source
• Programming support for Python™ and C/C++®
• Extensive documentation and example programs
• Free pre-sales and post-sales technical support

The Universal Library API for Linux is an MCC developed library


that supports our most popular USB devices. It includes an
interface to the library in Python™ as well as C/C++®.
Source code and examples are available on GitHub. Navigate
to www.mccdaq.com/ULforLinux for more information!

1 YEAR

www.mccdaq.com/ULforLinux
Contact us
1.800.234.4232
©2018 Measurement Computing Corporation, 10 Commerce Way, Nor ton, M A 02766 • info @mccdaq.com

Full Page Ad.indd 100 6/12/2018 6:28:47 PM


N&V-BACK-UL-June.indd 1 5/11/18 1:41 PM

You might also like