Skip to content

HeatShield

Gergely Takács edited this page Jul 15, 2022 · 180 revisions

Contents

Introduction
Application programming interface
   C/C++ API
   MATLAB API
   Simulink API
Examples
   System identification
   Temperature control
Detailed hardware description
   Circuit design
   Parts
   PCB
About
  Authors

Introduction

The HeatShield belongs to the family of control engineering education devices for Arduino that form a part of the AutomationShield project. This particular low-cost shield demonstrates the thermal control of a 3D printer heating block implementing a resistive heating cartridge as the actuator and a negative temperature coefficient (NTC) resistor as the sensor, which creates a simple single-input single-output (SISO) feedback loop. In place of the usual extrusion nozzle supplying the melted plastic filament is a steel screw connecting the heating block to a thermal insulator that prevents heat damage to the printed circuit board (PCB). The maximal temperature of the heating block is limited at ~80°C by an adjustable linear voltage regulator. The HeatShield also features an optional transparent safety enclosure.

Before you proceed, you may also want to watch a short video tutorial here.

Heat2

For a better visualization the entire assembly was 3D-modeled using the CAD software CATIA V5R20 (Student Edition) and can be downloaded from here. Note that it features the model of Arduino Uno available from here.

Application programming interface

C/C++ API

The basic application programming interface (API) serving the device is written in C/C++ and is integrated into the open-source AutomationShield Arduino library. This library contains hardware drivers and sample exercises for control systems engineering education. All functionality associated with the HeatShield is included in the HeatShield.h header, which contains the HeatShieldClass class that is constructed by default as the HeatShield object. The functions specific to this shield mostly perform input/output peripheral communication.

The summary of basic functions and the illustration below should get you started quickly:

  • Output (sensor): HeatShield.sensorRead();
  • Input (actuator): HeatShield.actuatorWrite();

Heat_Functions

The following subsections describe the methods used to access the input and output of the HeatShield. Note that before you begin an experiment you must initialize the hardware by calling

HeatShield.begin();

which determines the mode of the input and output pins.

Input

Assuming the power supplied to the heating cartridge is stored in the variable u as a floating point number in the range of 0-100 (%), the actuator is supplied by the input signal after calling the method

HeatShield.actuatorWrite(u);

which will convert the percentage value to an 8-bit number driving the pulse-width modulation (PWM) output of the microcontroller.

Output

The thermistor in the heating block is accessed by calling the method

y = HeatShield.sensorRead();

which returns the block temperature in degrees Celsius to the variable y as a floating point number. This function first calls the getThermistorVoltage() method, which returns the output potential at the voltage divider. Based on the known input reference voltage , the known reference resistance and the the output voltage one may use Kirchhoff's current law to compute the unknown resistance according to

which is implemented in the device's API as the getThermistorResistance() method. Though searching for the unknown temperature is more precise according to tables associating the nonlinear relationship of resistance and temperature, a simplified form of the Steinhart-Hart equation is used. Given a known reference temperature and corresponding nominal resistance ; and the properties of the thermocouple given by the parameter one may compute the unknown temperature by

which is what sensorRead() essentially does.

MATLAB API

If you cannot program in C/C++ just yet, you may want to try out the MATLAB API for the HeatShield that enables to access the hardware through the MATLAB command line and scripts. It utilizes the The MATLAB Support Package for Arduino Hardware which enables communication between the Arduino prototyping platform and the development computer. Various commands accessing the hardware are executed directly in quasi real time without the need to compile code. This means that code is not deployed to the processor, and the Arduino merely acts as an external laboratory measurement card.

To prevent confusion between the C/C++ and the MATLAB API, the two interfaces are as similar as possible. The MATLAB API is written in object-oriented script and the user must first create an instance from the class:

HeatShield=HeatShield;

The shield is then initialized by calling

HeatShield.begin();

which, unless already done, uploads the server code to the prototyping board.

The temperature reading procedure is identical to that of C/C++ API. The voltage from the getThermistorVoltage() method is passed to the getThermistorResistance() and this will calculate the resistance of the thermistor based on the voltage divider. The sensor is then directly accessed by calling the

y = HeatShield.sensorRead();

method, where the variable y will hold the temperature in degrees Celsius. Finally, the heating cartridge power is set through

HeatShield.actuatorWrite(u);

which accepts the input power u in percents.

Note that the use of the high-level commands of MATLAB allows for a simple implementation of more advanced control engineering concepts that would be complex and time consuming to implement in C/C++.

Simulink API

An even more intuitive to create control loops and perform live experiments is the Simulink API for the HeatShield. It utilizes the Simulink Support Package for Arduino Hardware which supplies algorithmic units in blocks that access the hardware functionality. In direct contrast with the way MATLAB handles Arduinos, the block scheme in Simulink is transcribed into C/C++, then compiled to machine code and uploaded to the microcontroller unit (MCU). In other words, code is run directly on the microcontroller. Simulink not only transcribes the block schemes for hardware, it also maintains the connection between the development computer and MCU. This way controllers can be fine-tuned in a live session, or data may be displayed and logged conveniently.

The Simulink API offers the following algorithmic blocks: HeatShield_Simulink_API

The 'Actuator Write' block accepts real numbers from 0-100% and supplies power to the cartridge.

The 'Sensor Read' block reads the input from the thermistor. Users may choose between raw ADC levels, voltage, resistance and temperature. The parameters of the voltage divider and the thermistor can be also fine-tuned.

The 'HeatShield' block unites the input and output functionality into a single entity that can be conveniently used for identification and control experiments.

The remaining two blocks mathematically represented the dynamic process of heating the printer head by a black-box nonlinear ARX model and a first-order ordinary differential equation. The blocks can be used to simulate the response of HeatShield and thereby tuning controllers without the need to run the experiments on the live system.

Examples

System identification

Input-output experiments for data gathering can be launched, displayed and logged in C/C++ (Arduino IDE), MATLAB and Simulink as well. For example, one worked C/C++ example sends a series of step changes that can be logged in various ways through the serial line, while another example also adds a random component to the inputs to collect more information-rich signals. Similarly, a worked MATLAB example and a worked Simulink example perform a simple step change of input, displays the progress of the response live on screen and saves a data file.

IDArduino

After you gather enough data sufficient for system identification, you may try to fit a model to the experimental response. By inspecting the response it is clear that the dynamics is of the first order, and one may assume that the identification procedure is straightforward. Nevertheless, the simple dynamics of the HeatShield holds surprises and may be used to illustrate several abstract principles by a real-life example.

The MATLAB API for the the proposed device contains a worked example for black-box system identification using the MATLAB's System Identification Toolbox. This creates a simple but inadequate process model (∼20% fit) and a more complex and valid nonlinear ARX model (∼90% fit). An even more sophisticated assignment is to develop a first-principle model, then fitting the data to this using grey-box methods. A worked example takes experimental data and searches for the unknown parameters of the first-principle model described by an ordinary differential equation (ODE). First, an initial guess of the model is created based on the assumed parameter values and model structure. The parameters are then found by a nonlinear grey box estimation procedure using an adaptive Gauss-Newton search method. The resulting model is an excellent match to the measured input-output data (∼92%). This model is also implemented in the Simulink API.

SimulatedResponse

More details on the identification procedure can be found here.

Temperature control

For a start you may want to experiment with a closed-loop temperature control by the proportional–integral–derivative controller (PID) algorithm.

The implementation of PID control in C/C++ is demonstrated by a worked example, which makes use of the interrupt-driven sampling subsystem of the AutomationShield library, and also its built-in input-saturated absolute-form PID methods with integral windup handling by clamping.
The progress of the experiments can be followed in real time through the Serial Plotter of the Arduino IDE or logged in MATLAB. The results of the PID controlled temperature response of the printer head are shown below. The same experiment can be conveniently launched from the MATLAB API as well, see the worked example.

HeatShield_PID_C

The same feedback control loop can be built even easier using the Simulink API. Shown below is the full block scheme for discrete saturated PID control of the process. You need only to select the 'HeatShield' block from the API library to implement the input/output of the hardware. Other blocks, such as the 'Discrete PID Controller', can be readily selected from the Simulink's default library.

SimulinkPID

After selecting the External running mode the block scheme is re-interpreted to C/C++ code, which is then compiled to AVR-specific machine code and downloaded to the MCU. Communication is possible between the block scheme and the hardware. You may use switches, sliders and knobs to select reference levels and inspect the response live using a 'Scope'.

ScopeShot

Note that the provided MATLAB and Simulink APIs enable to exploit full high-level mathematic power of MATLAB in order to create and test more complex estimation and control algorithms.

Detailed hardware description

The HeatShield is an open hardware product, you are free to make your own device. If you come up with improvements, please let us know so we can improve our design as well. The discussion below should help you to improvise a similar setup for experimentation on a breadboard or perforation board. You may even order a professionally made PCB by a PCB fabrication service.

For those who wish to use the board without the library, the components are connected to the following pins:

Heat_PIN

Circuit design

The circuit schematics has been designed in the Freeware version of the DIPTrace CAD software. You may download the circuit schematics for the HeatShield from here.

HeatScheme

The power circuitry is driven by an N-channel metal-oxide semiconductor field-effect transistor (MOSFET) Q1 connected to the PWM capable D3 pin of the Arduino. A series resistor R5 protects the MCU U1 in transients, while a resistor R6 parallel to ground ensures that floating electrical states do not cause the heater to turn off accidentally.

Normal temperatures used to melt plastics in 3D printing are over 200°C and may reach as high as 320°C for polycarbonate filaments. To make the experiment safer for general classroom use, the maximal temperature of the heating block is limited at ~80°C by an adjustable linear voltage regulator U2, which takes the external 12V input from the Vin pin of the MCU and reduces it to a voltage configured by resistors R3 and R4 supplying its adjustable input.

Temperature feedback is based on a negative temperature coefficient (NTC) thermistor R1 connected to the A0 analog input pin of the MCU in a voltage divider circuit paired with a resistor R2.

The exact component specification and required quantities are given next. Note that only components with through-hole technology (THT) mounting are utilized in order to make assembly and servicing easy even if you are inexperienced with electronics.

Parts

To make an HeatShield either on a PCB or on a breadboard you will need the following parts or their similar equivalents:

Part Name Type/Value/Note PCS
Q1 Transistor BUZ11, N-channel power MOSFET, 50V, TO-220, THT 1
U2 Voltage regulator LM317T, adjustable positive linear voltage regulator, 1.2-37V, TO-220, THT 1
R1 Thermistor NTC 3950, 100kΩ, rated 300°C with wiring 1
R2 Resistor 100kΩ, 1/4W ,THT 1
R3,R5 Resistor 1kΩ, 1/4W, THT 2
R4 Resistor 240kΩ, 1/4W, THT 1
- Heat sink for the voltage regulator, TO-220 package 1
- Heating cartridge 24V, 30W, 20x6mm 1
- Heating block aluminum, 20x16x12mm 1
- Thermal insulator hexagonal glass-filled polyester insulator, M6 IS20HH625, 25x20mm 1
- PCB FR4, 2-layer, 1.6mm thick 1
- Header 6x1, female, 2.54mm pitch 1
- Header 8x1, female, 2.54mm pitch 3
- Bolt M6x20mm, headless, block to insulator 1
- Bolt M6x10mm, rounded 3.3mm flat head, insulator to PCB 1

Note that the total cost of the above components and thus of the entire HeatShield is no more than $5 excluding labor and postage.

PCB

The printed circuit board has been designed in the Freeware version of the DIPTrace CAD software. The PCB is two-layer and fits within the customary 100x100mm limit of most board manufacturers. The DIPTrace PCB layout and circuit schematics can be downloaded here and here, respectively, while the ready-to-manufacture Gerber files are available from here.

pcb pcb2

About

This shield was designed and created for the subject of Microcomputers and Microprocessor Technology at the Institute of Automation, Measurement and Applied Informatics. The Institute belongs to the Faculty of Mechanical Engineering (FME), Slovak University of Technology in Bratislava.

Authors

  • Hardware design: Juraj Bavlna, Michal Kováč, Richard Köplinger, Sohaibullah Zarghoon, Richard Salíni, Gergely Takács
  • 3D model design: Michal Kováč, Erik Mikuláš
  • Software design: Gergely Takács, Richard Köplinger
  • Wiki: Martin Gulan, Erik Mikuláš and Gergely Takács