簡體   English   中英

如何在 VHDL 中將數字與兩位數分開

[英]How to separate digits from a two-digit number in VHDL

我在 VDHL 中有我的簡單代碼,它將數字與 2 位數字分開,但在測試時,我的分隔數字保持無符號 (u)。 我有一種預感,問題可能出在變量的類型上,當我對它們使用它們不支持的操作時。 在 gtkwave 中使用 ghdl 和 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;

感謝 Tricky 和 user16145658,這段代碼有效:

leastSingnificantDigit <= "mod" (value, 10)(3 downto 0);
mostSignificantDigit <= "/" (value, 10)(3 downto 0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM