+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Junior Member level 3
    Points: 493, Level: 4

    Join Date
    Jun 2016
    Posts
    29
    Helped
    0 / 0
    Points
    493
    Level
    4

    Integer convert to std_logic_vector ?

    I want to do tachometer from 20k to 70k rpms, and get every 5mS and make some changes to pwm output, how to convert from integer to std_logic_vector ?

    Code VHDL - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    entity mmmm is
            Port ( clk100        : in  STD_LOGIC;   
                   sensor         : in  STD_LOGIC;
                   result          : out std_logic_vector);
       end mmmm;
    architecture Behavioral of mmmm is
          constant period :integer:=2000000; --2000000 * 10 nano seconds
          constant strobe :integer:=500; --5 milliSeconds
            signal   counter:integer:=0;
                 signal   cnt    :integer:=0;
             signal   inte   :integer:=0;
               signal   rp5ms  : std_logic_vector(16 downto 0);
                
    begin
         process(clk100)
                begin             
             if rising_edge(clk100)
                then
                    if cnt = strobe 
                       then   cnt <= 0;               
                       else   cnt <= cnt + 1;  
                       inte <= inte + to_integer(unsigned'('0' & sensor)); --inte <= inte + 1 when (sensor = '1') else 0;
                    end if;
            end if;
         end process;
         result   <= std_logic_vector(unsigned(inte);
    Last edited by andre_teprom; 30th December 2017 at 18:24. Reason: added syntax tags

    •   Alt30th December 2017, 17:33

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 35,867, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,563
    Helped
    1913 / 1913
    Points
    35,867
    Level
    46

    Re: Integer convert to std_logic_vector ?

    slv <= std_logic_vector( to_unsigned(i, slv'length));

    Standard type conversion chart:
    http://www.bitweenie.com/listings/vhdl-type-conversion/


    1 members found this post helpful.

    •   Alt30th December 2017, 18:44

      advertising

        
       

  3. #3
    Member level 5
    Points: 753, Level: 6

    Join Date
    Aug 2016
    Location
    Bangalore, India
    Posts
    94
    Helped
    11 / 11
    Points
    753
    Level
    6

    Re: Integer convert to std_logic_vector ?

    Click image for larger version. 

Name:	vhdl-type-conversions-914x1024.png 
Views:	4 
Size:	136.2 KB 
ID:	144051
    Conversion list.


    1 members found this post helpful.

    •   Alt19th January 2018, 06:47

      advertising

        
       

  4. #4
    Super Moderator
    Points: 57,471, Level: 58
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    11,705
    Helped
    2715 / 2715
    Points
    57,471
    Level
    58

    Re: Integer convert to std_logic_vector ?

    Hi,

    I don't understand some statements:

    ...I want to do tachometer from 20k to 70k rpms, and get every 5mS and...
    20.000 RPM are 333 Hz = 333 pulses per second.
    1 or 2 pulses in 5ms

    70.000 RPM are 1167 Hz = 1167 pulses per second.
    5 or 6 pulses in 5ms
    ***
    --2000000 * 10 nano seconds
    = 20ms or 50Hz

    constant strobe :integer:=500; --5 milliSeconds
    ...then you need an input rate of 100kHz or 10us or 10.000ns

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. Thank you.


    1 members found this post helpful.

--[[ ]]--