AN3151 STMICROELECTRONICS | Alldatasheet
Document overview
- Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
- PDF pages: 34
Technical content
Datasheet sections
- 1 Hardware
- 1.1 Power stage
- 1.2 Control stage
- 2 Microcontroller peripherals
- 2.1 TIMER1: advanced control timer (TIM1)
- 2.2 AD converter
- 3 Overview of inverse buck con verter
- 3.1 Average current reading methodology
- 4 Independent current control for a multi-string system
- 5 Firmware implementation
- 5.1 Basic initialization of peripherals and I/O pins
- 5.2 Peripheral settings
- 5.3 PI regulator overview and firmware implem entation
- 6 Board description
- 7 Experimental results
- 8 Short-circuit protection
- 9 Bill of material
- 10 References
- 11 Revision history
August 2010 Doc ID 17051 Rev 1 1/34 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.
1 Hardware
based on the microcontroller unit. 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
1.1 Power stage
Figure 2. Power stage
5 RKP
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.
1.2 Control stage
Figure 3. Control stage
5 N5 N
2 Microcontroller peripherals
loops through PI standard controllers.
2.1 TIMER1: advanced control timer (TIM1)
Figure 4. TIM1 block diagram and motor control applications including protection for fault management.
- 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].
2.2 AD converter
Figure 5. TIM1 and ADC triggering functions
- 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). !-V &219(57(5 3RZHU $QDORJSLQV &ORFN 3UHVFDOHU 'DWD5HJLVWHUELWV95() 95() 9''$ 966$ $,1 $,1 $,1 *3,2V 7LPHU I$'& I0$67(5 $'&5HJLVWHUV (2&(QGRI ,QWHUUXSW 4RIGGER $ATABUS
3 Overview of inverse buck converter
same equations as the standard buck converter.
- VL=inductor voltage (V)
- L=inductance (H)
- IL=inductor current (A)
Figure 6. Inverse buck converter (single-string) Table 1. Electrical specs
Where N=Number of LEDs per string=10 and Vf is the typical forward voltage (4 V). These values must be considered for dimensioning of the power converter. In particular, these are necessary to calculate the duty cycle variation range. Table 1. Electrical specs (continued)
Overview of inverse buck converter AN3151 12/34 Doc ID 17051 Rev 1 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 DC- DC 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.
Figure 7. Counter(a), PWM(b) and I LED(c)
4 Independent current control for a multi-string system
strings in order to cover the entire power rating requirement. (Everlight, EHP-AX08EL-V4) [4] connected in series. hold circuitry a solution based on single-shot conversion is considered. of carrier waveform) is used for an Update event which triggers the ADC conversion. PI controller changes the duty cycle according to the control law. repeated cyclically until the four strings are controlled. string control is executed in 4 different Update events. Figure 8. Multi string current control methodology routine (EOC ISR) is served. such as communication for remote control.
strings while also looking after the dimming function. Further details of the multi-string control algorithm follow. controlled and updates the new value of duty cycle thanks to a PI standard controller. In short, a single PI controller in the EOC ISR is performed. Figure 9. Basic flowchart correct the duty cycle of the PWM in order to maintain the same average current level.
- 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. !-V 6WDUW &,QLWLDOL]DWLRQ 3HULSKHUDOV 6:,QLWLDOL]DWLRQ 0DLQ /RZSULRULW\\WDVNV &RPPXQLFDWLRQ 'LDJQRVWLF« $'&(2& ,65 %ND/F#ONVERSION 4IMER/VERFLOWEVENT4RIGGERS
Figure 10. Current control flowchart
AN3151 Firmware implementation Doc ID 17051 Rev 1 17/34
5 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);
Firmware implementation AN3151 18/34 Doc ID 17051 Rev 1 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);
AN3151 Firmware implementation Doc ID 17051 Rev 1 19/34 /*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 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 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 and, subtracting Equation 10 from Equation 9: Equation 11 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 ). () () () ∫ ττ+= t IP de*Kte*Ktu () () ( ) ∑ n IP ie*T*Kne*Knu () () ( ) ∑ ++=+ IP ie*T*K1ne*K1nu n IP ieie*T*Kne1ne*Knu1nu)n(u () ( )[] 1nene −Δ−Δ
AN3151 Firmware implementation Doc ID 17051 Rev 1 21/34 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;
Firmware implementation AN3151 22/34 Doc ID 17051 Rev 1 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));
6 Board description
The evaluation board is configured as constant current supply. Figure 12. LED street light platform Table 2. Board description
7 Experimental results
Please note that the streetlight platform has been validated with Everlight LEDs [4]. integral gains and set the control. Figure 13. I LED on 3 strings (green, blue and violet waveforms); PWM @100 kHz Figure 14. I LED on 3 strings (green, blue and violet waveforms); voltage across the
Figure 19. Overall efficiency (4 channels)
8 Short-circuit protection
necessary, the following circuitry can be taken into consideration (Figure 20). Figure 20. Short-circuit protection circuitry
9 Bill of material
have not been used in the power stage. Table 3. BOM C1,C4,C7,C10 220 nF Ceramic cap. C2,C5,C8,C11 47 µF Cap poly rad.
10 References
- 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
Table 4. Document revision history 24-Aug-2010 1 Initial release.