Engee documentation
Notebook

Event counting using enabled and triggered subsystems

In this model, we demonstrate the difference in the operation of the block. enabled and the block triggered, defining the operating conditions of the subsystem. The demonstration is based on the example of counting events.

Description of the model

A pulse generator is placed on the model Pulse Generator, which is in the mode Sample based It controls the signal parameters based on a set number of discrete simulation steps that must pass between switches.

image.png

Then the signal falls into two implementation options for counters:

  • one is implemented as a subsystem with a port EnablePort (triggered by the presence of a positive signal at the input,
  • the other is in the form of a subsystem TriggerPort, and it is triggered when registering the rising edge of the signal.
image.png

Both counters, when triggered, add one to their output signal. But, as we can see from the coloring, the response time (Sample Time The use of the second counter is due to the operation of the block TriggerPort, therefore, the color of the counter block differs from the color of the rest of the system blocks (for which the sampling time is 0.01).

The work of the model

The model allows you to study how different subsystem execution control units work. Let's run the model and analyze the results.

In [ ]:
modelName = "counters_demo";
model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");

# Запустим модель
data = engee.run( modelName, verbose=false )
Out[0]:
Dict{String, DataFrames.DataFrame} with 3 entries:
  "Счетчик Enabled"   => 226×2 DataFrame…
  "Счетчик Triggered" => 226×2 DataFrame…
  "Сигнал управления" => 226×2 DataFrame

The first signal demonstrates the operation of a discrete control signal source.

In [ ]:
plot( data["Сигнал управления"].time, data["Сигнал управления"].value )
Out[0]:

In the second graph, we see the work enabled-subsystems with the trigger logic specified by EnablePort. The counter increases with each clock cycle of the simulation when the subsystem receives a positive signal on the control port. While the subsystem is disabled, it returns the last accumulated signal value. When the positive control signal resumes, the output is reset – this behavior is set by the set configuration of the unit. EnablePort.

In [ ]:
plot( data["Счетчик Enabled"].time, data["Счетчик Enabled"].value )
Out[0]:

In the third graph, we see the work triggered-subsystems with a trigger logic set via TriggerPort. With each rising edge of the control signal, the counter increases by 1.

In [ ]:
plot( data["Счетчик Triggered"].time, data["Счетчик Triggered"].value )
Out[0]:

Why does the counter "skip" the first two rising edges? There is a block in his diagram Unit Delay, which returns 0 the first time it is triggered. And the first activation of this block does not occur at the moment t=0, and at the time of registration of the first rising pulse:

  • when starting the model, the control signal is initially set to 1 and there is no growing momentum,
  • when the first edge occurs, the counter is triggered for the first time and returns 0
  • when registering the second edge (the third pulse) , the counter will return to us 1.

Conclusion

Using various modes of operation of subsystems in Engee, it is possible to organize complex hybrid scenarios for simulating discrete or continuous processes. We have seen this using the example of two subsystem execution modifiers. – EnablePort and TriggerPort, but in Engee there are several more similar modifiers that allow you to set more complex operating conditions for subsystems, which can be found on the panel. Subsystems of the basic block library.