Manual switching of logic circuits¶
In this example, we show how to test or demonstrate the operation of a logic circuit by manually setting the desired input signals using switches.
Model description¶
This model consists of one block of type Logic
, which inputs logic signals set by manual switches - blocks of type Manual Switch
.
By rearranging the input switches we can set any acceptable combination of input signals and study the operation of the circuit under different conditions.
Execution of the model¶
The output can be studied by running the model and opening the graph panel. There the input and output data are collected in the form of a table.
Automatic check of all combinations¶
Let's organise automated testing of this model to see all input combinations. In this case our goal will be not to change anything in the topology of the model, but only to rearrange the switches programmatically.
Load the model (if necessary):
# Если модель еще не открыта, загрузим из файла
if "switching_logic" ∉ [m.name for m in engee.get_all_models()] engee.load( "$(@__DIR__)/switching_logic.engee"); end;
The symbol ∉
can be copied from the command line, where you can type $\LaTeX$ command \notin
and press the tab key Tab
.
To find out which parameters can be switched programmatically, call the command get_param
.
engee.get_param( "switching_logic/Manual Switch" )
Now let's organise a loop through all combinations of input conditions and build a table:
X1 = [ false, true ]
X2 = [ false, true ]
Y = zeros( length(X1), length(X2) )
for (i,x1) in enumerate(X1)
for (j,x2) in enumerate(X2)
# Переставим переключатели в нужное состояние
engee.set_param!( "switching_logic/Manual Switch", "PortValue"=>x1 )
engee.set_param!( "switching_logic/Manual Switch-1", "PortValue"=>x2 )
# Запустим модель с новыми параметрами
data = engee.run( "switching_logic" )
# Поместим результаты в матрицу
Y[i,j] = data["Y"].value[end]
end
end
It should be taken into account that each individual access to the model by means of software control takes about a second, regardless of the execution time of the model itself. For this reason, it is better to search for parameters within a not too large set of combinations.
Let us derive the truth table:
gr()
heatmap( X1, X2, Y, xticks=([0,1],["ложь", "истина"]), yticks=([0,1],["ложь", "истина"]) )
And plot another graph in a different format:
gr()
scatter( repeat(X1, inner=2), repeat(X2, outer=2), zcolor=Y[:],
markersize=40, xlimits=(-1.5,2.5), ylimits=(-0.5,1.5), size=(500,280),
xticks=([0,1],["ложь", "истина"]), yticks=([0,1],["ложь", "истина"]),
label=false )
Conclusion¶
The example shows how to model logic circuits without much difficulty by manually switching input signal values and then plotting for all input combinations.