ChatGPTに回路設計をやらせてみた 2
前回、ChatGPTにRTLを書いてもらったのですが、その正しさが分からずに終わってしまいました。今回は検証環境を整え、動作確認まで行いました。
検証環境導入
以下を参考にしました。
オープンソースのIcarus Veriog、GTKWaveを使用します。
https://miyanetdev.com/archives/240
rev. 0
前回ChatGPTに出力させたRTLをそのまま使います。
テストベンチは以下を使用しました。100円を入れて50円の商品を購入した時、お釣りが50円と出ればpassです。ChatGPTに出してもらったものをベースに、pin名の変更やIcarus Verilog対応(assertが使えない)などを行っています。すべての機能をテストできていない気もしますが、今回はこれがpassすればOKとします。
`timescale 1ns/1ns
module testbench();
// Inputs
reg [7:0] product_price;
reg [7:0] deposit;
reg clk;
reg reset;
reg btn;
// Outputs
wire [7:0] change;
wire dispense;
// Instantiate the DUT
vending_machine dut(
.clk(clk),
.reset(reset),
.product_price(product_price),
.deposit(deposit),
.change(change),
.dispense(dispense),
.btn(btn)
);
initial begin
$dumpvars;
// Initialize inputs
product_price = 8'h32; // 50 in decimal
deposit = 8'h64; // 100 in decimal
clk = 0;
btn = 0;
reset = 1;
//reset
#5; clk = 1; #5; clk = 0;
// Toggle clock and test
reset = 0;
btn = 1;
#5; clk = 1; #5; clk = 0;
if(change == 8'h32) ;else $display("Test failed: Incorrect change amount");
if(dispense) ; else $display("Test failed: Item not purchased");
// End simulation
$finish;
end
endmodule
実行結果
Test failed: Incorrect change amount
ChatGPTの解析によると以下が原因らしいです。
rev. 1
修正してもらいました。
実行結果。また同じエラーが出ました。
Test failed: Incorrect change amount
rev. 5
何度か修正してもらった結果、ようやくテストをpassできました。
ただ、passはしたものの、お釣りの金額がボタンを押す前から表示されてしまいます。しかも、お釣りの金額に商品価格が代入されているため、このテストではたまたま一致しただけのようです。とはいえ、この問題はChatGPTの設計が悪いわけではなく、テストベンチの問題です。続く。
この記事が気に入ったらサポートをしてみませんか?