This is only a preview of the January 2021 issue of Practical Electronics. You can view 0 of the 72 pages in the full issue. Articles in this series:
|
Fig.7. Supply wiring
to reduce noise.
S upply
C ircuit 1
S ignal
Fig.9. Triaxial
connector used with
triaxial cables for
guarded connections.
Guard
C ircuit 2
S upply
Ground loops
When two circuits, sub-circuits, instruments, or other equipment
are grounded at two separate points on a ‘ground bus’ we have
a situation know as a ground loop (or earth loop) (see Fig.8).
The ground bus may be a circuit board track, the chassis of the
equipment, point-to-point wiring, or the mains earth connected
at different outlets – many people have suffered unnecessary
levels of hum in their Hi-Fi systems due to earth loops!
The ground loop will pick up magnetic interference, probably
mains hum and may also act like an antenna picking up radio
frequency interference (RFI). Large loops will make the problem
worse. Ground loops are a particular problem when two or more
mains-powered systems (such as lab instruments and sensor circuits)
are separately earthed and connected together. It is also possible
for mains leakage currents to cause currents to flow in the earth
(eg, shields) of connections linking equipment. Leakage currents
can flow through parasitic capacitances and equipment ground,
for example in transformers and EMI filters. The interference
causes a current IL to flow in the ground loop, which in turn
causes an additional voltage drop (ILRG) across the resistance (RG)
of the ground connection between the equipment or subcircuits.
The solution to ground loops is to avoid them by using a
single grounding point (Fig.8). Use of differential signals,
only connecting screens at one end, use of very low resistance
ground connections between circuits (reducing RG), and signal
isolation using transformers or opto-isolators also help minimise
ground loop problems. Power isolation transformers may also
help with mains wiring. Again, it is worth pointing out that
some potential ‘solutions’ related to mains wiring, such as
disconnecting earths, could be lethal.
O uter shield/ chassis/ ground/ signal return
T riax ial C ab le
S ignal
S ensor
Ground
Fig.10. Guarded signal connection.
of shielding. The inner shield is connected to a signal of equal
voltage to the signal provided by a unity-gain amplifier (see Fig.10).
This means that there is a zero-voltage difference between the
signal and inner shield, so the leakage currents (and capacitance
effects) are minimised. The outer shield is usually grounded and
provides interference protection for the guard signal.
IM – IL
C ircuit 1
IM
RS
A )
IM–IL
RG
C ircuit 2
VM
IL
Signal guarding
Signal guarding is concerned with getting the most out of screened
cable connections, particularly when connecting very low-level
signals from high-impedance sources to high-precision circuits.
In such cases, effects such as leakage currents in the cables and
cable capacitance can cause significant errors. Signal guarding
uses triaxial cables and connectors (see Fig.9), which have an
inner conductor, carrying the signal of interest and two layers
x1
Guard
RS
IM
IM
RC
VM
IL
B )
IM
S ignal
Guard
RS
x1
IM
VM
IL
Ground
IM
C ircuit 1
IM
RC 1
C ircuit 2
0 v
RS
IM
I L2
VM
Guard
RC 2
x1
VM
I L2
Ground
Fig.8. Ground loops: currents induced in ground loops cause
voltage drops which introduce noise (upper schematic). Using a
common ground point can eliminate the loop (lower schematic).
56
Fig.11. Guarded resistance measurement: a) non-guarded setup,
b) non-guarded equivalent circuit, c) guarded setup, d) guarded
equivalent circuit.
Practical Electronics | January | 2021
As an example of how guarding works, consider the schematic
in Fig.11a, for which an equivalent circuit is shown in Fig.11b.
Here we are trying to measure the resistance of a sensor (RS) which
has a very high resistance value and therefore leakage through
the cable insulation resistance RC is significant. We apply VM
and measure IM – this should give the value of RS as VM/IM, but
if actually gives us this parallel combination of RS and RC due to
the leakage current IL. Using a guard (Fig.11c and Fig.11d) means
that the voltage across RC1 between the inner conductor and guard
is zero and hence no leakage current flows. The buffer amplifier
has no difficulty in supplying the guard-to-ground leakage current
IL2 and this does not disrupt the measurement.
ESR Electronic Components Ltd
All of our stock is RoHS compliant and CE
approved. Visit our well stocked shop for
all of your requirements or order on-line.
We can help and advise with your enquiry,
from design to construction.
Vibration and chemistry
Systems processing low-level signals are also prone to a variety
of forms of interference-based noise and errors other than
electrically/magnetically coupled signals, including mechanical
and electrochemical effects. Movement and vibration of cables
can create electric current through the triboelectric effect –
charges created due to friction between a conductor and an
insulator. Low-noise cables are available for situations where
this may be a particular problem. Making sure that cables are
well supported and not subject to vibration or large temperature
fluctuations helps reduce this effect for any cable. Movement can
also generate unwanted signals through the piezoelectric effect,
which occurs when mechanical stress is applied to insulators.
Unwanted signals due to movement and mechanical stress are
sometimes called microphonic effects, because if the signal is
listened to, the movement of (for example) a cable will be audible.
Batteries create electric current through electrochemical effects.
Similar processes can occur if contaminants are present on PCBs
and terminals. Variations in humidity can affect sensor systems
with very high impedances. Contaminants (handling cables and
connectors) can also reduce insulation resistance leading to errors.
3D Printing • Cable • CCTV • Connectors • Components •
Enclosures • Fans • Fuses • Hardware • Lamps • LED’s •
Leads • Loudspeakers • Panel Meters • PCB Production •
Power Supplies • Relays • Resistors • Semiconductors •
Soldering Irons • Switches • Test Equipment • Transformers
and so much more…
Monday to Friday 08:30 - 17.00, Saturday 08:30 - 15:30
Station Road
Cullercoats
North Shields
Tyne & Wear
NE30 4PQ
Tel: 0191 2514363 sales<at>esr.co.uk www.esr.co.uk
Your best bet since MAPLIN
Chock-a-Block with Stock
Visit: www.cricklewoodelectronics.com
O r phone our f riendly kn owledgeab le staf f on 020 8452 0161
JTAG Connector Plugs Directly into PCB!!
No Header!
Components • Audio • Video • Connectors • Cables
Arduino • Test Equipment etc, etc
No Brainer!
Our patented range of Plug-of-Nails™ spring-pin cables plug directly
into a tiny footprint of pads and locating holes in your PCB, eliminating
the need for a mating header. Save Cost & Space on Every PCB!!
Solutions for: PIC . dsPIC . ARM . MSP430 . Atmel . Generic JTAG . Altera
Xilinx . BDM . C2000 . SPY-BI-WIRE . SPI / IIC . Altium Mini-HDMI . & More
www.PlugOfNails.com
Tag-Connector footprints as small as 0.02 sq. inch (0.13 sq cm)
Practical Electronics | January | 2021
Vi s i t o u r Sh o p , Ca l l o r B u y o n l i n e a t :
w w w .c r i c k l e w o o d e l e c t r o n i c s .c o m
020 8452 0161
Vi s i t o u r s h o p a t :
40- 42 Cr i c k l e w o o d B r o a d w a y
Lo n d o n NW2 3ET
57
Max’s Cool Beans
By Max the Magnificent
Flashing LEDs and drooling engineers – Part 11
G
ood grief! I am bubbling over with excitement.
I have so many things I want to talk about that I don’t
have a clue where to begin. I know, I know... I need
to sit down, take a deep breath, start at the beginning, work
my way through the middle, and eventually stagger my way
to the end. The problem is deciding what to talk about first.
Ah, I can see in your eyes that you are desperate for me
to commence with gamma correction. Well, if you insist...
0 ° P rim ary
330 ° T ertiary
F F
F F
R ose
30 ° T ertiary
0 0 0 0
F lush O range
0 0 8 0
F F
30 0 ° S econdary
F F
8 0 0 0
6 0 ° S econdary
Magenta
0 0 F F
11
10
27 0 ° T ertiary
Electric
I ndigo
Feeling off-colour
R ed
9
0
Y ellow
F F
1
2
F F
0 0
9 0 ° T ertiary
C hartreuse
3
58
B rightness
B rightness
B rightness
8 0 F F 0 0
Way back in the mists of time when we started this mega-mini4
8
8 0 0 0 F F
series (PE, March 2020), we introduced the concept of pulse7
5
6
width modulation (PWM). Since we can turn an LED on and
24 0 ° P rim ary
120 ° P rim ary
off very quickly, the way we control its brightness is to vary
B lue
Green
the proportion of on time to its off time. We refer to this as the
0 0 0 0 F F
0 0 F F 0 0
‘duty cycle.’ A 20% duty cycle means the LED is on 20% of
210 ° T ertiary
150 ° T ertiary
the time and off for the other 80%, while an 80% duty cycle
A z ure
18 0 ° S econdary S pring Green
means the LED is on 80% of the time and off the other 20%.
0 0 8 0 F F
0 0 F F 8 0
C yan
0 0 F F F F
In the case of the microcontroller unit (MCU) we are working
with – the Seeedunio XIAO – we can use values from 0 (0x00
Fig.1. The colour wheel we’ve been using in our experiments.
in hexadecimal) being fully off (0% brightness) to 255 (0xFF
in hexadecimal) being fully on (100% brightness). Using this
I created a quick test sketch (program) to see how this would
PWM technique, a value of 128 (0x80 in hexadecimal) means
affect the colours on my 12×12 array (the full sketch is presented
the LED will be on half of the time and off the other half, rein file CB-Jan21-01.txt – it and the other files associated with this
sulting in 50% brightness.
article, are available on the January 2021 page of the PE website).
In a later column (PE, September 2020), we introduced the
Since the folks at Adafruit were conscious that some of their users
colour wheel (Fig.1) that we decided to use for our 12×12 pingwould be using low-end Arduinos with limited SRAM, they store
pong array experiments (Fig.2). If you have built one of these
their table in PROGMEM (the Flash program memory). By comarrays yourself, or if you are playing with tricolour LEDs in
parison, my Seeedunio XIAO has so much memory that I can
general, you may have noticed that some of the colours seem
afford to flaunt it, so I dispatched the butler to fetch my flauntto be a tad ‘off’. For example, the rose may appear very close
ing trousers and stored my table in SRAM (Fig.3.).
to magenta, while the flush orange may appear more yellow
Previously (PE, October 2020), we met the GetRed(), Getthat one might expect.
Green(), and GetBlue() functions that extract and return the
On the bright side (no pun intended), the red, green, and
8-bit red, green, and blue components from a 32-bit colour value.
blue elements in our tricolour LEDs work as expected and
Also, we introduced the BuildColor() function that accepts 8-bit
provide a linear response such that a 50% duty cycle does
red, green, and blue components and returns a 32-bit colour value.
indeed result in 50% brightness (Fig.2a). The problem is that
The thing is, we have to apply our gamma correction to each
our eyes have evolved to accommodate a huge dynamic range,
of the colour channels individually. Thus, in our new sketch,
from moonlight to sunlight and – as part of this – they have a
we’ve added a GetGammaCorrectedColor() function that
sort of built-in non-linearity (Fig.2b).
accepts a 32-bit colour value, splits it into its red, green and
Although not immediately obvious from my diagram, the
blue components, uses our GammaXref[] look-up-table to
curve of this non-linearity is defined by a somewhat tricky
apply gamma correction to each component, and then returns
power-law function. In order to address this, we need to drive
the gamma-corrected 32-bit result.
the red, green, and blue LEDs using the inverse
of this function, which results in our eyes per10 0 %
ceiving what we were hoping for in the first
W hat our
eyes perceiv e
T he LED
place (Fig.2c). We call the process of applying
W hat our
work s as
eyes perceiv e
ex pected
this inverse function, ‘gamma correction.’
50 %
There’s a great article on Adafruit’s website covering all of this in depth (https://bit.ly/31zaSLK).
H ow the LED
H ow the LED
is driv en
is driv en
As part of this, they provide what they call ‘The
H ow the LED
is driv en
Quick Fix’ in the form of a cross-reference lookP W M
P W M
P W M
0 %
up table that we can use to remap the linear
0 x 0 0
0 x 8 0
0 x F F
0 x 0 0
0 x 8 0
0 x F F
0 x 0 0
0 x 8 0
0 x F F
values we would like to use into their gamma( a) W hat we ex pect to see
( b ) W hat we actually see
( c) A pplying gam m a correction
corrected counterparts that will provide us with
the colours we want to see.
Fig.2. Gamma correction.
Practical Electronics | January | 2021
gammaCorrectedColor = BuildColor(tmpRed,
tmpGreen, tmpBlue);
The idea is that you have two programs fighting each other in
a virtual machine known as the Memory Array Redcode Simulator (MARS). The objective is to be the last program standing. To that end, each program can try to sabotage the other
one and/or try to defend itself by self-repairing. You can get a
really good feel as to what this is all about by reading the Beginner’s Guide to the Redcode pseudo assembly language that
is used to create the warrior programs (https://bit.ly/34m5YUo).
As Ken said in his email, ‘I figure this can be made visually appealing by presenting the memory array on a screen (or
ping-pong ball array) and colour-coding each cell either ‘Neutral,’ ‘Last written for or by Program A,’ or ‘Last written for or
by Program B’ — using green, blue, and red respectively, for
example — and running the programs at only a few steps per
second so progress can be followed.’
Initially, I was a tad skeptical that a 144-element MARS
would suffice but – having looked at the Redcode Beginner’s
Guide – I’ve changed my mind. Now I’m thinking about creating a MARS simulator to run on the Seeeduino XIAO that I’m
using to power my 12×12 array. I’m also thinking about creating a Redcode assembler utility that can generate the warrior
programs to run on the simulator.
But wait, there’s more! Do you remember me talking about
the NeoPixel Simulator that you can use to test your own programs to run on my 12×12 array (PE, November 2020)? Well, if
I manage to find the time to get a MARS simulator up and running, we could combine it with our NeoPixel Simulator, thereby allowing you to create and test your own Code War warrior
programs and then send them to me to be run on the real array.
return gammaCorrectedColor;
Keep your balance
const uint8_t GammaXref[] =
{
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
2,
2,
2,
2,
2,
2,
2,
2,
3,
3,
3,
3,
3,
3,
3,
4,
4,
4,
4,
4,
5,
5,
5,
7,
7,
8,
8,
8,
9,
9,
9, 10,
5,
6,
6,
6,
6,
7,
7,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 109, 110, 112, 114,
115, 117, 119, 120, 122, 124, 126, 127, 129, 131, 133, 135, 137, 138, 140, 142,
144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 167, 169, 171, 173, 175,
177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213,
215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255
};
Fig.3. Gamma-correction cross-reference look-up table.
uint32_t GetGammaCorrectedColor
(uint32_t uncorrectedColor)
{
uint8_t tmpRed;
uint8_t tmpGreen;
uint8_t tmpBlue;
uint32_t gammaCorrectedColor;
tmpRed = GammaXref[ GetRed(uncorrectedColor) ];
tmpGreen = GammaXref[ GetGreen(uncorrectedColor) ];
tmpBlue = GammaXref[ GetBlue(uncorrectedColor) ];
}
The rest of the sketch is used to load the left-hand side of the array
with uncorrected colours directly from our colour wheel and the
right-hand side with their gamma-corrected counterparts, starting with red at the bottom and ending with rose at the top (Fig.4).
Although it’s not easy to see from this image, in the real
world the gamma-corrected values do present what appears to
be a richer colour palette. For example, the gamma-corrected
orange (second row from the bottom) looks more orange and
the gamma-corrected rose (top row) appears more vibrant.
War, what is it good for?
According to Edwin Starr in his 1970 hit single ‘War’ – and
Frankie Goes to Hollywood more than a decade later – the
answer is ‘Absolutely nothing.’ Of course, it may be that neither
of these luminaries were familiar with the concept of ‘Code War’.
Actually, if the truth be told, neither was I until my chum, Ken
Wood, who has been following these columns, sent me an email
telling me all about this idea. In 1984, Alexander Dewdney wrote
a column in Scientific American magazine about a programming
game called Core War that he had created with DG Jones. A scan
of this original article, along with a lot of supporting material, can
be found on the CoreWars.org website and Wikipedia.
Fig.4. Uncorrected colours
(left) vs. gamma-corrected
colours (right).
Fig.5. 9DOF BoB (Image source:
Adafruit.com)
Practical Electronics | January | 2021
When I was a kid, my parents bought me a wooden marble
maze toy. I just found something quite similar on Amazon
(https://amzn.to/2HwZg4M), although the one I owned had
larger mazes and used smaller ball bearings.
The reason I mention this here is that a reader emailed me
to suggest I attach a sensor to my 12×12 array such that, if the
array is held in a horizontal plane, I could control the ‘rolling’
of a lit pixel by detecting the tilt of the array.
By some strange quirk of fate, I just happened to have one
of Adafruit’s BNO055-based 9DOF (nine degrees of freedom)
Fusion breakout boards (BOBs) in my treasure chest (junk box)
of spare parts (Fig.5) (https://bit.ly/3dP8EwU).
This little beauty is based on a BNO055 microelectromechanical system (MEMS) sensor from Bosch. In turn, the BNO055
contains a 3-axis accelerometer, a 3-axis gyroscope, and a
3-axis magnetometer (they also throw in a temperature sensor
for good measure). The really cool thing about this device is
that it also contains a 32-bit Arm Cortex M0+ processor, which
performs all sorts of mindbogglingly complicated sensor algorithms for you and provides you with data in a form you can
use without your brains leaking out of your ears.
As usual, the folks at Adafruit provide a wealth of information
on this sensor, including pinouts, wiring, and how to download
the required libraries (https://bit.ly/35sVvpz). Also included is
some sample Arduino Code, which I used to create my first test
program. The purpose of this initial sketch was to make sure I
could get my XAIO microcontroller to talk to the BNO055. All
we do is loop around reading the x, y, and z orientation values
from the BNO055 and display them as floating-point values on
the Arduino’s Serial Monitor. Note that the XIAO communicates
with the BNO055 via an I2C bus, which uses pins 5 and 6 on the
XIAO, but we don’t declare these pins in our sketch because
Adafruit’s libraries handle all of this for us (file CB-Jan21-02.txt).
The next step involved some mental gymnastics to visualize
how I was going to mount my breadboard in the 12×12 array
case, and which (sensor) values corresponded to what (left-right
and forward-backward) tilts. Eventually, I determined that the
59
|