16 Jun / Embedded Code Generation: Introduction
I don’t know if it is an objective for every young control and electronics engineer. Well, it was mine… For a long time, I wanted to be able to understand and actually master each step of control design and implementation roadmap. The idea is not to just use tools, but understand what the tools do from inside! I prepared a simple example for those who are as curious as I was. However, I realized that it would become too much content for a single post. For this reason, this post is just an introduction about the path that we are going to follow.
We start with a simple recurrence equation modeled in a Simulink Block Diagram, perform code generation (with my own algorithm), code compilation (by mapping high-level instructions into Assembly code for a microchip’s PIC microcontroller), and translate the Assembly code into binaries (by using Intel HEX format). This roadmap is summarized by the figure below:
There are several issues to take care, even regarding this very simple discrete transfer function. Design, discretization, quantization issues, and other related topics are intrinsic to this post. In other words, we derive the code to be implemented without so much discussion about other possible mappings. Productivity tools should allow us to work transparently on the highest level (block diagrams) and bring equivalent binary codes into hardware with minimal effort. On the other hand, we shouldn’t be so constrained to specific vendors and let them hold us hostage. In my point of view, the only way to be free is by a deeper knowledge about the whole process.
It doesn’t matter if you are using Matlab/Simulink, MatrixX/SystemBuild, LabView, Dymola, OpenModelica, Scilab, et cetera. We treat it here in a generic way. You could even use a raw block diagram IDE (Integrated Development Environment) or sketch your diagram on paper. The idea is to take a block diagram as a starting point, algorithmically turn it into a high-level code (C/C++ in our case), and translate this code progressively (manually!) up to the lowest level: binary codes ready to be loaded into the Microcontroller’s Program Memory.