So, you have a PLC and want to count something, for example the number of times a day a ball rolls through a tube of some kind. Simple? Well, depends on how you go about it. You could just use a counter and add 1 each time a ball rolls by, but that's only like five minutes of work and all too easy. Here is how the professionals do it:
Declare three arrays of the datatype word (which is 16 bits in this case) of length 150:
monthday AT %MW100 : ARRAY [1..150] OF WORD;
hourminute AT %MW200 : ARRAY [1..150] OF WORD;
secondnuffin AT %MW350 : ARRAY [1..150] OF WORD;
Now, every time a ball rolls by and we get a signal from the sensor you just have to take the current month, day, hour, minute and second and put that in the appropriate place in the array! To make this human readable you should make sure to assign it like this, assuming a ball rolled by on August 5th at 14:10:11:
monthday[currentIndex] := 16#0805;
hourminute[currentIndex] := 16#1410;
secondnuffin[currentIndex] := 16#1100;
currentIndex := currentIndex + 1;
IF currentIndex > 150 THEN
currentIndex := 1;
ENDIF
See the pattern? That's professional simplicity at work! Screw the datatypes specifically made for handling time and dates, nobody should use them anyway. When the index counter reaches 150 we'll just reset it to 1 and all will be good. At a specific time of day an external system will reach into the PLC and count the amount of non-zero entries and present the summarized ball droppings in a nice chart. To make this coding exercise even more exciting make sure to overlap two of the arrays.
(I have not yet seen the piece of code that translates the decimal dates/times into the obscene hexadecimal counterpart nor the other way around, and I am not sure I want to. The PLC controls pieces of heavy machinery, and yes, the rest of it is just as fucked up.)