Safe Designer --- Create a simple free running counter

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.

  1. 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.

  1. 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.

Any clever ideas for getting a free running counter?

  1. 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.
  2. why dont you call reset input at CTU when counter >= 31?
1 Like

Hi @Mike_Fossell ,
Welcome to the Community!
Below the answer from AI:


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

Thanks @Vratislav_Korinek for the hint with the Feedback-Column in the Variable Declaration.

Here some pictures from my Training Script.

You could try to program this… but it would set a Compiler Error.

Instead you have to Program this, and acknowledge the Compiler that you intendet to have the “Feedback” behaviour.

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.

Greetings
Michael

1 Like

I am using SafeDESIGNER 5.16.

I do not see a Feedback column in my variable declaration page.

What version of SafeDESIGNER added this?

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.

1 Like

The Feedback Column is only available for local Variables. You have opened the global Variables.

Greetings
Michael

Outstanding!

It builds! I’ll have to test it on Monday when I return to the office (working from home today).

Why or why does the Global variable tab not include this as well???

1 Like

Feedback from AI:

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.
    • B&R Online Help: B&R Online Help
    • AS Help 4 GUID: 257671a7-58ca-4d4f-811d-58b598370674
  • Columns in variables and worksheets

    • This page contains a description of the columns for SafeDESIGNER variable worksheets. Here is the detail on Feedback:
    • B&R Online Help: B&R Online Help
    • AS Help 4 GUID: d0abcd36-6a4e-4af6-bb27-60218ccc461b

Let us know how it goes with the testing on Monday.

1 Like

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:

Maybe we need a review for the duration: 32 * 40 ms = 1,28 s but on the trace I see 1.69 s

Thanks
Ciao
Valerio

Hi @Mike_Fossell, I think your issue is answered and solved. Can you mark a reply that helped you most as a solution, please?

image