+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Member level 1
    Points: 554, Level: 5

    Join Date
    Jun 2016
    Posts
    35
    Helped
    0 / 0
    Points
    554
    Level
    5

    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

    •   AltAdvertisment

        
       

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

    Join Date
    Jun 2010
    Posts
    6,614
    Helped
    1927 / 1927
    Points
    36,169
    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.

    •   AltAdvertisment

        
       

  3. #3
    Full Member level 1
    Points: 844, Level: 6

    Join Date
    Aug 2016
    Location
    Bangalore, India
    Posts
    103
    Helped
    12 / 12
    Points
    844
    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.

    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 61,891, Level: 60
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    12,614
    Helped
    2924 / 2924
    Points
    61,891
    Level
    60

    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. No friend requests. Thank you.


    1 members found this post helpful.

--[[ ]]--