module core_v(clk,ld,d0, q0,d1,d2,q1,q2,a,b,z,sel,d,q,d3,q3,d4,q4 );
input clk;
input ld;
reg [3:0] q0;
reg [3:0] q1;
reg [3:0] q2;
reg [3:0] z;
//add r0
core_v core_vr0 ( d0, q0);
input [3:0] d0;
output q0;
always @(posedge clk)
begin
if (ld==1) q0 <= d0;
end
// add r1
core_v core_vr1 ( d1, q1);
input d1;
output q1;
always @(posedge clk)
begin
if (ld==1) q1 <= d1;
end
//add r2
core_v core_vr2_i ( d2, q2);
input d2;
output q2;
always @(posedge clk)
begin
if (ld==1) q2 <= d2;
end
// add acc
core_v core_vacc( d, q);
input d;
output q;
reg [3:0] q;
always @(posedge clk)
begin
if (ld==1) q <= d;
end
//add temacc
core_v core_tempacc(d3,q3 );
input d3;
output q3;
always @(posedge clk)
begin
if (ld==1) q <= d;
end
// add accreg
core_v core_tempreg(clk, ld, d4, q4);
input d4;
output q4;
always @(posedge clk)
begin
if (ld==1) q4 <= d4;
end
//add alu
core_v core_alu (z,a,b,sel);
input a, b;
input sel;
output z;
always@(sel,a,b)
begin
case(sel)
4'b0000: z=a+b;
4'b0001: z=a-b;
4'b0010: z=b-1;
4'b0011: z=a*b;
4'b0100: z=a&&b;
4'b0101: z=a||b;
4'b0110: z=!a;
4'b0111: z=~a;
4'b1000: z=a&b;
4'b1001: z=a|b;
4'b1010: z=a^b;
4'b1011: z=a<<1;
4'b1100: z=a>>1;
4'b1101: z=a+1;
4'b1110: z=a-1;
endcase
end
endmodule
It would really help if you would declare your ports using the syntax added by Verilog-2001. It is 2014 after all.
How did you declare "q4".
I saw this link but when I compile this code I am getting errorI don't want to retype what is easily found on the web already, so here is a link that shows how to write a module that instantiates other modules.
As for the diagram, you as the designer will have to decide how you want to divide up the functionality. If it is a small amount of code, you might just write all of it in the main module and dispense with sub-modules. Or make the register block a sub-module and write the rest directly in the main module. Or any other way you feel is useful to you.
r.b.
module adder_implicit (
result , // Output of the adder
carry , // Carry output of adder
r1 , // first input
r2 , // second input
ci // carry input
);
// Input Port Declarations
input [3:0] r1 ;
input [3:0] r2 ;
input ci ;
// Output Port Declarations
output [3:0] result ;
output carry ;
// Port Wires
wire [3:0] r1 ;
wire [3:0] r2 ;
wire ci ;
wire [3:0] result ;
wire carry ;
// Internal variables
wire c1 ;
wire c2 ;
wire c3 ;
// Code Starts Here
addbit u0(
r1[0] ,
r2[0] ,
ci ,
result[0] ,
c1
);
endmodule
module adder_implicit (
result , // Output of the adder
carry , // Carry output of adder
r1 , // first input
r2 , // second input
ci // carry input
);
// Input Port Declarations
input [3:0] r1 ;
input [3:0] r2 ;
input ci ;
// Output Port Declarations
output [3:0] result ;
output carry ;
// Port Wires
wire [3:0] r1 ;
wire [3:0] r2 ;
wire ci ;
wire [3:0] result ;
wire carry ;
// Internal variables
wire c1 ;
wire c2 ;
wire c3 ;
// Code Starts Here
adder_implicit u0(
r1[0] ,
r2[0] ,
ci ,
result[0] ,
c1
);
endmodule
ok I have rewrite code again but still I a getting errorThe error comes because you are instantiating the adder_implicit module inside itself, giving infinite recursion.
module adder_implicit (
result , // Output of the adder
carry , // Carry output of adder
r1 , // first input
r2 , // second input
ci // carry input
);
// Input Port Declarations
input [3:0] r1 ;
input [3:0] r2 ;
input ci ;
// Output Port Declarations
output [3:0] result ;
output carry ;
// Port Wires
wire [3:0] r1 ;
wire [3:0] r2 ;
wire ci ;
wire [3:0] result ;
wire carry ;
// Internal variables
wire c1 ;
wire c2 ;
wire c3 ;
// Code Starts Here
u0(
r1[0] ,
r2[0] ,
ci ,
result[0] ,
c1
);
endmodule
Info: *******************************************************************
Info: Running Quartus II Analysis & Synthesis
Info: Version 9.0 Build 132 02/25/2009 SJ Web Edition
Info: Processing started: Thu Sep 25 03:16:35 2014
Info: Command: quartus_map --read_settings_files=on --write_settings_files=off basic -c basic
Info: Found 1 design units, including 1 entities, in source file core_v.v
Info: Found entity 1: core_v
Info: Found 1 design units, including 1 entities, in source file basic.v
Info: Found entity 1: basic
Info: Found 1 design units, including 1 entities, in source file adder_implicit.v
Info: Found entity 1: adder_implicit
Warning (10227): Verilog HDL Port Declaration warning at core_v.v(24): data type declaration for "q1" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at core_v.v(23): "q1" is declared here
Warning (10227): Verilog HDL Port Declaration warning at core_v.v(13): data type declaration for "q0" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at core_v.v(12): "q0" is declared here
Warning (10227): Verilog HDL Port Declaration warning at core_v.v(34): data type declaration for "q2" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at core_v.v(33): "q2" is declared here
Warning (10227): Verilog HDL Port Declaration warning at core_v.v(45): data type declaration for "q" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at core_v.v(44): "q" is declared here
Warning (10227): Verilog HDL Port Declaration warning at core_v.v(55): data type declaration for "q3" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at core_v.v(54): "q3" is declared here
Warning (10227): Verilog HDL Port Declaration warning at core_v.v(65): data type declaration for "q4" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at core_v.v(64): "q4" is declared here
Warning (10227): Verilog HDL Port Declaration warning at basic.v(24): data type declaration for "q1" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at basic.v(23): "q1" is declared here
Warning (10227): Verilog HDL Port Declaration warning at basic.v(13): data type declaration for "q0" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at basic.v(12): "q0" is declared here
Warning (10227): Verilog HDL Port Declaration warning at basic.v(34): data type declaration for "q2" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at basic.v(33): "q2" is declared here
Warning (10227): Verilog HDL Port Declaration warning at basic.v(45): data type declaration for "q" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at basic.v(44): "q" is declared here
Warning (10227): Verilog HDL Port Declaration warning at basic.v(55): data type declaration for "q3" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at basic.v(54): "q3" is declared here
Warning (10227): Verilog HDL Port Declaration warning at basic.v(65): data type declaration for "q4" declares packed dimensions but the port declaration declaration does not
Info (10151): Verilog HDL Declaration information at basic.v(64): "q4" is declared here
Critical Warning (10846): Verilog HDL Instantiation warning at adder_implicit.v(40): instance has no name
Info: Elaborating entity "adder_implicit" for the top level hierarchy
Warning (10034): Output port "result[3]" at adder_implicit.v(18) has no driver
Warning (10034): Output port "result[2]" at adder_implicit.v(18) has no driver
Warning (10034): Output port "result[1]" at adder_implicit.v(18) has no driver
Warning (10034): Output port "carry" at adder_implicit.v(19) has no driver
Error: Node instance "comb_4" instantiates undefined entity "u0"
Error: Quartus II Analysis & Synthesis was unsuccessful. 1 error, 17 warnings
Error: Peak virtual memory: 232 megabytes
Error: Processing ended: Thu Sep 25 03:16:39 2014
Error: Elapsed time: 00:00:04
Error: Total CPU time (on all processors): 00:00:03
Error: Quartus II Full Compilation was unsuccessful. 3 errors, 17 warnings
module blah (
input wire a,
input wire b,
output wire c
);
assign c = a | b;
endmodule
You are still not getting it. What is u0 supposed to do be doing?
Unfortunately, that website I pointed you to does not show the best example of writing a module. I should have looked closer.
Here is a super simple Verilog module:
Code:module blah ( input wire a, input wire b, output wire c ); assign c = a | b; endmodule
You do not need to instantiate a module inside itself as you have been trying to do.
r.b.
// Code Starts Here
u0(
r1[0] ,
r2[0] ,
ci ,
result[0] ,
c1
);
// Code Starts Here
u0(
r1[0] ,
r2[0] ,
ci ,
result[0] ,
c1
);
// Code Starts Here
[B][I][COLOR="#FF0000"]addbit[/COLOR][/I][/B] u0(
r1[0] ,
r2[0] ,
ci ,
result[0] ,
c1
);
module register (clk, ld, d0,d1,d2,q0,q1,q2);
input clk;
input ld;
// Input Port Declarations
input [3:0] d0 ;
input [3:0] d1 ;
input [3:0] d2 ;
// Output Port Declarations
output [3:0] q0;
output [3:0] q1;
output [3:0] q2;
// ports wire
wire [3:0] c0;
wire [3:0] c1;
wire [3:0] c2;
reg [3:0]q0;
always @(posedge clk)
begin
if (ld==1) q0 <= d0;
end
reg [3:0]q1;
always @(posedge clk)
begin
if (ld==1) q1 <= d1;
end
reg [3:0]q2;
always @(posedge clk)
begin
if (ld==1) q2 <= d2;
end
register r0 (clk,ld,d0,q0,so);
register r1 ( clk,ld,d1, q1,s1);
register r2 ( clk, ld,d2, q2,s2);
endmodule
endmodule
module register (clk, ld, d0,d1,d2,q0,q1,q2);
input clk;
input ld;
// Input Port Declarations ---- ads-ee useless comment not even worth typing this
input [3:0] d0 ;
input [3:0] d1 ;
input [3:0] d2 ;
// Output Port Declarations ---- ads-ee useless comment not even worth typing this
output [3:0] q0;
output [3:0] q1;
output [3:0] q2;
module register (
input clk,
// common D-FF load signal, active high
input ld,
// D-FF inputs
input [3:0] d0,
input [3:0] d1,
input [3:0] d2,
// D-FF outputs
output reg [3:0] q0,
output reg [3:0] q1,
output reg [3:0] q2
);
// ports wire
wire [3:0] c0;
wire [3:0] c1;
wire [3:0] c2;
reg [3:0]q0;
always @(posedge clk)
begin
if (ld==1) q0 <= d0;
end
reg [3:0]q1;
always @(posedge clk)
begin
if (ld==1) q1 <= d1;
end
reg [3:0]q2;
always @(posedge clk)
begin
if (ld==1) q2 <= d2;
end
always @(posedge clk) begin
if (ld) q0 <= d0;
end
always @(posedge clk) begin
if (ld) q1 <= d1;
end
always @(posedge clk) begin
if (ld) q2 <= d2;
end
module [COLOR="#FF0000"]register[/COLOR] (clk, ld, d0,d1,d2,q0,q1,q2);
//...
[COLOR="#FF0000"]register[/COLOR] r0 (clk,ld,d0,q0,so);
[COLOR="#FF0000"]register[/COLOR] r1 ( clk,ld,d1, q1,s1);
[COLOR="#FF0000"]register[/COLOR] r2 ( clk, ld,d2, q2,s2);
endmodule
endmodule
Code Verilog - [expand] 1 2 3 4 5 6 7 tags to post code. It will give people readable line numbers. - Post code with proper indentation. If you want people to read your code, make it readable. - Post your entire code. That way line numbers in errors you post will actually make sense. - Post full error messages. - Read a book on verilog, or [url=https://bit.ly/1msLUp5]read the LRM[/url]. At least 5 of the 6 apply to you. Spot the one you could possibly get out of.
when I don't use instantiating the module then I get more errorYou are also still instantiating the module register inside the module register. rberek has told you multiple times that you can't do that. If you don't take the advice from forum members that do this stuff professionally then why bother asking any questions?
module core_v(A,B,Cin,S,Cout);
input A, B, Cin;
output S, Cout;
wire S1, C1, C2;
(A, B, S1, C1);
(S1, Cin, S, Cout);
(Cout, C1, C2);
endmodule
Error: Quartus II Analysis & Synthesis was unsuccessful. 9 errors, 0 warnings
Error: Peak virtual memory: 230 megabytes
Error: Processing ended: Thu Sep 25 10:36:30 2014
Error: Elapsed time: 00:00:05
Error: Total CPU time (on all processors): 00:00:03
Code Verilog - [expand] 1 2 3 4 5 6 7 tags to post code. It will give people readable line numbers. And for bonus points it gives you syntax highlighting, making things even easier to read. How? See second post: And tapdancing Messiah in-the-act-of-procreation, post the relevant error message, not the summary.
when I don't use instantiating the module then I get more error
as you said i write code without instantiating the module but tell me why I am getting error
Code:module core_v(A,B,Cin,S,Cout); input A, B, Cin; output S, Cout; wire S1, C1, C2; (A, B, S1, C1); (S1, Cin, S, Cout); (Cout, C1, C2); endmodule
error
Code:Error: Quartus II Analysis & Synthesis was unsuccessful. 9 errors, 0 warnings Error: Peak virtual memory: 230 megabytes Error: Processing ended: Thu Sep 25 10:36:30 2014 Error: Elapsed time: 00:00:05 Error: Total CPU time (on all processors): 00:00:03
module core_v (clk, ld, d0,q0);
// Input Port Declarations
input clk;
input ld;
input [3:0] d0 ;
wire [3:0] c0;
// Output Port Declarations
output [3:0] q0;
reg [3:0]q0;
always @(posedge clk)
begin
if (ld==1) q0 <= d0;
end
endmodule
module registerr1(clk,ld,d1,q1);
input [3:0] d1 ,clk,ld;
output [3:0] q1;
wire [3:0] c1;
reg [3:0]q1;
always @(posedge clk)
begin
if (ld==1) q1 <= d1;
end
endmodule
module register2 (clk,ld,d2,q2);
input [3:0] d2,clk,ld ;
output [3:0] q2;
wire [3:0] c2;
reg [3:0]q2;
always @(posedge clk)
begin
if (ld==1) q2 <= d2;
end
core_v r0 (clk,ld,d0,q0,s0);
core_v r1 (clk,ld,d1q1,s1);
core_v r2 (clk,ld,d2,d2,s2);
endmodule
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?