[SOLVED] reduce clock cycle and use it in another block

Status
Not open for further replies.

muzammil007

Newbie level 5
Joined
Jul 22, 2013
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
93
Hey Guyz,

I am a newbie in the world of FPGA and HDL. I am using verilog as my HDL to code.
I am facing a problem. I am using a clock of 50 Mhz in my design and using clock divider I am reducing my clock to 1Hz.
Now the problem is want to connect this 1Hz output to my counter which I have designed( it counts from 00 to FF) and then I have
a hex to seven segment decoder which takes this count and displays it in seven segment.
How do I connect all these three blocks i.e. clock divider, counter and decoder so that my seven segment can display from 00 to ff.
If anybody needs the code, I can provide it if somebody can help me with the code.

Regards
Maxx
 


1/ you need to refer to your building blocks as modules.
2/ the way to connect your moduels is by instantiating them in a top module.
3/ basically you just need to google for it.
4/ a link for example is :
https://www.asic-world.com/verilog/syntax2.html
 

Couple of keywords you can use to google and to search edaboard for this subject:

"verilog clock divider"
"dcm clock divider"
"divider clock enables"
"counter clock enables"

And no I am not kidding, the above are reasonable search terms. If that answer is too short, blame the 34876234 "hay I am new to HDL gimme clue & free code plz kthxbye" one-post posters that came before you.
 

@mrflibble:
I have already done my coding for clock divider and was successful in generating 1hz clock, so I don't need a code. All I am asking is some source or some guide which can help me connect my three blocks so that I can see my output on seven segment. If you read my question carefully it clearly says "If anybody needs the code, I can provide it if somebody can help me with the code." It means I have already coded my program. All i need is your help connecting them.
Hope you understood
@aruipksni: thanks for your reply. I looked at it and got the idea.
But still I am not getting the thing I want. Can I PM you my code ?

Regards
maxx
 

My bad, you are right. I am blind.

In which case, post your full code so far. If you do, see this:

If all you need is connect your modules together, see that link aruipksni posted: https://www.asic-world.com/verilog/syntax2.html

Specifically the part "Modules connected by name". That should explain how to connect things.
 


Thanks for the reply bro!! I am posting my code with this message.
One more doubt, I declared one of my output as wire but that output is not been shown when I am simulating my code.
Do you have any idea like what could be the reason ?
Here goes the code :

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module clock_divide(clk_out,clk_50);
input clk_50;
output clk_out;
reg[24:0] count; // to count 25 million you need 25 bit counter
reg clk_out;
parameter TC=25'd25000000-25'd1;
 
initial begin
count=0;
clk_out=0;
end
always @(posedge clk_50)
begin
if (count==0)begin
count <=TC;
clk_out <=~clk_out;
end
else
count<=count-1'b1;
end
endmodule
  
//module up_counter( out, enable , clk, reset     );
 
 
 output [7:0] out;
input enable, reset, clk;
reg [7:0] out;
//-------------Code Starts Here-------
always @(posedge clk)
if (reset) begin
  out <= 8'h0 ;
end else if (enable) begin
  out <= out + 1;
end
endmodule 
 
// hex to seven segment decoder
 
