I would like to perform some arithmetic operation between an unsigned number and an unsigned fixed point number in VHDL:
signal A : ufixed(11 downto -8);
signal B : unsigned(11 downto 0);
signal C : ufixed(A'range);
What would be the best way to perform an arithmetic operation on the integer parts, something like this:
C <= A - B;
I could not find any information on converting an unsigned
to an ufixed
while keeping the same "value". Do I have to convert B
to a std_logic_vector
, pad 0s, and use the to_ufixed()
procedure?
Is there any sane way to do this type of operations? Thanks for any suggestions!
Update: add minimal example
I tried both suggestions using GHDL but still got a error saying: bound check failure at (the assignment operation) line.
Unfortunately I am still having trouble to make modelsim work on my Linux system.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.fixed_pkg.all;
entity sub is
port (
A : in ufixed (11 downto -8);
B : in unsigned (11 downto 0);
C : out ufixed (11 downto -8));
end entity;
architecture RTL of sub is
begin
-- C <= A - to_ufixed(B, 11, -8);
C <= A - ufixed(B);
end architecture;
Testbench file:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.fixed_pkg.all;
entity sub_tb is
end entity sub_tb;
architecture sim of sub_tb is
-- component ports
signal A : ufixed (11 downto -8) := (others => '0');
signal B : unsigned (11 downto 0) := (others => '0');
signal C : ufixed (11 downto -8);
begin -- architecture sim
-- component instantiation
DUT: entity work.sub
port map (
A => A,
B => B,
C => C);
-- waveform generation
WaveGen_Proc: process
begin
A <= "00000000111110000000";
B <= "000000000000";
wait for 100 ns;
B <= "000000000001";
wait for 100 ns;
B <= "000000001110";
end process WaveGen_Proc;
end architecture sim;
ghdl -r --std=08 sub_tb
./sub_tb:error: bound check failure at sub_tb.vhdl:16
./sub_tb:error: simulation failed
Do I have to convert B to a std_logic_vector, pad 0s, and use the to_ufixed() procedure?
is a yes/no question (No).Is there any sane way to do this type of operations
is not a specific programming question. Provide a minimal reproducible example with a specific error, show what you've tried. – user1155120