This is only a preview of the December 2023 issue of Silicon Chip. You can view 37 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Arduino Uno R4 Minima":
Items relevant to "Ideal Diode Bridge Rectifiers":
Items relevant to "Secure Remote Switch, Pt1":
Items relevant to "Multi-Channel Volume Control, Pt1":
Items relevant to "Coin Cell Emulator":
Items relevant to "Recreating Sputnik-1, Part 2":
Purchase a printed copy of this issue for $12.50. |
Part 1 by Tim Blythman
Many people now have home theatre/
surround sound systems and need to
control the volume of six or more audio
channels. This Multi-Channel Volume
Control has a touchscreen and receives
infrared remote signals. It can be
expanded up to 20 channels, although
six or eight will suit most applications.
Multi-Channel
Volume Control
T
he Multi-Channel Volume Control can
be built as a stand-alone unit in its
own enclosure, or as a modular system that can be incorporated into a
multi-channel preamplifier or amplifier. It can control up to 20 channels
in synchrony.
A microcontroller senses inputs
from the touchscreen, rotary encoder
or infrared remote control and drives
digital potentiometers to control the
volume of each channel.
One of the reasons behind this project was our publication of the Hummingbird Amplifier module in the
December 2021 issue (siliconchip.
au/Article/15126). That small, lowcost 100W amplifier module makes it
easy to build an amplifier with four,
six or even more channels. You need
something like this design to adjust the
volume of all those modules together.
The alternative would be a fourganged or six-ganged potentiometer,
but then you would have poor tracking and messy wiring. Pots can also go
scratchy after a while, unlike a digital
pot, which generally continues working flawlessly for decades.
This design is based on the Touchscreen Digital Preamp (September &
October 2021; siliconchip.com.au/
Fig.1: the performance is similar to the Touchscreen Digital
Preamp, with THD+N typically less than 0.002% across
much of the range. The dashed lines show the degradation
with 1μF ceramic coupling caps instead of 2.2μF tantalums.
60
Silicon Chip
Series/370), which only sports two
channels and is not expandable.
Besides this design, another option
is Phil Prosser’s “The Digital Potentiometer” (March 2023; siliconchip.
au/Article/15693). While it is a two-
channel design, it does allow you to
gang up multiple boards. However, it
is a more ‘bare bones’ design than this
one, lacking the touchscreen option or
any onboard audio sockets.
Performance
The Multi-Channel Volume Control is based on a Baxandall-style volume control circuit but uses a digital
Fig.2: a plot of THD+N against input level. The sweet spot
for input levels is ~1.5V, but anywhere in the range of 1-2.3V
RMS is fine. Above 2.3V RMS starts to cause clipping while
lower levels suffer due to the closer noise floor.
Australia's electronics magazine
siliconchip.com.au
potentiometer rather than the regular
kind. Handily, this circuit provides a
logarithmic response from a linearly
changing resistance, making it easy
to map the volume settings to levels
in decibels.
Figs.1-4 show the resulting performance. Fig.1 plots total harmonic distortion plus noise (THD+N) against frequency for an input signal level of 1.6V
RMS. As you’d expect, the plots are
similar to those for the Touchscreen
Digital Preamp.
The red plot was taken with a
20Hz-22kHz bandwidth, which best
represents the normal audible range
and thus what you would hear.
The cyan/blue plot was taken with
a wider bandwidth, up to 80kHz,
which includes the harmonics of
higher-frequency signals. They are not
directly audible but could intermodulate to affect audible frequencies.
As you can see, THD+N is below
0.001% for up to 2kHz and below
0.002% up to about 7kHz.
Fig.2 shows the total harmonic distortion plus noise (THD+N) against
signal level for three volume (gain)
settings. The distortion is higher at
lower signal levels as the fixed noise
dominates the smaller signals. The
sharp rise around 2.5V RMS is where
the Volume Control enters clipping.
The sweet spot is with an input signal around 1.5V RMS.
Fig.3 shows the crosstalk between
channels. The two plots show the
extremes that can be expected within
a single Volume Module (explained
Features & Specifications
»
»
»
»
»
»
»
»
»
»
»
»
»
Can control the volume of four, eight, 12, 16 or 20 channels
RCA sockets for inputs and outputs
Volume levels/gain settings: mute (-100dB) and -48dB to +16dB
1dB or smaller steps from -30dB to +16dB
Digital controls, including touchscreen, rotary encoder and IR remote
2.8in LCD screen shows the volume and mute status
Can be programmed to support many NEC-compatible IR codes
Each channel can have a preset offset applied
Volume and mute settings kept in EEPROM for next power on
Optional small OLED status display with rotary encoder
THD+N: typically less than 0.002% (see Fig.1)
Channel separation: >80dB (see Fig.3)
Signal handling: 0.1-2.5V RMS
Image source: unsplash.com/photos/HLhmbBw6xpY
later). The cyan/blue plot shows the
crosstalk from adjacent channels and
is around -80dB or better; these channels share some components. The red
plot shows the separation between
channels at opposite ends of a module, which is a little better.
Fig.4 shows the frequency responses
at three gain settings: +5dB (red), 0dB
(green) and -5dB (cyan/blue). There is
a slight but uniform roll-off at lower
frequencies, but the level difference
is uniform across the audible band. In
other words, the volume adjustment is
consistent, as is expected.
Modular design
While we are boasting up to 20 channels, most constructors will not need
that many. So rather than offering a
design based around a single PCB,
Fig.3: channel separation is about 80dB at worst and only
for adjacent channels that share an op amp in their audio
paths.
siliconchip.com.au
the Volume Control is modular. The
three modules are the Control/Power
Supply Module, the four-channel Volume Module and an optional OLED
Module.
The main Control and Power Supply
Module incorporates a microcontroller
that converts the user input into the
necessary actions to implement the
volume control. It also contains all
the power supply circuitry needed to
drive any other connected modules.
The power supply section only
needs a 12V AC supply, which can
be provided from a small mains transformer or AC plugpack if your system doesn’t already have a suitable
source. You probably won’t need a
separate transformer if your system
has a larger transformer incorporating
12V AC taps.
Fig.4: a frequency response plot at three different volume
settings (-5dB, 0dB and +5dB). There is only a slight roll-off
at the bottom end, and the effect of the volume settings is
very uniform across the spectrum.
Australia's electronics magazine
December 2023 61
The Control and
Power Supply Module has
parts on both sides. This side mostly
has the power-supply components.
Although we haven’t tested it, a
pair of ±15V DC rails could be fed to
the Control and Power Supply Module instead.
The Control/Power Supply module
also incorporates an infrared receiver
and a 2.8-inch LCD touchscreen. The
Module’s PCB is the same size as the
LCD panel at 50mm tall, making it a
comfortable fit for a 3U rack case, or
anything taller.
The Volume Module can control
the volume of up to four channels
and incorporates an AD8403 precision quad digital potentiometer. This
Module also has four input and four
output RCA sockets, plus other components to buffer and drive the audio
signal as it passes through.
A third type of module, the OLED
Module, is a simple and compact alternative (or supplement) to the touchscreen display. It includes a small
OLED screen for those who want something smaller and simpler; its input
control is a rotary encoder.
The various modules are connected
by a ribbon cable punctuated by IDC
connectors. This carries all power and
control signals between the modules.
The simplest configuration is a single Control and Power Supply Module with between one and five Volume
Modules, allowing 4-20 channels to
have their levels adjusted as they pass
through.
If the OLED Module is added, only
four volume modules can be connected, which limits the number of
controlled channels to sixteen. Still,
62
Silicon Chip
we don’t see that as a major limitation!
Due to the various ways this project can be arranged, and the fact that
many will be building it as part of a
larger system, we will not specify a
particular enclosure. You can choose
an enclosure based on your requirements that will also fit any amplifier
modules, transformers and other necessary bits.
We’ll start by describing how each
module works. Then, next month,
we’ll follow up by outlining the assembly of each type of module, along with
instructions on how they are wired
together, tested and used.
Control and Power
Supply Module
Fig.5 is the circuit diagram for the
Control and Power Supply Module. It
receives 12V AC via CON7 or CON8.
CON7 is a barrel socket and thus can
only accept a single 12V AC input. On
the other hand, CON8 has three terminals and is intended to connect to
a 24V AC centre-tapped transformer,
or two 12V AC phases; however, you
could connect a single winding via
CON8 if that’s all you had.
Either way, the AC supply passes
through bridge rectifier BR1 and a
pair of 1000µF electrolytic capacitors
to provide a nominally ±17V DC supply to be regulated. Feeding in two
AC phases via CON8 is preferred as
the capacitors only need to hold up
through the 10ms of each half-cycle
rather than 20ms for a full mains cycle.
The board generates five regulated
Australia's electronics magazine
DC rails. REG2 (78L12) and REG4
(79L12) provide +12V and -12V,
respectively, to power the analog circuitry. Their outputs are filtered by
100µF capacitors and taken to CON11,
which feeds the ribbon cable bus noted
earlier, for distribution to the other
modules.
The +12V rail is further regulated
to 5.5V by REG5, an LM317L and
its accompanying components. The
accompanying resistors and VR2 allow
its output voltage to be trimmed to
account for resistor tolerances.
A 220µF capacitor sits on the output of REG5, and this voltage is also
taken to CON11. If the 5.5V rail is
adjusted too high, zener diode ZD1
conducts and protects other circuitry
downstream.
The unregulated positive rail is also
dropped via a 22W 5W resistor (to
spread dissipation) and reduced to 5V
by REG1 (7805). It has a 100µF bypass
capacitor on its input and a 220µF filter capacitor on its output.
This 5V rail is used on the Control
and Power Supply Module to power
the LCD touchscreen; the power
needed by the LCD backlight, and the
resulting higher dissipation, is the
main reason why this regulator is a
larger TO-220 type, while the others
are in smaller TO-92 packages.
The 5V rail is reduced to 3.3V by
REG3 (MCP1700) to power microcontroller IC9. The 3.3V rail is also available on CON11 to power the microcontroller on the OLED Module.
Broadly, the +12V and -12V rails
power analog components, while the
5.5V rail primarily powers the digital
potentiometers. The 5V and 3.3V rails
power the digital components. The
separate power domains help to minimise any intrusion of digital signals
into the analog, which would affect
audio quality.
On the Control and Power Supply
Module, the remaining circuitry consists mainly of the microcontroller,
the LCD touchscreen and their essential ancillaries. IC9 is a 20-pin, 8-bit
PIC16F18146 microcontroller. It is
powered from the 3.3V rail, so it can
easily interface with the LCD controller, which also runs at 3.3V from its
own regulator on the LCD’s PCB.
A 10kW resistor pulls IC9’s pin 4
MCLR pin to the 3.3V rail, preventing spurious resets, while a 100nF
capacitor bypasses its supply to pins
1 and 20. These three pins, plus the
siliconchip.com.au
Fig.5: the Control and Power Supply Module circuit derives +12V, -12V, +5.5V, +5V and +3.3V rails to power the
control circuitry and external modules. The microcontroller handles the LCD touch panel and receives inputs from an
infrared receiver. It also sends signals to the two other module types over a 20-way bus via CON11.
siliconchip.com.au
Australia's electronics magazine
December 2023 63
PGC and PGD programming pins, go
to ICSP header CON10 for in-circuit
programming if needed.
Another nine of the micro’s digital
pins are wired to CON11 to control
the other modules. The SCK, MOSI
and MISO pins form the SPI serial
bus that controls the other modules.
The PIC16F18146 can remap its digital
peripherals to any digital pin, so the
pin allocation was chosen to simplify
the PCB routing.
Five CS (chip select) lines are
also broken out, allowing up to five
different slave modules to be independently addressed for the SPI bus.
The SHDN (shutdown) line allows the
micro to signal to all Volume Modules
that their outputs should be muted.
The SPI bus pins are also wired to
the LCD touchscreen via CON9, along
with the other four digital control
lines it needs. A pair of Mosfets plus
pullup and pulldown resistors power
the LED backlight in the LCD touchscreen, controlled by a digital signal
(LED_CON) from IC9.
Infrared receiver IRRx1 takes its
power from the 5V rail, smoothed by
the 100W resistor and 1µF capacitor. Its
output goes to the last of IC9’s unused
pins via a 1kW resistor.
These receivers typically have a
30kW internal pullup, so even though
it is powered from 5V, it can safely
interface to the microcontroller
expecting 3.3V levels. That’s because
the 5V drive is quite weak and easily clamped by the microcontroller’s
internal input protection diodes.
Volume Module
The circuit diagram for a single
Volume Module is in Fig.6. CON5
connects to the Control and Power
Supply Module’s CON11 via a 20-way
ribbon cable.
An adjustable padded divider that
includes trimpot VR1 is used to derive
a 2.75V rail from the 5.5V supply. VR1
trims this voltage, which is bypassed
by a 220µF capacitor. Test points are
provided to allow easy measurement
during setup. The 2.75V rail must be
Fig.6: the Volume Module circuit contains four substantially identical volume control stages, each using one channel of
the AD8403 precision digital potentiometer. It receives SPI control signals over the 20-way bus via CON5.
Up to five of these Volume Modules can be connected together, allowing
the volume of up to 20 channels to be controlled. The modules can be
incorporated into a larger system with other parts, like amplifiers.
set accurately to maximise the signal
swing and ensure symmetrical clipping if the signal level is excessive.
The Volume Module has a single
AD8403 quad precision digital potentiometer (IC10) powered from the
5.5V rail bypassed by a 100nF capacitor. The potentiometer’s RS (reset)
pin is pulled up to the 5.5V rail by
10kW since we do not use this feature
(which forces the potentiometers to
their midpoints).
The remaining digital pins of IC10
(SCK, MOSI, MISO and SHDN) connect to the corresponding lines on
the control bus via CON5. The CS pin
goes to five-way jumper JP2, so you
can choose which of the five CS lines
from the microcontroller on the Control Module will control this Volume
Module. Each ‘slave’ module in the
system is assigned a different CS line.
The SHDN pin is also connected to
a 47kW pulldown resistor to ground.
66
Silicon Chip
This ensures that the Volume Control is muted until the microcontroller initialises and decides otherwise.
The microcontroller can also drive the
pin low to enforce muting, helping to
eliminate noises during startup.
The remainder of the Volume Module consists of four practically identical analog sections, each using one of
the 10kW potentiometers internal to
IC10. This combination of four potentiometers (on each Volume Module) and
five CS lines gives us the 20-channel
limit of the Multi-Channel Volume
Control.
Analog circuitry
We will describe the operation of the
first channel only, as they all work the
same. All 16 op amps (in eight IC packages) are high-performance (low noise
and distortion) LM833 types powered
from the ±12V rails. Each op amp has
a 100nF bypass capacitor.
Australia's electronics magazine
A 100kW resistor biases the input
from the RCA socket to ground so it
doesn’t float if disconnected. The 100W
resistors, 470pF capacitor and ferrite
bead before the first op amp stage protect the inputs from excessive voltage
swing and filter out RF noise and ultrasonic frequencies.
The first op amp stage is a unity-gain
buffer to provide a high input impedance and low source impedance for
the subsequent stages. The output signal is AC-coupled and biased to the
2.75V rail.
Dual diode D1 clamps the signal if
it happens to deviate below the 0V
rail or above the 5.5V rail, with the
2.2kW resistor limiting the current
that flows in this case. The 0V to 5.5V
span has been chosen as the widest
that the AD8403 can handle in normal operation.
The 2.2kW resistor also forms a
divider with the 10kW of the digital
potentiometer, meaning that signals
up to 2.3V RMS (or 6.5V peak-to-peak)
are accepted at the input without clipping via D1.
The following two op amp stages
implement the Baxandall volume
control. The first stage is a unity buffer while also being a type of mixer,
while the second stage is an inverting amplifier with a gain of 14.7. One
effect of this is that this stage has its
output polarity inverted with respect
to its input.
The potentiometer is connected
between the input (‘A’ end) and output
(‘B’ end) of these two stages, providing logarithmic gain changes despite
the circuit using a linear potentiometer. Another dual diode at the other
end of the digital potentiometer’s track
to protects it from excessive voltages
from the output of the gain stage.
When the SHDN signal is asserted
(low), the digital potentiometer disconnects the A end of each potentiometer and connects the wiper to the
B end of the track; this means that output is fully muted.
The potentiometer exhibits a small
amount of resistance at the end of each
wiper, so even at the extreme ‘low’
setting, a small amount of signal will
pass through to the output unless the
SHDN signal is used.
Another capacitor and resistor bias
the signal back to its original ground
reference, and the final op amp stage
for each channel applies more gain to
allow us to get an output swing of up
siliconchip.com.au
to 2.5V RMS, despite the 5.5V peak-topeak limitation imposed by the digital
pot ICs. A 100W resistor between the
output and RCA socket isolates the op
amp from capacitive loads.
There is an option to use a jumper to
bypass the last op amp stage to reduce
the gain, saving a handful of components in the process.
An important feature is that the
four digital potentiometers can all be
set independently, allowing the channels to have different levels if needed
to maintain audio balance.
OLED Module
The OLED Module provides an
optional set of compact, tactile controls. Its circuit is very simple (see
Fig.7) as it has been designed so that
the PCB also forms a front panel with
its components on the back. This
Module is intended to be mounted
like a bezel over a cutout in an existing panel.
It connects to the ribbon cable bus
via its CON12, using the same 20-way
IDC box header as the other modules.
On this Module, only the SPI control
lines, the five CS lines, and 3.3V power
and ground are connected; its operation is entirely digital and does not
require the other supply rails.
This optional OLED Module
provides a more compact status
display and a rotary volume
control. If you don’t want to
use the touchscreen, you could
leave it off and make this as the
full interface (and with an IR
receiver wired back to the Control
Module).
A 14-pin 8-bit PIC16F15224 microcontroller (IC11) is connected to the
SPI bus as a slave, with its CS line
picked from the five on the bus by JP7.
JP7 uses solder shorting pads rather
than pin headers and a jumper to keep
this module compact.
A further three pins of IC11 are connected to a rotary encoder, which provides the user input. Two of these pins
are for the quadrature encoder and are
either pulled to ground by the contacts
in the rotary encoder or pulled up by
the 10kW resistors.
The pushbutton in the rotary encoder
is connected to a similar arrangement,
with each of these three pins also having a 100nF capacitor to ground to help
filter out contact bounce.
Two further pins from IC11 are also
used to drive the OLED via an I2C serial
interface. This OLED shows the Volume Control’s state as it is updated.
The typical arrangement for 8-bit
PICs is also present, consisting of a
supply bypass capacitor between 3.3V
and ground with a pullup to the MCLR
pin. These three pins and the PGC and
PGD pins used for in-circuit programming are also taken to the in-circuit
programming header, CON13.
Volume control
range limitations
Using a quad 8-bit digital potentiometer (IC10), rather than a purpose-
designed volume control IC, helps
keep costs down. However, it imposes
a limitation on the effective volume
control range.
A dedicated volume control IC
might give a range of 100dB or more,
Fig.7: the OLED Module circuit; it is a simple microcontroller-based board with an OLED and rotary encoder. Since it
only requires the 3.3V rail and the SPI bus, only 13 of the 20 pins on CON12 are connected
siliconchip.com.au
Australia's electronics magazine
December 2023 67
but an 8-bit digital potentiometer
only has 256 steps, meaning it has
an effective volume control range of
about 60dB.
That’s enough for most applications.
Still, you should check that the highest output level makes sense, or you
might end up without good control at
lower volume settings.
The default configuration has a
maximum gain of 16dB, giving a fullscale output of around 2V RMS from
an input signal close to 300mV RMS.
That’s well below line level, which is
typically more like 775mV RMS.
In this configuration, the lowest signal output level with a 1V RMS input
before muting is 4mV RMS or -48dB.
The steps above that are 9mV (-41dB),
15mV (-36.5dB), 21mV (-33.5dB),
27mV (-31.4dB), 33mV (-29.6dB) and
steps of about 1dB or less from there up.
While -48dB is 64dB below the maximum output level, the steps are pretty
large until around -30dB, giving a useful control range of about 46dB.
A variation of, say, 10dB between
different input signal sources will
reduce the effective volume control
range to 36dB. That gives a 4000:1
ratio between the highest and lowest
power output with decent control; if
maximum volume results in 100W
from your amplifier, you will have fine
control down to just 25mW.
That’s certainly good enough, but
the more the maximum possible gain is
above what you need, the more apparent the steps at lower volume levels
will become.
The system’s overall gain is set with
resistors, so you can easily adjust it
at the construction stage. Practically
speaking, if your power amplifier
will reach full power with less than
2V RMS (as many will, and all your
input-signals are at least line-level),
we suggest you omit the final 6dB op
amp gain stages. That will give you
6dB more room at the lower end of
the volume range.
Control firmware
We’ve chosen an 8-bit microcontroller for the Control Module as the
requirements are not too burdensome.
Although it is driving an LCD panel,
the user interface is not complex, with
only a single screen configuration
needed (no menus etc).
The LCD screen is overlaid by a
touch panel, which the micro scans
for user input.
68
Silicon Chip
Parts List – Multi-Channel Volume Control
1 Control and Power Supply Module (see below)
1-5 Volume Modules (each handles four channels; see below)
1 OLED Module (optional; see below)
1m length of 20-way ribbon cable (cut to suit application)
1 universal IR remote control (optional; see text) [Jaycar XC3718]
1 12V AC single winding or 24V AC centre-tapped transformer and appropriate
wiring/fusing
RCA cables to interface to existing hardware
Other mounting hardware to suit your application
Control and Power Supply Module
1 double-sided PCB coded 01111222, 87 × 50mm
1 2.8in LCD touchscreen [Silicon Chip SC3410]
1 2.1mm or 2.5mm DC jack socket (CON7; optional)
1 3-way 5mm/5.08mm pitch screw terminal block (CON8; optional)
1 14-way 0.1in female header (CON9; for LCD touchscreen)
1 5-way right-angle pin header (CON10; optional, for ICSP)
1 20-way box header and IDC inline plug (CON11) OR
1 20-way IDC transition header (CON11)
1 500W mini top-adjust trimpot (VR2)
1 3-pin infrared receiver, 38kHz (IRRx1)
[TSOP4138, TSOP33438, Jaycar ZD1952, Altronics Z1611A]
9 M3 × 5mm panhead machine screws
4 M3 × 12mm tapped spacers
1 M3 hex nut and washer (for mounting REG1)
Semiconductors
1 W04M bridge rectifier (BR1) [Jaycar ZR1304]
1 PIC16F18146-I/SO microcontroller programmed with 0111122B.HEX,
wide SOIC-20 (IC9)
1 IRLML2244TRPBF or SSM3J372R 20V 1A+ logic-level P-channel Mosfet,
SOT-23 (Q1)
1 2N7002 60V 115mA N-channel Mosfet, SOT-23 (Q2)
1 7805 +5V 1A linear regulator, TO-220 (REG1)
1 78L12 +12V 100mA linear regulator, TO-92 (REG2)
1 MCP1700-3.3 3.3V 250mA linear regulator, SOT-23 (REG3)
1 79L12 -12V 100mA linear regulator, TO-92 (REG4)
1 LM317L 100mA adjustable linear regulator, TO-92 (REG5)
1 5.6V 1W zener diode (ZD1)
Capacitors
2 1000μF 25V electrolytic
2 220μF 10V electrolytic
4 100μF 16V electrolytic
1 1μF 10V X7R ceramic, SMD M3216/1206 size
2 100nF 50V X7R ceramic, SMD M3216/1206 size
Resistors (all SMD M3216/1206 size 1% except as noted)
2 10kW
2 1kW
1 910W
1 560W
1 110W
1 100W
1 22W 5% 5W axial
We know of two otherwise interchangeable versions of this panel with
touch panels rotated by 180° compared
to each other. Our workaround is to
display the user control buttons in the
bottom half of the screen. Touches in
the top half of the panel are assumed
to correspond to touches on the bottom
half of the rotated display, so either
should work with no changes.
In retrospect, we might have chosen a more powerful (and faster)
Australia's electronics magazine
microcontroller, such as the 16-bit
PIC24FJ256GA702. At the time of
writing, they are not dissimilar in
price, although the SSOP version of
the PIC24FJ256GA702 is somewhat
more tricky to solder than the SOIC
part we are using.
The lesser flash memory available
on the PIC16F18146 meant that we
needed to compress the large font
that’s necessary to provide a clear and
legible display.
siliconchip.com.au
Volume Module
1 double-sided PCB coded 01111221, 82 × 94mm
2 quad right-angle RCA socket assemblies (CON1, CON2) [Altronics P0214]
1 20-way box header and IDC inline plug (CON5) OR
1 20-way IDC transition header (CON5)
4 SMD ferrite beads, M3216/1206 size (FB1-FB4) [Fair-Rite 2512066017Y1]
1 5×2 pin header and a jumper shunt (JP2)
1 500W mini top-adjust trimpot (VR1)
8 M3 × 6mm panhead machine screws
4 M3 × 12mmm tapped spacers
(or other mounting hardware to suit the application)
Semiconductors
8 BAT54S dual series schottky diodes, SOT-23 (D1-D8)
8(6) LM833 low-noise dual op amps, SOIC-8 (IC1-IC8)
1 AD8403ARZ10 quad precision digital potentiometer, SOIC-28 (IC10)
Capacitors (all SMD M3216/1206 size unless noted)
1 220μF 10V electrolytic
4 22μF 16V electrolytic
4 10μF 16V electrolytic
4 2.2μF 25V SMA size SMD tantalum 🔷
11(9) 100nF 50V X7R
4 470pF 50V C0G/NP0
4 100pF 50V C0G/NP0
Resistors (all SMD M3216/1206 size 1%)
8 100kW
5 47kW
4 22kW
5 10kW
4 2.2kW
10(2) 1kW
4 680W
12 100W
n numbers in brackets refer to requirements if the last op amp gain stage is
omitted
🔷 not recommended but 22μF 4V+ X5R/X7R ceramics in M3216/1206 can be
substituted (see panel on “Lessons learned during development”)
OLED Module
1 double-sided PCB coded 01111223, 51 × 76mm
1 0.96in I2C OLED module (MOD1)
1 PIC16F15224-I/SL microcontroller programmed with 0111122C.HEX,
SOIC-14 (IC11)
1 pulse-type rotary encoder with 18 tooth spline shaft (RE1)
[Silicon Chip SC5601]
1 knob to suit RE1
1 20-way SMD box header or 20-way dual-row SMD header (CON12) 🔵
1 20-way IDC inline plug
1 5-way pin header (CON13; optional, for ICSP)
4 M3 screws, washers and nuts to suit mounting requirements
4 100nF 50V X7R M3216/1206 size SMD ceramic capacitors
4 10kW M3216/1206 size SMD 1% resistors
several short pieces of solid wire (eg, component lead offcuts)
🔵 can be made by cutting 10 rows from Altronics P5415
The PIC16F18146 microcontroller we used for this project can store
around 16kB of font data in its flash
memory, so you can see how important careful managing font data is. We
were very close to running out of flash
memory before we started looking into
compression.
Font compression
To display text on a graphical screen
requires some form of font data to
siliconchip.com.au
encode the ‘glyphs’ (character representations) to show. The glyphs
usually correspond to a subset of the
ASCII character set, perhaps with
minor alterations to suit the project,
such as including the degrees (°) symbol instead of some other less-used
character.
The font data format we typically
use is widely known. It consists of two
header bytes describing the width and
height of the font in pixels, followed
Australia's electronics magazine
Control Module Kit
SC6793 ($50): also comes with 1m
of ribbon cable
Volume Module Kit
SC6794 ($55): includes all the listed
parts
OLED Module Kit
SC6795 ($25): includes all the listed
parts
Each kit includes all the parts listed
under each module in the parts list.
The only other items needed are
a case, power supply and remote
control.
by another two bytes denoting the first
ASCII character code point (eg, 32 for
a space is typical) and the number of
characters within the font.
This is followed by bits of pixel
data in bitmap form for each character
within the font. Since each byte can
hold eight pixels, a small 8×8 pixel
font of 95 characters (the full ASCII
set) takes up 764 bytes.
Fig.a (in the panel overleaf) shows
how such a font is translated from
bitmap data into the corresponding C
code. Other languages, such as MMBasic, use a similar format adapted to the
syntax of the specific language.
A 16×24 pixel font, our typical
choice for legible text on a typical
3.5in LCD panel, uses around six
times as many bytes or just over 4kB.
Larger fonts are possible by upscaling
smaller fonts, but the result does not
look as good.
The flash memory of these 8-bit
PICs uses 14-bit words. They are
often described as having 28kB of
flash memory, but it is arranged as
16k x 14-bit words rather than 28k x
8-bit bytes.
The ideal font size for the large dB
display in this project is 44×60 pixels;
that would take 31,354 bytes to store
as a full ASCII font, which obviously
wouldn’t fit in the PIC16F18146.
We can reduce the space required by
only encoding the characters we need.
For example, truncating the 12×16 font
we use for buttons and smaller text to
only include from the space character
up to the capital letters brings its size
down from 2284 bytes to 1420 bytes.
Similarly, we reduced the font used
for the dB display to the digits 0-9, a
blank space, a negative sign, a decimal point (or full stop) and the ‘d’ and
‘B’ characters. That takes it down to
December 2023 69
RLE compression
RLE stands for run length encoding and takes advantage of
repetitive values in data; in this case, runs of the same pixel
colour. RLE has existed in displays and computing for at least
50 years. RLE is used in the JPEG image standard (although it
is only part of the compression used there). It was also used
by fax machines (remember them?).
For our implementation, rather than storing bitmap data,
the data encodes a run of pixels of the same state (on/off).
The top bit indicates whether the pixels are on or off (ie, add
128 for on pixels), while the remaining seven lower bits encode
the number of consecutive pixels with that property.
Fig.b shows a glyph encoded using our RLE strategy. This
small font is not a great example for this sort of compression, as the resulting data has ballooned from eight bytes up
to 25 bytes.
RLE could be seen to encode how often the pixel state
changes on each line. So characters such as “1” should encode
better than “0” and, indeed, the RLE data only comes to 15
bytes for “1” in this particular font.
The space character for this font is encoded as a single
byte of value 64, meaning all 64 pixels are off.
This variability in glyph size is accounted for by adding a
header specifying the number of bytes before each group of
RLE data. It’s easy to write code to step through the data
jumping forward by the header’s byte count until we reach
the glyph we need to display; we then have the count of the
number of bytes we need to decode.
The RLE-compressed font we ended up with only uses 2013
bytes (including all header data) compared to the 4954 bytes
for the uncompressed version.
As an extreme example, the space character for this large
font (which consists of 2640 black pixels) takes up 330
bytes uncompressed, but only 22 bytes after compression.
Another extreme, the ‘0’ character, takes up the same 330
bytes uncompressed but only 196 bytes when compressed,
a 40% saving.
For the numerals 0-9 and space, the RLE encoding provides
a notable saving for fonts as small as 16×24 pixels. Different
font subsets, including letters like M and W, will not compress
as well as they include shorter runs.
Other advantages
The microcontroller can copy the RLE-compressed data to
the screen faster than bitmap data. There is less data to be
read from flash in the RLE case and the decoding is simpler too.
The uncompressed bitmap data needs to be decoded one
bit at a time. Each individual bit has its value checked, then
the appropriate colour pixel is written to the LCD. For the
RLE data, a group of consecutive pixels is decoded and can
be efficiently sent to the LCD in a tight loop.
Similarly, the code to show the RLE-encoded font is smaller
0b01111100
→
0b11000110
0b11000110
0b11000110
0b11000110
0b11000110
0b01111100
0b00000000
0 1 1 1 1 1 0 0 →
1 1 0 0 0 1 1 0
1 1 0 0 0 1 1 0
1 1 0 0 0 1 1 0
1 1 0 0 0 1 1 0
1 1 0 0 0 1 1 0
0 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0
const
0x08,
0x00,
0x18,
0x66,
0x6C,
0x18,
0x00,
0x38,
...
0x7c,
char TinyFont[764] = {
0x08, 0x20, 0x5F,
0x00, 0x00, 0x00, 0x00,
0x3C, 0x3C, 0x18, 0x18,
0x66, 0x24, 0x00, 0x00,
0x6C, 0xFE, 0x6C, 0xFE,
0x3E, 0x60, 0x3C, 0x06,
0xC6, 0xCC, 0x18, 0x30,
0x6C, 0x38, 0x76, 0xDC,
0x00,
0x00,
0x00,
0x6C,
0x7C,
0x66,
0xCC,
0x00,
0x18,
0x00,
0x6C,
0x18,
0xC6,
0x76,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
//
//
//
//
//
//
//
Space
!
"
#
$
%
&
0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x7C, 0x00, // 0
Fig.a: bitmap font data is encoded with a ‘1’ bit indicating a pixel is
set to the foreground colour or a ‘0’ bit if the pixel is the background
colour. The last line shows the bitmap data for the number 0.
than its bitmap equivalent, about half the size in program
flash memory. The bitmap routine also calls another function
to perform a multiplication; there would be further savings if
the same routine were not needed by other code.
Being able to update the display more quickly is a clear
upside. We suspect the effect would not be so pronounced
with a faster microcontroller, but it would still be present.
OLED fonts
We have not used RLE fonts in the firmware for the OLED
Module. Firstly, these displays are monochrome, so they do
not require individual pixel colours to be written. Instead,
they expect data to arrive in blocks of eight bits at a time,
which maps to eight pixels on the screen. In other words, they
natively work with bitmap data.
Also, the OLED has a much lower resolution, so it does not
need to display very large fonts as often. Given that larger
fonts benefit more from RLE, there is less incentive to apply
it to the smaller fonts.
Bitmaps image compression
The Silicon Chip logo shown on the LCD screen is a bitmap
and is stored similarly to the bitmap fonts. So, we experimented with a different encoding that stores a run of pixels (from 0 to 15) in each nibble of a byte. The top nibble is
assumed to be the background colour, while the lower nibble
is the foreground colour.
The code to decode this data is similar in speed and program flash memory usage, and we found this algorithm offered
about 40% compression on the Silicon Chip logo. So we used
this encoding for the logos and icons that are displayed.
Conclusion
RLE encoding a larger font gives superior image quality
than upscaling a smaller font, is faster and can use a similar
amount of flash or even less. So it seems like the way to go.
The only downside is the extra complexity in the initial encoding.
Some font examples can be found at:
www.rinkydinkelectronics.com/r_fonts.php
Download the FontTweak Font editing program from:
www.c-com.com.au/MMedit.htm
convert to RLE encoding
0111110011000110110001101100011011000110110001100111110000000000
↓
1x0,5x1,2x0,2x1,3x0,2x1,1x0,2x1,3x0,2x1,1x0,2x1,3x0,2x1,
1x0,2x1,3x0,2x1,1x0,2x1,3x0,2x1,2x0,5x1,10x0
↓
1,133,2,130,3,130,1,130,3,130,1,130,3,130,1,130,3,130,1,130,3,130,2,133,10
Fig.b: mapping of the pixels to bitmap data is from top left to bottom right in horizontal rows. For an eight-pixel wide
font, each row maps to one byte of data. With RLE encoding, each run of same-coloured pixels maps to a byte of data,
so one byte can encode up to 127 pixels. It is much more effective for fonts that have more glyphs.
70
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
4954 bytes before we apply RLE compression.
The compression technique used
is called run-length encoding (RLE).
Rather than storing simple bitmaps
for the characters to show on the display, RLE stores a run of pixels as its
count and on or off state (hence runlength encoding).
The resulting font data is less than
half its original size. That is helpful
when the font uses up nearly a third
of the available flash memory. Another
advantage is that the encoding is easy
to decompress for display, making
screen updates faster! We’ve gone into
this in greater detail in a panel, for
those interested in that sort of thing.
Infrared remote control
The IR decoding routine is designed
to receive signals encoded with the
NEC protocol. It uses pulse position
encoding with 38kHz modulation; the
IR receiver demodulates this carrier,
so the microcontroller only needs to
decode the pulse encoding.
The microcontroller uses a timer/
counter to measure the pulse lengths
and thus extract the necessary data.
The NEC protocol transmits 32 data
bits, including a device byte, its
inverse, a command code and the
command code’s inverse. The inverses
allow the microcontroller to reject corrupted codes.
The Control Module can be programmed to accept different device
and command codes, so it can be used
with fixed or programmable IR remote
controls. We’ll get more into those
details later.
The Control Module communicates
over the SPI bus on the ribbon cable.
If an OLED module is present, data is
sent out from the Control Module to
update its display; the Control Module also receives data back if there has
been activity on the rotary encoder or
its button.
The micro on the control module
signals the digital potentiometers to
set a new volume level whenever the
volume is changed. If the mute function is activated, the volume is ramped
down as low as possible, after which
the SHDN pin is pulled low to mute
the audio fully.
Unmuting is simply the reverse. The
SHDN pin goes high, then the volume
level ramps up. The same process
occurs when the unit is powered on,
avoiding clicks and pops.
siliconchip.com.au
Lessons learned during development
We solved two significant but subtle problems in developing this design. The first
was that, to save components and simplify setup, we generated the +2.75V rail
on the Power Supply & Control board and fed it via the ribbon cable to the Volume Modules.
The problem with this was that any tiny amount of noise or ripple picked up in
the ribbon cable ends up getting injected into the signals because this is a virtual ground rail. Adding extra capacitance to ground for this rail on each Volume
Module didn’t fix it. The only way to get acceptable performance was to move the
+2.75V rail generation circuitry onto the Volume Modules.
The other problem we ran into was that we accidentally used 1μF X7R multilayer ceramic capacitors to couple the signal to the last op amp stage (eg, from
pin 1 of IC2a to pin 3 of IC3a). This type of capacitor simply isn’t very linear and
the result was a significant rise in distortion below 200Hz, shown by the dashed
portions of the curves in Fig.1.
There are two solutions to this. Our preferred solution is to switch to using
2.2μF tantalum capacitors, which luckily are available in the same size (the SMA
tantalum case is basically the same dimensions as M3216/1206 ceramic chip
capacitors). Being electrolytic capacitors, these are not as linear as say plastic
film types, but significantly more linear than X7R ceramics.
Unlike ceramic capacitors, tantalum capacitors are polarised. There is 2.75V
between these points, so the capacitors are orientated with the positive leads
to the op amp pin 1 outputs.
As a less-desirable alternative, X7R multi-layer ceramic capacitors can still be
used but with a significantly higher value; at least 10μF, and ideally 22μF or more.
That pushes the distortion down so instead of starting below 200Hz, it starts
below 20Hz, which is in the inaudible part of the frequency range.
There usually won’t be much signal below 20Hz; our concern is that, if there is,
the resulting distortion harmonics could be in the audible range. Hence our preference for the tantalum capacitors.
Otherwise, the main loop updates
the display when necessary and reads
input from the touch panel.
We had provision for an IR receiver
on the OLED Module, but since the
Control Module is mandatory and
already has an IR receiver, we have not
fitted it to our prototypes and there is
no support for it in the firmware.
OLED module firmware
The microcontroller on the OLED
Module monitors the rotary encoder
and button for action, sends and
receives data to and from the Control
Module and updates the OLED screen
as required.
It acts as an SPI slave device, meaning it must be ready to respond whenever the Control Module wants to communicate. For simplicity, we designed
the communication between these two
modules to only use a single byte in
each direction.
The Master sends out the volume
level (in steps of 0.5dB) relative to a
value of 128. A value of zero means
that the mute is active. Thus, the OLED
Module doesn’t need to retain any
state data; it simply updates its display
whenever data is received.
Australia's electronics magazine
The data that the OLED Module
sends back to the Control Module is
in a similar format. The OLED module
counts the number of rotary encoder
steps (forward or backward) that have
accumulated and sends that to the
Control Module, offset from a value
of 128.
The offset helps avoid receiving spurious commands if no OLED Module is
connected. The data is designed not to
use the values of 0 or 255 (00000000
and 11111111 in binary) as might
occur if the data line was pulled up
or pulled down permanently.
A special value of 51 (00110011 in
binary) indicates a press of the rotary
encoder’s button. This works as a toggle, so the OLED Module does not need
to know the current state and simply
reports to the Control Module that the
mute state needs to change.
Next month
That’s all we can fit in this month’s
article; we will describe construction and assembly in the next issue.
Short-form kits for all three modules
are available, so you might like to
gather the parts together in preparation.
SC
December 2023 71
|