module hexadecimalcounter(hex_1, hex_0, hex_num);
input [3:0] hex_num;
output[6:0] hex_1;
output[6:0] hex_0;
reg [6:0] hex_1;
reg [6:0] hex_0;
always @(hex_num)  
begin
  case (hex_num)
     4'h0: {hex_1, hex_0} = {7'b1111111, 7'b1000000};  // 7-seg for 0
     4'h1: {hex_1, hex_0} = {7'b1111111, 7'b1111001} ; // 7-seg for 1
     4'h2: {hex_1, hex_0} = {7'b1111111, 7'b0100100} ; // 7-seg for 2
         4'h3: {hex_1, hex_0} = {7'b1111111, 7'b0110000} ; // 7-seg for 3
         4'h4: {hex_1, hex_0} = {7'b1111111, 7'b0011001} ; // 7-seg for 4
     4'h5: {hex_1, hex_0} = {7'b1111111, 7'b0010010} ; // 7-seg for 5
     4'h6: {hex_1, hex_0} = {7'b1111111, 7'b0000010} ; // 7-seg for 6
     4'h7: {hex_1, hex_0} = {7'b1111111, 7'b1111000} ; // 7-seg for 7
     4'h8: {hex_1, hex_0} = {7'b1111111, 7'b0000000} ; // 7-seg for 8
     4'h9: {hex_1, hex_0} = {7'b1111111, 7'b0011000} ; // 7-seg for 9
     4'ha: {hex_1, hex_0} = {7'b1111001, 7'b1000000} ; // 7-seg for A
     4'hb: {hex_1, hex_0} = {7'b1111001, 7'b1111001} ; // 7-seg for B
     4'hc: {hex_1, hex_0} = {7'b1111001, 7'b0100100} ; // 7-seg for C
     4'hd: {hex_1, hex_0} = {7'b1111001, 7'b0110000} ; // 7-seg for D
     4'he: {hex_1, hex_0} = {7'b1111001, 7'b0011001} ; // 7-seg for E
     4'hf: {hex_1, hex_0} = {7'b1111001, 7'b0010010} ; // 7-seg for F
  default: {hex_1, hex_0} = {7'b1111001, 7'b1111111} ; // 7-segment code for blank
  endcase   
  end  
  endmodule
 
// top level module counter_hexa
module counter_hexa( enable, clk_50, reset, hex_1, hex_0, clk_out);
input enable, clk_50, reset;
output [7:0] hex_1, hex_0;
output wire clk_out;
 
wire [7:0] out;
 
clock_divide ch_cd(clk_out,clk_50);
up_counter  ch_upc(clk_out, reset, enable, out);
hexadecimalcounter ch_hxdc(out, hex_1, hex_0);
endmodule
 
Here is the code. Hope to hear from you soon.
 
[COLOR="silver"][SIZE=1]- - - Updated - - -[/SIZE][/COLOR]
 
sorry, there is a slight change in up counter module, i commented it out...so here is the new code
 
module up_counter( out, enable , clk, reset );
output [7:0] out;
input enable, reset, clk;
reg [7:0] out;
//-------------Code Starts Here-------
always @(posedge clk)
if (reset) begin
out <= 8'h0 ;
end else if (enable) begin
out <= out + 1;
end
endmodule

 

Hey guys,

I am waiting for your reply. Did any body found any errors in the above code ? I am designing this counter to make a 00 to FF counter and displaying this in seven segment on my board?
Hope to hear soon

Regards
Maxx
 

your port mapping is incorrect.
try "Modules connected by name" as you were advised.
 

should be up_counter ch_upc(out,enable ,clock_out ,reset)

no..what i am trying to do so is that i have my output clk_out, which is actually a slow clock, in order to see my counter counting from 00 to FF. So i have designed these three modules. The output of clock_divide will serve as clock input to my counter block.

- - - Updated - - -

your port mapping is incorrect.
try "Modules connected by name" as you were advised.

I did it as you advised but still i am unable to see any output.
Should i forward you the code again ?
 


1. mappings :
clock_divide ch_cd(clk_out,clk_50);
up_counter ch_upc(out,enable ,clk_out ,reset);
hexadecimalcounter ch_hxdc(hex_1, hex_0, out);

2. use correct vector size :
module hexadecimalcounter(hex_1, hex_0, hex_num);
input [3:0] hex_num;
output[7:0] hex_1;
output[7:0] hex_0;
reg [7:0] hex_1;
reg [7:0] hex_0;

also in top :
wire [3:0] out;

3. add init , keep size correct :

module up_counter( out, enable , clk, reset );
output [3:0] out;
input enable, reset, clk;
reg [3:0] out;
//-------------Code Starts Here-------
initial begin
out=4'h0;
end
always @(posedge clk)
if (reset) begin
out <= 4'h0 ;
end else if (enable) begin
out <= out + 1;
end
endmodule

 



Thanks...it worked after some trial and error...thanks a lot
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…