How to generate verilog with simulink and run it in a hierarchical block Qspice.

29 次查看(过去 30 天)
I've been exploring running spice hierarchical blocks and have had success utilizing discrete controller code implemented in both floating pont and fixed point code generated by Simulink and hooked by the DLL wrapper in cpp source file for a Qspice hierarchical block to control a simple buck regulator. I'm trying to take this the next step farther and generate Verilog code that can be included in a verilog file that gets compiled to A C/C++ source for a Dll for Qspice. Qspice will generate a template that defines all the IO on the hierarchical block. The file needs modification to map the Qspice hierarchical block I/O to the simuliink verilog fixed point controller I/O and instantiate the fixed point controller.

回答(1 个)

Adit
Adit 2025-8-13,10:13
Hi Erick,
You have used Simulink-generated C++ code in Qspice hierarchical blocks for your buck regulator project. Now, you want to generate Verilog from Simulink, convert it for use in Qspice, and ensure correct I/O mapping between your fixed-point controller and Qspice’s hierarchical block structure. Here’s a step-by-step guide to accomplish this:
1. Generate Verilog Code from Simulink:
  • Design your controller in Simulink using blocks to model your fixed-point controller.
  • Ensure all data types are compatible with HDL code generation (use Fixed-Point Designer if necessary).
  • Open the HDL Coder app in Simulink.
  • Select your controller subsystem.
  • Set the target language to Verilog.
  • Run the HDL Workflow Advisor to produce Verilog code (.v file).
2. Prepare the Qspice Hierarchical Block:
  • In Qspice, create a new hierarchical block for your controller.
  • Qspice will generate a C/C++ template file for the block, detailing all the I/O ports.
  • Compare the generated Qspice block I/O with the Verilog module I/O.
  • Take note of any differences in naming, data types, or widths, and plan for any necessary conversions.
3. Integrate Verilog with Qspice:
  • Use a tool like Verilator to compile your Verilog code into C++. Verilator is open-source and widely used for this purpose.
  • Wrap the generated C++ code in a DLL (Dynamic Link Library), following the structure and I/O mapping specified by the Qspice template. Ensure all signals connect correctly and handle any type conversions (e.g., fixed-point to double).
  • Edit the Qspice-generated C/C++ template to instantiate your controller’s C++ class and connect all I/O. Compile this into a DLL and place it in the appropriate directory for Qspice to access.
4. Test and Debug
  • Add your new hierarchical block to a Qspice schematic.
  • Connect signals and test the simulation.
  • Debug any interface mismatches or logic errors.
For more information, refer to the following documentation links: 

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by