Okay then, here are my suggestions:
- you are only ever doing anything with the statistics at the expiry of the 2s (2000ms) repeating timer, and the .DN of that timer should be 1 for only one scan at a time,
- so you don't need the CTU built-in one-shot (rising edge) functionality.
- You can instead use a simple INT[0..15] array to keep track of the counts of the directions, and use the ADD instruction to increment the count-in-this-minute INT tag of the current direction by 1 on that single scan when that .DN is 1
- Another nice result of this is that you can clear all sixteen INTs in that array with a single FLL instruction e.g. at the start of every minute
- The same is true, i.e. the .DN is true for only one scan, at the end of every minute (i.e. 30 2s-timer expiries.
- The same is true for the counts (sums; e.g. last_10minutes_dominant_counts_array[0..15]), for the sixteen compass points' directions, that keep track of how many minutes of the last ten minutes each compass point was dominant.
- The 10-element FIFO, that is updated once per minute, will
- FFU the index, [0..15], call it DD_OLDEST, of the dominant direction of the minute that passed ten minutes ago
- So decrementing last_10minutes_dominant_counts_array[DD_OLDEST] by 1 will adjust that direction's count for that fact that it was the dominant direction 11 minutes ago
- FFL the index, [0..15], call it DD_NEWEST, of the dominant direction that of the most recent minute
- So increment last_10minutes_dominant_counts_array[DD_NEWEST] by 1 will adjust that direction's count for that fact that it was the dominant direction in the most recent minute.
- You will want to initialize the 10-element FIFO with ten invalid values, e.g. -1, which will alert the code to not decrement anything over the first ten minutes
The best part of this will be if the compass point calculation is based on an analog value e.g. a direction in the range [0..360), that you are converting to individual booleans. Instead, simply adding 11.25 to that [0..360)-ranged number to a REAL, then dividing that REAL by 22.5 putting the result in an INT, then bitwise ANDing that INT by 15, will give you the integer direction in the range [0..15] that you can use as an index into the per-minute dominant direction count arrays, and also allow you to keep track of the index with the highest count during that minute, and not have to compare all 16 values to find the dominant direction.