初级会员
- 积分
- 158
- 金钱
- 158
- 注册时间
- 2017-4-24
- 在线时间
- 29 小时
|
1金钱
代码如下,功能就是对输入时钟分频输出1S间隔的脉冲信号以及1MS的间隔的脉冲信号,在对MS进行计数的always模块中count_ms无法自增(红色代码段),仿真始终显示为0
module s_count_block
#(
parameter sys_clk_Mhz = 50
)
(
input wire sys_clk , //50Mhz - 20ns
input wire sys_rst_n ,
output reg s_count_flag , //计数完1s标志位
output reg ms_count_flag , //计数完1ms标志位
output reg [19:0] BINARY_NUM //二进制输出
);
reg [5:0] sys_clk_count ; //时钟计数变量
reg [9:0] count_ms ; //ms计数变量
localparam count_ms_max = 10 ;
//系统时钟计数块
always@(posedge sys_clk or negedge sys_rst_n) begin
if(sys_rst_n == 0)
begin
sys_clk_count <= 6'd0;
ms_count_flag = 1'b0;
end
else if(sys_clk_count == sys_clk_Mhz-1)
begin
ms_count_flag = 1'b1;
sys_clk_count <= 6'd0;
end
else
begin
ms_count_flag = 1'b0;
sys_clk_count <= sys_clk_count + 1'b1;
end
end
//ms计数程序块
always@(posedge sys_clk or negedge sys_rst_n) begin
if(sys_rst_n == 0)
begin
count_ms <= 10'd0;
s_count_flag <= 1'b0;
end
else if((count_ms == count_ms_max - 1) && (ms_count_flag == 1'b1))
begin
count_ms <= 10'd0;
s_count_flag <= 1'b1;
end
else if(ms_count_flag == 1'b1)
begin
count_ms <= count_ms + 1'b1;
s_count_flag <= 1'b0;
end
else
begin
count_ms <= count_ms;
s_count_flag <= 1'b0;
end
end
always@(posedge sys_clk or negedge sys_rst_n) begin
if(sys_rst_n == 0)
BINARY_NUM <= 20'd0;
else if((BINARY_NUM == count_ms_max - 1) && (ms_count_flag == 1'b1))
BINARY_NUM <= 20'd0;
else if(ms_count_flag == 1'b1)
BINARY_NUM <= BINARY_NUM + 1'b1;
else
BINARY_NUM <= BINARY_NUM;
end
endmodule
|
最佳答案
查看完整内容[请看2#楼]
程序没问题,是不是你外部例化的时候parameter sys_clk_Mhz 赋值过大,计数器reg [5:0] sys_clk_count 溢出,计数器异常导致的if(sys_clk_count == sys_clk_Mhz-1)条件一直不成立,
|