Vhdl 运行后重置输出

Vhdl 运行后重置输出,vhdl,bcd,Vhdl,Bcd,我正在做一个学习VHDL的小项目。目前我正在研究BCD转换器(将二进制文件转换为BCD编号) 但是我在实现测试台的时候被卡住了。应用模式后,它不会重置输出 实体的我的VHDL代码: library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity bcd_mod is port ( entry: in std_logic_vector(16 downto 0);

我正在做一个学习VHDL的小项目。目前我正在研究BCD转换器(将二进制文件转换为BCD编号)

但是我在实现测试台的时候被卡住了。应用模式后,它不会重置输出

实体的我的VHDL代码:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity bcd_mod is
        port (
                entry: in std_logic_vector(16 downto 0);
                outp: out std_logic_vector(20 downto 0)
        );
end bcd_mod;

architecture calculate of bcd_mod is

begin
        process(entry)
                variable outp_cp : std_logic_vector(20 downto 0) := (others => '0');
                variable place : integer := 1;
                variable digit : integer := 0;
                variable number : integer := 0;

                begin

                        for i in 16 downto 0 loop
                                case entry(i) is
                                        when '0' => null;
                                        when '1' => number := number + (2**i);
                                        when others => null;
                                end case;
                        end loop;

                        if number > 99999 then
                                outp_cp(20) := '1';
                        else
                                while (number > 0) loop
                                        digit := number mod 10;

                                        if place = 1 then
                                                outp_cp(3 downto 0) := std_logic_vector(to_unsigned(digit, 4));
                                        elsif place = 2 then
                                                outp_cp(7 downto 4) := std_logic_vector(to_unsigned(digit, 4));
                                        elsif place = 3 then
                                                outp_cp(11 downto 8) := std_logic_vector(to_unsigned(digit, 4));
                                        elsif place = 4 then
                                                outp_cp(15 downto 12) := std_logic_vector(to_unsigned(digit, 4));
                                        else
                                                outp_cp(19 downto 16) := std_logic_vector(to_unsigned(digit, 4));
                                        end if;

                                        number := number - digit;
                                        number := number / 10;
                                        place := place + 1;
                                end loop;
                        end if;

                        outp <= outp_cp;
                        outp_cp := (others => '0');

        end process;

end calculate;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
实体bcd_mod为
港口(
条目:标准逻辑向量(16到0);
输出:输出标准逻辑向量(20到0)
);
结束bcd_mod;
bcd_模块的结构计算是
开始
流程(条目)
变量outp_cp:std_logic_vector(20到0):=(其他=>'0');
变量位置:整数:=1;
变量位:整数:=0;
变量号:整数:=0;
开始
对于16到0循环中的i
案例条目(i)为
当“0”=>null时;
当“1”=>number:=number+(2**i);
当其他=>null时;
终例;
端环;
如果号码>99999,则
输出cp(20):=“1”;
其他的
while(number>0)循环
数字:=10模数字;
如果place=1,则
输出cp(3到0):=标准逻辑向量(到无符号(数字,4));
如果位置=2,则
输出cp(7到4):=标准逻辑向量(到无符号(数字,4));
如果地点=3,则
输出cp(11到8):=标准逻辑向量(到无符号(数字,4));
如果地点=4,则
输出cp(15到12):=标准逻辑向量(到无符号(数字,4));
其他的
输出cp(19到16):=标准逻辑向量(到无符号(数字,4));
如果结束;
数字:=数字-位数;
编号:=编号/10;
地点:=地点+1;
端环;
如果结束;
输出“0”);
结束过程;
结束计算;
我的代码测试台:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity bcd_mod_testbench is
end bcd_mod_testbench;

architecture calculate of bcd_mod_testbench is
        component bmt
                port(entry : in std_logic_vector(16 downto 0); outp : out std_logic_vector(20 downto 0));
        end component;

        for bmt_0: bmt use entity work.bcd_mod;
                signal entry : std_logic_vector(16 downto 0);
                signal outp : std_logic_vector(20 downto 0);
                begin

        bmt_0: bmt port map (entry => entry, outp => outp);

        process
                type pattern_type is record
                        entry : std_logic_vector(16 downto 0);
                        outp : std_logic_vector(20 downto 0);
                end record;

                type pattern_array is array (natural range <>) of pattern_type;
                constant patterns : pattern_array :=
                (("00000110111101101", "000000011010101100101"),
                 ("00000000000000011", "000000000000000000011"),
                 ("00000000000011011", "000000000000000100111"));
                begin

                for i in patterns'range loop

                        entry <= patterns(i).entry;

                        wait for 1 ns;

                        assert outp = patterns(i).outp
                        report "Wrong BCD number." severity error;
                end loop;

                assert false report "End of test." severity note;
                wait;
        end process;
