使用通用来确定 VHDL 中的(解)复用器大小? [英] Use a generic to determine (de)mux size in VHDL?

查看:28
本文介绍了使用通用来确定 VHDL 中的(解)复用器大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一个通用的p"来定义一个多路复用器将有多少输出.输入和所有输出均为 1 位.输出、控制和输入可以很简单,例如:

I want to use a generic 'p' to define how many outputs a demux will have. Input and all outputs are 1 bit. The outputs, control, and input can be something simple like:

 signal control : std_logic_vector(log 2 p downto 0); -- I can use a generic for the log2..
 signal input : std_logic;
 signal outputs : std_logic_vector(p-1 downto 0);

但是多路复用器的实现代码是什么?甚至有可能吗?

But what would the mux implementation code be? Is it even possible?

推荐答案

不需要泛型:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity demux is
    port(
        control : in unsigned;
        input   : in std_logic;
        outputs : out std_logic_vector
        );
end entity demux;

architecture rtl of demux is
    -- Check size of input vectors
    assert 2**control'length = outputs'length 
           report "outputs length must be 2**control length" 
           severity failure;
    -- actually do the demuxing - this will cause feedback latches to be inferred
    outputs(to_integer(unsigned(control)) <= input;

end architecture;

(未经测试,只是在我的头顶输入...)

(Untested, just typed in off the top of my head...)

这将推断闩锁 - 这是您想要的吗?

This will infer latches though - is that what you want?

这篇关于使用通用来确定 VHDL 中的(解)复用器大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