You are on page 1of 14

VHDL CODE FOR COUNTER ON 7-SEGMENT

INTRODUCTION
The 7 segment display allows us to provide information to the user. Fig. below shows the 4 digit 7 segment displays. A seven-segment display, or seven-segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot-matrix displays. Seven-segment displays are widely used in digital clocks, electronic meters, and other electronic devices for displaying numerical information. A seven segment display, as its name indicates, is composed of seven elements. Individually on or off, they can be combined to produce simplified representations of the arabic numerals. The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top, middle, and bottom.

Figure 1.1 7-Segment Display Seven segment display detail and cathode pattern to display the Decimal digits. The segments of a 7-segment display are referred to by the letters A to G, as shown in Fig.

THE 7-SEGMENT DISPLAY FORMAT
In practice current limiting resistors of about 470 to 220O ohms would be connected in series between the decoder/driver chip and each LED display segment to limit the maximum current flow. Different display decoders or drivers are available for the different types of
Dept. of ECE, MSRIT Page 1

Often the seven segments are Dept. For large numeric displays. and cheaper. but how can these digits be connected to form a multi-digit display? The first approach is to connect each segment to a micro-controller pin. e. mechanical shocks without problems. Presently. like clock‟s. Individually on or off. A seven segment display. they can be combined to produce simplified representations of the Arabic numerals. That‟s fine if you need just one number to display. since the common pin is doubled. The individual segments of a seven-segment display. after all we are talking about LED‟s not bulbs. because of its simple construction it is very robust and can function in very low or high temperatures. this way for each digit you need 8 pins and isn‟t elegant at all. MSRIT Page 2 . for what the LCD would fail to work or even get permanently damaged. each segment depending on its size can handle a few miliamps. and the other terminal is connected to a standalone pin. there are a still few applications for which these devices are more suited. each of them has one terminal connected to a common pin. thus multiplexing the data. from this comes the name common anode or common cathode. can withstand vibrations. as its name indicates. Lets take as example the common anode type. it consists of 7 led rectangular boxes called 'segments' and are arranged forming the number 8. and pull to ground the segments.VHDL CODE FOR COUNTER ON 7-SEGMENT display available. and power the digits one at a time. to light the segments we need to connect the positive supply rail to the common pin. or the CMOS CD4543 for liquid crystal display (LCD) types. is composed of seven elements. railway station displays. of ECE.g. we have the 10 pins for each digit. 74LS48 for common-cathode LED types. both LCD and LED displays are combined together to form larger Dot-Matrix Alphanumeric type displays which can show letters and characters as well as numbers in standard Red or Tri-colour outputs. The most simple led display available is the seven segment display. The other solution is to connect each corresponding segment from the digits to a common bus. low -cost measuring devices or very stressing environments the led based displays are better. If we look at one digit we can see 10pins each segment and the small dot are LED‟s. Liquid crystal displays (LCD´s) have one major advantage over similar LED types in that they consume much less power and nowadays. the price drop of LCD‟s tend to overtake the market. 74LS47 for common-anode LED types.

