新手上路
- 积分
- 36
- 金钱
- 36
- 注册时间
- 2022-11-29
- 在线时间
- 9 小时
|
2金钱
做了一个串行数据接收模块,将串行数据变成12位输出,但是综合后里面的计数器被优化掉了,输出全部接地,求大佬帮忙这种怎么解决
下面是我的代码
module serial_rec
(
input wire sys_clk ,
input wire rst_n ,
input wire SDATA ,
input wire sample_flag ,
output reg out_flag ,
output reg [11:0] data_rec ,
output reg CS
);
wire sclk ;
wire aclk ;
reg [3:0] cnt ;
reg out_flag_reg ;
reg sample_flag_pre ;
reg [4:0]cnt_2m ;
pll_ip pll_ip_inst
(
// Clock out ports
.clk_out1(sclk), // output clk_out1
// Status and control signals
.reset(!rst_n), // input reset
// Clock in ports
.clk_in1(sys_clk)); // input clk_in1
always@(posedge sys_clk or negedge rst_n)
begin
if(!rst_n)
cnt_2m<=5'd0;
else if(cnt_2m==5'd24)
cnt_2m<=5'd0;
else
cnt_2m<=cnt_2m+1'b1;
end
assign sclk=(cnt_2m>5'd12)?1'b1:1'b0;
always@(negedge sclk or negedge rst_n) //cnt
begin
if(!rst_n)
cnt<=4'd0;
else if(cnt==4'd14)
cnt<=4'd0;
else if(CS==1'b0)
cnt<=cnt+1'b1;
end
always@(negedge sclk or negedge rst_n) //data_rec
begin
if(!rst_n)
data_rec<=12'd0;
else case(cnt)
4'd2 :data_rec[11]<=SDATA;
4'd3 :data_rec[10]<=SDATA;
4'd4 :data_rec[9]<=SDATA;
4'd5 :data_rec[8]<=SDATA;
4'd6 :data_rec[7]<=SDATA;
4'd7 :data_rec[6]<=SDATA;
4'd8 :data_rec[5]<=SDATA;
4'd9 :data_rec[4]<=SDATA;
4'd10:data_rec[3]<=SDATA;
4'd11:data_rec[2]<=SDATA;
4'd12:data_rec[1]<=SDATA;
4'd13:data_rec[0]<=SDATA;
default:;
endcase
end
always@(negedge sclk or negedge rst_n) //打一拍
begin
if(!rst_n)
out_flag_reg<=1'b0;
else if(cnt==4'd13)
out_flag_reg<=1'b1;
else
out_flag_reg<=1'b0;
end
always@(negedge sclk or negedge rst_n)
begin
if(!rst_n)
out_flag<=1'b0;
else
out_flag<=out_flag_reg;
end
always@(posedge aclk or negedge rst_n) //采样上升沿检测
begin
if(!rst_n)
sample_flag_pre<=1'b0;
else
sample_flag_pre<=sample_flag;
end
always@(posedge aclk or negedge rst_n) // CS
begin
if(!rst_n)
CS<=1'b1;
else if(sample_flag&(~sample_flag_pre))
CS<=1'b0;
else if(cnt==4'd14)
CS<=1'b1;
else
CS<=CS;
end
endmodule
|
|