VHDL-如何将两个代码合并在一起?

时间:2019-05-10 11:21:52

标签: merge vhdl fpga

我正在尝试将两个代码合并在一起。一个代码使用前一个的输出并将其转换为标准逻辑向量。

我尝试使用过程功能,但失败了

这些是代码

此代码用于将频率输出分成3个不同的数字,以进行3个七段显示  ...

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

 entity dividerr is
 generic (
 divide_ratio:integer:=1000;
inc    :integer:=256);
 port (
 clckin : in integer range 0 to 256000;
x,y,z : out integer range 0 to 10);
end dividerr;

architecture divider of dividerr is
begin
dividing: process (clckin)
variable div : integer range 0 to divide_ratio;
variable I : integer range 0 to inc;
begin
 if clckin >= 100000 then
div := divide_ratio;
I := clckin/div;
x <= I/100;
y <= (I rem 100)/10;
z <= I rem 10;
elsif clckin >= 10000 or clckin < 100000 then
div := divide_ratio;
I := clckin/div;
x <= 0;
y <= I/10;
Z <= I rem 10;
elsif clckin >= 1000 or clckin < 10000 then
div := divide_ratio;
I := clckin/div;
x <= 0;
y <= 0;
z <= I;
elsif clckin >= 500 or clckin < 1000 then
div := divide_ratio;
I := clckin/div;
x <= 0;
y <= 0;
z <= I * 10;
else I := 0;

end if;
end process dividing;

end divider;

....

此代码是先将数字转换为二进制,然后再将其转换为bcd并将它们映射到de2板上的七个分段显示器上 ...

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

entity converter is 
port (
x : in integer range 0 to 3;
y,z : in integer range 0 to 9;
xout, yout, zout : out std_logic_vector (7 downto 0));
end converter;

architecture module of converter is   
begin

    xout <= std_logic_vector(to_unsigned(x, xout'length));
    yout <= std_logic_vector(to_unsigned(y, yout'length));
    zout <= std_logic_vector(to_unsigned(z, zout'length));

end module;

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您需要实例化您的两个实体,例如更高级别的实体:

entity top is
  generic (
    divide_ratio:integer:=1000;
    inc         :integer:=256);
  port (
    clckin           : in integer range 0 to 256000;
    xout, yout, zout : out std_logic_vector (7 downto 0));
end top;

architecture A of top is
  signal x,y,z : integer range 0 to 10;
begin

  INSTANCE1 : entity work.dividerr 
    generic map (
      divide_ratio => divide_ratio,
      inc          => inc)
    port map (
      clckin =>  ,
      x => x,
      y => y,
      z => z);

  INSTANCE2 : entity work.converter  
    port map (
      x => x,
      y => y,
      z => z,
      xout => xout,
      yout => yout,
      zout => zout);

end A;

https://www.edaplayground.com/x/3pJu