Can a function be synchronous?

Discussion in 'VHDL' started by cruzin, Nov 21, 2003.

  1. cruzin

    cruzin Guest

    Is it possible to make a function synchronous to the clock?

    I have written an arbitrary-size mux using a recursive function:

    function mux( ... )
    begin
    ...
    return ( mux(top_half), mux(bottom_half) );
    end mux;

    To improve synthesized performance, I want to register each level of
    the mux. Something like:

    function mux( clk, ... )
    begin
    ...
    wait until clk='1';
    return ( mux(top_half), mux(bottom_half) );
    end mux;

    I realize I can not use wait in a function.

    Are functions always meant to complete in zero-time? Is my only
    recourse to write the synchronous mux using a recursive component
    model?
     
    cruzin, Nov 21, 2003
    #1
    1. Advertising

  2. cruzin

    Jim Lewis Guest

    You are correct you cannot use wait in a function.

    If you want to create a register in either a function
    or procedure, I recommend using rising_edge:

    architecture RTL of Shift4x1 is -- 4 Stage Shift Reg
    procedure FF(
    signal Clk : in Std_Logic ;
    nReset : in Std_Logic ;
    D : in Std_Logic ;
    signal Q : out Std_Logic
    ) is
    begin
    if nReset='0' then
    Q <= '0';
    elsif Rising_Edge(Clk) then
    Q <= D;
    end if;
    end FF;
    -- Clk, nReset, D, Q are ports of std_logic
    signal Reg1, Reg2, Reg3 ;
    begin
    FF(Clk, nReset, D, Reg1);
    FF(Clk, nReset, Reg1, Reg2);
    FF(Clk, nReset, Reg3, Q);
    end RTL ;


    Currently this may not be synthesizable in all
    tools, but it should be in the future as it is
    called for in 1076.6-200X.


    Obviously this does not solve your recursion problem.
    I cannot see a way to handle it with a procedure as
    you would need to be able to create a signal to hold
    intermediate values. As a result, I think your
    only alternative is to have some fun with an entity
    with a generic and generate.


    This is not the way I would solve your problem though.
    First to give the synthesis tool good control of
    a multiplexer chain, I prefer to use and-or logic.
    And-Or at the first level, and then it becomes OR
    at the upper levels.

    Next, if I have a timing problem, I would plan on
    using the pipeline retiming capability of the
    synthesis tool. Basically code N registers in
    sequence after the multiplexer and allow the synthesis
    tool to move them around as it sees fit.

    This will also allow you to tune the number of
    registers you need based on your timing, rather than
    having a register following each multiplexer stage.

    Cheers,
    Jim
    --
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Jim Lewis
    Director of Training mailto:
    SynthWorks Design Inc. http://www.SynthWorks.com
    1-503-590-4787

    Expert VHDL Training for Hardware Design and Verification
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    cruzin wrote:
    > Is it possible to make a function synchronous to the clock?
    >
    > I have written an arbitrary-size mux using a recursive function:
    >
    > function mux( ... )
    > begin
    > ...
    > return ( mux(top_half), mux(bottom_half) );
    > end mux;
    >
    > To improve synthesized performance, I want to register each level of
    > the mux. Something like:
    >
    > function mux( clk, ... )
    > begin
    > ...
    > wait until clk='1';
    > return ( mux(top_half), mux(bottom_half) );
    > end mux;
    >
    > I realize I can not use wait in a function.
    >
    > Are functions always meant to complete in zero-time? Is my only
    > recourse to write the synchronous mux using a recursive component
    > model?
     
    Jim Lewis, Nov 21, 2003
    #2
    1. Advertising

  3. cruzin wrote:
    > Is it possible to make a function synchronous to the clock?


    No. A function is a value calculation.
    It is wires and gates, not flops.

    > To improve synthesized performance, I want to register each level of
    > the mux. Something like:
    >
    > function mux( clk, ... )
    > begin
    > ...
    > wait until clk='1';
    > return ( mux(top_half), mux(bottom_half) );
    > end mux;
    >
    > I realize I can not use wait in a function.



    The only wait you really need for
    synthesis is

    elsif rising_edge(clk) then

    Consider calling a procedure from inside
    a clocked process. Use a process variable
    to keep track of the mux state.

    -- Mike Treseler
     
    Mike Treseler, Nov 21, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas
    Replies:
    2
    Views:
    1,112
    Mario Trams
    Jul 6, 2003
  2. Pedro Claro

    bad synchronous

    Pedro Claro, Aug 18, 2003, in forum: VHDL
    Replies:
    1
    Views:
    1,658
    Mike Treseler
    Aug 18, 2003
  3. Valentin Tihomirov

    Are clock and divided clock synchronous?

    Valentin Tihomirov, Oct 23, 2003, in forum: VHDL
    Replies:
    11
    Views:
    3,392
    louis lin
    Oct 28, 2003
  4. GroupReader

    Can a ClientCallback be Synchronous?

    GroupReader, Oct 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    402
    GroupReader
    Oct 20, 2006
  5. Rickert
    Replies:
    0
    Views:
    718
    Rickert
    Oct 6, 2011
Loading...

Share This Page