Docsity

Using AHDL to Implement Functions: Seven-Segment LED Decoder and Application, Lab Reports of Digital Electronics

Toggle sidebar
bg1
EE 231L Fall 2005
EE 231L
Using AHDL to Implement Functions
For a complex design, it is best to implement well-defined modules and design your circuit
by connecting these modules together. A module will have a set of inputs and outputs, and logic
which describes how to generate the outputs from the inputs. To use a module in a design, you
need to know what the module does, and what inputs and outputs it has. You don’t really need
to know the logic which is used to implement the module.
A seven-segment LED is an array of seven LEDs which can be used to display numbers. A
seven-segment LED decoder has four inputs and seven outputs — for an input between 0x0 and
0xF (hex 0 to hex F), the outputs will tell which of the segments should be lit to display that
number. Here is an AHDL program which will implement a seven-segment LED decoder (modified
from a design in Altera’s Max+PLUS II AHDL manual):
% -a- %
% f| |b %
% -g- %
% e| |c %
% -d- %
SUBDESIGN 7segment
(
i[3..0] : INPUT;
o[6..0] : OUTPUT;
)
BEGIN
TABLE
i[3..0] => o[6..0]; % a b c d e f g %
H"0" => B"1111110";
H"1" => B"0110000";
H"2" => B"1111111";
H"3" => B"1111001";
H"4" => B"0110011";
H"5" => B"1011011";
H"6" => B"1011111";
H"7" => B"1110000";
H"8" => B"1111111";
H"9" => B"1111011";
H"A" => B"1110111";
H"B" => B"0011111";
H"C" => B"1001110";
H"D" => B"0111101";
H"E" => B"1001111";
H"F" => B"1000111";
END TABLE;
1
pf3

Partial preview of the text

Download Using AHDL to Implement Functions: Seven-Segment LED Decoder and Application and more Lab Reports Digital Electronics in PDF only on Docsity!

EE 231L

Using AHDL to Implement Functions

For a complex design, it is best to implement well-defined modules and design your circuit by connecting these modules together. A module will have a set of inputs and outputs, and logic which describes how to generate the outputs from the inputs. To use a module in a design, you need to know what the module does, and what inputs and outputs it has. You don’t really need to know the logic which is used to implement the module.

A seven-segment LED is an array of seven LEDs which can be used to display numbers. A seven-segment LED decoder has four inputs and seven outputs — for an input between 0x0 and 0xF (hex 0 to hex F), the outputs will tell which of the segments should be lit to display that number. Here is an AHDL program which will implement a seven-segment LED decoder (modified from a design in Altera’s Max+PLUS II AHDL manual):

% -a- % % f| |b % % -g- % % e| |c % % -d- %

SUBDESIGN 7segment ( i[3..0] : INPUT; o[6..0] : OUTPUT; ) BEGIN TABLE i[3..0] => o[6..0]; % a b c d e f g %

H"0" => B"1111110"; H"1" => B"0110000"; H"2" => B"1111111"; H"3" => B"1111001"; H"4" => B"0110011"; H"5" => B"1011011"; H"6" => B"1011111"; H"7" => B"1110000"; H"8" => B"1111111"; H"9" => B"1111011"; H"A" => B"1110111"; H"B" => B"0011111"; H"C" => B"1001110"; H"D" => B"0111101"; H"E" => B"1001111"; H"F" => B"1000111"; END TABLE;

END;

If you were designing a circuit which used four of these decoders, it would be tedious to write this code four times. You could instead use this code as a function in another TDF file. Here is an AHDL program which uses the above design file to implement a design to display a 16-bit binary number on a set of four seven-segment LEDs:

FUNCTION 7segment (i[3..0]) RETURNS (o[7..0]);

SUBDESIGN 16display ( in[15..0] : INPUT; out1[6..0] : OUTPUT; out2[6..0] : OUTPUT; out3[6..0] : OUTPUT; out4[6..0] : OUTPUT; ) VARIABLE dc1 : 7segment; dc2 : 7segment; dc3 : 7segment; dc4 : 7segment; BEGIN dc1.i[3..0] = in[15..12]; out1[6..0] = dc1.o[6..0]; dc2.i[3..0] = in[11..8]; out2[6..0] = dc2.o[6..0]; dc3.i[3..0] = in[7..4]; out3[6..0] = dc3.o[6..0]; dc4.i[3..0] = in[3..0]; out4[6..0] = dc4.o[6..0]; END;

This implements four seven-segment decoders as variables. The logic section then indicates how to connect the inputs and outputs of those decoders. A period (.) is used to identify the inputs and outputs of the function. For example, dc1.i[3..0] refers to the four input lines of the first decoder, and dc1.o[6..0] refers to the seven output lines of the first decoder.

Here is another way to do the same thing, using in-line functions:

FUNCTION 7segment (i[3..0]) RETURNS (o[6..0]);

SUBDESIGN 16display ( in[15..0] : INPUT; out1[6..0] : OUTPUT;