[SOLVED] Verilog: Design counter using adders

Status
Not open for further replies.

akipro

Newbie level 6
Joined
Mar 14, 2013
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,361
The following is one simple 4 bit up counter verilog code I made using a 4 bit adder verilog code ( a working file , tested). I happens that when I include the adder instantiation the clock stops working and hence entire code stops working. Any suggestions of what possibly went wrong????


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
module four_bit_counter(
 
output reg [3:0] a
);
 reg clock ;
 reg [3:0] temp;   // wire [3:0] temp;
 initial
 begin
    a = 4'b0000;
    clock =0 ;
    temp = 4'b0000;  // remove this
 end
 
 four_bit_adder add(.a(temp), .b(4'b0001), .s(a));  // four_bit_adder add(.a(a), .b(4'b0001), .s(temp)); [ Ensure o/p of adder is of type wire ]
 
 always  begin 
    #10 clock = ~clock;
 end
 
 always @(posedge clock) 
    begin 
        assign temp = a;  //   a<=temp;
    end
endmodule

 
Last edited:

Also note that you cannot use assign in an always block. When you use an assign statement, it is a continuous assignment and thus cannot be further defined by saying assign only on posedge clock.

r.b.
 

Found the problem, I was not thinking of it as hardware, but as a normal C problem with variables. Instead thought of the hardware first and then made its verilog code. Am commenting the changes made which made it work.

- - - Updated - - -

Indeed. Ditch the assign and the =, and use <= instead.

What is he differnece b/w " = " and " <= " ???
 

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