Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Verilog - Programmable 3 digit Timer - Xilinx - Basys2 -[Help needed]

Status
Not open for further replies.

charlie73

Newbie level 1
Joined
Aug 28, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
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 posted a 3-digit BCD counter code in this thread:
https://www.edaboard.com/threads/262991/
Although it's for a Spartan-3e kit, it might help you in coding. And try commenting your code as it helps others analyze it.

Regards...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top