I haven't learned how to use the built in coils for: counters, sequencers, timers, except for the Clk: ones that I'm using. I will learn what I need to, if I need to, but at the moment it appears that splitting up the actions into 5 different seconds of a 5 second cycle is doing the trick. Although, I'm not done writing the program, so I'm not out of the woods yet.
I would have to look more closely, but I don't think any of my functions can be skipped if one function takes too long to execute, so using an interrupt just moves the problem around.
My flow meters (and at this time all my sensors) are 4-20mA analog signal. I think this allows me to avoid leaning Pulse-* commands for now, as I can't use them with the sensors that are already bought.
However, I'm trying to read the output every 5 seconds and apply the observed flow rate to the previous 5 seconds to compute volume. If the PLC falls behind real time then I'm not calculating the flow volume correctly anymore. At that point it's better to go to a 10-second cycle giving each of the 5 parts 2 seconds to run, or have 10 parts at 1 ssecond each.
I think it's time to write a piece of code that compares the number of cycles to the number expected over a longer period of time. The weekend is coming up, a perfect time to test!
General questions about efficient coding:
Is it better to us "AND-OR" or to nest the IF statements?
If I have many "IF" statements that are normally false (testing for problems) do these statements get processed very fast?
The idea is to build a nested structure with the least likely "TRUE" test at the top, so that the least amount of the nested structure gets analyzed at any pass through. The downfall is that this will take more lines of code because I will have fewer nested IFs within each IF statement.
(I should have paid more attention in school when they talked about efficent coding practices.
)
My code is only 2000 lines so far, and I think the biggest limitation is reading over the RS485. If I find I still have problems with inefficient code I'll ask more questions about how to streamline what I'm trying to do. Thanks for all the help!