Showing posts with label Digital. Show all posts
Showing posts with label Digital. Show all posts

Divide by 2 clock in VHDL

Clock dividers are ubiquitous circuits used in every digital design. A divide-by-N divider produces a clock that is N times lesser frequency as compared to input clock. A flip-flop with its inverted output fed back to its input serves as a divide-by-2 circuit. Figure 1 shows the schematic representation for the same.

A divide by 2 clock circuit produces output clock that is half the frequency of the input clock
Divide by 2 clock circuit
                                          
Following is the code for a divide-by-2 circuit.
-- This module is for a basic divide by 2 in VHDL.
library ieee;
use ieee.std_logic_1164.all;
entity div2 is
                port (
                                reset : in std_logic;
                                clk_in : in std_logic;
                                clk_out : out std_logic
                );
end div2;

-- Architecture definition for divide by 2 circuit
architecture behavior of div2 is
signal clk_state : std_logic;
begin
                process (clk_in,reset)
                begin
                                if reset = '1' then
                                                clk_state <= '0';
                                elsif clk_in'event and clk_in = '1' then
                                                clk_state <= not clk_state;
                                end if;
                end process;
clk_out <= clk_state;

end architecture;

Hope you’ve found this post useful. Let us know what you think in the comments.

Latency and throughput – the two measures of system performance

Performance of the system is one of the most stringent criteria for its success. While performance increases the desirability among customers, cost is what makes it affordable. This is the reason why system designers aim for maximum performance with available resources such as power and area constraints. There are two related parameters that determine the performance output of a system –

Throughput - Throughput is a measure of the productivity of the system. In electronic/communication systems, throughput refers to rate at which output data is produced. Higher the throughput, more productive is the system. In most of the cases, it is measured as time difference between two consecutive outputs (nth and n+1th). Throughput also refers to the rate at which input data can be applied to system.
Let us discuss with the help of an example:

throughput summary diagram


Above figure depicts the throughput of 3 number adder. Result of input set applied at 1st clock cycle appears at output at 3rd clock cycle and in 4th clock cycle next input set is applied and output comes in 6th clock cycle.  Hence, throughput of above design is ⅓ per clock cycle. As we can see from diagram, first input is applied in first clock cycle and 2nd input is applied in 4th clock cycle. Hence we can also say that throughput is rate at which input data can be applied to system.

Latency- Latency is the time taken by a system to produce output after input is applied. It is a measure of delay response of a design. Higher the latency value, slower is the system. in synchronous designs, it is measured in terms of number of clock cycles. In combinational designs, latency is basically propagation delay of circuit. In non pipelined designs, latency improvement is major area of concern. In more general terms, it is time difference between output and input time.
Latency
Relationship between throughput and latency: Both latency and throughput are inter-related. It is desired to have maximum throughput and minimum latency. Increasing latency and/or throughput might make the system costly. Let us take an example. Consider a park with 3 rides and it takes 5 minutes for a ride.  A child can take sequentially these rides; i.e, ride 1, ride 2 and then ride 3. Firstly, let us assume that only one child at a time is allowed to enter park at a time. While he is taking a ride, no one is allowed to enter the park. Thus, the throughput of the park is 15 minutes per child and latency is 15 minutes. Now, let us assume that while a child has finished taking ride1, another child is allowed to enter park. Thus, in this case, throughput will be 5 minutes per child whereas latency is still 15 minutes. Thus, we have increased the throughput of the system without affecting latency and at the same cost.

­Our world – Digital or analog

