@Article{electronics12132786, AUTHOR = {Saralegui, Roberto and Sanchez, Alberto and de Castro, Angel}, TITLE = {Efficient Hardware-in-the-Loop Models Using Automatic Code Generation with MATLAB/Simulink}, JOURNAL = {Electronics}, VOLUME = {12}, YEAR = {2023}, NUMBER = {13}, ARTICLE-NUMBER = {2786}, URL = {https://www.mdpi.com/2079-9292/12/13/2786}, ISSN = {2079-9292}, ABSTRACT = {Hardware-in-the-loop testing is usually a part of the design cycle of control systems. Efficient and fast models can be created in a Hardware Description Language (HDL), which is implemented in a Field-Programmable Gate Array (FPGA). Control engineers are more skilled in higher-level approaches. HDL models derived automatically from schematics have noticeably lower performance, while HDL models derived from their equations are faster and smaller. However, even models translated automatically into HDL using the equations might be worse than manually coded models. A design workflow is proposed to achieve manual-like performance with automatic tools. It consists of the identification of similar operations, forcing signal signedness, and adjusting to multiplier input sizes. A detailed comparison was performed between three workflows: (1) translation of high-level MATLAB code, (2) translation of a Simulink model, and (3) working directly in the HDL. Sources of inefficiency were shown in a buck converter, and the process was validated in a full-bridge with electrical losses using a Runge–Kutta method. The results showed that the proposed approach delivered code that performed very close to a reference VHDL implementation, even for complex designs. Finally, the model was implemented in an off-the-shelf FPGA board suitable for a hardware-in-the-loop test setup.}, DOI = {10.3390/electronics12132786} }