|
楼主 |
发表于 2013-5-24 11:07:20
|
显示全部楼层
本帖最后由 yong19891101 于 2013-5-24 20:20 编辑
回复 3# ivor_kandy
我按你说的搞了一遍 稍微你改了以下 数据都对了 就是和理论的那个仿真图相比,所有数据整体提前了一个周期 要是能和延迟一个就好了 不过已经很不错了 非常感谢 高手啊!!!!module sample1(clk,set,ena,pulse,counter_up,counter_down,rmem_out,counter_k,addrb,wea,addra,dina,
up_en,down_en,mask_data,rmem_rden,rdata_ready);
input clk,set,wea,pulse,ena;
input[6:0]addra,dina;
output [6:0]counter_up,counter_down,addrb,rmem_out,counter_k,mask_data,rdata_ready;
output down_en,up_en,rmem_rden;
reg [6:0]counter_up,counter_down,counter_k;
reg rdata_ready;
reg [6:0]addrb;
wire [6:0]mask_data;
assign rmem_rden=pulse|(mask_data==1);
assign up_en=rmem_rden;
assign down_en=(mask_data>1);
//counter_r_up
always@(posedge clk)
begin
if(set)
begin
counter_up<=0;
end
else if(up_en==1)
begin
counter_up<=counter_up+1;
end
end
//counter_d_down
always@(posedge clk)
begin
if(set)
begin
counter_down<=7'd127;
end
else if(down_en==1)
begin
counter_down<=counter_down-1;
end
end
//selectassign addrb=(down_en==1 )?counter_up :counter_down ;
//up_en delay
always@(posedge clk)
begin
if(set)
begin
rdata_ready<=0;
end
else
begin
rdata_ready<=rmem_rden;
end
end
//mask_data
assign mask_data=(rdata_ready)?rmem_out:counter_k;
//counter_k_down
always@(posedge clk)
begin
if(set)
begin
counter_k<=7'b0;
end
else if(rdata_ready==1)
begin
counter_k<=rmem_out-1;
end
else
if(counter_k>1)
begin
counter_k<=counter_k-1;
end
end
//rMEM use
rMEM MYrMEM (
.clka(clk), // input clka
.ena(ena), // input ena
.wea(wea), // input [0 : 0] wea
.addra(addra), // input [6 : 0] addra
.dina(dina), // input [6 : 0] dina
.clkb(clk), // input c // input [6 : 0] addra
.rstb(set), // input rstb
.enb(rmem_rden), // input enb
.addrb(addrb), // input [6 : 0] addrb
.doutb(rmem_out) // output [6 : 0] doutb
);
endmodule
rMEM存储前5个数据是 3、1、4、2 、3
仿真图如下:
|
|