cd00263933

AN3151
Application note
Digital constant-current controller for
LED applications based on STM8S208X
Introduction
LEDs have been used for many years simply as status indicators but are now playing a
considerable role in a host of application fields, even with high power requirements, due to
improvements in lighting efficiency, longer lifetime, reliability, and costs. LED-based lighting
systems are increasingly used in display panels, emergency lighting, architectural lighting
and also backlighting.
The growth of such systems is mainly due to new manufacturing technologies and
innovations in this segment area, which probably represent the most important markets
within the lighting field.
The intent of this application note is to describe a new technique, based on a digital
approach, performing a real average current-control on an LED streetlighting platform.
A demonstration board, based on this approach, is orderable with the STEVAL-ILL031V1
code.
Further details are shown in STEVAL-ILL031V1 documentation.
The LED streetlight platform has been developed on a DC-DC converter based on an
“inverse buck” converter, creating advantages in terms of power switch control and
conditioning signal circuitry for the current sensing.
Moreover, performance, including cost performance, is also looked at.
This solution has been customized for a streetlighting application but can be extended to
many other fields.
The advantages offered are in terms of low energy consumption, low maintenance, and a
small and lightweight design.
The real aim of this application note is to describe the average current-control methodology
suitable for LED driving.
The effectiveness of the control with the inverse buck's advantages is described on a
dimmable platform, based on a multi-string system up to 120 W with independent current
control. Two different kinds of dimming have been implemented: analog, also called linear
dimming, and digital.
The control has been implemented on the STM8S208RB microcontroller, [1] which is the
best compromise in terms of cost and performance, validating an innovative current reading
methodology.
August 2010
Doc ID 17051 Rev 1
1/34
www.st.com
Contents
AN3151
Contents
1
2
3
Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1
Power stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2
Control stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Microcontroller peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1
TIMER1: advanced control timer (TIM1) . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2
AD converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Overview of inverse buck converter . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.1
Average current reading methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4
Independent current control for a multi-string system . . . . . . . . . . . . 14
5
Firmware implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.1
Basic initialization of peripherals and I/O pins . . . . . . . . . . . . . . . . . . . . . 17
5.2
Peripheral settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.3
PI regulator overview and firmware implementation . . . . . . . . . . . . . . . . 19
6
Board description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7
Experimental results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8
Short-circuit protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
9
Bill of material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
10
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
11
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2/34
Doc ID 17051 Rev 1
AN3151
List of figures
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
Figure 12.
Figure 13.
Figure 14.
Figure 15.
Figure 16.
Figure 17.
Figure 18.
Figure 19.
Figure 20.
Figure 21.
Figure 22.
Principle schematic of the circuit described . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Power stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Control stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
TIM1 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
TIM1 and ADC triggering functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Inverse buck converter (single-string). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Counter(a), PWM(b) and ILED(c) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Multi string current control methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Basic flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Current control flowchart. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
PI standard controller with anti-saturation control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
LED street light platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
ILED on 3 strings (green, blue and violet waveforms); PWM @100 kHz (yellow
waveform) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
ILED on 3 strings (green, blue and violet waveforms); voltage across the sense resistor
(yellow waveform) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
ILED on 3 strings (green, violet and blue waveforms) @ 60% of duty cycle (PWM
dimming) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
ILED on string (violet waveform) @ minimum PWM dimming; PWM (yellow waveform) . . 25
MOSFET turn-on zoom. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
MOSFET turn-off zoom. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Overall efficiency (4 channels) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Short-circuit protection circuitry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Short-circuit event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Electro-optical characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Doc ID 17051 Rev 1
3/34
Hardware
1
AN3151
Hardware
The hardware is mainly composed of the power conversion section and the control stage,
based on the microcontroller unit.
From a common DC voltage input the 4 strings are driven by 4 inverse DC-DC buck
converters.
The inverse buck converter offers advantages not only in the driving section and the ground
referred circuitry but also in terms of cost.
All these aspects are explained in detail in the power stage.
The principle schematic of the circuit described in this application note is shown in Figure 1.
Figure 1.
Principle schematic of the circuit described
7
9LQ 7
7
7
3:0
3
:
0
$'&
$
'
&
3
:
0
$
'
&
3
:
0
$
'
&
6706[[
0LFURFRQWUROOHU
3:0
!-V
4/34
Doc ID 17051 Rev 1
AN3151
Power stage
Figure 2 shows the schematic of the power stage with 4 output channels:
Figure 2.
Power stage
9EXV
-
'
-
&
X9
9
5
&21
6736/$60$
&
Q)9
6711)627
&21
/
4
2KP
3:0)LUVW6WULQJ
5:
5
5 RKP
&
S
9EXV
9EXV
-
'
6736/$60$
6711)627
&
Q)9
&
X9
5
3:06HFRQG6WULQJ
&21
/
4
2KP
5
9
'
-
5:
5
*1'
6HQVLQJ6HFRQG6WULQJ
RKP
&
S
9EXV
1'2
9EXV
&
'
&
X9
*1'
5
3:07KLUG6WULQJ
-
6736/$60$
Q)9
&
Q)9
6711)627
&
X)9
/
&21
4
&21
2KP
5
6HQVLQJ7KLUG6WULQJ
5:
5
RKP
&
S
9EXV
9EXV
-
'
&
X9
2KP 5
3:0)RXUWK6WULQJ
6711)627
6736/$60$
&
Q)9
/
&21
4
5
6HQVLQJ)RXUWK6WULQJ
5:
RKP
5
1.1
Hardware
&
S
9EXV
!-V
Doc ID 17051 Rev 1
5/34
Hardware
AN3151
Four DC-DC buck converters allow 4 LED strings to be driven, managing up to 120 W. From
a 48 DC input voltage the buck stage adapts the output voltage in order to drive the LEDs
with the imposed current. 3 W LEDs have been chosen in order to obtain 30 W per string,
covering the total power with 10 LEDs [4] in series on each string.
The buck stage works in continuous conduction mode (CCM) in order to minimize the
current ripple on the LEDs.
The inverse buck stage offers:
●
Low voltage sensing circuitry
●
Logic level MOSFETs driven by the microcontroller without a gate driver (ground
referred)
●
High efficiency of up to 98 %
The LED current, to be measured by the microcontroller, is sensed by a ground referred
shunt resistor. This solution allows the current reading only when the MOSFET is on. This is
an important aspect to be evaluated for the current reading methodology to be described.
6/34
Doc ID 17051 Rev 1
&RPP&RQQHFWRU
-
Q)
&
9
-
;
9
5
Doc ID 17051 Rev 1
S)
S)
&
Q)
&
Q)
5(6(7
26&,1
26&287
7,0B&+
*1'
*1'
9 N
5
'
5('
&
X)
9B9''$
-2<B/()7
-2<B5,*+7
-2<B83
-2<B'2:1
-2<B6(/
%($'
/
5
5
5
5
5
5
5
5
5
5
&
Q)
9''$
3'B6ZLP
3&B026,
3:03&
3:03&
3:03&
3:03&
3'B-2<67,&.B6(/
5(6(7
9
&
&
S)
9
67065%
9'',2B
9'',2B
9''
9''$
966
966$
966,2B
966,2B
-
&
S)
&
S)
&
S)
&
S)
X)
'
6HQVLQJ)RXUWK6WULQJ
6HQVLQJ7KLUG6WULQJ
6HQVLQJ6HFRQG6WULQJ
6HQVLQJ)LUVW6WULQJ
3*
N
5
N
5
N
5
N
5
9
5 5 &
*1'
'
'
'
5 N
6HQVLQJ7KLUG6WULQJ
6HQVLQJ)RXUWK6WULQJ
6HQVLQJ6HFRQG6WULQJ
6HQVLQJ)LUVW6WULQJ
9B9''$
5 5
5 5
9UHI
(QDEOH)RXUWK6WULQJ
/&'B&6
3*
3*B/&'B&6
3*
(QDEOH)LUVW6WULQJ
(QDEOH6HFRQG6WULQJ
(QDEOH7KLUG6WULQJ
3)&K7KLUG6WULQJ
3)&K)RXUWK6WULQJ
3)&K'LPPLQJ
N 5
N 5
N 5
3(&K6HFRQG6WULQJ
3(&K)LUVW6WULQJ
-2<67,&.07$
9UHI
9UHI
3,
3*&$1B7;
3*&$1B5;
3*
3*
3*
3*
3*
3*
3)$,1
3)$,1
3)$,1
3)$,1
3)$,1
3)$,1
3(&/.B&&2
3(7,&B6&/
3(7,&B6'$
3(7,0B%.,1
3(
3(63,B166
3($,1
3($,1
&
&
&
&
&
Q) Q) Q) Q) Q)
*1'
5 5 5 5 5 5
. . . . .
3'7,0B&+>7,0B%.,1@>&/.B&&2@
3'6:,0
3'7,0B&+>7,0B&+@
3'7,0B&+>$'&B(75@
3'7,0B&+>%((3@
3'8$57B7;
3'8$57B5;
3'7/,>7,0B&+@
3&7,0B&+
3&7,0B&+
3&7,0B&+
3&7,0B&+
3&63,B6&.
3&63,B026,
3&63,B0,62
1567
3$26&,1
3$26&287
3$7,0B&+>7,0B&+@
3$8$57B5;
3$8$57B7;
3$8$57B&.
9&$3
3%$,1>7,0B&+1@
3%$,1>7,0B&+1@
3%$,1>7,0B&+1@
3%$,1>7,0B(75@
3%$,1>,&B6&/@
3%$,1>,&B6'$@
3%$,1
3%$,1
8
6:
UHVHW
*1'*1'*1'*1' *1'
5 5
7,0B&+
&
Q) N
5
9
5
5
3%B8VHU%XWWRQ
3%B-2<67,&.B/()7
3%B-2<67,&.B5,*+7
3%B-2<67,&.B83
3%B-2<67,&.B'2:1
0
5
9
&
9
-2<B6(/
6ZLP&RQQHFWRU
63,B026,B/&'
3:0)LUVW6WULQJ
3:06HFRQG6WULQJ
3:07KLUG6WULQJ
3:0)RXUWK6WULQJ
(QDEOHB
(QDEOHB
86(5B%87721
-2<B/()7
-2<B5,*+7
-2<B83
-2<B'2:1
& S) 3$8$57B5;
3$8$57B7;
&21$
-
0+]
& S)
&
Q)
.
5
9
3
*1'
N
Figure 3.
1.2
9
AN3151
Hardware
Control stage
The control stage is based on an STM8S208RB. A 64-pin package has been used but the
application can be easily implemented on smaller packages of the same product family
(performance line). PWMs, ADC channels, GPIOs, used for this application, are provided
directly to the power stage. Figure 3 shows the complete schematic:
Control stage
!-V
7/34
Microcontroller peripherals
2
AN3151
Microcontroller peripherals
The control is fully dedicated to the microcontroller which is suitable for managing PWM
generation, analog sensing, by means of ADC, and executing four independent current
loops through PI standard controllers.
2.1
TIMER1: advanced control timer (TIM1)
Figure 4 shows the TIM1 block diagram
Figure 4.
TIM1 block diagram
The TIM1 is a 16-bit advanced control timer with many settings and features for industrial
and motor control applications including protection for fault management.
The main features are:
●
16-bit Up, Down, and Up/down counter with auto reload function
●
4 independent channels with several configurations (input capture, output compare,
edge or center aligned PWM, one pulse mode and complementary outputs)
●
Break input
●
Interrupt and trigger event
The current reading methodology used in this application needs a trigger event, generated
by the timer, in order to start the ADC.
For further details refer to the STM8S reference manual RM0016 [1].
8/34
Doc ID 17051 Rev 1
AN3151
2.2
Microcontroller peripherals
AD converter
Some interesting characteristics of this microcontroller are highlighted here, like PWM
peripheral and ADC triggering functions conducting to a PI current regulation loop for every
channel.
Figure 5.
TIM1 and ADC triggering functions
95()
95()
9''$
966$
3RZHU
$QDORJSLQV
'DWD5HJLVWHUELWV
,QWHUUXSW
(2&(QGRI
$,1
$,1
$ATABUS
*3,2V
I$'&
$1$/2*72',*,7$/
&219(57(5
&ORFN
3UHVFDOHU
I0$67(5
$'&5HJLVWHUV
$,1
3'
4RIGGER
7LPHU
!-V
In Figure 5 above, the ADC peripheral block diagram is shown. The main ADC features
used in this application are:
●
10-bit with 16 multiplexed channels
●
3.5 µs of conversion time @ 4 MHz
●
External trigger and timer trigger selection
●
End of conversion interrupt
The most important feature is the triggering function, forced by TIM1, used to enable the
conversion on some timer events (reset, enable, up/down, and count).
Doc ID 17051 Rev 1
9/34
Overview of inverse buck converter
3
AN3151
Overview of inverse buck converter
The inverse buck stage offers the advantages previously mentioned and is managed by the
same equations as the standard buck converter.
Here in short, some details related to the DC-DC converter stage, with further details of the
analog designing [3].
Theory of operation
The voltage across the L inductor is calculated using the following formula:
Equation 1
VL= L
di l
dt
where:
●
VL=inductor voltage (V)
●
L=inductance (H)
●
IL=inductor current (A)
Figure 6.
Inverse buck converter (single-string)
W2)) WLPH
9
9,1
9/ 9/('
3:0
9/ 9,19/('
W21 WLPH
$'&
3:0
!-V
The following equations were used in the design:
Table 1.
Electrical specs
Description
Symbol
Value
Unit
Input voltage
VIN
48
V
Everlight EHP-AX08EL P03-V4
White LED
LED forward voltage
10/34
VF
Doc ID 17051 Rev 1
Vfmin=3.85 @ 700 mA
Vfmax=4.15 @ 700 mA
V
AN3151
Overview of inverse buck converter
Table 1.
Electrical specs (continued)
Description
ILEDAVG = Average LED current
Ripple current on the LEDs
Symbol
Value
Unit
ΔILED
10
%
The output voltage =VLED = N* VF(Typical)=40 V
Where N=Number of LEDs per string=10 and Vf is the typical forward voltage (4 V).
Forward voltage has some variation in respect to the typical value and the LED
manufacturer reports also the minimum forward voltage Vfmin and maximum forward voltage
Vfmax.
These values must be considered for dimensioning of the power converter.
The LED characteristics are strongly dependent on manufacturer and are reported in their
corresponding datasheets.
In particular, these are necessary to calculate the duty cycle variation range.
Design spec calculation:
Equation 2
VOUTmin= VLEDmin=N*Vfmin=10*3.85 V=38.5 V
Equation 3
VOUTmax=VLEDmax=N*Vfmax=10*4.15 V=41.5 V
δ=Ton/Ts and expressed in terms of voltage for a buck converter:
Equation 4
δ=Vout/Vin
Equation 5
δmin= VOUTmin/Vin=80.2 %
Equation 6
δmax= VOUTmax/Vin=86.4 %
The current ripple admitted for this application is less than 10 % depending on the following
formula:
Equation 7
⎧ΔILED = ΔIL ≤ 10%
⎪
Vout min ⎛ Vout min ⎞
⎨
⎪ΔIL = Fs * L ⎜1 − Vin ⎟
⎝
⎠
⎩
Doc ID 17051 Rev 1
11/34
Overview of inverse buck converter
AN3151
where:
Fs= 100 kHz is the switching frequency; obtaining an inductance value of 1mH. A smaller
value of 820 uH has been chosen for space saving reasons.
3.1
Average current reading methodology
The current reading methodology is based on an innovative technique suitable for the DCDC stage (inverse buck) working in continuous conduction mode (CCM) or even in transition
mode.
The aim is to control the current because the LEDs need a current control in order to
maximize lifetime and brightness, and guarantee the technical specs provided by the LED
manufacturers.
The most important target is to maintain a constant current even though, for thermal issue,
the typical forward voltage can change.
This technique has been patented and is based on microcontroller peripherals allowing the
LEDs current to be sensed, flowing during the MOSFET conduction, on the Ton/2 event.
The Ton/2 current reading and conversion, by the microcontroller, allows the average current
value to be estimated.
The current reading has been implemented on an STM8S208RB but can be easily
implemented on the STM8S2x product family.
The most important feature of this microcontroller is the ADC triggering function by some
timer events. Further details can be seen in the reference manual [1].
The current sense has been obtained avoiding any external circuitry. The sense resistor is
chosen in order to have the best compromise between signal noise ratio and power
dissipation issues. Below are some waveforms describing the proposed technique. The
PWM counter is configured in the center-aligned mode. The counter counts from 0 to the
auto-reload value (content of the TIMx_ARR register) -1, generates a counter overflow
event, then counts from the auto reload value down to 1 and generates a counter underflow
event. Then it restarts counting from 0. The up/down counting defines the center aligned
pattern providing a triangular carrier. The overflow and underflow event can be used for ADC
triggering. In Figure 7 the counting in up/down mode provides a triangular carrier. The OC
register sets the duty cycle. The overflow event, during the Ton/2, triggers the AD conversion
and the result provides the average current value to be used in the control loop.
12/34
Doc ID 17051 Rev 1
AN3151
Overview of inverse buck converter
Figure 7.
Counter(a), PWM(b) and ILED(c)
&RXQWHU
2&5HJLVWHU
A
3:0
B
,/('
$YHUDJH
C
$'&VDPSOLQJ#7RQ
!-V
Doc ID 17051 Rev 1
13/34
Independent current control for a multi-string system
4
AN3151
Independent current control for a multi-string system
The aim of this control is to implement an average current control on four independent
strings in order to cover the entire power rating requirement.
The total power, 120 W, is covered using four strings up to 30 W with ten 3 W LEDs
(Everlight, EHP-AX08EL-V4) [4] connected in series.
The ADC peripheral, in terms of maximum conversion time, doesn't allow instantaneous
conversion of 4 channels and in order to minimize the error introduced by the sample and
hold circuitry a solution based on single-shot conversion is considered.
The advanced timer TIM1 starts the counting in Up/Down mode. The overflow event (crest
of carrier waveform) is used for an Update event which triggers the ADC conversion.
The single-shot conversion is enabled on a selected ADC channel. Once the analog to
digital conversion is performed, the end of conversion interrupt (EOC ISR) is served and the
PI controller changes the duty cycle according to the control law.
Moreover, the new channel to be converted at the next Update event is set and this is
repeated cyclically until the four strings are controlled.
The PI controllers, related to the other 3 channels, are not performed at this time. The fourstring control is executed in 4 different Update events.
Figure 8 shows a simple block diagram highlighting the four-string control:
Figure 8.
Multi string current control methodology
2&UHJ
TON
!$#
4RIGGERING
3:0
!$#
4RIGGERING
!$#
4RIGGERING
!$#
4RIGGERING
!$#
6ALUE#H
!$#
6ALUE#H
&IRST3TRING
#URRENT
3ECOND3TRING
#URRENT
4HIRD3TRING
#URRENT
!$#
4RIGGERING
$YHUDJHFXUUHQW
0)$APPLIEDON34 3TRING
!$#
6ALUE#H
0)$APPLIEDON34 3TRING
$YHUDJHFXUUHQW
0)$APPLIEDONND 3TRING
!$#
6ALUE#H
$YHUDJHFXUUHQW
!$#
0)$APPLIEDONRD 3TRING 6ALUE#H
&OURTH3TRING
#URRENT
$YHUDJHFXUUHQW
0)$APPLIEDONTH 3TRING
$'&VDPSOLQJ#7RQIRUHYHU\FKDQQHO
!-V
The current control loop is executed as soon as the end of conversion interrupt service
routine (EOC ISR) is served.
The Update event, which triggers the ADC for the single shot conversion, occurs once every
five PWM Periods.
Although this decreases the system bandwidth, it leaves some time to other important tasks
such as communication for remote control.
14/34
Doc ID 17051 Rev 1
AN3151
Independent current control for a multi-string system
A sort of “state machine”, implemented in the EOC ISR, manages the current control on four
strings while also looking after the dimming function.
Further details of the multi-string control algorithm follow.
Once the first channel conversion is completed the control checks which string is to be
controlled and updates the new value of duty cycle thanks to a PI standard controller.
Once the duty cycle is updated, the control sets the next channel, related to another string to
be controlled, which is converted during the next Update event on seven PWM counter
overflows.
In short, a single PI controller in the EOC ISR is performed.
The four PIDs are executed in 200 µs calculated in this way:
PWM period=10 µs
The Update event occurs every 5 x PWM period= 50 µs
And, multiplying by 4, the total timing to execute and update the four PI controllers is
obtained.
PIDs execution = 200 µs
Figure 9.
Basic flowchart
6WDUW
—&,QLWLDOL]DWLRQ
3HULSKHUDOV
6:,QLWLDOL]DWLRQ
0DLQ
/RZSULRULW\WDVNV
&RPPXQLFDWLRQ
'LDJQRVWLF«
4IMER/VERFLOWEVENT4RIGGERS
$'&(2&
,65
Note:
%ND/F#ONVERSION
!-V
After initialization, wait until interrupt state is entered. The idea is to convert the current and
correct the duty cycle of the PWM in order to maintain the same average current level.
In Figure 10 the basic algorithm flowchart is shown:
●
Basic initialization of peripherals, timer synchronization with ADC, interrupts and I/O
pins.
●
Reading the LED currents the ADC EOC is served and the duty cycle updated. The
entire control algorithm is executed into the interrupt routine thanks to PI controllers
with anti wind-up in order to regulate the average current at target.
Doc ID 17051 Rev 1
15/34
Independent current control for a multi-string system
AN3151
Figure 10. Current control flowchart
$'&,65
%/#&IRST3TRING
9ES
0)$&IRST3TRING
3ETNEXT!$#ONV #H
9ES
0)$3ECOND3TRING
3ETNEXT!$#ONV #H
.O
%/#3ECOND3TRING
.O
%/#4HIRD3TRING
9ES
0)$4HIRD3TRING
3ETNEXT!$#ONV #H
9ES
0)$&OURTH3TRING
3ETNEXT!$#ONV #H
.O
%/#&OURTH3TRING
.O
!PPLY$IMMING
9ES
3ET"LANKING4IME
3ETNEXT!$#ONV #H
)2%4
!-V
Note:
16/34
A “state machine” has been implemented into the EOC ISR in order to control either a PI
controller or the software dimming function. For any state, the new channel to be converted
is set.
Doc ID 17051 Rev 1
AN3151
5
Firmware implementation
Firmware implementation
Below are some details of firmware implementation.
It's not an exhaustive firmware implementation description but it mainly focuses on some
important microcontroller settings: TIM1, ADC and PI controller implementation.
The firmware developed for the LED Streetlight application is based on STM8S firmware
library release 1.1 and entirely downloadable from the internet.
The firmware described in this application note is entirely available; to obtain a copy please
contact your closest ST office.
5.1
Basic initialization of peripherals and I/O pins
At the beginning of the main program, all the peripherals and I/O pins are configured as
described below:
●
The Clock source is selected in order to have the maximum frequency by means of an
external 24 MHz oscillator.
●
GPIO PINs are configured for: ADC channels (floating input) and I/Os.
●
TIMER (TIM1) configuration: Ch1, Ch2, Ch3, and Ch4 are configured in center aligned
mode and provide an AD triggering signal to ADC for conversion by TRGO.
●
ADC Configuration: AIN8, AIN9, AIN10, AIN11, and AIN12 are converted one by one
during the “update” event forced by TIM1. Single shot conversion has been set.
Other firmware settings are for interrupt and joystick/pushbutton management. The joystick,
soldered onto the control section, is useful in debug phase to change the PI gains.
This feature is implemented on a low priority interrupt.
5.2
Peripheral settings
The main peripheral settings are:
●
Clock configuration
●
TIM1 configuration
●
ADC configuration
The clock configuration is related to the PRESCALER by means of the function:
/* Configure the Fcpu to DIV1*/
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
The TIM1 configuration is:
TIM1_DeInit();
TIM1_TimeBaseInit(0,TIM1_COUNTERMODE_CENTERALIGNED1, PWM_PERIOD,5);
Doc ID 17051 Rev 1
17/34
Firmware implementation
AN3151
TIM1_OC1Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE, CCR1_PWM_DEFAULT, TIM1_OCPOLARITY_HIGH,
TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCIDLESTATE_RESET);
TIM1_OC2Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE, CCR2_PWM_DEFAULT, TIM1_OCPOLARITY_HIGH,
TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCIDLESTATE_RESET);
TIM1_OC3Init(TIM1_OCMODE_PWM2, TIM1_OUTPUTSTATE_ENABLE,
TIM1_OUTPUTNSTATE_ENABLE, CCR3_PWM_DEFAULT, TIM1_OCPOLARITY_HIGH,
TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET,
TIM1_OCIDLESTATE_RESET);
TIM1_OC4Init(TIM1_OCMODE_PWM2,TIM1_OUTPUTSTATE_ENABLE,CCR4_PWM_DEFA
ULT,
TIM1_OCPOLARITY_HIGH,TIM1_OCIDLESTATE_RESET);
/* Configure the TIM1 Master/Slave mode */
TIM1_SelectMasterSlaveMode(ENABLE);
/* Trigger the conversion */
TIM1_SelectOutputTrigger(TIM1_TRGOSOURCE_UPDATE);
TIM1_CtrlPWMOutputs(ENABLE);
TIM1_Cmd(ENABLE);
The ADC Configuration is:
ADC2_DeInit();
ADC2_PrescalerConfig(ADC2_PRESSEL_FCPU_D2);
ADC2_ConversionConfig(ADC2_CONVERSIONMODE_SINGLE,
ADC2_CHANNEL_8, ADC2_ALIGN_RIGHT);
/* Enable EOC interrupt */
ADC2_ITConfig(ENABLE);
18/34
Doc ID 17051 Rev 1
AN3151
Firmware implementation
/*Configure the ADC2 external trigger */
ADC2_ExternalTriggerConfig(ADC2_EXTTRIG_TIM, ENABLE);
ADC2_Cmd(ENABLE);
5.3
PI regulator overview and firmware implementation
The general formula for an analog PI regulator is:
Equation 8
t
u(t ) = K P * e(t ) + K I * e(τ)dτ
∫
0
where:
●
µ(t) is the driving signal
●
e (t) is the error signal, the difference between the actual value and the target value
●
KP and KI are the proportional and the integral constant respectively
In the case of digital regulators, the above equation becomes:
Equation 9
u(n) = K P * e(n) + K I * T *
n
∑ e(i)
i=0
where:
●
µ (n) is the driving signal sampled at the instant nT
●
e (n) is the error signal sampled at the instant nT
●
KP, KI are respectively the proportional and integral gains
●
T is the sampling time
The following can also be written:
Equation 10
u(n + 1) = K P * e(n + 1) + K I * T *
n +1
∑ e(i)
i= 0
and, subtracting Equation 10 from Equation 9:
Equation 11
⎡ n+1
Δu(n) = u(n + 1) − u(n) = K P * [e(n + 1) − e(n)] + K I * T * ⎢ e(i) −
⎢⎣ i= 0
∑
n
⎤
i= 0
⎦
∑ e(i)⎥⎥
The equation shows the variation of the duty cycle Δµ(n) at the instant nT due to the current
error in the same instant (term e(n)) and to its variation at the instants nT and (n-1)T (terms
Δe(n) and [Δe(n) − Δe(n − 1)]).
Doc ID 17051 Rev 1
19/34
Firmware implementation
AN3151
In the PI algorithm, the error is first computed, and based on this, the variation of the duty
cycle is calculated according to the equation, to reach and maintain the target average
current.
PI parameters tuning
In order to perform a working average current regulation, it is fundamental to choose the
right PI parameters depending on the system's bandwidth.
Unfortunately, to get the best PI parameters, there isn't a general procedure to follow and
the fastest way to tune them is trial and error.
However, please note that, besides making the closed loop system stable, the KP and KI
parameters can also compensate the non-linearity introduced into the system.
PI algorithm
An easy and efficient PI controller is implemented. The algorithm uses an anti Wind-Up
effect. This methodology allows the freezing of the integral action when the error signal is
out of working range. In this way, it's possible to improve the dynamic of the current loop. In
Figure 11, below, the diagram of the PI regulator is shown:
Figure 11. PI standard controller with anti-saturation control
The C code is shown here:
/*****************************************************************
* Function Name
: PID_Regulator_FIRST_STRING
* Description
regulation.
: Compute the PI output for the current loop
* Input
: none
* Output
: s16
* Return
: None
*****************************************************************/
s16 PID_Regulator_First(PI_ControllerTYPEDEF *PID, u16
Current_String_Input)
20/34
Doc ID 17051 Rev 1
AN3151
Firmware implementation
{
s16 Proportional_Term, Integral_Term;
s16 Error, output_s16;
Error = (PID->Reference - Current_String_Input);
// Proportional term computation
Proportional_Term = PID->Kp_Gain * Error;
// Integral term computation
Integral_Term = PID->Ki_Gain * Error;
if ( (Integral_FirstRow >= 0) && (Integral_Term >= 0) && (PID>Max_PID_Output == FALSE) ) // freeze integral term in case of
over/underflow
{
if ( (s32)(Integral_FirstRow + Integral_Term) < 0)
{Integral_FirstRow = S16_MAX;
}
or else
{Integral_FirstRow += Integral_Term;
}
}
or else if ((Integral_FirstRow <= 0) && (Integral_Term <= 0) &&
(PID->Min_PID_Output == FALSE) )
{ if ( (s32)(Integral_FirstRow + Integral_Term) > 0)
{ Integral_FirstRow = -S16_MAX;
}
or else
{Integral_FirstRow += Integral_Term;
}
}
or else if ( (Integral_FirstRow <= 0) && (Integral_Term >= 0) )
{Integral_FirstRow += Integral_Term;
}
or else if ( (Integral_FirstRow >= 0) && (Integral_Term <= 0) )
{Integral_FirstRow += Integral_Term;
}
Doc ID 17051 Rev 1
21/34
Firmware implementation
AN3151
output_s16 = (s16)((Proportional_Term>>12) +
(Integral_FirstRow>>16));
if (output_s16 >= (s16)(PID->Upper_Limit_Output))
{PID->Max_PID_Output = TRUE;
return(PID->Upper_Limit_Output);
}
or else if (output_s16 < (s16)(PID->Lower_Limit_Output))
{ PID->Min_PID_Output = TRUE;
return(PID->Lower_Limit_Output);
}
or else
{PID->Min_PID_Output = FALSE;
PID->Max_PID_Output = FALSE;
return((s16)(output_s16));
}
}
22/34
Doc ID 17051 Rev 1
AN3151
6
Board description
Board description
The evaluation board is configured as constant current supply.
Table 2 gives some details of the board:
Table 2.
Reference
Board description
Name
Description
J2
J2
DC input voltage(48 V)
J26
J26
Logic input voltage (5 V)
J11
Swim connector
Programming connector
SW1
Reset button
Reset the microcontroller
P1
Trimmer
Trimmer for dimming
designator
Figure 12. LED street light platform
Doc ID 17051 Rev 1
23/34
Experimental results
7
AN3151
Experimental results
Please note that the streetlight platform has been validated with Everlight LEDs [4].
Others kinds of LEDs may require some control parameter tuning. The joystick soldered
onto the control section can be useful in order to increase/decrease the proportional and
integral gains and set the control.
Figures 13, 14, 15, and 16 show the experimental results:
Figure 13. ILED on 3 strings (green, blue and violet waveforms); PWM @100 kHz
(yellow waveform)
Figure 14. ILED on 3 strings (green, blue and violet waveforms); voltage across the
sense resistor (yellow waveform)
24/34
Doc ID 17051 Rev 1
AN3151
Experimental results
Figure 15. ILED on 3 strings (green, violet and blue waveforms) @ 60% of duty cycle
(PWM dimming)
Figure 16. ILED on string (violet waveform) @ minimum PWM dimming; PWM (yellow
waveform)
Doc ID 17051 Rev 1
25/34
Experimental results
AN3151
Some important information related to the power switches is also detailed. Figures 17, 18,
and 19 show some power dissipation issues and the total efficiency estimation:
Figure 17. MOSFET turn-on zoom
MOSFET turn on zoom
Maximum power dissipation
at turn on ∼40W
Figure 18. MOSFET turn-off zoom
MOSFET turn off zoom
Maximum power dissipation
at turn off ∼26W
26/34
Maximum Vds extra voltage is 53.4V
never achieving the avalanche
Doc ID 17051 Rev 1
AN3151
Experimental results
Figure 19. Overall efficiency (4 channels)
Doc ID 17051 Rev 1
27/34
Short-circuit protection
8
AN3151
Short-circuit protection
Failure protection is managed by the microcontroller and allows hardware damage to be
avoided. This feature has not been implemented on the STEVAL-ILL031V1 but, if
necessary, the following circuitry can be taken into consideration (Figure 20).
K
K
K
5$
,-433/0
,-433/0
5#
3ENSING4HIRD3TRING
3ENSING&IRST3TRING
3ENSING3ECOND3TRING
Doc ID 17051 Rev 1
3ENSING&OURTH3TRING
6
K
6
5"
,-433/0
K
,-433/0
N&6
5!
2
#
2
2
6
2
2
K
2
6
28/34
3HORTCIRCUIT 0ROTECTION&AULT./4 )-0,%-%.4%$ ON 34%6!,),,6
(#433/0
5"
(#433/0
(#433/0
#
5!
N&6
5#
(#433/0
5$
&!5,4
Figure 20. Short-circuit protection circuitry
!-V
AN3151
Short-circuit protection
Short-circuit protection is implemented by means of a simple external circuitry based on:
●
Low-power quad voltage comparator (LM339)
●
Quad 2 input AND gate(74HC08)
The sensing signal is compared with an external reference set by a voltage divider providing
an active low output on each string.
The four outputs are in AND in order to have a single FAULT signal, which is an input
managed by the microcontroller thanks to the TIM1_BKIN pin.
When TIM1_BKIN input (Figure 4) is active, with a programmable polarity, the output stage
control disables all channels in order to protect the hardware.
Figure 21 shows a short-circuit event managed by the TIM1_BKIN.
Figure 21. Short-circuit event
Doc ID 17051 Rev 1
29/34
Bill of material
AN3151
9
Bill of material
Table 3.
BOM
Reference
Part / value
Technology
information
C1,C4,C7,C10
220 nF
Ceramic cap.
C2,C5,C8,C11
47 µF
Cap poly rad.
C3,C6,C9,C12
220 pF
SMD mult.ceramic cap.
0805
C41,C44
100 nF
SMD mult.ceramic cap.
0805
C43
10 µF
Cap poly rad.
0805
D1,D2,D3,D4
STPS1L60
Power Schottky
rectifier
D10
LED diode
J1,J2,J3,J5,J7,
J26
Package
Manufacturer
Manufacturer
code
STMicroelectronics
STPS1L60
Wurth electronics
Inc
7447709821
STMicroelectronics
STN3NF06
Cyntec
RLT16324R680FN-06
1206
Connector
TH
J4
PWM connector
Connector-female
TH
J6
Sensing
connector
Connector-female
TH
L1,L2,L3,L4
820 uH
Inductor
Q1,Q2,Q3,Q4
STN3NF06
STripFET™ II power
MOSFET
SOT223
R2,R5,R56,
R11
620 Ω
Thick film resistor
1206
R1
10 Ω
R3,R6,R9,R12
0.68 Ω
Thick film resistor
1206
R7,R10,R60
10 Ω
Thick film resistor
1206
R47
1 kΩ
Thick film resistor
1206
1206
Another inductor has been tested on this platform. Better results in terms of efficiency were
achieved thanks to a lower DC resistance. For mechanical space reasons these inductors
have not been used in the power stage.
For any efficiency tests consider also the MURATA power inductor with 1.5 mH up to 1.3 A
(1415513C).
30/34
Doc ID 17051 Rev 1
AN3151
Bill of material
Figure 22 gives some technical information related to the Everlight LED:
Figure 22. Electro-optical characteristics
Doc ID 17051 Rev 1
31/34
References
10
32/34
AN3151
References
1.
STM8S reference manual; RM0016
2.
STM8S207xx/STM8S208xx datasheet; Performance line, 24 MHz STM8S 8-bit MCU,
up to 128 Kbytes Flash, integrated EEPROM, 10-bit ADC, timers, 2 UARTs, SPI, I2C,
CAN
3.
AN2928 application note; Modified buck convertor for LED applications
4.
Everlight high power LED-3W: EHP-AX08EL/GT01H-P03/5670/Y/N11-V4
Doc ID 17051 Rev 1
AN3151
11
Revision history
Revision history
Table 4.
Document revision history
Date
Revision
24-Aug-2010
1
Changes
Initial release.
Doc ID 17051 Rev 1
33/34
AN3151
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the
right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any
time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no
liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this
document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products
or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such
third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void
any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any
liability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.
© 2010 STMicroelectronics - All rights reserved
STMicroelectronics group of companies
Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan Malaysia - Malta - Morocco - Philippines - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America
www.st.com
34/34
Doc ID 17051 Rev 1
Similar pages