1
0
mirror of https://github.com/WangXuan95/FpOC.git synced 2025-02-05 08:08:22 +08:00
FpOC/SIM/tb_clark_park_tr.v

109 lines
4.5 KiB
Coq
Raw Permalink Normal View History

2022-04-01 05:22:10 +08:00
//--------------------------------------------------------------------------------------------------------
// Module : tb_clark_park_tr
// Type : simulation, top
2023-06-09 20:54:43 +08:00
// Standard: Verilog 2001 (IEEE1364-2001)
2022-04-01 05:22:10 +08:00
// Function: testbench for sincos.sv , clark_tr.sv , park_tr.sv
//--------------------------------------------------------------------------------------------------------
module tb_clark_park_tr();
initial $dumpvars(1, tb_clark_park_tr);
reg rstn = 1'b0;
reg clk = 1'b1;
always #(13563) clk = ~clk; // 36.864MHz
initial begin repeat(4) @(posedge clk); rstn<=1'b1; end
2023-06-09 20:54:43 +08:00
reg en_theta = 0;
reg [11:0] theta = 0; // 当前电角度简记为 ψ取值范围0~40950对应0°1024对应90°2048对应180°3072对应270°
localparam [11:0] PI_M2_D3 = (2*4096/3); // (2/3)*π
localparam [11:0] PI_D3 = ( 4096/3); // (1/3)*π
2022-04-01 05:22:10 +08:00
wire en_iabc;
wire signed [15:0] ia, ib, ic;
wire en_ialphabeta;
wire signed [15:0] ialpha, ibeta;
wire en_idq;
wire signed [15:0] id;
wire signed [15:0] iq;
// 这里只是刚好借助了 sincos 模块来生成正弦波给 clark_tr 只是为了仿真 FOC 设计中 sincos 模块并不是用来给 clark_tr 提供输入数据的而是被 park_tr 调用
2023-06-09 20:54:43 +08:00
sincos u1_sincos (
2022-04-01 05:22:10 +08:00
.rstn ( rstn ),
.clk ( clk ),
.i_en ( en_theta ),
2023-06-09 20:54:43 +08:00
.i_theta ( theta + PI_M2_D3 ), // input : θ + (2/3)*π
2022-04-01 05:22:10 +08:00
.o_en ( en_iabc ),
.o_sin ( ia ), // output: Ia, 振幅为±16384初相位为 (4/3)*π 的正弦波
.o_cos ( )
);
2023-06-09 20:54:43 +08:00
sincos u2_sincos (
2022-04-01 05:22:10 +08:00
.rstn ( rstn ),
.clk ( clk ),
.i_en ( en_theta ),
2023-06-09 20:54:43 +08:00
.i_theta ( theta + PI_D3 ), // input : θ + (1/3)*π
2022-04-01 05:22:10 +08:00
.o_en ( ),
.o_sin ( ib ), // output: Ib, 振幅为±16384初相位为 (2/3)*π 的正弦波
.o_cos ( )
);
2023-06-09 20:54:43 +08:00
sincos u3_sincos (
2022-04-01 05:22:10 +08:00
.rstn ( rstn ),
.clk ( clk ),
.i_en ( en_theta ),
.i_theta ( theta ), // input : θ
.o_en ( ),
.o_sin ( ic ), // output: Ic, 振幅为±16384初相位为 0 的正弦波
.o_cos ( )
);
// clark 变换
2023-06-09 20:54:43 +08:00
clark_tr u_clark_tr (
2022-04-01 05:22:10 +08:00
.rstn ( rstn ),
.clk ( clk ),
.i_en ( en_iabc ),
.i_ia ( ia / 16'sd2 ), // input : 振幅为±8192初相位为 (4/3)*π 的正弦波
.i_ib ( ib / 16'sd2 ), // input : 振幅为±8192初相位为 (2/3)*π 的正弦波
.i_ic ( ic / 16'sd2 ), // input : 振幅为±8192初相位为 0 的正弦波
.o_en ( en_ialphabeta ),
.o_ialpha ( ialpha ), // output: Iα 应该为初相位为 (4/3)*π 的正弦波
.o_ibeta ( ibeta ) // output: 相位应该比 Iα 滞后 (1/2)*π 也就是与 Iα 正交
);
// park 变换
2023-06-09 20:54:43 +08:00
park_tr u_park_tr (
2022-04-01 05:22:10 +08:00
.rstn ( rstn ),
.clk ( clk ),
.psi ( theta + 12'd512 ), // input : θ + (1/4)*π
.i_en ( en_ialphabeta ),
.i_ialpha ( ialpha ), // input : Iα
.i_ibeta ( ibeta ), // input :
.o_en ( en_idq ),
.o_id ( id ), // output: Id 应该变为一个定值因为 park 变换把转子又变回定子了
.o_iq ( iq ) // output: Iq 应该变为一个定值因为 park 变换把转子又变回定子了
);
2023-06-09 20:54:43 +08:00
integer i;
2022-04-01 05:22:10 +08:00
initial begin
while(~rstn) @ (posedge clk);
2023-06-09 20:54:43 +08:00
for (i=0; i<1000; i=i+1) @ (posedge clk) begin
2022-04-01 05:22:10 +08:00
en_theta <= 1'b1;
theta <= theta + 12'd10;
@ (posedge clk);
en_theta <= 1'b0;
repeat (9) @ (posedge clk);
end
$finish;
end
endmodule