lab4_statement
lab4_statement
Introduction
This laboratory session aims to design a digital controller for your buck converter. The goal is to reproduce the design
procedure covered in the practical lecture of Monday November 4, and to validate the controller implementation in
the PIC18F26K22 microcontroller through HIL simulations. At the end of the lab, you should be able to:
You are not expected to get the final controller implementation at the end of this lab. The idea of the lab is to
introduce you to the design process and to the HIL tools to validate your design. Subsequent appointments can
be taken with Bastien EWBANK to complete the validation of the control with HIL devices, before moving to the
final implementation of your project, where the control board directly controls the power board.
As a reminder, here are the steps to design a digital controller for a DC-DC power converter:
1. Determine the uncompensated delay-corrected loop gain, Tu† (s), in the s-domain.
2. Design a PID controller in the s-domain.
3. Transform the controller coefficients to their digital version.
4. Implement the controller in the PIC18F26K22.
1 Continuous-Time Averaged Modeling
This section ask you to establish the loop gain transfer function expression of your buck converter and to find the
appropriate PID coefficients for your controller. This is the first and second steps of the design process.
Note : Don’t take too much time during the lab session to do this first section. Prepare this either
before or after the lab session. It is not essential to have the exact PID coefficients during the lab.
The goal is to understand the design process and the tools to validate it.
Using the Jupyter notebook provided and introduced during the practical lecture of Monday November 4:
4. Look at the Bode plot of the uncompensated delay-corrected loop gain Tu† (s), observe the current phase
margin of the uncompensated system. Choose an appropriate crossover frequency fc .
1
5. Determine the PID coefficients of your controller (not digitalized, meaning float values and in V unit).
For your report: Indicates your buck specifications, the values of your components, the expression of the different
transfer functions, the estimated total loop delay, the crossover frequency you chose, and the PID coefficients you
found. Explain and justify when it is needed. Include Bode plots of Tu† (s), Gc (s) and of T (s) in the report to
brighten your explainations up.
Lab 2 - page 1
2 Digital PID controller
Before implementing the controller in the PIC18F26K22 microcontroller, it is a good practice to simulate the con-
troller. In this way, you can verify the controller design, pre-tune the controller parameters and anticipate imple-
mentation mistakes.
In practice, take back your buck converter model. Update the electrical component values according to your
measurements after building the powerboard, and don’t forget to include the equivalent series resistance of the
inductor and capacitor. Reset the Buck converter to ”internal modulator” control mode instead of digital inputs.
The ”In” signal of the buck converter will be the output signal of the controller block which will be the duty cycle
of the PWM. The ”En” signal is still a ON/OFF signal to enable switching of the buck converter.
During the last HIL lab, you used few signal processing components (probably ”SCADA inputs”) to simulate the
duty cycle and the ON/OFF signals inside Typhoon HIL software. This time, you will use more advanced signal
processing components to simulate a digital PID controller. The exercise is to reproduce the digital PID controller
of Figure 2.
As a reminder the recurrence relation of this digital
PID controller is given by:
with e[k] the error signal and u[k] the control signal
(≡ the duty cycle signal), at time k. Figure 2: Digital PID controller
Hint : Use the component ”unit delay” to store a value at the previous time step. Substractions are available with
the ”Sum” component if you indicates ’-’ in the textbox. Your PID controller in Typhoon HIL should look really
similar to Figure 2.
To close the loop of your system, pick the output voltage signal up and substract it to the reference signal to obtain
the error signal. The reference signal can be a SCADA input signal to be able to change it during the simulation.
No test is required for this section. The next section teach you how to verify the correctness of your PID controller
prototype using a frequency response analysis.
Questions for the report : According to your specifications, what should be the sampling period (time step between
instant k and instant k − 1)? What value should you give to the ”execution rate” parameter in the signal processing
blocks?
Lab 2 - page 2
3 Loop Gain Measurement
The next step in the lab is to learn how to measure the frequency response of a system using Typhoon HIL
software. This tool is useful for validating the stability and performance of your controller before implementing it
in real hardware. The frequency response analysis is done by injecting a sinusoidal signal at the input of the system
you want to measure. The amplitude and the phase of the system is measured by observing the output response of
the system to this sinusoidal signal. To obtain a complete Bode plot along the frequency, this process is repeated
for different frequencies of the input sinusoidal. This is sometimes called a ”frequency sweep” analysis.
To do this, in Typhoon HIL software, you will need 1. to add few components to your schematic model, 2. to learn
how to configure the ”Frequency response widget” in the SCADA to display the Bode plot of the system. NB :
This exercise can be performed in Virtual-HIL at home if you run out of time during the lab session.
• Choose the system to measure and identify his input and output. As an example, for the PID controller you
just built, the input is the error signal e[k], and the output is the control signal u[k].
• Add a voltage source that will be used to inject the small sinusoidal signal. You don’t have to configure it,
this source will be auto-controlled by the simulation and the ”Frequency response widget” later.
• Add a Voltage measurement component connected to this source in order to able to send this signal in the
signal processing domain(=the blue part of the schematic). Let’s name this signal ẽ[k] as it is a small signal
perturbation.
• Sum this signal with the error signal e[k], just before the PID controller block.
• Add signal processing probes to be able to measure e[k] + ẽ[k] signal and u[k] signal in the SCADA.
Figure 3
Lab 2 - page 3
2. Frequency response widget configuration:
• Open the SCADA and add a ”Frequency response widget” to your SCADA panel.
• When you double click on it, the window depicted in Figure 3b should appear.
• Before launching the frequency sweep, you have to configure the input and the output of the system to
measure. On the top left corner in the ”Signal Settings” tab, you have to tell which source will be auto
controlled to generate the ”Perturbing source”. In our case, it is the ”Vdist” source from Figure 3a. Then
you have to tell which signal is the input of the system you want to analyze. Here it is the e[k] + ẽ[k] signal.
Finally, you have to tell which signal is the output of the system, here u[k]. As a reminder, this is required
because the transfer function of a system is the ratio of their output to their input : Gpid (s) = ũ(s)
ẽ(s) .
• Below signal settings, you have to configure the frequency range of the sweep. Choose an appropriate range
and resolution. The range is limited by the software between [0.5 Hz, 500 kHz]. Keep in mind that your
controller runs in discrete time and therefore the Nyquist sampling theorem applies.
• Below the frequency range settings, let the ”Multi-Tone” mode but adjust the ”Amplitude” of the perturbing
source to not saturate in some signal processing components.
• On the left bottom corner, you have to specify a repository where the ”Frequency response” widget will store
auxiliaries files and the measurement. The sweep will not start if you don’t specify a directory.
• On the right tabs, you will find advanced settings. I would advise you to reproduce the settings of Figure 3b
to avoid any issue.
• When everything is ready press on the ”Play” button in the top left corner. Be patient, the frequency sweep
requires a bit of time depending on the frequency range you configured.
The exercise of this section is to reproduce all this procedure for the PID controller to measure the Bode plot of
your controller GP ID (s). Then, adapt this procedure to measure the buck converter response Gvd (s) and the loop
gain T (s), by properly positioning the small signal perturbation and the probes. Measure the uncompensated loop
gain, Tu (s), by removing the controller.
For the report : Include Bode plots of each measured transfer function (Gpid (s), Gvd , T (s), Tu (s)) and theoretical
Bode plots from the jupyter notebook. (Don’t repeat them if you have already included these figures in the first
section). Comments them a bit. Specify also the values of kp , ki , kd you set and why you are confident to use these
PID coefficient for controlling your system.
In the final part of this lab, you will implement your PID controller on the PIC18F26K22 microcontroller and
validating it using C-HIL.
Connect your control board to the HIL device, as you learned in the previous HIL lab. Set back the ”Buck” in
”digital inputs” control mode and reconfigure the ”Output settings” to cope with the cable connection between the
HIL and the control board. The goal is now to code in MPLAB the PID algorithm and to check using the SCADA
that the controller is working as expected. Hint : Think to the recurrence relation of the digital PID controller.
The code should be more straightforward to write from that.
This lab is the last guided part of the project. The remaining task after it will be to come up with your own stable
and performant controller implementation and to compete for the bottle of champagne. Here is non exhausitve list
of guidelines that will help you to reach a working controller implementation. Don’t worry, you won’t probably
succeed to achieve all of this during the lab session.
Lab 2 - page 4
• Call the PID computation one single time per PWM period. However, don’t code it in the interrupt routine
but in the main loop.
• Work only with 16bits integer variables (or lower bits type) to avoid too long computation time. Be careful
to overflow issues during your computation as your are limited to 16 bits2 .
• Don’t forget to scale the PID coefficients according to the scaling and resolution of the ADC if you have not
already done it. An additional normalization of the PID coefficient is probably required depending of your
specifications.
• Use state machine variables to control the ON/OFF behavior of the controller. The OFF-ON condition : ”Is
there an input voltage within a decent range ?” Choose the range that fits your specifications. This is where
the second ADC conversion you learn in the previous lab comes in handy.
• Implement advanced PID features, saturation and anti-wind up, to avoid unforseen behavior of the controller.
These features is introduce in slides 57-58 of the theoretical lecture.
• Use digital signals of your PIC18F26K22 that you can monitor in the HIL SCADA to debug your code and
observe execution time. An example is provided hereunder. This is important because you have to check that
a complete iteration of your controller is done before the next PWM period.
1. Implement the simple version (without saturation and anti-windup) of the PID controller in the PIC18F26K22
microcontroller. ON/OFF management is not mandatory.
2. Measure with C-HIL the time it takes to complete the ADC conversion(s) and your PID computations.
For the report : Include figures that show the execution times of your code that you measured with C-HIL. Include
also a figure of the Vout (t), iL (t) signals of the buck converter while you are testing the controller (at steady state
or at start up, as you prefer). Provide also your source code (.c file) even if it is in progress.
2 Ex: (signed int16) 214 ∗ 2 = 215 is an overflow as the maximum value for a 16 bits signed integer is 215 − 1. The result of this
Lab 2 - page 5
Deliverables and Scoring Guidelines
Deadline: Monday 18/11 at 23:59pm. Send at [email protected]: 1) a short report (max 5 pages) that
includes the same sections as this document, 2) Your Jupyter notebook file, 3) Typhoon HIL files (.tse and .cus)
you used for the Loop Gain Measurement section, 4) the source code (.c file) of your controller implementation.
2 The explanations are clear and demonstrate a full understanding of the concepts.
Explanations
The students provide basic explanations but do not demonstrate a full understanding of control
and Under- 10 % 1 design concepts.
standing
0 Explanations are missing or unclear. The students do not demonstrate acgood understanding.
Lab 2 - page 6