|
A decoder contains combinatorial logic that interprets input patterns and converts them to output values. In AHDL, you can use a Truth Table Statement or the lpm_compare
or lpm_decode
functions to create a decoder.
The 7segment.tdf file shown below is a decoder that specifies logic for patterns of light-emitting diodes (LEDs). The LEDs are illuminated in a seven-segment display to show the hexadecimal numbers 0 to 9 and the letters A to F.
% -a- % % f| |b % % -g- % % e| |c % % -d- % % % % 0 1 2 3 4 5 6 7 8 9 A b C d E F % % % SUBDESIGN 7segment ( i[3..0] : INPUT; a, b, c, d, e, f, g : OUTPUT; ) BEGIN TABLE i[3..0] => a, b, c, d, e, f, g; H"0" => 1, 1, 1, 1, 1, 1, 0; H"1" => 0, 1, 1, 0, 0, 0, 0; H"2" => 1, 1, 0, 1, 1, 0, 1; H"3" => 1, 1, 1, 1, 0, 0, 1; H"4" => 0, 1, 1, 0, 0, 1, 1; H"5" => 1, 0, 1, 1, 0, 1, 1; H"6" => 1, 0, 1, 1, 1, 1, 1; H"7" => 1, 1, 1, 0, 0, 0, 0; H"8" => 1, 1, 1, 1, 1, 1, 1; H"9" => 1, 1, 1, 1, 0, 1, 1; H"A" => 1, 1, 1, 0, 1, 1, 1; H"B" => 0, 0, 1, 1, 1, 1, 1; H"C" => 1, 0, 0, 1, 1, 1, 0; H"D" => 0, 1, 1, 1, 1, 0, 1; H"E" => 1, 0, 0, 1, 1, 1, 1; H"F" => 1, 0, 0, 0, 1, 1, 1; END TABLE; END;
In this example, the output pattern for all 16 possible input patterns of i[3..0]
is described in the Truth Table Statement.
The decode3.tdf file shown below is an address decoder for a generalized 16-bit microprocessor system.
SUBDESIGN decode3 ( addr[15..0], m/io : INPUT; rom, ram, print, sp[2..1] : OUTPUT; ) BEGIN TABLE m/io, addr[15..0] => rom, ram, print, sp[]; 1, B"00XXXXXXXXXXXXXX" => 1, 0, 0, B"00"; 1, B"100XXXXXXXXXXXXX" => 0, 1, 0, B"00"; 0, B"0000001010101110" => 0, 0, 1, B"00"; 0, B"0000001011011110" => 0, 0, 0, B"01"; 0, B"0000001101110000" => 0, 0, 0, B"10"; END TABLE; END;
In this example, thousands of possible input patterns exist, so it is impractical to specify all of them in the Truth Table Statement. Instead, you can use an X
(don't care) logic level to indicate that the output does not depend on the input corresponding to the position of the X
characters. For example, in the first line of the TABLE
statement, rom
would be high for all 16,384 input patterns of addr[15..0]
that start with 00
. Therefore, you need to only specify the common portion of the input pattern (that is, 00
), and then use X
characters for the rest of the input pattern. With don't care inputs, your project may require fewer device resources.
When you use X (don't care) characters to specify a bit pattern, you must ensure that the pattern cannot assume the value of another bit pattern in the truth table. AHDL assumes that only one condition in a truth table is true at a time; therefore, overlapping bit patterns may cause unpredictable results. |
The decode4.tdf file shown below uses the lpm_decode
function to achieve the same functionality as decode1.tdf (described in Using Numbers).
INCLUDE "lpm_decode.inc"; SUBDESIGN decode4 ( address[15..0] : INPUT; chip_enable : OUTPUT; ) BEGIN chip_enable = lpm_decode(.data[]=address[]) WITH (LPM_WIDTH=16, LPM_DECODES=2^10) RETURNS (.eq[H"0370"]); END;
- PLDWorld - |
|
Created by chm2web html help conversion utility. |