Chào các anh/chị/bạn
Em viết một chương trình cho hiển thị bộ Up/Down Counter 4bit bằng Verilog CHẠY TRÊN KIT CPLD như bên dưới. Nhưng khi cho mô phỏng thì lại ko chạy. Em ko hiểu nó sai chỗ nào, có anh chị hay bạn nào biết, chỉ giúp em với. Em cảm ơn nhiều!
Test bench:
Em viết một chương trình cho hiển thị bộ Up/Down Counter 4bit bằng Verilog CHẠY TRÊN KIT CPLD như bên dưới. Nhưng khi cho mô phỏng thì lại ko chạy. Em ko hiểu nó sai chỗ nào, có anh chị hay bạn nào biết, chỉ giúp em với. Em cảm ơn nhiều!
Code:
`timescale 1ns / 1ps
module U_Dcounter(reset, clk_in, control, out);
input reset, clk_in, control;
output [6:0] out;
reg clk_out;
reg [3:0] count;
reg [6:0] out;
reg [27:0] counter;
// chia tan so
always@(posedge reset or posedge clk_in)
begin
if (reset == 1'b1)
begin
clk_out <= 0;
counter <= 0;
end
else
begin
counter <= counter + 1;
if ( counter == 25_000_000)
begin
counter <= 0;
clk_out <= ~clk_out;
end
end
end
//counter dem len xuong
always @ ( posedge clk_out )
begin
if(reset) // neu reset == 0
count[3:0] <= 4'd0;
else
begin
if (control)
begin
if (count == 4'd15)
count <= 4'd0;
else
count[3:0] <= count[3:0] + 4'd1;
end
else
begin
if (count == 4'd0)
count <= 4'd15;
else
count <= count - 4'd1;
end
end
end
//LED
always @ (*)
begin
case (count[3:0])
default: out = 7'b0111111;
4'h0: out = 7'b0111111;
4'h1: out = 7'b0000110;
4'h2: out = 7'b1011011;
4'h3: out = 7'b1001111;
4'h4: out = 7'b1100110;
4'h5: out = 7'b1101101;
4'h6: out = 7'b1111101;
4'h7: out = 7'b0000111;
4'h8: out = 7'b1111111;
4'h9: out = 7'b1101111;
4'hA: out = 7'b1110111;
4'hB: out = 7'b1111100;
4'hC: out = 7'b0111001;
4'hD: out = 7'b1011110;
4'hE: out = 7'b1111001;
4'hF: out = 7'b1110001;
endcase
end
endmodule
Code:
`timescale 1ns / 1ps
module U_DTest(reset, control, clk_in, out);
input reset, control, clk_in;
output [6:0] out;
U_Dcounter counter1
(
.reset(reset), .out(out[6:0]), .control(control), .clk_in(clk_in)
);
endmodule

Comment