This is only a preview of the December 2022 issue of Silicon Chip. You can view 42 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Dual-channel Breadboard PSU":
Items relevant to "Breadboard PSU Display Adaptor":
Items relevant to "Active Monitor Speakers, Part 2":
Items relevant to "Digital Boost Regulator":
Purchase a printed copy of this issue for $11.50. |
Digital Boost
Regulator
By Tim Blythman
This board lets you use a PIC18F18146
8-bit microcontroller for any task while
its onboard peripherals generate an
adjustable voltage without interfering
with what it’s doing. It even includes
some capacitive sense buttons and a
seven-segment display that can be used to
show the voltage or for other uses!
T
he PIC16F18146 micro has some
interesting onboard peripherals.
We realised it is possible to combine
several of them with a small number of
external parts to make a free-running,
programmable boost voltage regulator that doesn’t require any processor
intervention while running.
This small PCB allows you to experiment with or use this concept. Since
this 8-bit microcontroller has 20 pins,
we’ve connected them all to headers
for making off-board connections.
This design was prompted by our
review of the latest 8-bit PICs in the
October 2022 issue (siliconchip.au/
Article/15505).
We’ve added a small LED display
and some touch-sensitive pads to create a standalone, digitally controllable
boost voltage regulator with a digital
readout. If you’re a keen programmer,
you might be interested in testing
your own designs using this chip. It
could be used as the basis of all sorts
of devices.
You could leave off most of the components and use the board to experiment with the bare chip, although we
already presented a ‘breakout board’
that does that in October (siliconchip.
au/Article/15506). Most recent 8-bit,
20-pin PIC microcontrollers have a
siliconchip.com.au
similar pin layout, so this board could
possibly be used with them too.
We purchased some PIC16F18146
chips in SOIC packages for this project and potentially for use in other
projects. We chose that one over
the others we looked at in October
because it has more peripherals than
the PIC16F18045, and importantly, it
was available in a SOIC package (that
isn’t hard to solder) at the time.
The PIC16F17146 differs only in
that it also has an internal op amp
peripheral. That could be handy for
some designs, but we shall have to
see when stock becomes available to
design a project around it.
The Digital Boost Regulator PCB
suits all three of the aforementioned
chips if you wish to experiment with
them instead.
However, the other chips will need
slightly different code to work, and
we will leave that as an exercise for
the reader.
The working principle of the boost
circuit on this board is not novel.
What is different is that instead of
using a dedicated boost controller IC,
we are simply configuring some of the
PIC16F18146’s internal peripherals to
perform the same role.
Most dedicated switchmode controller ICs have more features, such
as current limiting and short-circuit
protection, that this design lacks. We
have specified our circuit modestly to
keep it simple.
Note that a dedicated chip will probably have a better control algorithm
and thus tighter voltage regulation.
While our design is not bulletproof,
it is a working proof-of-concept that
is usable in many roles.
Features & Specifications
∎ Onboard digitally controllable boost (voltage step-up) converter
from 5V to up to 20V
∎ Output power of up to 0.5W (output current depends on selected
voltage)
∎ Capacitive touchpad interface
∎ Four-digit LED display
∎ Breaks out all microcontroller pins to headers
Australia's electronics magazine
December 2022 81
Fig.1: in a switched inductor boost
circuit, energy is stored in the
inductor’s magnetic field when
current flows through it. As the
magnetic field collapses, it drives
current to the output via the diode. By
changing the switch duty cycle, the
average energy in the inductor can
be changed, controlling the output
voltage.
This design is a way to show how
valuable these advanced device
peripherals can be. In particular, the
configurable logic cells (CLCs) allow
events to be responded to without
requiring any processor attention.
We’re only using a very small subset of the peripherals, so it won’t seriously impact the chip’s ability to perform other tasks if you were to use it
for the basis of a design. For example,
the PIC16F18146 has two DACs and
two comparators, but we only use one
of each.
Boost regulator
Fig.1 shows the basic arrangement
of the inductor-based boost circuit we
are implementing.
If the switch is closed, as shown at
the top of the diagram, current from
the incoming supply flows through
inductor L1 to ground, charging the
inductor’s magnetic field. When the
82
Silicon Chip
switch opens, the inductor continues
to pass current, but it is diverted via
diode D1 to the capacitor and load on
the right-hand side.
Consider the case when the switch
stays open. Due to the diode drop, the
output voltage settles just below the
incoming supply. This is the minimum
output voltage; such a circuit cannot
deliver a voltage much lower than the
incoming supply.
If the switch spends some of its time
closed, the average inductor current
is higher and thus, the output voltage
increases. The theoretical maximum
(disregarding efficiency factors such
as resistance and voltage drops across
the diode) is equal to the supply voltage divided by the switch’s open duty
cycle. So if the duty cycle is 50%, the
voltage output is (in theory) double
the input.
Theoretically, if the duty cycle
drops to 10% open (which is the same
as 90% closed), the output voltage will
be ten times the input voltage. However, with such a high boost ratio, the
peak inductor current becomes so high
that the output deviates substantially
from the theoretical voltage.
Circuit details
Fig.2 shows the full circuit of our
Digital Boost Regulator and breakout
board.
IC1 is the PIC16F18146 microcontroller with a 10kΩ resistor pulling its
MCLR pin (pin 4) to its supply rail to
prevent spurious resets. A 100nF supply bypass capacitor is provided for
stable operation.
CON1 and CON2 are possible
sources for the supply voltage. CON1
is a standard mini-USB socket with
only its power pins connected. The
circuit nominally runs on 5V and is
perfectly happy with anything from
4.5V to 5.5V, as might come from a
USB power supply.
CON2 is used to connect a programmer, such as an PICkit 4 or Snap,
which can also supply power (the
Snap requires a modification to do so).
Q1 performs the role of the switch
from Fig.1; the 10kΩ resistor from its
gate to ground holds it off when there
is no signal from the microcontroller
(eg, during programming).
A capacitor on the supply side of L1
provides a stable, local power supply
for the boost circuit from the 5V rail.
The output capacitor, downstream of
the diode’s cathode, is supplemented
Australia's electronics magazine
by a pair of resistors forming a voltage divider.
This allows the microcontroller to
sense an output voltage that might be
higher than it could otherwise accept.
This divided voltage is taken to a pin
on IC1 that can be configured as an
input to the internal comparator. The
divided voltage can also be sampled by
the analog-to-digital converter (ADC)
peripheral, so we can measure the output voltage.
The output voltage on the capacitor
is also taken to two-pin header CON4
so that you can feed it elsewhere.
TP1-TP3 are connected to PCB touch
pads. They aren’t external components but are formed from PCB traces
designed to effect a change in capacitance when touched (the capacitors shown attached to the ‘switches’
represent the capacitance between
the tracks). They each connect to an
ADC-enabled pin of IC1. 17 of the 20
pins on the PIC16F18146 can be connected to the ADC.
Finally, LED1 is a four-digit seven-
segment display connected to the
remaining pins, configured as digital
I/Os to drive the display in a multiplexed manner. Each of the eight segments (including the decimal point)
has a series resistor for current limiting.
Firmware
Fig.3 shows how the internal
peripheral blocks are configured to
run the boost regulator.
Timer 1 is set running from the
instruction clock. The comparator can
be set to synchronise with this clock.
We do this to prevent the comparator
from oscillating at a high frequency
when the output is near the setpoint.
The firmware also starts one of the
PWM peripherals, set to operate at a
20% off and 80% on duty cycle. This
puts a theoretical upper limit on the
boost voltage that can be achieved,
around five times the input voltage.
The PWM output is not sent to an
I/O pin, but instead routed via an
internal multiplexer to one of the CLC
instances.
The FVR is set up to provide a
2.048V reference to one of the DACs
(digital-to-analog converters). The
DAC is enabled and is internally connected to the non-inverting input of
the comparator. The 8-bit DAC can
thus apply a voltage from 0 to 2.040V
in 8mV steps.
siliconchip.com.au
In practice, the FVR reference is not
precisely 2.048V. The stated accuracy
is 4%, but the factory measured value
can be read from the chip’s DIA (device
information area).
With a 10:1 (10kΩ/1kΩ) divider, the
output range is about 22.44V in 88mV
steps. The upper limit of the boost circuit with an 80% duty cycle is around
25V, depending on the supply voltage.
So we should be able to achieve 20V
at the boost output easily, and that’s
what we’ve specified.
The inverting input of the comparator is connected to the divided output
voltage. Being an analog input, this can
be one of four software-selectable pins.
The comparator output is not exposed
externally, although it could be. It is
instead fed to one of the CLCs alongside the PWM signal.
The CLC is configured to simply
provide a logical AND of the comparator output and the PWM signal. This
is about the simplest possible application of the CLC.
The output of the CLC AND gate is
fed to one of the I/O pins and thus to
the gate of the Mosfet. Since it is a digital signal, we could map it to any one
of the 17 I/O pins on the PIC16F18146.
At power-on, assuming the DAC
output is set to a sufficient level, the
divided output voltage is well below
the DAC setting. So the comparator
output is high, and the Mosfet drive
signal follows the PWM signal.
When the voltage rises above the
setpoint, the comparator output drops
low, and the Mosfet drive is shut off
until the voltage decays below the
setpoint.
We can change the output voltage
simply by altering the DAC value. So
the processor does not need to spend
any time handling the boost converter
unless it wishes to change the settings.
The Timer 1 synchronisation takes
care of any jitter that might occur
around the comparator’s switching
point, preventing the Mosfet from
Fig.2: the lower section of the circuit shows the microcontroller connected to the rows of ‘breakout’ headers, along with
the 7-segment LED display and the three touchpads. The boost circuitry at the top is driven by circuitry hidden inside IC1
(shown in Fig.3).
siliconchip.com.au
Australia's electronics magazine
December 2022 83
Fig.3: the peripherals inside
IC1 used to control the boost
regulator are equivalent
to five distinct ICs: a
voltage reference, a digital
potentiometer, a comparator,
an oscillator and an AND logic
gate. We initialise and connect
these peripherals as shown
by setting various registers.
They then control the external
circuitry shown in Fig.2
without further intervention
from the processor.
trying to switch too frequently by
synchronising its state changes to the
timer.
While it might seem a simple exercise, this demonstrates just how useful and configurable the peripherals
can be. For the sake of two external
pins, an application circuit can make
do without a separate boost controller
chip and, as a bonus, have a programmable voltage setpoint!
Once the peripherals have been initialised, this part of the circuit continues to run without taking up any more
processor cycles.
Scope 1 shows typical operation
with an output voltage of around 8.5V,
including the Mosfet gate drive and
drain voltage. The broader peaks are
complete PWM cycles, while the narrower peaks are when the PWM cycle
has been interrupted by the comparator sensing that the voltage is above
the programmed threshold.
A dedicated boost control IC would
dynamically control the pulse widths
and provide more uniformity, giving
a smoother output, better regulation
and better efficiency, hence our conservative ratings for our boost circuit.
Still, it does the job of regulating the
output at the target voltage.
Touch sensing
We’ve discussed the operation of
84
Silicon Chip
shared-capacitance touch sensing
previously, with quite a bit of detail
in the ATtiny816 Breakout Board
project (January 2019; siliconchip.
au/Article/11372). The principle is
that a finger brought near a touchpad
increases its apparent capacitance and
that change can be detected.
The PIC16F18146 has an advanced
ADCC or ‘analog-to-digital converter
with computation’. It can perform multiple samples and provide computed
results based on these samples.
One of the modes supports the
measurement of a capacitive voltage
divider, the same principle used in
shared-capacitance touch sensing.
Effectively, we are comparing the
internal capacitance of the ADCC’s
sample capacitor (which the data sheet
reports is around 28pF) to the capacitance of whatever is connected to the
touchpad.
When a cycle is started, the ADCC
performs a precharge step, which
briefly connects the internal capacitor
to the supply voltage and the external
pad to ground (and vice versa). The
internal capacitor and pad are connected together during the sample
phase of the ADCC cycle.
The numerical result of the conversion depends on the relative capacitance values. Higher values correlate
to a higher capacitance at the external
Australia's electronics magazine
pad, as it can hold and thus contribute
more charge from the precharge cycle.
The PIC16F18146 can actually perform two measurements with inverted
precharge polarities and report the difference. Once the ADCC is configured
correctly, the channel (corresponding
to one of the pads) is set, and the cycle
starts. The result is read back a short
while later.
Scope 2 shows the voltages on two
touch pads during their cycles. You
can see the two precharge and measurement steps for each pad.
While we could calculate the actual
capacitance from the reading, it is simpler and sufficient to pick a threshold
value that can distinguish between the
presence or absence of a finger near the
pad. A brief software routine scans the
pads and sets the values in an array to
whether or not a touch was detected
on each pad.
The other job of the firmware is multiplexed driving of the 7-segment LED
display. For this, a timer interrupt is
set to trigger 240 times per second. The
display is blanked at each interrupt,
and the output pins are changed to
display the next digit in turn.
As it is a common-anode (CA) display, one of the four anodes is pulled
high, while the remainder are left
floating. Any segments to be lit on
that digit are pulled low. The 60Hz
siliconchip.com.au
Scope 1: the blue
trace shows the
signal from the
microcontroller
to drive the gate
of Q1 while the
boost circuit is
delivering 8.5V
under load (green
trace). The red
trace is the voltage
at the anode of D1.
Dedicated boost
controller chips
typically change
their duty cycle
dynamically to
control the output,
while this circuit
uses a fixed duty
cycle modulated to
limit the voltage.
Scope 2: the
voltages at the
I/O pins for
two touchpads
during the ADCC
sampling cycle.
The period
labelled “1” is
precharge while
“2” indicates
sampling. “3” and
“4” are the same
phases but with a
positive precharge.
Note how the stage
2 and 4 levels for
the blue trace are
further apart than
for the red trace;
that pad is being
touched, and it is
that difference that
the ADCC reports.
update rate combined with the persistence of vision makes the display
appear steady.
After construction is complete, we’ll
discuss the actual use and operation
of the default firmware.
Construction
The following assumes that you
want to build the Boost Breakout as
described above. You could instead
omit some parts and make a custom
circuit by adding parts or connections
to the breakout headers while using
some or all of the included features.
The Digital Boost Regulator
and breakout board is built on a
siliconchip.com.au
double-
sided PCB coded 24110224
that measures 50 × 89mm (see Fig.4).
It uses practically all surface-mounting
parts, so you should have flux paste,
tweezers, a magnifier, a fine-tipped
iron and some solder-wicking braid on
hand. The flux will generate smoke, so
use fume extraction or work outside
to avoid breathing it in.
Start by fitting USB socket CON1.
Place flux on the pads, then rest the
socket on top. This part has lugs that
will locate it correctly, so alignment
shouldn’t be difficult.
Clean the iron tip and apply some
fresh solder to it. Touch the iron to
the small pads and allow the solder to
Australia's electronics magazine
flow onto them. Only the two longer
pads need to be soldered. If you form
a bridge, use the braid and extra flux to
remove it. Then solder the four larger
pads around the sides of the shell to
secure it mechanically.
Apply flux to the pads on the PCB,
then fit IC1. Rest it in place, tack one
lead and confirm that it is flat and
aligned with all the pins. Also ensure
that the divot or notch marking pin 1
is at the upper left as per the PCB silkscreen markings. When everything is
aligned, solder the remaining pins.
Add some flux to the rest of the
pads for the surface mounting parts.
Q1 is the only transistor and should
December 2022 85
be orientated as shown. The solitary
diode D1 must be aligned with its cathode stripe to the right. The remaining
parts are not polarised.
Use the same technique of soldering
one lead and checking that the part is
correctly positioned before soldering
the remaining leads.
The two 10μF capacitors are near L1
and D1, while the 100nF capacitor is
above IC1. Fit these next, being careful not to mix them up as they won’t
have markings.
There are only two different resistor values, but take care not to mix
them up. Most of the 1kW resistors are
grouped together near CON1; these are
the current limiting resistors for the
LED segments.
The last surface-mounting part is L1.
Turn up your iron temperature a little,
if possible, as this part has more thermal mass than the others. Add a thin
layer of flux paste to its pads then, as
for the smaller parts, tack one side,
check the position and then solder
the other leads.
Refresh any solder joints that look
dry or rough by adding more flux and
touching a clean iron tip. The solder
should flow and smooth out.
Before fitting the remaining throughhole parts, clean the PCB of excess
flux using a recommended solvent and
allow it to evaporate.
Then check the alignment of LED1,
being sure to orientate it as per our
photos and overlays. Solder it from
the back of the PCB and trim the leads
close.
If you want to fit CON3 (for a 5V supply) or CON4 (to run the boosted voltage elsewhere), these can be header
pins or sockets. If you like, you could
add 10-way socket headers to the
breakout pads to allow breadboard
jumper wires to be used.
CON2 is only needed for in-circuit
programming of IC1, so it can be omitted if you are working with a programmed chip, such as you would
purchase from the S ilicon C hip
Online Shop, and don’t plan to experiment with the code. A right-angled
header is recommended if you do fit
CON2.
Programming IC1
If this is necessary, you can use a
PICkit 4 or Snap programmer. The
Snap will require power to be supplied, which can come via CON1.
You will need a relatively recent version of the MPLAB X IDE or IPE and
the PIC16F1xxxx device family pack
(DFP). We’re using MPLAB X v6.00. If
you wish to experiment with the software, you’ll also need the XC8 v2.40
compiler.
Although the programming pins are
also used to drive the LED display,
they don’t interfere with programming. At worst, there is faint ghosting on the LED display when the programmer is connected. We didn’t run
into any problems with programming
the chip after the board was complete,
although it didn’t seem possible to perform debugging.
Connect your programmer to CON2
and upload the 2411022A.HEX file
using the MPLAB X IPE.
We did run into one odd bug, and
you might, too; the programming software reports that 0x3112 is an invalid
device ID, even though the data sheet
indicates that this is the correct
device ID for the PIC16F18146. If you
get the same error message with that
exact value (see Screen 1), it is safe
to ignore it.
You can continue to use the programmer to supply power, but the
PICkit 4 cannot provide much current
and won’t be very useful for running
the boost regulator. For that, you’ll
need to connect an external 5V supply, which could be as simple as a
USB cable from a computer or charger.
Operation
Fig.4: the Digital Boost Regulator mainly uses SMD parts, but they are all fairly
easy to work with. Watch the orientation of the diode, IC1 and LED display,
and you should have few troubles. If you omit all parts except IC1 and its two
adjacent passives, you can use the PCB as a breakout board that suits many
recent 8-bit PICs in 20-pin SOIC packages.
86
Silicon Chip
Australia's electronics magazine
Assuming you have a 5V supply
connected, you should see the display reading around 4.70 (the units
are always volts) with the rightmost
decimal point also lit. You can connect a multimeter to CON4 to check
the output voltage.
If the displayed or measured voltage
is much higher than the input, there
may be a problem, so you should shut
down the Boost Breakout and check
the construction. The limited duty
cycle should prevent the output from
going way too high if there is a problem with the feedback system.
This default display shows the output voltage while the rightmost decimal point indicates that the boost circuit is enabled. If the supply voltage
drops too low (below 4V), the output
will switch off until the supply voltage increases above 4.5V.
As newly programmed, the boost
circuit is enabled, but with a target of
0V, so the output voltage is simply the
supply less the drop due to the diode.
Pressing and holding the > button
under TP3 will cause the display to
siliconchip.com.au
Parts List – Digital Boost Regulator
1 double-sided PCB coded 24110224, 50 × 89mm
1 SMD mini USB socket (CON1)
1 5-way right-angle pin header (CON2; optional, for ICSP)
1 2-way pin header (CON3; optional)
1 2-way pin header or socket (CON4; optional)
1 47μH 1A 6×6mm inductor (L1) [eg, Taiyo Yuden NR6045T470M]
Semiconductors
1 PIC16F18146-I/SO programmed with 2411022A.HEX, wide SOIC-20 (IC1)
1 14mm/0.56in blue common-anode 4-digit 7-segment LED display (LED1)
[eg, 7FB5461BB]
1 SS34 or similar 40V 3A schottky diode, DO-214AB (D1)
1 2N7002P, 2N7002K or AO3400 N-channel Mosfet, SOT-23 (Q1)
Capacitors (all SMD M3216/1206-size X7R ceramic)
2 10μF 25V+ 1 100nF 50V
Resistors (all SMD M3216/1206-size 1% 1/8W)
3 10kΩ
9 1kΩ
SC6597 Kit ($30 + postage)
A complete kit with all the parts listed above (including the optional
components). The microcontroller is supplied pre-programmed.
switch to the setpoint display and start
flashing 0.00. You can change the setpoint by holding one of the up or down
buttons while holding the > button.
The change happens straight away.
Each step of the setpoint corresponds to one step of the DAC output.
The displayed voltages are calculated
based on the internal voltage reference values from the device information area, so the steps are not uniform
(due to rounding) and the maximums
might not align. Still, you should have
no trouble setting and achieving a 20V
output.
Releasing the > button will return
to the actual voltage output display.
You should see the output tracking
the setpoint as long as it is above 5V.
The output will float a bit high with a
light (or no) load as the boost circuit
does not shut off until the output voltage is above the setpoint.
Pressing the up and down buttons
together will display “b” and the supply voltage.
Finally, if all three buttons are
pressed simultaneously, all segments
will flash on, and the setpoint is saved
to EEPROM so that it is used by default
at power-up. The safest way to do this
is to hold the up and down buttons and
then press the > button. That way, the
setpoint can’t change.
If all the segments don’t light up,
the saved value may be the same as
setpoint, meaning it doesn’t need to
write to the EEPROM. If it did, that
siliconchip.com.au
would cause extra write cycles (and
wear) on the EEPROM.
If you find the Boost Breakout is not
responding to touches or is flashing
when no touch pads are pressed, then
be sure that you don’t have anything
connected to the touchpad I/O pins,
especially circuitry that may affect the
capacitances.
Code details
We tested our prototype with various power supplies, both grounded
and ungrounded and chose our touch
sensitivity values based on those tests.
These are the TOUCH_DOWN and
TOUCH_UP values near the top of the
“io.h” file. Having two values allows
us to provide some hysteresis and thus
debounce the buttons.
Since the measured value increases
on a touch, the sensitivity can be
reduced by increasing these values.
Conversely, the sensitivity can be
increased by lowering the values. You
shouldn’t need to make any changes if
you are using the board as designed,
but if you try to make touchpads by
running wires from TP1-TP3, the
capacitances may change.
No doubt some people will be interested in using bits of our code, especially the boost and touch sections.
So we’ve tried to make it modular and
section the code into dedicated functions for each.
The doTouch() function calls several
other functions to check the state of
the touch pads and store them in the
t[] array. The other functions include
initADCcvd() and getADCcvd().
The boostInit() function sets up the
peripherals used for the boost controller. Controlling it simply requires the
DAC to be set using the DAC1DATL
register after it is enabled by clearing
the TRIS bit of the RA2 port pin (which
has been defined as SWPIN).
Minimal circuitry
If you want to use the board as a
breakout for the PIC16F18146, only
the 100nF capacitor and 10kΩ resistor
adjacent to IC1 are needed for operation. The LED display and its eight
1kΩ resistors can be omitted to free
up 12 I/O pins.
Q1, L1, D1, CON4 and the associated passives, which include a 1kW,
two 10kW resistors and two 10μF
capacitors constitute the components
that provide the boost feature. Leaving these off will free up two IO pins.
Naturally, you will need to change
the code to work without the display,
and if you need a further three I/O
pins, you will need another control
method to replace the touch pads.
However, they can’t easily be physically removed without sawing off the
SC
bottom section of the PCB.
Screen 1: if, during programming, you see an error message indicating that
0x3112 is an invalid device ID for the PIC16F18146, you can safely ignore it.
The data sheet shows that 0x3112 is the correct ID.
Australia's electronics magazine
December 2022 87
|