FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-08-2006, 06:28 PM
Tadeu
Guest
 
Posts: n/a
Default Using Module on Module

///////////////////////////////////////////////////////////////////////////////
//Logical Unit
module UnidadeLogica(a, b, s, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;

assign f = Logica(a,b,s);

function[0:3] Logica;
input [0:3] a,b;
input [0:1] s;
case(s)
2'b00 : begin//AND
Logica = a & b;
end
2'b01 : begin//OR
Logica = a | b;
end
2'b10 : begin//XOR
Logica = a ^ b;
end
2'b11 : begin//XNOR
Logica = ~(a ^ b);
end
default: begin
Logica = 4'bz;
end
endcase
endfunction
endmodule
////////////
This works good. Now I intended to create a aritmetical unit but for
that I need a fullAdder4Bits created by me "FullAdderQuatro" then I
tried to do this:
///////////////////////////////////////////////////////////////////////////////
//Unidade Aritmética
module UnidadeAritmetica(a, b, s, cIn, cOut, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;
input cIn;
output cOut;

wire [0:4] result;

assign result = Aritmetica(a,b,s,cIn);
assign f = result[0:3];
assign cOut = result[4];

function[0:4] Aritmetica;
input [0:3] a,b;
input [0:1] s;
input cIn;
case(s)
2'b00 : begin//transfer a to output adding cIn
FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
end
2'b01 : begin
FullAdderQuatro fa4(cIn,a,b,Aritmetica[0:3],Aritmetica[4]);
end
default: begin
Aritmetica = 4'bz;
//$display("Operação não existe!");
end
endcase
endfunction
endmodule
//////////////
but I got this error:

and.v:145: parse error
and.v:145: error: malformed statement
and.v:148: parse error
and.v:148: error: malformed statement

where line 145 is FullAdderQuatro
fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);

what is the problem now?
tnkz

Reply With Quote
  #2 (permalink)  
Old 09-09-2006, 06:03 AM
mk
Guest
 
Posts: n/a
Default Re: Using Module on Module

On 8 Sep 2006 09:28:56 -0700, "Tadeu" <[email protected]> wrote:

>//Unidade Aritmética
>module UnidadeAritmetica(a, b, s, cIn, cOut, f);
>input [0:3] a,b;
>input [0:1] s;
>output [0:3] f;
>input cIn;
>output cOut;
>
>wire [0:4] result;
>
>assign result = Aritmetica(a,b,s,cIn);
>assign f = result[0:3];
>assign cOut = result[4];
>
>function[0:4] Aritmetica;
>input [0:3] a,b;
>input [0:1] s;
>input cIn;
>case(s)
> 2'b00 : begin//transfer a to output adding cIn
> FullAdderQuatro
>fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
> end
> 2'b01 : begin
> FullAdderQuatro fa4(cIn,a,b,Aritmetica[0:3],Aritmetica[4]);
> end
> default: begin
> Aritmetica = 4'bz;
> //$display("Operação não existe!");
> end
> endcase
>endfunction
>endmodule
>//////////////
>but I got this error:
>
>and.v:145: parse error
>and.v:145: error: malformed statement
>and.v:148: parse error
>and.v:148: error: malformed statement
>
>where line 145 is FullAdderQuatro
>fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
>
>what is the problem now?
>tnkz


You can not instantiate modules in fuctions.You should instantiate
FullAdderQuatro outside the function but inside the module
UnidadeAritmetica. Generate a vector bin which muxes 0 and b input of
the module and connect the FAQ outputs to f & cOut directly. Even if
you could instantiate FAQ in the function, you would get two copies of
it which is probably not what you want. Instantiate it once and put a
mux at the b input.

HTH.
Reply With Quote
  #3 (permalink)  
Old 09-09-2006, 07:04 PM
Tadeu
Guest
 
Posts: n/a
Default Re: Using Module on Module

mk escreveu:

> On 8 Sep 2006 09:28:56 -0700, "Tadeu" <[email protected]> wrote:
>
> >//Unidade Aritmética
> >module UnidadeAritmetica(a, b, s, cIn, cOut, f);
> >input [0:3] a,b;
> >input [0:1] s;
> >output [0:3] f;
> >input cIn;
> >output cOut;
> >
> >wire [0:4] result;
> >
> >assign result = Aritmetica(a,b,s,cIn);
> >assign f = result[0:3];
> >assign cOut = result[4];
> >
> >function[0:4] Aritmetica;
> >input [0:3] a,b;
> >input [0:1] s;
> >input cIn;
> >case(s)
> > 2'b00 : begin//transfer a to output adding cIn
> > FullAdderQuatro
> >fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
> > end
> > 2'b01 : begin
> > FullAdderQuatro fa4(cIn,a,b,Aritmetica[0:3],Aritmetica[4]);
> > end
> > default: begin
> > Aritmetica = 4'bz;
> > //$display("Operação não existe!");
> > end
> > endcase
> >endfunction
> >endmodule
> >//////////////
> >but I got this error:
> >
> >and.v:145: parse error
> >and.v:145: error: malformed statement
> >and.v:148: parse error
> >and.v:148: error: malformed statement
> >
> >where line 145 is FullAdderQuatro
> >fa4(cIn,a,4'b0000,Aritmetica[0:3],Aritmetica[4]);
> >
> >what is the problem now?
> >tnkz

>
> You can not instantiate modules in fuctions.You should instantiate
> FullAdderQuatro outside the function but inside the module
> UnidadeAritmetica. Generate a vector bin which muxes 0 and b input of
> the module and connect the FAQ outputs to f & cOut directly. Even if
> you could instantiate FAQ in the function, you would get two copies of
> it which is probably not what you want. Instantiate it once and put a
> mux at the b input.
>
> HTH.

thank you I solved the problem with your suggestion, I changed the
Aritmetica function so it only return the operators needed in
FullAdderQuatro()
here is the code I used:
module UnidadeAritmetica(a, b, s, cIn, cOut, f);
input [0:3] a,b;
input [0:1] s;
output [0:3] f;
input cIn;
output cOut;

wire [0:7] result;
wire [0:3] a1,b1;
assign result = Aritmetica(s);

assign a1 = result[0:3];
assign b1 = result[4:7];

FullAdderQuatro fa4_0(cIn,a1,b1,f,cOut);

function[0:7] Aritmetica;
input [0:1] s;
begin
case(s)
2'b00 : begin//transfer a to output adding cIn
assign Aritmetica = {a,4'b0000};
end
2'b01 : begin
assign Aritmetica = {a,b};
end
2'b10 : begin
assign Aritmetica = {a,~b};
end
2'b11 : begin
assign Aritmetica = {~a,b};
end
default: begin
Aritmetica = 4'bxxxx;
end
endcase
end

endfunction
endmodule

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
task and module Linh Hoang Verilog 2 06-27-2005 06:33 AM
module inside module problem. shragafr Verilog 2 05-24-2004 08:03 PM
Using a module inside another module Adam Preble Verilog 0 04-01-2004 06:38 AM
All Paths in RTL Module HDLDesigner Verilog 6 02-25-2004 12:02 PM
anybody can help me write a DCT module? walala Verilog 1 11-19-2003 05:48 PM


All times are GMT +1. The time now is 09:04 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved