conversion: natural -> time

Discussion in 'VHDL' started by Simone Winkler, Apr 1, 2004.

  1. Hello!

    I've got a simple question: I have to model a key with debounce. So I've got
    to assign a value of type natural to a time in milliseconds.
    My formular would be:

    bounce_wait = nr_of_bounces/bounce_frequ * 1 ms;

    I've got the code I did below, but it doesn't compile in the line where the
    natural-time conversion is done. Also my resolution setting of modelsim is
    ok - I'm using modelsim SE 5.5f.

    The critical line is:
    constant bounce_wait : time := nr_of_bounces/bounce_frequ * 1 ms;

    Can you help me?

    Thank you!!

    ____________________________________

    library ieee;
    use ieee.std_logic_1164.all;
    use work.basic_pkg.all;

    entity key is
    generic(
    bounce_frequ: natural;
    nr_of_bounces: natural);
    port(
    in_terminal: in std_logic;
    out_terminal: out std_logic;
    key_status: in key_action
    );
    end entity key;

    architecture behavioural of key is

    signal out_terminal_sig: std_logic;
    constant bounce_wait : time := nr_of_bounces/bounce_frequ * 1 ms;

    begin

    out_terminal <= '1' after bounce_wait when (in_terminal='1' and
    key_status=pressed) else out_terminal_sig <= 'Z';


    end architecture behavioural;
    Simone Winkler, Apr 1, 2004
    #1
    1. Advertising

  2. Simone Winkler

    Jim Lewis Guest

    Simone,
    I got it to compile. I did not find any issues with
    bounce_wait. I did need to fix the syntax of the
    assignment to out_terminal:

    out_terminal <=
    '1' after bounce_wait when (in_terminal='1' and key_status=pressed)
    else 'Z'; -- note removed: "out_terminal_sig <="

    If you still have problems with your constant, either upgrade
    to a newer version of the tool or perhaps try adding parentheses:
    constant bounce_wait : time := (nr_of_bounces/bounce_frequ) * 1 ms;
    ^ ^

    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
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



    Simone Winkler wrote:

    > Hello!
    >
    > I've got a simple question: I have to model a key with debounce. So I've got
    > to assign a value of type natural to a time in milliseconds.
    > My formular would be:
    >
    > bounce_wait = nr_of_bounces/bounce_frequ * 1 ms;
    >
    > I've got the code I did below, but it doesn't compile in the line where the
    > natural-time conversion is done. Also my resolution setting of modelsim is
    > ok - I'm using modelsim SE 5.5f.
    >
    > The critical line is:
    > constant bounce_wait : time := nr_of_bounces/bounce_frequ * 1 ms;
    >
    > Can you help me?
    >
    > Thank you!!
    >
    > ____________________________________
    >
    > library ieee;
    > use ieee.std_logic_1164.all;
    > use work.basic_pkg.all;
    >
    > entity key is
    > generic(
    > bounce_frequ: natural;
    > nr_of_bounces: natural);
    > port(
    > in_terminal: in std_logic;
    > out_terminal: out std_logic;
    > key_status: in key_action
    > );
    > end entity key;
    >
    > architecture behavioural of key is
    >
    > signal out_terminal_sig: std_logic;
    > constant bounce_wait : time := nr_of_bounces/bounce_frequ * 1 ms;
    >
    > begin
    >
    > out_terminal <= '1' after bounce_wait when (in_terminal='1' and
    > key_status=pressed) else out_terminal_sig <= 'Z';
    >
    >
    > end architecture behavioural;
    >
    >
    Jim Lewis, Apr 1, 2004
    #2
    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. magik
    Replies:
    4
    Views:
    9,123
    kunal.bandekar
    May 24, 2011
  2. Replies:
    10
    Views:
    14,906
  3. Aidan
    Replies:
    2
    Views:
    919
    Gordon Beaton
    Aug 1, 2003
  4. flamesrock
    Replies:
    8
    Views:
    430
    Hendrik van Rooyen
    Nov 24, 2006
  5. Replies:
    2
    Views:
    497
Loading...

Share This Page