使用2个不同的7段显示器显示4位0到15计数器

时间:2016-03-23 13:11:39

标签: verilog

我试图在basys 3 fpga上的2个不同的7段显示器上显示一个4位计数器。 basys 3 fpga配有4个不同的7段显示器,带有不同的阳极但是常见的阴极可以照亮我们的显示器。我无法在显示屏上显示两个不同的值。

最终,我需要使用所有4个不同的7个显示段来构建0000到9999计数器,因此使用十六进制计数对我来说不起作用。

请帮忙。

代码:

module counter(

input press, 
input clock,
output reg [6:0] seg,
output reg [3:0] an 
);

reg [3:0]count = 4'b0000;
wire pulse;

// Don't need to worry about the exact code in this function call

singlepulse sp(clock,press,pulse);

always @(posedge pulse) begin
count <= count + 1;
end

integer k;
reg [3:0]ones=0;
reg [3:0]tenths=0;

//convert binary to BCD

always @( count )
    begin

    ones = 4'd0;
    tenths = 4'd0;

    for ( k=4; k>=0; k=k-1 ) begin
    if( tenths>=5 ) tenths=tenths+3;
    if( ones>=5 ) ones=ones+3;
    tenths=tenths<<1;
    tenths[0]=ones[3];
    ones=ones<<1;
    ones[0]=count[k];
    end    

end

always @(posedge clock) begin

// Here is the problem, if I let an=4'b1110 only the first display will light up
// If I let an=4'b1100 both display light shows the same number instead of the correct number
// How should I make it such that both displays shows different number at the same time?
case (ones)
0 : seg=7'b100_0000;
1 : seg=7'b111_1001;
2 : seg=7'b010_0100;
3 : seg=7'b011_0000;
4 : seg=7'b001_1001;
5 : seg=7'b001_0010;
6 : seg=7'b000_0010;
7 : seg=7'b111_1000;
8 : seg=7'b000_0000;
9 : seg=7'b001_0000;
endcase

case (tenths)
0 : seg=7'b100_0000;
1 : seg=7'b111_1001;
2 : seg=7'b010_0100;
3 : seg=7'b011_0000;
4 : seg=7'b001_1001;
5 : seg=7'b001_0010;
6 : seg=7'b000_0010;
7 : seg=7'b111_1000;
8 : seg=7'b000_0000;
9 : seg=7'b001_0000;
endcase

end

endmodule  // counter

由于

1 个答案:

答案 0 :(得分:0)

这似乎是一个逻辑设计问题,而不是Verilog问题。我认为您的解决方案是 time multiplex 。换句话说,你需要依次驱动每个7段显示器一小段时间,足够快,以便眼睛无法察觉。您需要一个电路,以便为每个seg输出不同地驱动an输出,并快速旋转。