end calculate;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
实体bcd_mod_测试台为
端部bcd_模块_试验台;
bcd_mod_测试台的结构计算如下:
组件式bmt
端口(输入:输入标准逻辑向量(16向下至0);输出:输出标准逻辑向量(20向下至0));
端部元件;
对于bmt_0:bmt使用实体work.bcd_mod;
信号输入:标准逻辑向量(16至0);
信号输出:标准逻辑向量(20至0);
开始
bmt_0:bmt端口映射(entry=>entry,outp=>outp);
过程
类型模式\类型为记录
条目:标准逻辑向量(16到0);
输出:标准逻辑向量(20到0);
结束记录;
类型pattern_数组是pattern_类型的数组(自然范围);
常量模式:模式数组:=
(("00000110111101101", "000000011010101100101"),
("00000000000000011", "000000000000000000011"),
("00000000000011011", "000000000000000100111"));
开始
对于模式范围循环中的i

条目在VHDL中,
变量
在进程重新输入之间保留其值。因此,当您输入编号
X“000003”
的过程时,所有变量仍然具有它们在
X“003565”
处理结束时添加的值

快速测试表明,在流程开始时将
place
设置为
1
,可以解决问题:

process(entry)
    variable outp_cp : std_logic_vector(20 downto 0) := (others => '0');
    variable place : integer := 1;
    variable digit : integer := 0;
    variable number : integer := 0;
begin
    place := 1;

    ...

您的问题出现在
bcd\u mod
中的未标记过程中。您没有在每个新条目上将
place
初始化为1:

architecture calculate of bcd_mod is

begin
unlabeled:
    process(entry)
        variable outp_cp:  std_logic_vector(20 downto 0) := (others => '0');
        variable place:  integer := 1;
        variable digit:  integer := 0;
        variable number:  integer := 0;
    begin
        place := 1;   -- ADDED
        for i in 16 downto 0 loop
如果你看一下二进制值,问题就显而易见了,我在你的测试台上使用了报告语句:

architecture foo of bcd_mod_testbench is
    component bmt
        port (
            entry:  in  std_logic_vector(16 downto 0);
            outp:   out std_logic_vector(20 downto 0)
        );
    end component;
    for bmt_0: bmt use entity work.bcd_mod;
    signal entry:  std_logic_vector(16 downto 0);
    signal outp:   std_logic_vector(20 downto 0);

    function to_string(inp: std_logic_vector) return string is
        variable image_str: string (1 to inp'length);
        alias input_str:  std_logic_vector (1 to inp'length) is inp;
    begin
        for i in input_str'range loop
            image_str(i) := character'VALUE(std_ulogic'IMAGE(input_str(i)));
        end loop;
        return image_str;
    end;
 begin

bmt_0: 
    bmt 
        port map (
            entry => entry,
            outp => outp
        );

unlabeled:
    process
        type pattern_type is record
            entry:  std_logic_vector(16 downto 0);
            outp:  std_logic_vector(20 downto 0);
        end record;

        type pattern_array is array (natural range <>) of pattern_type;
        constant patterns:  pattern_array := (
             ("00000110111101101", "000000011010101100101"),
             ("00000000000000011", "000000000000000000011"),
             ("00000000000011011", "000000000000000100111")
        );
    begin
        for i in patterns'range loop
            entry <= patterns(i).entry;
            wait for 1 ns;
            assert outp = patterns(i).outp
            report "Wrong BCD number pattern (" & integer'image(i) & ")"
            severity error;
            report "entry = " & to_string(entry);
            report "outp = " & to_string(outp);
        end loop;
        assert false report "End of test." severity note;
        wait;
    end process;
end architecture;
bcd_mod_测试台的架构foo是 组件式bmt 港口( 条目:标准逻辑向量(16到0); 输出:输出标准逻辑向量(20到0) ); 端部元件; 对于bmt_0:bmt使用实体work.bcd_mod; 信号输入:标准逻辑向量(16至0); 信号输出:标准逻辑向量(20至0); 函数到_字符串(inp:std_逻辑_向量)的返回字符串为 变量image_str:字符串(1到inp'长度); 别名输入\u str:std\u逻辑\u向量(1到inp'长度)是inp; 开始 对于输入_str'range循环中的i 图像(i):=字符值(标准逻辑)图像(输入(i)); 端环; 返回图像; 终止 开始 bmt_0: bmt 港口地图( entry=>entry, 输出=>outp ); 未标记: 过程 类型模式\类型为记录 条目:标准逻辑向量(16到0); 输出:标准逻辑向量(20到0); 结束记录; 类型pattern_数组是pattern_类型的数组(自然范围); 常量模式:模式_数组=( ("00000110111101101", "000000011010101100101"), ("00000000000000011", "000000000000000000011"), ("00000000000011011", "000000000000000100111") ); 开始 因为我在模式中