- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a vector A(7 down to 0).Now we have to add this vector with an integer(let it be 5).B(7 down to 0) is output.Then how to write the vhdl code.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it depends what type A and B are. If A is a std_logic_vector you need to first convert it to an unsigned then add the integer. make sure you also include the numeric_std package (and do not add the std_logic_arith package).
if A and B are already unsigned, you can just write: B <= A + 5; But we need to see the declaration of A and B to see what code you really need.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have written the code as below:
Library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; use IEEE.STD_LOGIC_UNSIGNED.ALL; use IEEE.STD_LOGIC_ARITH.ALL; entity improc is port (clk : in std_logic; ipixel : in std_logic_vector(23 downto 0); opixel : out std_logic_vector(23 downto 0) ); end entity improc; architecture rtl of improc is begin process (clk) begin if rising_edge (clk) then opixel(23 downto 16) <= std_logic_vector(unsigned( ipixel(23 downto 16)))+ conv_std_logic_vector(unsigned(9,8))); opixel(15 downto 8) <= std_logic_vector(unsigned( ipixel(15 downto 8)))+ conv_std_logic_vector(unsigned((9,8))); opixel(7 downto 0) <= std_logic_vector(unsigned( ipixel(7 downto 0)))+ conv_std_logic_vector(unsigned((9,8))); end if; end process; end architecture rtl; But it gives error.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The main problem is that you have included std_logic_arith AND numeric_std. They conflict with each other, so you need to remove std_logic_arith (its not standard VHDL. Neither is std_logic_unsigned, but Ill let you keep that)
the answer would then be: opixel(23 downto 16) <= std_logic_vector( unsigned( ipixel(23 downto 16) ) + 9 );- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it necessaryto convert 9 into vector form using conv_std_logic_vector.Beacuse ipixel is 8 bit and 9 is constant.Plearse help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No. Like I showed you, you can add an integer to an unsigned number. There is no need to use conv_std_logic_vector because you're adding an integer to an unsigned. (conv_std_logic_vector is NOT standard VHDL).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Then what is the actual meaning of these "std_logic_vector(unsigned( ipixel(23 downto 16)))".Little bit confused...............
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ipixel is a std_logic_vector
unsigned( ipixel(23 downto 16)) converts the top 8 bits to an unsigned type. std_logic_vector( unsigned( ipixel(23 downto 16)) ) converts the unsigned back to a std_logic_vector. A std_logic_vector is not a number, it is just a collection of bits. An unsigned type is a similar array that can be treated as an unsigned number, hence the ability to do arithmatic with it. So the answer I proposed: opixel(23 downto 16) <= std_logic_vector( unsigned( ipixel(23 downto 16) ) + 9 ); converts the input to an unsigned, adds 9 to it, then converts the result back to a std_logic_Vector.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks...............

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page