Code generation for MIC32 (Engee Logo)¶
This demo shows the development of the Engee model for outputting vectors with coordinates of the points that make up the Engee logo to the two DAC channels of the MIK32V2 microcontroller.
Introduction¶
The target device used in this demo is a MIK32 NUKE V0.3 debug board based on K1948VC018 MIK32 Amur microcontroller. In the Engee model developed in this example, the generation of variable signals X and Y is carried out on two DAC channels, when oscillographing the Y(X) function, get the Engee logo. Compilation and loading of the code into the microcontroller is made from VS Code with PlatformIO extension.
Obtaining signal variables¶
We have already presented a demo drawing the Engee logo.
# Переходим в директорию примера
cd("/user/start/examples/base_simulation/polar_plot_engee_logo/");
# Выполняем скрипт примера
engee.script.run("/user/start/examples/base_simulation/polar_plot_engee_logo/draw_polar_engee_logo.ngscript");
After executing the example script, all the necessary variables should appear in the workspace. Let's draw the resulting logo by points.
gr()
plot( s["y"].value, s["x"].value; aspect_ratio=:equal, seriestype = :scatter)
Since the DACs of the microcontroller are 12-bit, the variables passed to them (X and Y coordinates of the logo points) must have the format uint16_t
and belong to the range of values $[0, 4095]$. Let's shift and scale the points:
# Инвертируем значения
X = -s["x"].value
Y = -s["y"].value
# Масштабируем диапазоны значений
Y_max = maximum(Y)
Y_min = minimum(Y)
Y_rng = Y_max-Y_min
Y = (Y .- Y_min)./ Y_rng .* 4095
X_max = maximum(X)
X_min = minimum(X)
X_rng = X_max-X_min
X = (X .- X_min)./ X_rng .* 4095
# Преобразуем в целочисленный формат
X = convert.(Int,X.÷1);
Y = convert.(Int,Y.÷1);
# Прореживаем вектора для экономии памяти контроллера
New_X = Vector{Int}(undef, 250);
New_Y = Vector{Int}(undef, 250);
for i in 1:length(New_X)
New_X[i] = X[i*4]
New_Y[i] = Y[i*4]
end
# Построим логотип по прореженным, отмасштабированным значениям
plot( New_X, New_Y; aspect_ratio=:equal, seriestype = :scatter)
Model description¶
The model for this example is mik32_engee_logo.engee
. It is similar to the model mik32_dac.engee
, except for the way the input variables for the DAC are set.
To set the variables of DAC signals, the obtained variables of coordinates of the logo points New_X
and New_Y
are written in the blocks Repeating Sequence Stair
. It is possible to reproduce the model and make sure that the given points in the model are built similarly to the previous graph, but we will not repeat ourselves. Let's move on to code generation.
Code generation and project building¶
# @markdown **Генерация кода:**
# @markdown Папка для результатов генерации кода будет создана в папке скрипта:
папка = "code" # @param {type:"string"}
имя_модели = "mik32_engee_logo" # @param {type:"string"}
# @markdown Генерация кода для подсистемы:
включить = false # @param {type:"boolean"}
if(включить)
подсистема = "" # @param {type:"string"}
engee.generate_code( "$(@__DIR__)/"*имя_модели*".engee", "$(@__DIR__)/"*папка;
subsystem_name = подсистема)
else
engee.generate_code( "$(@__DIR__)/"*имя_модели*".engee", "$(@__DIR__)/"*папка)
end
The project with the model is assembled in IDE VS Code+PlatformIO, the assembly process is similar to the process from the example MIC32: Sawtooth Signal Generator. Let's proceed to code execution on the microcontroller.
Code execution on MIK 32¶
After successful assembly and compilation of the project, connect an oscilloscope to both DAC channels of the microcontroller and display the oscillogram in the function Y(X).
As you can see in the animation, the DAC channels play the variable signals that build the Engee logo.
Conclusion¶
We have used our early work - examples with building the Engee logo in polar coordinates and working with the DAC of the MIC 32 microcontroller - to arrange for variables with complex functional dependencies to be output to the analogue outputs.