【问题标题】:3-bit serial input bubble sort in VHDL not sortingVHDL中的3位串行输入冒泡排序未排序
【发布时间】:2017-10-25 03:40:21
【问题描述】:

我正在尝试设计一个 3 位串行输入冒泡排序,但无法让输出实际排序。

不幸的是,我对 VHDL 或一般编程不是很熟悉。

我读到我的一个潜在问题是我使用信号并在我的流程中分配它们的方式。然而,当我尝试纠正它并让它编译时,我的输出被破坏了。

还有一个关于 VHDL 中使用数组的冒泡排序的问题,我也尝试以此为基础,但也没有成功。我从中尝试的主要内容是for i in ___ to ___ loop 进程。

以下是我最近使用的代码和测试台。

任何建议或解释将不胜感激!

library ieee;
use ieee.std_logic_1164.all;

entity bubble_sort_bs is
    generic (
        width : integer := 3);
    port ( 
        X0, X1, X2 : in std_logic;
        Y0, Y1, Y2 : out std_logic;
        clk, enable : in std_logic);
end entity bubble_sort_bs;

architecture bubble_sort_bs_behav of bubble_sort_bs is
    signal comb_out : std_logic;
    signal inp : std_logic_vector((width-1) downto 0);
    signal inp1 : std_logic_vector((width-1) downto 0);
    signal inp2 : std_logic_vector((width-1) downto 0);
    signal pass_in, pass_out : std_logic_vector((width-1) downto 0);
    signal outp : std_logic_vector((width-1) downto 0); --trash
    signal x_vector : std_logic_vector((width-1) downto 0);
begin 
    x_vector <= X0 & X1 & X2;
    Y0 <= pass_out(2);
    Y1 <= pass_out(1);
    Y2 <= pass_out(0);

    Output : process(all)
    begin
        if rising_edge(clk) then
            if enable <= '1' then
                inp1 <= x_vector;
                inp2 <= pass_in;
            end if;
        end if;

        if inp1 > inp2 then  --x_vector
            comb_out <= '1';
            outp <= inp1;
            pass_in <= inp2;
        elsif inp2 > inp1 then --x_vector
            comb_out <= '0';
            outp <= inp2;
            pass_in <= inp1;
            ----inp2 <= inp1;
        elsif inp2 = inp1 then 
            comb_out <= '0';
            outp <= inp2;
            pass_in <= inp1;
        end if;
        pass_out <= outp;
    end process Output;
end architecture bubble_sort_bs_behav;

测试台:

library ieee;
use ieee.std_logic_1164.all;

entity bubble_sort_bs_tb is
end entity bubble_sort_bs_tb;

architecture tb_behav of bubble_sort_bs_tb is
    component bubble_sort_bs
        generic (
            width : integer);
        port (
            X0, X1, X2 : in std_logic;
            Y0, Y1, Y2 : out std_logic;
            clk, enable : std_logic
        );
    end component;
    constant bit_width : integer := 3;
    signal inp, outp : std_logic_vector((bit_width-1) downto 0);
    signal t_clk, t_enable : std_logic := '0';
begin
    U1 : bubble_sort_bs 
        generic map (bit_width)
        port map (
            X0 => inp(0),
            X1 => inp(1),
            X2 => inp(2),
            Y0 => outp(0),
            Y1 => outp(1),
            Y2 => outp(2),
            clk => t_clk,
            enable => t_enable
        );

    t_clk <= not t_clk after 5 ns;
    test_process : process
    begin
        inp <= "001";
        t_enable <= '1';
        wait for 20 ns;

        inp <= "100";
        t_enable <= '1';
        wait for 20 ns;

        inp <= "111";
        t_enable <= '1';
        wait for 20 ns;

        inp <= "000";
        t_enable <= '1';
        wait for 20 ns;

        wait; 
    end process;
end tb_behav;

【问题讨论】:

  • 你说你“不熟悉一般的编程”。 VHDL不是一种编程语言——它是一种硬件描述语言。当您编写 VHDL 时,您正在设计硬件。你是对的:你在这个过程中分配信号的方式是错误的。但是,实际上,您的代码非常混乱。我建议你退后一步,学习更多的 VHDL,特别是编码风格,特别是你用 VHDL 编写的内容与硬件的关系。
  • 您可能想阅读我公司网站上的this。继续点击“下一步”,直到看到“实用提示组合”,然后确保至少查看“顺序流程”提示。

标签: sorting vhdl bubble-sort


【解决方案1】:

好的,您的代码有很多问题。 首先,从输入到x_vector 的映射将位反转,您也在输出中执行此操作。
接下来pass_in 永远不会得到值,导致您的第一次比较inp1 &gt; inp2 始终为真。因此,您实际做的是给出一个输入信号,将其与任何内容进行比较,然后稍后将其返回一个时钟周期。 See Picture.
要进行冒泡排序,您至少需要在开始时有两个输入。

正如其他人所说,在继续之前尝试一些教程以更熟悉 VHDL。我可以推荐asic-world tutorial
祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    相关资源
    最近更新 更多