0

I have my simple code in VDHL that seperates digit from 2-digit number, but when testing, my seperated digits remain unsigned (u). I have a hunch that the problem may be in the types of variables, when I use operations on them that they do not support. I use ghdl with gtkwave Variables in gtkwave

--FULL LOGIC--
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity DigitSeparator is
    port(
        value: in unsigned(6 downto 0);
        leastSingnificantDigit: out unsigned(3 downto 0);
        mostSignificantDigit: out unsigned(3 downto 0)
    );
end entity DigitSeparator;

architecture DigitSeparator of DigitSeparator is
begin
    -- Set the outputs to 1111 1111 if the input is greater than 99
    process(value)
    begin
        if value > 99 then
            leastSingnificantDigit <= "1111";
            mostSignificantDigit <= "1111";
        else
            leastSingnificantDigit <= value mod 10;
            mostSignificantDigit <= value / 10;
        end if; 
    end process;
end architecture DigitSeparator;
--TEST BENCH--
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;


entity DigitSeparatorTB is
end entity DigitSeparatorTB;

architecture DigitSeparatorTB of DigitSeparatorTB is
    component DigitSeparator
        port(
            value: in unsigned(6 downto 0);
            leastSingnificantDigit: out unsigned(3 downto 0);
            mostSignificantDigit: out unsigned(3 downto 0)
        );
    end component DigitSeparator;


    signal value: unsigned(6 downto 0) := "0110000";
    signal leastSingnificantDigit: unsigned(3 downto 0);
    signal mostSignificantDigit: unsigned(3 downto 0);


begin
    kaka: DigitSeparator port map (value, leastSingnificantDigit, mostSignificantDigit);
    value <= "0110000", "1111111" after 100 ns, "1000010" after 200 ns;
end architecture DigitSeparatorTB;

6
  • I suspect here you have not bound the DigitSeparator component in the testbench to the entity. The DigitSeparator entity has syntax errors. leastSingnificantDigit <= value mod 10; results in a 7 bit result, not 4. So I suspect you have not even compiled the DigitSeparator code.
    – Tricky
    Commented Dec 16, 2022 at 20:56
  • you're right, when I try to run it without a condition, I get an error The error: ghdl.exe:error: bound check failure at DigitSeparator.vhdl:18 ghdl.exe:error: simulation failed Is there any way to fix it?
    – demon
    Commented Dec 16, 2022 at 21:06
  • leastSingnficantDigit <= "mod" (value, 10)(3 downto 0); The return value of a function call of the function implementing the operator overload can be sliced, it's a named expression. Here the resize function would return a descending range so the direction of the slice is known as well as it's right bound. You'll have a similar problem for value / 10. See the package body in numeric_std-body.vhdl Commented Dec 16, 2022 at 22:09
  • So it's not types of 'variables' (actually signals), it's the subtype of operator return value where the natural operand is converted to unsigned and resized to match the other operand which also defines the length of the return value. And it's not a syntax error, rather a semantic error. See IEEE Std 1076-2008 8. Names 8.1 General, a run time error (which should be checked during synthesis as well). Commented Dec 16, 2022 at 22:19
  • Because ghdl won't produce a waveform dump file when simulating your testbench because of the bound check error(s) my comment on a syntactical cure for a semantic error is not applicable to your actual question. Commented Dec 16, 2022 at 22:34

1 Answer 1

0

The problem is when I try to assign a 4 bit variable (leastSingnificantDigit, mostSignificantDigit) a result that has 7 bits, so I have to guarantee that the result will only have 4 bits thanks to the parenthesis "3 downto 0"

This works:

leastSignificantDigit <= "mod" (value, 10)(3 downto 0);
mostSignificantDigit <= "/" (value, 10)(3 downto 0);
2
  • Because Tricky was basically right with his first comment to your question the first of three errors would be not analyzing DigitSeparator into the current working library causing a warning that kaka is unbound. As well as a slice of the return value of a function call of a function implementing an operator overload, you could have resized the operator results. Commented Dec 16, 2022 at 22:41
  • Instead of simply providing the answer directly, try writing a detailed comment that explains the solution, as long as the explanation is not too lengthy. @demon.
    – DSDmark
    Commented Dec 21, 2022 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.