charlie73
Newbie level 1
Hi,
I need help to develop three BCD counters 0 .. 9 on 3 independent displays on board BASYS. For a one counter could do. The code is as follows:
------------------------------------------------------------------------------------------------------------------------------------------------------------
COUNTER:
`timescale 1ns / 1ps
module COUNTER_UND(RST_TIMER, CLK_50M, SEVEN_SEG, AN0, AN1, AN2, AN3, OK_UND);
input RST_TIMER;
input CLK_50M;
input OK_UND;
output [6:0] SEVEN_SEG;
output AN0;
output AN1;
output AN2;
output AN3;
reg [3:0] COUNT;
reg CLK_1HZ= 1'b0;
reg [24:0] COUNTER_50M;
parameter COUNT_50M = 25000000;
DECODER d1 (.COUNT(COUNT),.SEVEN_SEG(SEVEN_SEG));
always @(posedge CLK_50M or posedge RST_TIMER)
begin
if (RST_TIMER)
begin
COUNTER_50M <= 0;
CLK_1HZ <= 1'b0;
end
else
if (COUNTER_50M == COUNT_50M)
begin
COUNTER_50M <= 0;
CLK_1HZ <= !CLK_1HZ;
end
else
COUNTER_50M <= COUNTER_50M + 1;
end
//count 0..9
always @(posedge CLK_1HZ or posedge RST_TIMER)
begin
if (RST_TIMER)
COUNT <= 4'b000;
else
if (OK_UND)
begin
if (COUNT == 4'b1001) //9
COUNT <= 4'b000;
else
COUNT <= COUNT + 1;
end
end
assign AN0 = 1'b0; //anodo 0 ON
assign AN1 = 1'b1; //anodo 1 ON
assign AN2 = 1'b1; //anodo 2 ON
assign AN3 = 1'b1; //anodo 3 OFF
endmodule
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
DECODER:
module DECODER(COUNT, SEVEN_SEG);
input [3:0] COUNT;
output [6:0] SEVEN_SEG;
reg [6:0] SEVEN_SEG;
parameter zero = 7'b100_0000;
parameter um = 7'b111_1001;
parameter dois = 7'b010_0100;
parameter tres = 7'b011_0000;
parameter quatro = 7'b001_1001;
parameter cinco = 7'b001_0010;
parameter seis = 7'b000_0010;
parameter sete = 7'b111_1000;
parameter oito = 7'b000_0000;
parameter nove = 7'b001_0000;
parameter def = 7'b100_0000;
always @ (COUNT)
case (COUNT)
0: SEVEN_SEG = zero;
1: SEVEN_SEG = um;
2: SEVEN_SEG = dois;
3: SEVEN_SEG = tres;
4: SEVEN_SEG = quatro;
5: SEVEN_SEG = cinco;
6: SEVEN_SEG = seis;
7: SEVEN_SEG = sete;
8: SEVEN_SEG = oito;
9: SEVEN_SEG = nove;
default SEVEN_SEG = def;
endcase
endmodule
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
When I press the OK_UND button on the BASYS the counter increments and stop when button off.
The idea is make a programmable timer 0 .. 999. programming the 3 digit separately. For that need to add two counters 0 .. 9 on other two displays.
Another question: after the timer programmed in the 3 digit and how sending this value to a counter to count down to zero?
Thanks for any help you can give me
I need help to develop three BCD counters 0 .. 9 on 3 independent displays on board BASYS. For a one counter could do. The code is as follows:
------------------------------------------------------------------------------------------------------------------------------------------------------------
COUNTER:
`timescale 1ns / 1ps
module COUNTER_UND(RST_TIMER, CLK_50M, SEVEN_SEG, AN0, AN1, AN2, AN3, OK_UND);
input RST_TIMER;
input CLK_50M;
input OK_UND;
output [6:0] SEVEN_SEG;
output AN0;
output AN1;
output AN2;
output AN3;
reg [3:0] COUNT;
reg CLK_1HZ= 1'b0;
reg [24:0] COUNTER_50M;
parameter COUNT_50M = 25000000;
DECODER d1 (.COUNT(COUNT),.SEVEN_SEG(SEVEN_SEG));
always @(posedge CLK_50M or posedge RST_TIMER)
begin
if (RST_TIMER)
begin
COUNTER_50M <= 0;
CLK_1HZ <= 1'b0;
end
else
if (COUNTER_50M == COUNT_50M)
begin
COUNTER_50M <= 0;
CLK_1HZ <= !CLK_1HZ;
end
else
COUNTER_50M <= COUNTER_50M + 1;
end
//count 0..9
always @(posedge CLK_1HZ or posedge RST_TIMER)
begin
if (RST_TIMER)
COUNT <= 4'b000;
else
if (OK_UND)
begin
if (COUNT == 4'b1001) //9
COUNT <= 4'b000;
else
COUNT <= COUNT + 1;
end
end
assign AN0 = 1'b0; //anodo 0 ON
assign AN1 = 1'b1; //anodo 1 ON
assign AN2 = 1'b1; //anodo 2 ON
assign AN3 = 1'b1; //anodo 3 OFF
endmodule
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
DECODER:
module DECODER(COUNT, SEVEN_SEG);
input [3:0] COUNT;
output [6:0] SEVEN_SEG;
reg [6:0] SEVEN_SEG;
parameter zero = 7'b100_0000;
parameter um = 7'b111_1001;
parameter dois = 7'b010_0100;
parameter tres = 7'b011_0000;
parameter quatro = 7'b001_1001;
parameter cinco = 7'b001_0010;
parameter seis = 7'b000_0010;
parameter sete = 7'b111_1000;
parameter oito = 7'b000_0000;
parameter nove = 7'b001_0000;
parameter def = 7'b100_0000;
always @ (COUNT)
case (COUNT)
0: SEVEN_SEG = zero;
1: SEVEN_SEG = um;
2: SEVEN_SEG = dois;
3: SEVEN_SEG = tres;
4: SEVEN_SEG = quatro;
5: SEVEN_SEG = cinco;
6: SEVEN_SEG = seis;
7: SEVEN_SEG = sete;
8: SEVEN_SEG = oito;
9: SEVEN_SEG = nove;
default SEVEN_SEG = def;
endcase
endmodule
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
When I press the OK_UND button on the BASYS the counter increments and stop when button off.
The idea is make a programmable timer 0 .. 999. programming the 3 digit separately. For that need to add two counters 0 .. 9 on other two displays.
Another question: after the timer programmed in the 3 digit and how sending this value to a counter to count down to zero?
Thanks for any help you can give me