# Integer convert to std_logic_vector ?

1. ## 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);```

•

2. ## 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.

•

3. ## Re: Integer convert to std_logic_vector ?

Conversion list.

1 members found this post helpful.

•

4. ## 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

1 members found this post helpful.

--[[ ]]--