Ladder logic 401: Data acquisition and analysis
A programmable logic controller (PLC) is designed to not only provide information on signal levels, but it can also capture data and it can be analyzed, but there are a number of challenges the user faces from a software and logistical standpoint.
A programmable logic controller (PLC) is designed to not only provide information on signal levels, but it can also capture data and it can be analyzed. The methods, however, can vary a great deal depending on the platform so this will focus on a generic level.
First, capturing the signal levels: These assume a signed integer signal from an analog card, unknown resolution.
The image above shows a random sampling of values collected from a typical analog card. Since analog/device (AD) converters don't change values very quickly, it can be difficult to see the spikes that may occur in the signal.
If values can be sampled at a higher rate than a typical proportional-integral-derivative (PID) control scheme might require, it might show some data like this. The spikes in these images illustrate what you can do if you do some simple limiting of values based on averaging.
It is important to note that any modification of data collected will require a delay of the signal. After all, it takes time to process the signals and improve them.
This is one method of creating sampling pulses that will work on pretty much any PLC platform, a free-running timer. One problem with it is that it is not going to be particularly precise since it operates within the scan. If it is necessary to improve precision, a cyclic routine or interrupt can be used.
This is a method of capturing ten values into an array. It uses a first in, first out (FIFO) instruction, which is available in most of the more expensive processors. If the user wants to capture more values, increase the size of the array.
Here is another method for a user who doesn't have or doesn't want to use a FIFO instruction. Array and file movement capabilities are still needed, however. The first instruction moves nine elements, leaving room for the current signal value to be copied into the first, most recent element.
This takes about 20 instructions for movement of 10 values. The MOV instructions would each need to be replaced with a LD Vxxx and an OUT Vxxx where the V's are your desired data locations; sensor value and storage location. These are 16-bit accumulators.
Here is an instruction that averages all of the elements in an array. Again, this is available on higher-end PLCs.
This is the method needed if the user doesn't have arrays or an average instruction. Sum up all of the values and divide by the number of values. The user can keep a running average of values this way for two or three values at a time. This could in turn be read back into another array for a running record of averages for smoothing.
This rung calculates the rate of change or Delta between consecutive captures and it works on any platform. Again, this could be read back into an array for analysis. It is useful for determining the direction of change as well as its amplitude. For filtering, the user can capture "spike" values.
When analyzing signals it can be useful to capture signals as quickly or frequently as possible, unlike control and filtering. The limit will be how often the card actually posts a new value to its register. By capturing lots of values in an array, you can determine the update rate of your analog card, or A-D converter. If the user has an average of five identical values in a row at a capture rate of 5ms, your card updates every 25ms. Also, the faster you capture signals, the more likely you are to record a "spike" or out of tolerance value.
The next post on ladder logic will focus on data manipulation once the data has been captured from the analog card.
Frank Lamb is the founder of Automation Consulting Services Inc. This article originally appeared on the Automation Primer blog. Automation Primer is a CFE Media content partner. Edited by Chris Vavra, production editor, Control Engineering, CFE Media, email@example.com.
For more articles on PLCs and programming, see related articles below.