Digtal device interfacing with so-called analog worldThere are two kinds of electronic systems that we encounter in our daily life – digital and analog. Digital systems are the ones in which the variables to be dealt with can presume only some specified values whereas in analog systems, these variables can assume any of the infinite values. The superiority of digital devices over analog devices has ever been a topic of discussion. This is the reason why digital devices have taken over analog in almost all the areas that we encounter today. Digital computers, digital watches, digital thermometers etc. have replaced analog computers, analog watches and analog thermometers, and so on. Digital devices have replaced the analog ones due to their superior performance, better ability to handle noise and reliability in spite of being more costly than analog ones. Although most of the devices used today are digital, but in general, the world around us seems to be analog. All the physical quantities around us; i.e. Light, heat, current are analog. The so called digital devices have to interface with this analog real world only. For instance, a digital camera interfaces with analog signal (light) and converts it into information in the form of pixels that collectively form a digital image. Similarly, a music system converts the digital information stored in a music CD into pleasant music which is nothing but analog sound waves. All the digital devices that we know have this characteristic in common. Simply speaking, there are devices known as Analog to Digital converters (ADC) and Digital to Analog converters (DAC) that acts as an interface between the real analog world and the digital devices and converts the data sensed by analog sensor into the digital information understood by the digital system and vice-versa. They all interface with the so called analog world. But is the analog world really analog? Is it true that analog variables can take any number of values? Or is there some limit of granularity for them too. Is this world inherently digital or analog in nature? Is digital more fundamental than analog?
 As we all know, there are many fundamental quantities in this universe viz. Mass, length, time, charge, light etc. We have been encountering these ever since the world has begun. Now the question arises – whether all these quantities are inherently analog or digital? Finding the answer to this question will automatically bring us to the answer of our main question; i.e. whether the basics of this world lie in analog or digital. It is often said that “Heart of digital devices is analog.” (See figure below). This is because, as visible on a macroscopic scale, the current and voltage waveforms produced by a digital circuit/system are not digital in fact. This can be observed from the fact that the transition from one logic state to another cannot be abrupt.  Also, there are small spikes in the voltage levels even if the system is stable in one state. But, seen at microscopic level in terms of transfer of current by transfer of electrons, since, there can only be

transfer of an integral number of electrons, current can only take one of numerous values, and not just any value. Let us take an illustration. The charge on an electron is 1.6E19 (or 0.00000000000000000016) represented as ‘e’. It is the smallest charge ever discovered. It is well known that charge can exist only in the multiples of ‘e’. Thus, electric charge is a digital quantity with the smallest unit ‘e’. When we say that the value of charge at a point is +1C, we actually mean that the charge is caused by transfer of 6250000000000000000 electrons. Since, the smallest unit of charge is 0.00000000000000000016 C, hence, there cannot exist any charge of value 1.00000000000000000015 C, since that will make the number of electrons to be a fraction. Since, the magnitude of 1C is very large as compared to charge on 1e, it appears to us as continuous and not discrete. For us, there is no difference between 1. 00000000000000000015 and 1 as the devices we use don’t measure with that much precision. Hence, we infer these quantities as analog. Similar is the case with other physical quantities.

Many laws have been formed by our great scientists postulating about the quantization of some basic physical quantities. Viz. Planck’s quantum theory states that angular momentum of an electron in the orbit of an atom is quantized. Simply stated, it states that the angular momentum can take only specified values given as multiples of h/2Π. Thus, the smallest angular momentum an electron can have is h/2Π and the angular momentum can increment only in steps of h/2Π. If we take h/2Π as one unit, then we can say that angular momentum of an electron is a digital quantity. Similarly speaking, Light is also known to consist of photons. According to Planck’s quantum theory, the light intensity is also an integral multiple of the intensity of a single photon. Thus, light is also inherently a digital quantity. Also, as stated above, the charge is also quantized.

But there are some physical quantities of which quantization is yet to be established. Mass is one of those quantities. But, it is believed that the quantization of mass will be established soon.

Thus, we have seen that most of the physical quantities known are known to be digital at microscopic level. Since, we encounter these at macroscopic level having billions and billions of basic units, the increments in these seem to be continuous to us as the smallest incremental unit is negligible in comparison to actual measure of the quantity and we perceive them as analog in nature.

Thus, we can come to the conclusion that most of the quantities in this world are digital by their blood. Once the quantization of mass will be established, we can conclude with surety that digital lies in the soul of this world. This digital is similar to our definition of digital systems; just the difference is that it occurs at a very minute scale which we cannot perceive at our own.

Read also: