Example Code

Control I/O to Monitor and Control a BJTs Temperature

    Other

  • ELVIS III

Code and Documents

Attachment

Description

In addition to the instruments available with the NI ELVIS III, there are integrated Analog Inputs, Analog Outputs, and Digital I/O connections. Internally they are used in various ways to read encoders, output PWM signals, and communicate via digital protocols like SPI and I2C.

How to Use

In this example, we will build a simple temperature control application to limit a BJTs temperature so that it stays near a target temperature value. Most control applications require tight timing and most instruments are designed to deliver a set of data which it has collected during a previous time period and not simply return the value as quickly as possible. This can introduce an unnecessary time delay if they were used. Instead, we will read a Thermistors value directly using the Analog Input, condition the voltage value to convert to resistance, convert the resistance to Temperature, and finally evaluate the temperature to control the BJT. The final circuit diagram will be:


Figure 1: Thermal Plant Circuit Diagram
 
Start by building the Sensing Circuit as follows:
 

  1. Supply 5V and ground signal from the workstation to the breadboard.
    1. Using a jumper wire, connect the +5 V DC from the breadboard strip to the + rail of breadboard.
    2. With another jumper wire, connect the AGND from the breadboard strip to the – rail of the breadboard. 
  2. Connect the 10 K resistor R1 to 5V DC.
    1. Locate a 10 kΩ resistor in the kit, the color code is brown, black, orange. Connect one end to the + rail of the breadboard.
    2. Connect the other end to an empty area in the breadboard.
  3. Connect thermistor to the R1 and ground.
    1. Connect one end of the thermistor to the same node as R1.
    2. Connect the other end to the – rail, to ground the circuit.
  4. Connect AI0 (analog input) from bank A to measure the voltage divider.
    1. Use a jumper wire to connect from analog input AI0 to the same node as the voltage divider RI and thermistor.
       

It should look like this image:


Figure 2: Sensing Circuit
 
With the Temperature Sensing circuit in place we can now build the Thermal Plant. We will add the BJT and attach it to the Thermistor.
 

  1. Place the BJT on the breadboard such that it is in contact with the Thermistor
    1. Ideally heat shrink can be used to keep the Thermistor and BJT touching so that the heat can be measured. Tape can be used if heat shrink is not available. 
  2. Connect the 10 K resistor R2 to the NPN Transistors Base.
    1. Locate a 10 kΩ resistor in the kit, the color code is brown, black, orange. Connect one end to the Base connection of the BJT.
    2. Connect the other end to an empty area in the breadboard.
  3. Connect AO0 (analog output) from bank A to control the BJT.
    1. Use a jumper wire to connect from analog output AO0 to the empty area connected 10kΩ resistor.
  4. Connect the BJT to the Ground and Voltage Rails.
    1. Connect the Collector to the 5V rail of the Breadboard.
    2. Connect the Emitter to the Ground rail of the Breadboard.


Figure 3: Final Thermal Plant Circuit
 
The code itself is quite simple and broke into several steps. The overall flow will be described below and then the two conversion steps will be covered in more detail. The code accomplishes the following:
 

  1. The Analog Input VI reads a single sample from A/AI0 (Pin 0)
  2. The value is converted from Voltage to the Thermistor's Resistance (Ohm) based on the Voltage Divider Parameters.
  3. The Thermistor Resistance is then converted to Temperature (C) using the Thermistor Parameters.
  4. The Temperature is then compared to the Temperature Setting (C) to determine whether the Analog Output A/AO0 (Pin 48) is turned on or off.
  5. The current status of the Analog Output is indicated by LED0
     



Figure 4: LabVIEW Top Level Thermal Plant Control Code

 

Figure 5: Voltage Divider SubVI


Figure 6: Thermistor Volt to C Conversion SubVI

With the circuit constructed and the example code downloaded you are now ready to open and run the example.
 

  1. Extract the bjt_thermistor_control.zip attached.
  2. Open the Academic IO - Control IO - BJT Temperature Control.lvproj
  3. Open the RT Main.vi from the Project Window.
  4. Run the VI
  5. You can adjust the temperature using the Temperature Setting knob.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.