码迷,mamicode.com
首页 > 其他好文 > 详细

VHDL之concurrent之generate

时间:2015-05-21 01:17:13      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

GENERATE

  It is another concurrent statement (along with operators and WHEN). It is equivalent to the sequential statement LOOP in the sense that it

allows a section of code to be repeated a number of times, thus creating several instances of the same assignments. 

  FOR / GENERATE:  notice that GENERATE must be labeled.

label: FOR identifier IN range GENERATE
  (concurrent assignments)
END GENERATE;

  IF/GENERATE

   An irregular form is also available, which uses IF/GENERATE (with an IF equivalent; recall that originally IF is a sequential statement). Here ELSE is not allowed.  

label1: FOR identifier IN range GENERATE
  ...
label2: IF condition GENERATE
  (concurrent assignments)
END GENERATE;
...
END GENERATE;

 

Example 1

SIGNAL x: BIT_VECTOR (7 DOWNTO 0);
SIGNAL y: BIT_VECTOR (15 DOWNTO 0);
SIGNAL z: BIT_VECTOR (7 DOWNTO 0);
...
G1: FOR i IN xRANGE GENERATE
  z(i) <= x(i) AND y(i+8);
END GENERATE;

 

Example 2  Vector Shifter

  The output vector must be a shifted version of the input vector, with twice its width and an amount of shift speci?ed by another input.

For example, if the input bus has width 4, and the present value is ‘‘1111’’, then the output should be one of the lines of the following

matrix (the original vector is underscored):

  row(0): 0 0 0 0 1 1 1 1

  row(1): 0 0 0 1 1 1 1 0

  row(2): 0 0 1 1 1 1 0 0

  row(3): 0 1 1 1 1 0 0 0

  row(4): 1 1 1 1 0 0 0 0

1 ------------------------------------------------
2 LIBRARY ieee;
3 USE ieee.std_logic_1164.all;
4 ------------------------------------------------
5 ENTITY shifter IS
6 PORT ( inp: IN STD_LOGIC_VECTOR (3 DOWNTO 0);
7     sel: IN INTEGER RANGE 0 TO 4;
8     outp: OUT STD_LOGIC_VECTOR (7 DOWNTO 0));
9 END shifter;
10 ------------------------------------------------
11 ARCHITECTURE shifter OF shifter IS
12   SUBTYPE vector IS STD_LOGIC_VECTOR (7 DOWNTO 0);
13   TYPE matrix IS ARRAY (4 DOWNTO 0) OF vector;
14   SIGNAL row: matrix;
15 BEGIN
16   row(0) <= "0000" & inp;
17   G1: FOR i IN 1 TO 4 GENERATE
18     row(i) <= row(i-1)(6 DOWNTO 0) & 0;
19   END GENERATE;
20   outp <= row(sel);
21 END shifter;
22 ------------------------------------------------

 

VHDL之concurrent之generate

标签:

原文地址:http://www.cnblogs.com/mengdie/p/4518568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!