![]() |
|
||||||||||||||||||
There are plenty of situations in which viewing a graphic trend is the quickest and most effecient way to display information.
While the benefits of being able to visually see trends over time can be self-evident, the implementation can be a little daunting for the beginning
programmer. This is especially true for somewhat reduced enviroments such as the C-More Micro line of graphic HMI's.
I have no professional connection whatsoever with the vendor Automation Direct other than having used many of their products, including the newer C-More Micro HMI's, in a number of varying projects and can personally attest that they are extremely robust and flexible units. Costing only around $130 they are well worth the money and can be coaxed into some very nifty tricks. The principles I outline here, however, can be adapted for many different purposes and equipment from any manufacturer. For the purposes of this example I will be trying to keep everything as straight-forward as possible, concentrating on the underlying concepts and techniques rather than any specific implementation. While in this article I will just be keeping count the number of times an input is triggered every hour for the last 24 hours, real world applications can be anything at any interval over any length of time. For instance, this example is directly derived from a project where I average temperature readings for an hour then store that value to make the last 24 hours visble from a graphic trend. Now, Through some discussions with C-More customer support, I have been told that there may well be a built-in trend object available in the C-More's future. At that time this may all be moot - or it may be just as necessary. The basic function is pretty simple: reserve a block of memory locations for each interval of the history. For 24 hours use a block of 24 registers. For 60 minutes, 60 registers. Etc, etc, etc... Each time your interval times out, push your queue, write the current value to the top, then reset the current value. (If any of that sounds vague or confusing fret not - all is explained in detail below.) The memory block will be handled as a 'queue' (aka: ring buffer or FIFO). This is a standard memory-handling methodology, and just means that we will make it behave reminiscent of people waiting in line. FIFO stands for "First In, First Out" - just like people in line. When I said "Push the queue" above, that means taking all but the last item and pushing them down one slot. When this happens we lose the oldest item and gain a new newest item. In the "people in line" analogy, the person who had been standing in line the longest had gotten on and someone new has gotten in line at the other end.
We'll be counting the times input X0 goes from low to high in an hour, so we'll need a place to keep this count: let's use V2000.
We'll also need a timer to count our hour: T0 (using a realtime clock would be much preferable, but we're keeping it simple) We will be timing 3600.0 seconds in an hour. Since a standard timer can only count up to 999.9 seconds we need to use an Accumulating Timer (TMRA) An Accumulating Timer needs a seperate reset line, so we'll use C0 as the Reset Flag. Finally, we need 24 locations for our 24 hours: V2100-2127
The first rung is just setting up our timer. As mentioned an Accumulating timer is used in order to be able to time an entire hour.
In reality, you would be better served using a realtime clock. Since not all Automation Direct PLC's have an internal RTC, and the method of timing is
incidental to the more important matter of the history log, I opted for the TMRA.
The C0 Timer Reset flag is used to reset the timer as well as reset itsself.
The next rung counts the times input X0 gets energized
The next 3 rungs could actually be joined into a single rung, but are seperated here for clarity.
This particular rung executes the actual pushing of the queue. Using the MOV instruction: first load the accumulator with the number of memory locations to move. For a queue application this will be one less than the total number of locations in the queue (since we are moving all but the oldest memory location) In our 24 hour block, we will be moving 23 locations. The LD instruction takes a hex value: 23 decimal is 17 hex. Next use the LDA load address instruction to specify our starting address (The top of our queue) Finally, use the MOV instruction to specify our destination address (The second location in our queue) After this rung executes our queue will have moved locations 1 through 23 to locations 2 through 24
This rung copies our current value to the first location of our queue. Now our queue is again current
The final rung resets the count to zero and sets the Timer Reset flag
In the next part we will make our 24 hour graphic trend visible on the C-More Micro HMI, and later installments will add layers of abstraction to allow you to view selected portions of the larger history and then view multiple cross-sections of multiple histories... |
|||||||||||||||||||