一、FPGA
1.1 打印结果到TCL 中
直接打印,默认打印10进制,%h 打印16进制
always @(posedge i_clk)
if (!i_rstn) begin
// 复位时不操作
end else if (o_calc_valid) begin
$display("i_freq= ", i_freq);
$display("i_angle_thta= ", i_angle_thta);
$display("i_angle_phi= ", i_angle_phi);
$display("o_calc_data = %h", o_calc_data);
end
2.2 保存结果到txt中
integer data_file;
initial begin
data_file = $fopen("FPGA_tx_module_output.txt", "w");
// 等待仿真结束
#1000000; // 或者使用更精确的结束条件
$fclose(data_file); // 关闭文件,确保数据写入磁盘
$display("数据已保存到 FPGA_tx_module_output.txt");
$finish; // 结束仿真
end
// 保存文件的数据写入部分
always @(posedge i_clk) begin
if (i_rstn && o_valid ) begin
// 写入一行数据
$fdisplay(data_file, "%0d,%0d,%0d,%0d,%0d",
test_index + 1, // index从1开始
current_theta_reg/100, // theta/100
current_phi_reg/100, // phi/100
o_alpha, // alpha
o_beta); // beta
test_index = test_index + 1;
end
end
二、MATLAB
2.1 打印
fid = fopen('matlab_rx_calculation_results.txt', 'w');
fprintf(fid, '%d,%d,%d,%d,%d\n', row_idx, thta_scan, phi_scan, alpha_fpga, beta_fpga);
fclose(fid);
2.2 保存到txt
disp(hex_str);
或者需要打印的变量末尾直接去掉;
% 打印到控制台
fprintf('第%d组 | theta=%3d° | phi=%3d° | alpha_fpga=%d | beta_fpga=%d\n', ...
row_idx, thta_scan, phi_scan, alpha_fpga, beta_fpga);