🛠️ SimulinkモデルからCコードを生成する方法

🛠️ How to Generate C Code from Simulink Models

GitHub
Hybrid License


本ガイドは、Simulinkで設計した制御ブロックをCコードに自動変換し、
その出力を SoC_DesignKit_by_ChatGPT/c_to_hdl/ へ橋渡しするための手順を解説します。

This guide explains how to automatically convert control blocks designed in Simulink into C code,
and how to bridge the output to SoC_DesignKit_by_ChatGPT/c_to_hdl/ for further processing.


✅ 使用ツール / Required Tools

ツール / Tool 用途 / Purpose
MATLAB / Simulink(R2021以降推奨 / R2021 or later recommended) 制御モデル設計 / Control model design
Simulink Coder Cコード自動生成(必須) / Automatic C code generation (required)
対象モデル / Target Model pid_simulink_example.slx

📘 手順概要 / Procedure Overview

ステップ / Step 操作内容 / Operation
pid_simulink_example.slx を開く / Open the model
[Simulink] メニュー → 「コード」 → 「Cコードの生成」 / Select [Simulink] → Code → Generate C Code
codegen フォルダに pid.c, pid.h などが生成される / Files such as pid.c, pid.h will be generated in codegen
生成Cコードから主要演算式を抽出(例:output = Kp * error + Ki * integral;) / Extract key equations from the generated C code (e.g., output = Kp * error + Ki * integral;)
c_to_hdl/conversion_prompt.md に貼り付けて、ChatGPTにVerilog化を依頼 / Paste into c_to_hdl/conversion_prompt.md and request Verilog conversion via ChatGPT

💬 ChatGPT連携プロンプト例 / Example Prompt for ChatGPT

タスク / Task

以下のCコードをVerilogに変換してください
Convert the following C code to Verilog.

条件 / Conditions

output = Kp * error + Ki * integral;

💡 HDL変換には c_to_hdl/conversion_prompt.md を活用してください。
💡 Use c_to_hdl/conversion_prompt.md for HDL conversion.


🧪 応用例 / Applications


パス / Path 内容 / Description
matlab_tools/ Simulinkモデル群(PID, 状態空間) / Simulink models (PID, State-space)
c_to_hdl/ C→HDL変換テンプレとプロンプト / Templates & prompts for C→HDL conversion
execution_logs/ ChatGPT応答ログ記録(任意) / Logs of ChatGPT responses (optional)

📄 ライセンス / License

教材・コード・図表の性質に応じたハイブリッドライセンスを採用
Hybrid licensing based on the nature of the materials, code, and diagrams.

項目 / Item ライセンス / License 説明 / Description
コード(Code) MIT License 自由に使用・改変・再配布可
Free to use, modify, and redistribute
教材テキスト(Text materials) CC BY 4.0 著者表示必須
Attribution required
図表・イラスト(Figures & diagrams) CC BY-NC 4.0 非商用利用のみ可
Non-commercial use only
外部引用(External references) 元ライセンスに従う
Follow the original license
引用元を明記
Cite the original source

🏠 トップページへ戻る / Back to Top