I would like to have a counter that increments from 0 to 31 and returns to 0 on the increment from 31. The increment would happen every 50 milliseconds.
I tried a simple ADD block, but even with a temporary variable and an intervening operation, I received an error. Various combinations of temporary variables and order of operations resulted in much the same error messages.
ADD 1, store in a Temp, Multiply the Temp by 1 and store in the original variable. All variables are declared Global.
The error read: Global variable ‘si16_Temp_Counter’ is read before written.
Attempt #2 was to use the CTU block with a PULSE_GEN. This worked until the counter reached 32767 and then it stopped. (I did a modulo operation of the result to turn the value into a 0 to 31 counter). Setting PV to 0 means the counter never starts. Same for -1. No matter what the counter stops after a period of time.
The error read: Global variable ‘si16_Temp_Counter’ is read before written. → you can solve by checkbox si16_Temp_Counter as “fallback” variable at variable list. Check help.
why dont you call reset input at CTU when counter >= 31?
so basically you are already using the elements available in SafeDESIGNER, but I need to learn more about Safety maybe later I’ll give you more inputs.
Ciao
Valerio
In General i like the usage of the CTU Block more, as it clearly shows the intention of the Application to Count. Also the Timer is a good way to generate your timing requirements.
I think he also needs here the Feedback to loop the Q to the Reset , to make the Reset at 31. But i think there is a little bit of additional logic needed to supress the Pulse for this cycle, to not immediate count to 1 again.
It could look like this, if i did not made a mistake. Maybe you need a Edge generator to only set TRUE for one Cycle. A simple TON could be better suited. If 40ms went over, just CNT or RESET and let TON start again.
If you have the final solution, would be cool to see it.
I am also interessted in the “Safety” use Case where you need such a Counter.
As you program it in “grey” logic there could in general also be a discussion if this could be handled by grey PLC.
The Use Case is to implement J1939-76 in the Safety Application. This is the J1939 specification for transmitting Safe Data, on either a white channel (no other devices) or a black channel (other non-safe devices present). The protocol includes a CRC, as well as a sequence. The sequence is incremented with each successive transmission of the CAN message. I will gladly post the example when I get it working.
Hi @Mike_Fossell, glad you were able to make progress on implementing the counter. The below Help pages expand on the rules for programming implicit feedback in your Safe Application.
Programming implicit feedback in FBD
This page contains the rules for using feedback variables (including the fact that only local variables can be used) and details on the implementation of implicit feedback in FBD within SafeDESIGNER.
Thanks Rafael for your input!
When I asked Conversational Help “What does it mean feedback on variable declaration in SafeDESIGNER?“ I found your pages (same question I asked with google AI):
We have so many data now in the Help (+ I see cases where after AS Help upgrades the location of some pages are different) so I’m trying to practice more with this tool to reduce my research time.
Grande @michael.bertsch ! it works, just added 2 variables for in/out with SLX for enable the counter and trace that inside AS: