Engee documentation
Notebook

Event counting with enabled and triggered subsystems

In this model we demonstrate the difference in the operation of the block enabled and the block triggered, which determine the conditions of triggering the subsystem. The demonstration is carried out on the example of counting events.

Model description

The model contains a pulse generator Pulse Generator, which in the Sample based mode controls the signal parameters based on the specified number of discrete simulation steps that must elapse between switches.

image.png

Next, the signal goes into two counter realisations:

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

image.png

Both counters, when triggered, add one to their output signal. But, as we can see from the colouring, the triggering time (Sample Time) of the second counter is determined by the operation of the TriggerPort block, so the colour of the counter block differs from the colour of the other blocks in the system (for which the sampling time is set to 0.01).

Model operation

The model allows us to study how different subsystem execution control blocks work. Let's run the model and analyse 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 operation of enabled-subsystem with triggering logic defined by EnablePort. The counter increases with each simulation cycle when the subsystem receives a positive signal on the control port. While the subsystem is disabled, it returns the last accumulated value of the signal. When the positive control signal is resumed, the output is reset - this behaviour is set by the block configuration set EnablePort.

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

In the third diagram we see the operation of triggered-subsystem with the triggering logic set via TriggerPort. With each rising edge of the control signal, the counter is incremented by 1.

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

Why does the counter "miss" the first two rising edges? There is a block in its circuit Unit Delay, which returns 0 at the first triggering. And the first triggering of this block occurs not at the moment of t=0, but at the moment of registration of the first rising edge:

  • when the model is started, the control signal is initially at 1 and there is no rising pulse,
  • when the first edge occurs, the counter is triggered for the first time and returns 0,
  • when the second edge is registered (third pulse) the counter will return 1.

Conclusion

Using different modes of subsystems triggering in Engee it is possible to organise complex hybrid scenarios of simulation of discrete or continuous processes. We have seen this with two subsystem execution modifiers - EnablePort and TriggerPort, but Engee has several more such modifiers that allow you to set more complex subsystem conditions, which can be found in the Subsystems panel of the basic block library.

Blocks used in example