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.

Why functions\procedures in VHDL does not support sequential clock based arguments?

Status
Not open for further replies.

xtcx

Advanced Member level 1
Joined
Dec 22, 2007
Messages
493
Helped
65
Reputation
130
Reaction score
58
Trophy points
1,308
Location
Bangalore, India
Activity points
5,003
Hi, I've been having this doubt for a long time, but just thought of asking out. I've been using functions\procedures so far only for combo circuits such as complex adder\mult, muxer, etc. However I've always wondered why not use clock based seq logics, by passing in the arguments, but compiler throws error, so left it. (Sorry, if this is given in any text books, I never read much books fully in that case :-D

1) Why edge functions cannot be used inside function\procedure body?.
2) Is it VHDL limitations?, then how about verilog?
3) Is it not a good to be practiced?.
4) Can it atleast be used for simulation purpose?.

Please share your thoughts to clarify my doubt

Thanks.
 

Hi, I've been having this doubt for a long time, but just thought of asking out. I've been using functions\procedures so far only for combo circuits such as complex adder\mult, muxer, etc. However I've always wondered why not use clock based seq logics, by passing in the arguments, but compiler throws error, so left it. (Sorry, if this is given in any text books, I never read much books fully in that case :-D

1) Why edge functions cannot be used inside function\procedure body?.
2) Is it VHDL limitations?, then how about verilog?
3) Is it not a good to be practiced?.
4) Can it atleast be used for simulation purpose?.

Please share your thoughts to clarify my doubt

You're correct that functions cannot be procedural (i.e. have any form of 'wait' statements). You're not correct when you lump procedures into that group, they most certainly can.

Functions and procedures accomplish different things:
- Functions return only one thing; procedures can output as many things as you'd like
- Functions cannot 'wait'; procedures can
- The parameters to a function are always inputs; parameters for a procedure can be in/out/inout as you see fit.
- Functions and procedures can be freely used either as part of a standalone concurrent statement or within a process.

Since your doubts seem to be based on some incorrect expectations, perhaps it would be better for you to post some code that you think demonstrate the issue that you see for others to comment.

Kevin Jennings
 
  • Like
Reactions: xtcx

    xtcx

    Points: 2
    Helpful Answer Positive Rating
You're correct that functions cannot be procedural (i.e. have any form of 'wait' statements). You're not correct when you lump procedures into that group, they most certainly can.

Functions and procedures accomplish different things:
- Functions return only one thing; procedures can output as many things as you'd like
- Functions cannot 'wait'; procedures can
- The parameters to a function are always inputs; parameters for a procedure can be in/out/inout as you see fit.
- Functions and procedures can be freely used either as part of a standalone concurrent statement or within a process.

Since your doubts seem to be based on some incorrect expectations, perhaps it would be better for you to post some code that you think demonstrate the issue that you see for others to comment.

Kevin Jennings

Thanks. See I am aware of the usage or functions too. But this is not related to coding perspective. This is only a doubt about VHDL language. Are sequential statements\execution based on edge detect functions like (clk'event\falling_edge) are usually allowed inside procedure body or not?.

May be
eg.,
Code:
procedure dff( D : in std_logic;
                    Q : out std_logic;
                     C : in std_logic);
is
begin
if rising_edge(c) then
Q <= D;
end if;
end procedure;

in main code,
Code:
use xxx.work.all -- pack incl

entity dff_t is

port ( clock : in std_logic;
Q_op : out std_logic);
end diff_t;

archi.....

begin
process (clock)
begin

dff('1',Q_op,clock);
dff('0',Q_op,clock);

end process;

Consider i've declared the procedure in pack and included above. Is this type declaration (rising_edge) allowed inside procedure?. Pls ignore the meaning of the code, I am keen at syntax and VHDL support
 

rising_edge is just a function. It detects whether there as been a rising_edge on C at the given point in time.

There is a problem with the procedure though, is that by deafault, inputs are constant unless specified otherwise. The rising_edge function only works on signals. So thats why the code wont compile. If you decalre C as an input signal, then it will work fine.
 
  • Like
Reactions: xtcx

    xtcx

    Points: 2
    Helpful Answer Positive Rating
Okay, If I change to

Code:
dff(d_in,q_op,clock);

Should this procedure call work on every rising_edge of clock?

---------- Post added at 17:24 ---------- Previous post was at 17:23 ----------

Now all are signals rite...
 

no, I mean the procedure declaration has to declare C as a signal:

Code:
procedure dff(        D : in std_logic;
                      Q : out std_logic;
               signal C : in std_logic);
is
begin
  if rising_edge(c) then
    Q <= D;
  end if;
end procedure;
 
  • Like
Reactions: xtcx

    xtcx

    Points: 2
    Helpful Answer Positive Rating
Thanks a lot buddy....will use this approach from now on....for all sequential logics.
 

Thanks a lot buddy....will use this approach from now on....for all sequential logics.

Procedures are very useful in testbenches, but it is not easy to see what they will synthesize to. It can be something that is not optimal.
 
  • Like
Reactions: xtcx

    xtcx

    Points: 2
    Helpful Answer Positive Rating
yes, I understood. I am more looking to use for simulation only. Since writing bunch of codes again and again is so tiresome. Anyway thanks for the hint bro
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top