PC Automated Pressure Measurements

Pressure Cooker

Pressure Cooker

One of the vivid memories from my childhood is working in the garden picking vegetables. We lived on a farm and it was common to have a big garden. My mother would can all types of food, such as tomatoes, pickles and green beans. Part of this canning process involved boiling the jars of food in a pressure cooker. The release valve, with its hot hissing steam escaping, always intrigued me.

Canning food in the kitchen is a relatively simple process and easily controlled by the cook, but there are many other applications where it makes sense to automate the process. For instance, you may have a process where it is important to know the exact pressure at a specific point in a process and, based on that pressure, control other parameters of the system.

Another example where automation would be ideal is monitoring pressure over time. You could manually take measurements at a given period over some number of hours, but it makes much more sense to automate and let the monitoring equipment record the measurements while you do other things. Because it is automated, this method is more precise and allows you to immediately analyze the data.

The first thing needed for measuring pressure is a pressure sensor. There are many sensors available with analog voltage outputs. These can be used with the Expert I/O 1000 by connecting the sensor’s analog output to an analog input on the Expert I/O 1000. The Expert I/O 1000 has six 0-5V analog inputs and it isn’t difficult to find pressure sensors with 0-5V outputs.

To properly specify the pressure sensor, the following parameters must be defined.

  • Pressure range being measured.
  • Accuracy required.
  • Pressure fitting. How it attaches to the object being measured (1/4″ pipe thread is the most common).
  • Electrical termination (connector or direct to cable).

With these specifications in hand, you are now ready to shop for a sensor. Here are links to a few vendors that carry pressure sensors.

For easiest connection to the Expert I/O 1000, you’ll want to get a sensor with 0-5V analog output, but you probably noticed that another common output is 4-20mA. These can also be used with the Expert I/O 1000 by adding a 250 Ohm resistor from the output signal to ground. Adding the resistor converts the 4-20mA signal to a 1-5V signal. It’s not hard to deal with the 1V offset in software. The ground terminal next to each of the Expert I/O 1000 analog input terminals provide a convenient place to ground the 250 Ohm resistor.

Use a 250 Ohm resistor to ground to convert a 4-20mA output to 1-5V.

Use a 250 Ohm resistor to ground to convert a 4-20mA output to 1-5V.

Now that you have a sensor picked out, all that is left is to write a little software. Here is a snippet of code that initializes the Expert I/O 1000, samples an analog input and then exits.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Open the Expert I/O API.
eioOpen();

// Scan the USB and gather descriptors.
eioGetDescriptors( &DescriptorGroup );

// Claim the interface.
eioClaimInterface( DescriptorGroup.Descriptors[0], &EioHandle );

// Read analog input 1.
eioAdcReadCount( EioHandle, 3, &AdcCount )

// Release the interface.
eioReleaseInterface( EioHandle );

// Close the Expert I/O API.
eioClose();

If you read Between Mac and PC: The Expert I/O API, much of the code will be familiar to you. I’ll go through it again for those that didn’t read the article.

Lines 1 through 8 are initialization and only need to be executed once. The initialization starts with calling eioOpen(). This allows the API to configure its internal settings and ready itself for communicating on the USB.

The next step is to call eioGetDescriptors() to scan each USB bus and locate all Expert I/O devices. It returns a DescriptorGroup which contains an array of Descriptors[]. Each descriptor in Descriptors[] describes an Expert I/O found connected to the USB.

Descriptors contain a model ID and a serial number. By inspecting the descriptors, you can locate the specific Expert I/O you wish to access. For the purpose of this example, we simply choose the first device found on the bus. On line 8, we use the first descriptor to obtain a handle to the device.

A device’s handle is exactly as it sounds. It is a “handle” to grab hold of the Expert I/O to control it. The handle is used every time you perform an operation on the device.

Line 8 serves another purpose, it claims the Expert I/O’s interface for exclusive use by our application. This is important, because the last thing you want is 2 applications trying to control the same Expert I/O simultaneously. Applications can share access to an Expert I/O, but no more than one application at a time can claim it’s interface.

Now we are ready to read the analog input. Line 11 reads analog input 3 by calling eioAdcReadCount and places the result into AdcCount. AdcCount contains a value between 0 and 255, linearly related to the input voltage. If the input voltage is 0V, AdcCount will be 0. If the input voltage is 5V, AdcCount will be 255. AdcCount will vary linearly with the input voltage between 0 and 5V. Notice how we use the handle to identify the Expert I/O.

At this point, you can use AdcCount as needed. For instance, you could make a decision, based on the value of AdcCount, to activate an output or you could plot the time and value on a chart. The possibilities are endless.

When finished accessing the Expert I/O and ready to relinquish control of its interface, call eioReleaseInterface() (line 14 in our example). With the interface released, it is now accessible to other applications that wish to claim it.

The last thing to do is to notify the API that we are finished using it. This is done on line 17 with a call to eioClose(). Closing the API allows it to release any memory that it has allocated and to shut down in a structured manor.

That’s it. Now you know how to measure pressure using the Expert I/O 1000. It’s equally easy to monitor other characteristics. In a future article, I’ll go through the process of measuring temperature.

Please post questions and comments below.


Think USB requires you to be shackled to a computer no more than 5 meters away? Think again. This free guide and cheat sheet will show you the light: “TIED IN KNOTS – A Must-Have Guide to Untangling USB Extension Options for PC Based Automation”. Get it now!

 


Submit Story to Del.icio.us Share on Twitter Submit Story to StumbleUpon

Tags: , , , , , , , ,

Comments are closed.


Call or Email       (317) 608-0500       sales@dajac.com