找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 4187|回復: 0
打印 上一主題 下一主題
收起左側(cè)

三人表決器vhdl程序

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:574539 發(fā)表于 2019-6-29 13:48 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
代碼如下:
-三人表決器(三種不同的描述方式) vhdl
-- Three-input Majority Voter
-- The entity declaration is followed by three alternative architectures whichachieve the same functionality in different ways.
ENTITY maj IS
PORT(a,b,c : IN BIT; m : OUT BIT);
END maj;
--Dataflow style architecture
ARCHITECTURE concurrent OF maj IS
BEGIN
--selected signal assignment statement (concurrent)
WITH a&b&c SELECT
m <= '1' WHEN"110"|"101"|"011"|"111",'0' WHENOTHERS;
END concurrent;
--Structural style architecture
ARCHITECTURE structure OF maj IS
--declare components used in architecture
COMPONENT and2 PORT(in1, in2 : IN BIT; out1 : OUT BIT);
END COMPONENT;
COMPONENT or3 PORT(in1, in2, in3 : IN BIT; out1 : OUT BIT);
END COMPONENT;
--declare local signals
SIGNAL w1, w2, w3 : BIT;
BEGIN
--component instantiation statements.
--ports of component are mapped to signals
--within architecture by position.
gate1 : and2 PORT MAP (a, b, w1);
gate2 : and2 PORT MAP (b, c, w2);
gate3 : and2 PORT MAP (a, c, w3);
gate4 : or3 PORT MAP (w1, w2, w3, m);
END structure;
--Behavioural style architecture using a look-up table
ARCHITECTURE using_table OF maj IS
BEGIN
PROCESS(a,b,c)
CONSTANT lookuptable : BIT_VECTOR(0 TO 7) := "00010111";
VARIABLE index : NATURAL;
BEGIN
index := 0; --index must be cleared each time process executes
IF a = '1' THEN index := index + 1; END IF;
IF b = '1' THEN index := index + 2; END IF;
IF c = '1' THEN index := index + 4; END IF;
m <= lookuptable(index);
END PROCESS;
END using_table;

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表