though trapezoids and rectangles can also be used). Figure 1. and bottom. however. The animation to the left cycles through the common glyphs of the ten decimal numerals and the six hexadecimal "letter digits" (A–F). though in the case of adding machines. this is done to obtain a unique.2 Decimal Numbers The segments of a 7-segment display are referred to by the letters A to G. angular blocks and serifs for segments. unambiguous shape for each letter (otherwise. these have mostly been replaced by dot-matrix displays. middle. There are also fourteen-segment displays and sixteen-segment displays (for full alphanumeric). It is an image sequence of a "LED" display. as shown to the right. a capital D would look identical to an 0 (or less likely O) and a capital B would look identical to an 8). the fewest required to represent each of the ten Hindu-Arabic numerals with a distinct and recognizable glyph. effectively. MSRIT Page 3 . the vertical segments are longer and more oddly shaped at the ends in an effort to further enhance readability. however. Seven segments are. Each of the numbers 0. of ECE. which aids readability. the seventh segment bisects the rectangle horizontally. Dept.VHDL CODE FOR COUNTER ON 7-SEGMENT arranged in an oblique (slanted) arrangement. Bloggers have experimented with six-segment and even five-segment displays with such novel shapes as curves. 6. Notice the variation between uppercase and lowercase letters for A–F. 7 and 9 may be represented by two or more different glyphs on seven-segment displays. where the optional DP decimal point (an "eighth segment") is used for the display of non-integer numbers. Additionally. the seven segments are of nearly uniform shape and size (usually elongated hexagons. In most applications.The seven segments are arranged as a rectangle of two vertical segments on each side with one horizontal segment on the top. which is described technology-wise in the following section. LED-based 7-segment display showing the 16 hex digits.

Figure 1. In the 7 segment display all of the anodes are tied together.VHDL CODE FOR COUNTER ON 7-SEGMENT these often require complicated and/or non-uniform shapes and sometimes create unrecognizable glyphs. “b”. of ECE. “e”. “d”. each digit of the display has 7 segments called “a”. every digit consists of 8 diodes. Dept. So to light up a segment. we have to supply a positive voltage to the anode and Gnd to the respective cathode. “g” as well as a decimal point “dp”. Consequently. The two terminals of an LED are called the “anode” and the “cathode”.3 7-Segment Display Format for Common Anode As illustrated in the figure. “c”. “f”. In fact every segment (and the decimal point) is an LED (light emitting diode). MSRIT Page 4 .

For example if the line corresponding to „f „and „e‟ are activated then segments f and e of the display glows indicating a “1″. of ECE. MSRIT Page 5 .1 Driver Circuit diagram for 7-Segment Display The decoder block converts the given input signal into an 8 line code corresponding to the „a‟ to „g‟ segments and the decimal point which controls the segments to display the desired number. Dept. If the input quantity is an anal ogue signal then it must be converter into digital format using an ADC before applying to the decoder. The same line is buffered by the switching element and is available as output line „a‟ of the driver. The “a” output of the decoder is connected to the input terminal (base/gate) of the corresponding switching element inside the driver stage.VHDL CODE FOR COUNTER ON 7-SEGMENT OPERATION OF SEVEN SEGMENT Figure 2. A typical 7 segment display driver stage consists of an array (8 nos ) transistor or FET based switches. then the driver stage is not required. The purpose of the driver stage is to provide the necessary current drive in order to drive the LED seven segment display. This output is connected to the corresponding „a‟ element of the display. The driver can be arranged in sinking or sourcing mode. If the decoder stage is powerful enough to drive the display. For example consider the line „a‟ . If the input signal is digital then there is no need for the ADC and the decoder alone will convert the particular input code into the 8 line code compatible to the seven segment LED display.

(not shown). To Turn an LED ON . The amount of current is controlled by a series resistor. 1. CATHODE (‒) (+) ANODE ← Current Flow Page 6 Dept. Shown below is a common anode seven segment.5v) than the CATHODE.2 Numbers and Alphanumeric Characters BASIC LED OPERATIONS There are two types of LED 7-segment displays: common cathode (CC) and common anode (CA).VHDL CODE FOR COUNTER ON 7-SEGMENT SSD Display Possibilities Decimal Digits 0-9 Select Alpha Characters Simple Messages 4 Figure 2. The difference between the two displays is the common cathode has all the cathodes of the 7-segments connected directly together and the common anode has all the anodes of the 7-segments connected together. of ECE. To understand how a seven-segment display works. The amount of current flowing through the LED will determine the brightness of the LED. 3. MSRIT . we must review how an LED works. The ANODE must be at a higher voltage potential (1. 2.

of ECE. the counter can be used as a digital instrument to measure time and therefore period or frequency. MSRIT Page 7 . Asynchronous counter 2. Synchronous counter ASYNCHRONOUS COUNTER A Digital counter in which all the Flip-Flops are not triggered simultaneously. trailing edged triggered Flip-Flops are used . Dept.Flip-Flops are connected in such a way that output of Flip-Flop is fed to the successive Flip-Flop clock input.1 Counter used in counting of Cricket Balls TYPES OF COUNTERS Basically the counter is of two types 1. Figure 3. A counter is driven by a clock can be employed for counting the number of clock cycles. In this counter.VHDL CODE FOR COUNTER ON 7-SEGMENT COUNTER A counter is one of the most useful and versatile sub systems in a digital system. Since the clock pulse occur at fixed and known intervals. A counter can be described as tallying device that tallies or count some number of events.

In this way it will count up to 111 at the seventh clock pulse. Therefore q0 goes from low to high . MSRIT Page 8 . So q0 changes from high to low and this negative going signal applied to clock of ff 2. and at the eighth clock pulse all ff reset to 0.this becomes a positive going signal at the clock input of ff2. SYNCHRONOUS COUNTER The ripple counter is simplest to build.VHDL CODE FOR COUNTER ON 7-SEGMENT Figure 3. At the negative going edge of the second clock pulse ff1 toggles.flops connected to form a asynchronous or ripple counter are shown. When the first clock pulse is applied ff1 toggles at the negative going edge of this pulse. This drawback has been overcome in synchronous counter by triggering every flip flop in Dept. input of flip-flop is obtained from its preceding flip-flop so trigger moves from first flip-flop to last flip-flop like a ripple in water that is why this counter is called the ripple counter.2 Asynchronous Counter OPERATION OF SYNCHRONOUS COUNTER Three Trailing edge triggered flip. In this counter. So ff2 is not affected and hence the state of the counter after one clock pulse is 001. The counter is initially reset to 000. but there is a limit to its highest operating frequency. of ECE. activates ff2 and hence q1 goes from low to high thus we get output 010.

But just at the end of first clock pulse. every flip flop is triggered in synchronism with the clock.VHDL CODE FOR COUNTER ON 7-SEGMENT synchronism with the clock. MSRIT Page 9 . setting time is equal to the propagation delay time of a single flip flop.this does make any change in the output states of flip flop b and flip flop c because t input terminals of flip flop b and c were at logic 0.3 Synchronous Counter OPERATION OF SYNCHRONOUS COUNTER Circuit diagram of a 3-bit synchronous counter is shown above. Flip-flop c supplied with the and gate a2. So in this counter. T-input terminal of flip-flop a is supplied with high level signal. All the flip-flop are triggered by the same clock signal. so They toggle just at the end of second clock pulse. Since in this counter. Input terminal t of the flip flop a and b are at logic 1 before the arrival of second clock pulse. Dept. So it is called synchronous counter Figure 3. In this counter two and gate are also used with three t-flip-flops. flip flop a toggles and output qa changes from logic 0 to 1. and gate a2 turns on only when output of flip-flop b & and gate a1 are high and only during this period flip-flop c toggles. so flip-flop a toggles just at the end of every pulse. of ECE. before the arrival of the first clock pulse. Initially all flip flop are reset to zero. and gate a1 turns on only output of flip-flop a is high and only during the outputs of flip-flop c for this duration flip-flop b toggles. so output is 000.t-input of flip-flop b is supplied with the and gate a1. which also turns on and gate a1.

g. Totalizing counters. 3. production. of ECE.VHDL CODE FOR COUNTER ON 7-SEGMENT APPLICATIONS 1. printing.4 Output of Seven Segment Display in Counting Process Dept. portable equipment and meters. plastic molding. Counters as the name suggest is specifically used where we need to do calculations e. Mechanical Counters OUTPUT Figure 3. 4. In generating sequential pulses. These devices are used in the following type of machines: packaging. metalworking. In Electronic preset counter. food processing. in calculators etc 2. MSRIT Page 10 .

Tata Mcgraw-Hill. "Driving 7-Segment Displays”. [6] Johansson. Rogers. [4] Warren O. Eleventh Reprint 2007. Electronics Devices And Circuits. MSRIT Page 11 .B. [2] R. of ECE. Power Plant Signalling System. Modern Digital Electronics.P. "New frequency counting principle improves resolution" Dept. Power and the Engineer.Jain.VHDL CODE FOR COUNTER ON 7-SEGMENT REFERENCES [1] A Anand Kumar. Staffan. [3] J. [5] Maxim Integrated. Fundamentals Of Digital Circuits.Gupta.

Architecture count of c09 is component sec_clk Port ( clk rst op ).op1. of ECE. end component. determine the inputs and outputs for the problem. The libraries and entity: library ieee.op2. Next.std_logic_1164. simulate your design and configure it into the board. : out std_logic component seg7 port(m: in integer range 0 to 15.op3: out std_logic_vector(6 downto 0)). end component. : in std_logic. Dept.all. use ieee.all. use ieee. use ieee. The architecture that describes input and output signal for various components. MSRIT Page 12 . implement the design using VHDL in ISE 9. entity c09 is port ( rst. 1. num: out std_logic_vector(6 downto 0)). : in std_logic. end c09.numeric_std.std_logic_unsigned. 2.1.all.clk: in std_logic.VHDL CODE FOR COUNTER ON 7-SEGMENT VHDL CODE First. op0.

rst.flag). if m0 /= 9 then Dept. begin if rst='0' then m0:=0. b<=m1. variable m1: integer range 0 to 10:=0. MSRIT Page 13 . process(rst. begin c1: sec_clk port map(clk. m2:=0. c<=m2. variable m2: integer range 0 to 10:=0. elsif flag'event and flag='1' then a<=m0. signal d: integer range 0 to 10. d<=m3. signal a: integer range 0 to 10. of ECE. signal b: integer range 0 to 10. 4. m3:=0. m1:=0.VHDL CODE FOR COUNTER ON 7-SEGMENT 3. signal c: integer range 0 to 10. Signal declaration signal flag: std_logic. Start our design using the next process for working with the user input. variable m3: integer range 0 to 10:=0.flag) variable m0: integer range 0 to 10:=0.

op0). m0:=0. m2:= m2 + 1. end if.op1). z2: seg7 port map(c. end if. end count. m1:= m1 + 1. elsif m0=9 and m1 /= 9 then m0:=0. m1:=0. elsif m2=9 and m3/= 9 and m0=9 and m1=9 then m1:=0. m3:=0. 5.op2). z0: seg7 port map(a. elsif m3=9 then m0:=0. m2:=0. MSRIT Page 14 .op3). m3 := m3 + 1. z1: seg7 port map(b. of ECE. m0:=0. z3: seg7 port map(d. m2 :=0. elsif m1=9 and m2 /= 9 and m0=9 then m1:=0. end process. Finish the VHDL code. simulation and implementation of your counter.VHDL CODE FOR COUNTER ON 7-SEGMENT m0:= m0 + 1. Dept.