Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
最大公约数VHDL-FSM_Vhdl - Fatal编程技术网

最大公约数VHDL-FSM

最大公约数VHDL-FSM,vhdl,Vhdl,我正在尝试使用FSM实现VHDL中的最大公约数 这些是美国 还有更多关于设计的细节 我按照描述进行了此实现,但在模拟过程中没有得到正确的结果 entity fsm is port (clk,rst: in std_logic; gt,eq,lt: in std_logic; sel,ld,sub: out std_logic_vector(1 downto 0); out_en: out std_logic); end fsm; architecture fsm o

我正在尝试使用FSM实现VHDL中的最大公约数

这些是美国

还有更多关于设计的细节

我按照描述进行了此实现,但在模拟过程中没有得到正确的结果

entity fsm is
    port (clk,rst: in std_logic; gt,eq,lt: in std_logic;
    sel,ld,sub: out std_logic_vector(1 downto 0);
    out_en: out std_logic);
end fsm;

architecture fsm of fsm is
    type STATES is (S1,S2,S3,S4,S5,S6,S7,S8);
    signal state: STATES;
begin
    process (clk, rst)
    begin
        if (rst='0') then 
            state<=S1;
        elsif (clk'event and clk='1') then
            case state is
                when S1 =>
                    sel(0) <= '1';
                    sel(1) <='0';                   
                    state <= S2;
                when S2 =>
                    ld(0) <= '1';
                    ld(1) <= '1';
                    state <= S3;
                when S3 =>
                    if(gt='1') then
                        state <= S4;
                    elsif(eq='1') then
                        state <= S6;
                    elsif(lt='1') then
                        state <= S7;
                    end if;
                when S4 =>
                    sub(0) <= '1';
                    state <= S5;
                when S6 =>
                    out_en <= '1';
                when S7 =>
                    sub(1) <= '1';
                    state <= S8;
                when S8 =>
                    sel(1) <= '1';
                    state <= S2;
                when S5 =>
                    sel(0) <= '0';
                    state <= S2;
                when others => null;
            end case;
        end if;
    end process;

end fsm;
编辑 模拟


我的VHDL不是很流利,但看起来您需要在状态
S2
之后重置
ld
信号,或者在
S4
S7
之后重置
sub
信号。有一个时钟周期,减法器和负载信号都处于激活状态。

我的VHDL不是很流利,但看起来您需要在状态
S2
之后重置
ld
信号,或者在
S4
S7
之后重置
sub
信号。有一个时钟周期,减法器和负载信号都处于激活状态。

情况S6的代码从不将状态设置为另一个值,因此它将“锁定”并保持在该状态。

情况S6的代码从不将状态设置为另一个值,因此它将“锁定”并保持该状态。

en
为0时,减法器是否阻止其输出?是阻止它。出于某种原因,它进入状态6,这将实际启用输出寄存器。因此,实际值尚未计算,输出错误。当
en
为0时,减法器是否锁定其输出?是将其锁定。出于某种原因,它进入状态6,这将实际启用输出寄存器。所以实际值还没有计算出来,输出是错误的。你能给出测试用例的输入和观察到的输出吗?这可能会让我们了解出了什么问题。@vhallac我添加了模拟图像。希望这有帮助。由于它进入S6,因此必须在某个点断言
eq
信号。您可能还需要在模拟过程中查看其值。它可能与x和y寄存器在第一次加载触发它之前的初始值有关。你能给出测试用例输入和观察到的输出吗?这可能会让我们了解出了什么问题。@vhallac我添加了模拟图像。希望这有帮助。由于它进入S6,因此必须在某个点断言
eq
信号。您可能还需要在模拟过程中查看其值。这可能与第一次加载触发x和y寄存器之前的初始值有关。我知道。我修好了。问题是,当它不应该去的时候,它会进入状态6。@marcushatchenson:在这种情况下,我可以建议你重新粘贴你的实际代码。。。很可能从那以后你又介绍了别的东西。我知道。我修好了。问题是,当它不应该去的时候,它会进入状态6。@marcushatchenson:在这种情况下,我可以建议你重新粘贴你的实际代码。。。很可能从那以后你又介绍了其他东西。
library IEEE;
use IEEE.std_logic_1164.all;

entity gcd_calc is
    port (
        clk,rst: in std_logic;
        x_i,y_i: in std_logic_vector(7 downto 0);
        data_o: out std_logic_vector(7 downto 0));
end gcd_calc;

architecture struct of gcd_calc is

component mux8_2x1 
        port (sel: in std_logic;
            inp_a,inp_b: in std_logic_vector(7 downto 0);
            mout: out std_logic_vector(7 downto 0));
    end component;  
component reg8 
        port (en,clk: in std_logic;
            inp: in std_logic_vector(7 downto 0);
            outp: out std_logic_vector(7 downto 0));
    end component;

component cmp8 
        port (inp_a,inp_b: in std_logic_vector(7 downto 0);
            a_gt_b,a_eq_b,a_lt_b: out std_logic;
            outp: out std_logic_vector(7 downto 0));
    end component;

component sub8
        port (en: in std_logic;
            inp_a,inp_b: in std_logic_vector(7 downto 0);
            outp: out std_logic_vector(7 downto 0));
    end component;

component fsm
        port (clk,rst: in std_logic; gt,eq,lt: in std_logic;
            sel,ld,sub: out std_logic_vector(1 downto 0);
            out_en: out std_logic);
    end component;
    signal muxx_o,regx_o,subx_o: std_logic_vector(7 downto 0);
    signal muxy_o,regy_o,suby_o: std_logic_vector(7 downto 0);
    signal cmp_o: std_logic_vector(7 downto 0);
    signal x_sel,y_sel,x_ld,y_ld,x_sub,y_sub: std_logic;
    signal x_gt_y,x_eq_y,x_lt_y,data_en: std_logic;
begin
    mux_x: mux8_2x1 port map (x_sel,subx_o,x_i,muxx_o);
    mux_y: mux8_2x1 port map (y_sel,y_i,suby_o,muxy_o);
    reg_x: reg8 port map (x_ld,clk,muxx_o,regx_o);
    reg_y: reg8 port map (y_ld,clk,muxy_o,regy_o);
    cmp: cmp8 port map
        (regx_o,regy_o,x_gt_y,x_eq_y,x_lt_y,cmp_o);
    sub_x: sub8 port map (x_sub,regx_o,regy_o,subx_o);
    sub_y: sub8 port map (y_sub,regy_o,regx_o,suby_o);
    reg_out: reg8 port map (data_en,clk,cmp_o,data_o);
    ctrl: fsm port map
        (clk,rst,x_gt_y,x_eq_y,x_lt_y,
        sel(0)=>x_sel,sel(1)=>y_sel,
        ld(0)=>x_ld,ld(1)=>y_ld,
        sub(0)=>x_sub,sub(1)=>y_sub,out_en=>data_en);
end struct;