Introduction
LabVIEW (Laboratory Virtual Instrument Engineering Workbench) is NI's flagship product based on graphical programming through "wiring" of nodes. LabVIEW was released initially in 1986, and was proposed as a more intuitive and easier alternative to text-based programming. As it can be expected, NI's hardware works seamlessly with LabVIEW. Here I will show how to build a temperature control system that uses the thermocouple kit to measure the temperature.
Setup
The setup was built as shown.
A Peltier device was powered with a source measure unit (SMU) so that the Peltier could be used to transport heat in any direction. The Peltier was sandwiched between a mineral-oil-filled-beaker and a heatsink. Thermal paste was used on both sides of the Peltier to facilitate heat flow to/from the beaker and to/from the heatsink. Two computer fans powered by a power supply were used to keep the heatsink temperature close to the ambient temperature. The thermocouple was immersed into the oil at a relative close distance to the bottom of the beaker so that the temperature would change faster when the Peltier injected or removed heat from the beaker.
The Virtual Instrument
LabVIEW programs are called Virtual Instruments (VIs) and their appearance resembles that of physical instruments. VIs are composed of two parts: the front panel and the block diagram. The front panel is the user interface of the instrument and is made of controls and indicators. Controls, such as knobs, push buttons, sliders and strings allow the user to interact with the VI. In contrast, indicators such as LEDs, graphs, charts and strings, allow the VI to display the output to the user. The logic that glues the control input to the indicator output is specified in the block diagram. The block diagram contains the program logic and is made of "wired" nodes. Nodes can have inputs and outputs, but can also be control structures such as case structures or while loops. Each node begins its execution only when it has received data through all its inputs, and produces an output only after its execution finishes. For the same reason the order of execution depends on the movement of the data through the nodes.
I designed the front panel of the temperature control system like this.
The VI uses two comboboxes to select the SMU VISA resource and the Thermocouple channel. Once the Connect button is pressed, the VI enters the temperature control loop. It reads the liquid temperature and depending on the setpoint temperature, and the PID parameter Kp, Ti and Td, it controls the SMU to generated the desired current output. The setpoint temperature and PID parameters can be modified on the fly and the PID controller will still generate the proper output based on the new values. The Liquid temperature input and the current output indicators display the most recent values, while the graphing area plots the setpoint and the liquid temperature to aid with the tuning of the control system.
The block diagram can be divided into 3 parts, the thermocouple reading part, the SMU control part, and the control loop part.
Let's begin describing what the VI has to do to read data from the thermocouple. To configure and use the DAQ a set of NI-DAQmx nodes must be used. As described earlier, a node will execute only after it has received its input, and since all the NI-DAQmx nodes are connected together, they execute sequentially.
The execution is as follows:
- The input channel combobox outputs the selected cDAQ channel string name. Once the Connect button is pressed, the next node executes.
- The channel is configured as a K-type thermocouple channel that uses the built-in Cold Junction Compensation (CJC) channel built into the terminal block and outputs the temperature in Celsius.
- The DAQ is set to sample at 5 Hz continuously.
- Data acquisition process initiates.
- One sample is sampled and its value is displayed on the Liquid (°C) indicator and also fed into the PID section (which I will describe soon). This node is within a while loop and executes continuously until either Connect or Exit is pressed.
- Data acquisition stops.
- The previously reserved resources are freed.
The SMU is controlled trough VISA nodes.
The execution is as follows:
- The VISA resource combobox outputs the selected VISA resource string. Only once the Connect button is pressed, the next node executes.
- The VI connects to the SMU.
- A set of SCPI commands are sent to the SMU. These commands set the SMU as a current source with a maximum and minimum voltage of +12 and -12 V respectively, and then turn its output on.
- SCPI commands to set the current output are continuously sent in a while loop until either Connect or Exit is pressed.
- The SMU output is turned off.
- VISA resources are freed.
The PID section of the VI has a couple of nodes that can run in parallel because they do not require the input of a previously executed node.
The execution of this parts works like this:
- The Elapsed Time node generates a True output every time 1 second has passed and False otherwise. Only when True is sent out of this node, the Case structure gets executed. Since the While structure runs at a much faster speed, limited only by the cDAQ acquisition rate (5 Hz), the Elapsed Time node is used to send an updated current output to the SMU at 1 Hz instead.
- Every second the PID node receives the setpoint and liquid temperature (which are also sent to the Waveform Chart node so that they get plotted), the PID parameter Kp, Ti and Td, the dt interval (1 s), and the range of valid PID output values (hidden behind an icon but set to be from -3 A to +1 A).
- The real number output of the PID node is sent to the Output (A) indicator, but also converted to a string and appended to the "curr " string to generate an SCPI command (e.g, "curr 2.0" to output 2 A) that finally is sent to the SMU to generate the computed current output.
Results
After manually tweaking the PID parameters a bit, I was able to get he PID controller to converge to the setpoint temperature with minimal overshooting. Note that the temperature transitioned very fast because the measurements were made close to the bottom of the beaker.
Conclusion
LabVIEW is a great tool that makes it relatively easy to build virtual instruments compared to text-based programming languages. Here, I showed how it can be used to build a simple temperature control system that controls the cDAQ and an SMU. As expected, hardware built by NI is very easy to control from LabVIEW, but I also showed here that controlling instruments manufactured by other companies through VISA nodes is also relatively simple. The ability to easily design instrument front panels, and interface LabVIEW with all kind of instruments is what makes LabVIEW a great tool for engineers and scientists.