Switching Power Supply Design With The PIC16F785: Electrical
Switching Power Supply Design With The PIC16F785: Electrical
Switching Power Supply Design With The PIC16F785: Electrical
ELECTRICAL:
INTRODUCTION • 9-12 VDC input
Microcontrollers are rapidly gaining ground as required • 2.0-3.9 VDC output at 10A
components in the design of Switching Mode Power • <100 mV Ripple at the output
Supply designs (SMPS). Their flexibility and program- • Non-isolated buck-topology
mable nature gives manufacturers the ability to cus- • Current mode configuration
tomize designs quickly in response to customer
• Continuous inductor current operation
demands, and implement the wide variety of complex
and custom features required by today’s electronic sys- • Synchronous switching for increased efficiency
tems. However, even with all of the microcontroller’s • Ambient temperature sensor
strengths, adding a microcontroller to a SMPS design To keep the focus of the design, and simplify the firm-
still adds one or more devices to an already crowded ware design, the communications system for the
PCB. design will be limited to a simple parallel system. The
That is, it used to add additional devices; the new following is a description of the interface:
PIC16F785 actually reduces the number of devices in
a design by including not only the necessary interface COMMUNICATIONS:
peripherals for a SMPS design, but also two channels
of analog PWM, two voltage comparators, and two op • Active low SHUTDOWN input
amps. • Active high POWERGOOD output
Now, all the parts needed to implement the analog con- • Active high FAULT output
trol sections of up to two SMPS channels are included • Four preset voltage outputs, stored in on-chip
in the microcontroller. This means fewer parts to han- EEPROM and selected by two voltage select
dle, a simpler layout, and even a lower material cost. In jumpers.
addition, the microcontroller control over the SMPS
The deterministic functions that are implemented in the
analog blocks allows control up through a Level 3
design include the following:
design (on/off control, output control, and topology/con-
figuration control), something that is only rarely possi-
ble with a separate microcontroller/PWM controller DETERMINISTIC FEATURES:
solutions.
• Delayed start-up for sequencing with other power
In this application note, we will examine a typical buck supplies
topology intelligent SMPS design using the
• Soft start of the output voltage
PIC16F785. The design employs a Level 2 microcon-
troller integration, allowing the microcontroller to • Under voltage lockout
enable/disable and output voltage control. The micro- • Slew rate limiting on output changes
controller also has the ability to monitor the perfor- • Hysteretic over temp error
mance of the analog section of the SMPS design. • Shorted output Fault detection with limited restart
Using both, control and monitoring, the microcontroller • Over current alarm
implements a variety of deterministic functions.
Current Current
Loop Transformer
SMPS SECTION T1
+
D2
PWM BST Q1
DRVH
C8 L1
PHA IN SW Output
C1 C9
PIC16F785 DRVL Q2
U3
MOSFET U4
DRIVER
IL
Inductor
Current
PHA
DRVH
on
Q1
off
12V
SW
-.7V -.7V
DRVL
on
Q2
off
Time
VOLTAGE FEEDBACK
The desired current flow in L1, from the previous sec-
tion, is set by the output of the error amplifier/loop filter
in the voltage feedback loop. The voltage feedback
loop consists of the all the elements in the current feed-
back loop, plus the output capacitors C1 and C9, the
error amplifier/loop filter (using the on-chip opa2 in the
PIC16F785), and a voltage reference generated by the
timer-based CCP PWM function in the microcontroller
(see Figure 4). The current flow in L1 is designed to be
continuous; it supplies all of the output current during
the cycle, with the output capacitors storing the extra
current from the high side of the charge cycle, for dis-
charge during the low side. The challenge in a continu-
ous current configuration is to make sure that the
R4 C6 R19
R5
- OP2-
OP2
R6
+ OP2+ CCP
OPA2
C19
T1 +12V
D2
Voltage
Comparator
-
C2
+ C2IN+
BST
Phase
Counter Q1
PWM
DRVH
C8 L1
PHA IN SW Output
Q2 C1 C9
DRVL
U3 PIC16F785
U4
Loop Filter
MOSFET + LC
Combined
Loop
Loop Filter
MOSFET + LC
Combined
Loop
180°
PWM to
PHA
MOSFET Driver
C12
- From
T1 R4 C6 R19
C2
+ From
Voltage VOUT
R5
Comparator 1 -
OPA2
+ CCP
CVREF
0
MUX1
S1
-
C1 Continuous MUX = 1, S1 = Open
Voltage + Discontinuous MUX1 = 0, S1 = Closed
Comparator PIC16F785
3. The two phase capability of the analog feedback
PWM module allows the system to switch
between a single, two, or three phase PWM load
share system on the basis of load current, allow-
ing the use of multiple smaller power chains in
the place of one larger chain (see Figure 7 and
8).
+12V
T1
-
C2
+
DH L1
SW VOUT
PHA IN DL
DH L2
SYNC SW
PHB IN DL
MCP1630
OSC DH L3
CS SW
DL
VXT IN
-
OPA1
+
CCP
PHA
IL1
VOUT Time
Single Phase
PHA
IL1
PHB
IL2
VOUT Time
Two Phase
PHA
IL1
PHB
IL2
VXT
IL3
VOUT Time
Three Phase
GET_INPUTS Recall that the INIT routine begins this process by start-
ing a conversion on the first input to be measured. That
The GET_INPUTS routine is charged with routinely means that the first time the statemachine is called,
sampling the various analog voltages in the system. To there will already be a value waiting for the
do this efficiently, a data indexed statemachine is used. statemachine to retrieve. This pre-conversion, and the
There are two standard forms of a statemachine, the clearing of the data array, presets all the variables to
execution indexed and the data indexed. In the more safe values so the DECISIONS routine will function
recognizable execution indexed form, a state variable properly. This prevents random data in the array from
is used to determine which, of several possible, blocks causing undesirable decisions and erroneous outputs.
of code is to be executed when the statemachine is Note: The INIT routine will also preset the state
called (see Figure 10). A data indexed statemachine, variable for the GET_INPUTS routine, so it
on the other hand, executes the same block of code will know where to place the data from the
each time it is called. It is the data acted upon by the first conversion.
statemachine that is indexed by the state variable (see
Figure 11).
This has several advantages for a routine such as the
GET_INPUTS routine:
1. The basic routine to control the ADC is the same
for all of the analog inputs; only the channel
select bits are changed. Using a data indexed
statemachine saves redundant coding for each
channel.
2. If the results from the ADC are stored in an
array, the state variable can be used to automat-
ically access the correct location for storing the
data, retrieving the next input configuration
value, and accessing alarm limits for the
individual analog inputs.
DETERMINISTIC FUNCTIONS:
• Delayed start-up for sequencing
STATE = 1 Block 1
• Soft start
• Under voltage lockout
• Slew rate limiting on all VOUT changes
• Hysteretic over temp error
STATE = 2 Block 2 • Shorted output fault detection with limited restart
• Over current alarm
• Four programmable VOUT presets
The Delayed start-up indicates that there is a DELAY
state needed between the SHUTDN and ACTIVE
STATE = 3 Block 3 states.
Soft start function indicates that there will also be a
RAMP state in which the output will be ramp up from 0
to the final output voltage.
Under voltage lockout does not seem to indicate an
STATE = 4 Block 4 additional state, rather it is just a condition that would
force the transition from ACTIVE to SHUTDN, or
SHUTDN to DELAY.
Default Slew rate limiting on all VOUT changes indicates that
are additional states for ramping the output up and
down is required. However, if a single RAMP state is
Return created to ramp up or down, a separate state will not be
needed.
FIGURE 11: DATA INDEXED STATE The hysteretic over temp fault requires that the system
declare a error at one temperature, but then clear the
MACHINE
error at lower temperature. This will require an addi-
Start tional active state in which there is a error, but the
output is still active. Let’s call this the ERROR state.
Block A shorted output condition is an immediate fault, and a
Data[State] simple jump to the SHUTDN state, followed by a
restart, should be sufficient to handle the fault. How-
ever, if the fault persists, it may be necessary to have a
Return “Sticky” fault condition that requires intervention by the
communications function to clear. So, for this design, it
seems advisable to create a Fault state which can be
DECISIONS entered in response to a persistent fault and requires
The next section of the firmware design is the DECI- user intervention to move to the SHUTDN state.
SIONS section. In this section of the firmware, the data The over current alarm is similar to the over tempera-
gathered in the GET_INPUTS section is analyzed and ture alarm, however, it doesn’t require hysteresis, so it
the appropriate actions are taken. To perform this can be handled as simple comparison. If an over
function, an execution indexed statemachine is used. current condition exists, and if the power supply has
To design the required statemachine, it is first neces- completed the start-up delay and soft start, then turn on
sary to determine the various states in which the sys- the alarm LED. When and if the condition clears, then
tem can exist, and the reasons for changes in these turn off the LED. So, because the condition does not
states. Two obvious states are: SHUTDN, in which the require an additional historical information to operate, a
system is powered but is not producing an output, and separate state is not required.
ACTIVE, in which the system is powered and produc-
SHUTDN
En
ab
le
an
dL
ow
En
su
ly
abl
pp
pp
ea
ly
su
ow
nd
rL
Low
o
le
sup
ab
En
ply
FAULT DELAY
Shorted Output and Retry = 0
Shorted O
Delay Complete
Ena
ply
upply
ble
r Lowsup
utput and
and
Shorted Output and Retry > 0
Lows
Lo ws
Enable o
le or
Retry > 0
upply
Enable or Lowsupply
E nab
Low Temp
ACTIVE
VOUT < > Target
MEMORY USAGE
The memory usage for the control program is as
follows:
Program memory 466 words out of 2K words
Data memory 30 bytes out of 128 bytes
EEPROM 8 bytes out of 256 bytes
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
12/08/06