先讲一下我的想法:我是想持续给FPGA送8位的数据,然后在某个IO口高电平时将之前最大的一个数据(所以我需要一直比较)送出。代码如下:
- module peak(
- clk,
- rst_n,
- dete_start,
- clk_2,
- data_in,
- data_out,
- tx_start
- );//数据读取和处理模块
- input clk; //AD的时钟源,始终与系统的时钟相同
- input rst_n; //复位信号
- input dete_start; //频率改变的触发信号
- input [7:0]data_in; //ad输入数据
- output clk_2; //系统时钟供ad使用
- output reg [7:0]data_out; //发送给tx_mod的数据寄存器
- output reg tx_start;
- assign clk_2 = clk; //系统时钟供ad使用
- //----------------------频率改变的触发信号-------------------//
- reg dete_start_r1,dete_start_r2; //dete_start寄存器
- always @(posedge clk or negedge rst_n)
- if(!rst_n)
- begin
- dete_start_r1 <= 1'b0;
- dete_start_r2 <= 1'b0;
- end
- else
- begin
- dete_start_r1 <= dete_start;
- dete_start_r2 <= dete_start_r1;
- end
- wire data_rst = dete_start_r1 & ~dete_start_r2;//上升沿置高一个时钟周期
- //**********************串口发送所需时间计数模块***************//
- reg[12:0] cnt;
- always @ (posedge clk or negedge rst_n)
- if(!rst_n) cnt <= 13'd0;
- else
- if(data_rst)
- begin
- cnt <= 13'd0;
- tx_start <= 1'b1;
- end
- else
- if(cnt == 100)
- tx_start <= 1'b0;
- else
- cnt <= cnt+1'b1;
- //**********************读取AD采集的电压值***************//
- reg [7:0]data_cache;
- always @ (posedge clk or negedge rst_n)
- if(!rst_n)
- begin
- data_cache <= 8'd0;
- data_out <= 8'd0;
- end
- else
- if(data_rst)
- begin
- data_cache <= 8'd0;
- data_out <= data_cache;
- end
- else
- if(data_in >= data_cache)
- data_cache <= data_in;
- endmodule
复制代码我在用modelsim进行仿真时好像不对啊,输出端口总是X。vt文件如下:
- `timescale 1 ns/ 1 ps
- module peak_vlg_tst();
- // constants
- reg clk;
- reg [7:0] data_in;
- reg dete_start;
- reg rst_n;
- // wires
- wire clk_2;
- wire [7:0] data_out;
- wire tx_start;
- // assign statements (if any)
- peak i1 (
- // port map - connection between master ports and signals/registers
- .clk(clk),
- .clk_2(clk_2),
- .data_in(data_in),
- .data_out(data_out),
- .dete_start(dete_start),
- .rst_n(rst_n),
- .tx_start(tx_start)
- );
- initial
- begin
- clk = 0;
- rst_n = 1;
- dete_start = 0;
- data_in = 0;
-
- #50;
- data_in = 49;
- #50;
- data_in = 149;
- #50;
- data_in = 49;
- #50;
- data_in = 29;
- #50;
- data_in = 59;
- #50;
- data_in = 19;
- #10;
- dete_start = 1;
- #30;
- dete_start = 0;
- end
- always
- begin
- #20 clk = ~clk;
- end
- endmodule
复制代码波形中输出端口始终是高阻态X,这是为什么呢?希望能给我解答一下!先谢了!
此帖出自
小平头技术问答
一周热门 更多>