Showing posts with label using. Show all posts
Showing posts with label using. Show all posts

Op Amp design tutorial using IC741

| 0 comments |
Operational amplifier finds many application in electronics design. They are one of the corner stone building blocks of any electronics system. They were conceived in early 1940s but were made available in 1952 using vaccum tubes. In this op amp design tutorial, operational amplifier circuit analysis in various application setting are described with illustration using the IC741.

Operational amplifier applications includes circuit design that requires mathematical functions such as adder, subtractor, multiplier, divider, integrator and differentiators. Not only can they be used to realize mathematical function but also realize inverting, non-inverting amplifier, unity gain amplifier(buffer) and also op-amp comparator.

Inverting Operational Amplifier Circuit Analysis

The inverting operational amplifier circuit is shown below. The circuit uses IC741 op-amp. An ac signal is applied at the inverting input and the non-inverting input is grounded. A dc signal can also be applied to the inverting input instead of ac signal. The R1 and RF resistors are the input and the feedback resistors respectively.

inverting operational amplifier circuit

One can derive an equation that relates the input and output voltages using two KVL equations. The input and the output voltage relation is,

vout = - vin*(Rf/R1)

 To derive the input and output voltage relation for the inverting operational amplifier it is helpful to remember two things- Consider that the op-amp is ideal then in absence of any input source there is no current flowing either into the two input terminals and that there is no voltage difference between the two input terminals.

Then after ac source(or dc source) is applied to the inverting terminal of the op-amp, the current i flows into R1 then goes into Rf and appears at the output. In this case we can apply KVL as follows,
[v_{in}=iR_1+iR_f+v_{out}]
or,
[v_{out}=v_{in}-i(R_1+R_f)]
Then we derive another KVL equation using the fact that since there is no voltage difference between the two terminal then the voltage at the point X as shown in the figure below is also at Zero volt because the non-inverting terminal is at Zero volt.

inverting operational amplifier circuit

The point X is also called virtual ground. The KVL equation considering this gives us-
[v_{in}=iR_1]
Substituting i from this equation into the above equation we get the relation between the input an output voltage for the inverting amplifier as follows,
[v_{out}=-v_{in}(frac{R_{f}}{R_{1}})]
 The ratio Rf/R1 is called the gain or attenuation of the inverting op-amp. If Rf is greater than R1 then we have an amplifier and if Rf is less than R1 then we have an attenuator. The negative sign in the equation shows that the output voltage signal is out of phase with the input voltage signal.

The following graph shows the input and the output voltages waveforms;


The input voltage is 1V ac signal and the output voltage is amplified 2V ac signal. Notice that they are out of phase by 180 degree which is due to the negative sign in the output voltage equation above.

Non-Inverting Operational Amplifier Circuit Analysis

Next consider the circuit design of a non-inverting op-amp. In this case the input is applied to the non-inverting input terminal of the op-amp. The inverting terminal is grounded via a resistor(R1). The feedback from the output terminal is taken to the input terminal at the inverting terminal. This circuit is shown below,


In this case the output voltage is,
[v_{out}=v_{in}(1+frac{R_{f}}{R_{1}})][v_{out}=v_{in}(1+frac{R_{f}}{R_{1}})]
The absence of the negative sign indicates that the output voltage is in phase with the input voltage.

The following graph shows the output voltage and the input voltage waveform.


The above waveform graph illustrates that the input and output voltages are in phase and that the output voltage is amplified.

Adder Operational Amplifier Circuit Analysis

Op-amps can be used for doing mathematical operation. One is the addition of analog continuous signal. The adder operational amplifier circuit is shown below.



In the adder circuit above, the input V1, V2 and V3 have amplitude of 1V, 2V and 3V respectively and all had the same frequency of 10Hz. These input were connected together and applied at the inverting input of the IC741. The resistor values are the same so that the output voltage is the sum of the 3 inputs, that is the output signal has 6V(1V+2V+3V). Had we taken different value of Rf(i.e the feedback resistor) but same input resistor values then we would have amplified the signal and not 6V. In the circuit above we took 10K ohm resistor but we could have equally taken 1K ohm resistor for all of those resistors or any other value of resistance.

The output voltage in terms of input voltage and resistor values is,
 [v_{out}=-(v_{1}+v_{2}+v_{3})(frac{R_{f}}{R})]
 Now the following shows the waveform of various inputs and output.

The 3 input voltages with frequency of 10Hz.


The following shows the Vin at the input terminal of the op-amp.


Then the following is the output voltage waveform which has 6V amplitude,



Difference/Differential Operational Amplifier Circuit Analysis

 Another application of the op-amp is realizing a subtractor or a difference or differential amplifier. Here two signal which are to be subtracted are applied at the non-inverting and inverting terminals of the op-amp. The op-amp outputs the difference signal given that the input resistors at the input terminals and the feedback resistor are the same.

The differential operational amplifier circuit is shown below,


 In the above differential op amp circuit design, the input V1 has amplitude of 1V and the input V2 has amplitude of 3V and both have frequency of 10Hz. The output should be an ac signal with amplitude 2V(3V-1V).

The equation relating the output and inputs signal for the difference amplifier is,
[v_{out}=v_{2}-v_{1}]



Voltage Follower/ Unity Gain Amplifier/ Buffer Operational Amplifier Circuit Analysis

 Another application of operational amplifier is buffering signal. Why this is essentially useful is that it signal which are distorted can be smoothed using buffer and also the input signal can be delayed or saved or buffered for certain time. Such circuit is also called voltage follower because the output signal is the same as the input signal, that is same in respect to magnitude and phase. The circuit is also called unity gain amplifier because the output signal is not amplified, in other words, the magnitude of the output signal is not increased.

The following figure shows the voltage follower operational amplifier circuit,


 The mathematical relation between the output and input signal is very simple:
Vout=Vin

The following waveform graph shows the output and input signal waveform which are overlapping.

Read More..

VHDL tutorial on Shift Register Design using D Flip Flop as component

| 0 comments |

This VHDL tutorial shows how D flip flop symbols can be used to implement a block diagram of a shift register and stimulate the design. The shift register has 4 flip flops. So first we need a D flip flop vhdl design then we can use it as component for the top level block diagram.

The VHDL code for the D flip flop is as follows,

library ieee;
use ieee.std_logic_1164.all;

entity DFF is
    port(
    clk: in STD_LOGIC;
    rst: in STD_LOGIC;
    D: in STD_LOGIC;
    Q: out STD_LOGIC
    );
    end DFF;

    architecture DFF_arch of DFF is
    begin
process (CLK)
begin
    if CLKevent and CLK=1 then 
        if rst=1 then   
            Q <= 0;
        else
            Q <= D;
        end if;
    end if;
end process;
    end DFF_arch;

Next we use create the shift register as a block diagram and place the D flip flop symbol that was created earlier into the block diagram. First we need create a new block diagram in the VHDL Software then we need to add its port which are Din, clk and rst as std_logic inputs and Dout which is the std_logic output.

After defining the block diagram we insert four D flip flip into the block diagram and connect them as shown in the following figure.

Shift register with D flip flop


The VHDL code for the same block diagram is as follows,

library IEEE;
use IEEE.std_logic_1164.all;

entity shift_reg_block is
  port(
       Din : in STD_LOGIC;
       clk : in STD_LOGIC;
       rst : in STD_LOGIC;
       Dout : out STD_LOGIC
  );
end shift_reg_block;

architecture shift_reg_block of shift_reg_block is

component DFF
  port (
       D : in STD_LOGIC;
       clk : in STD_LOGIC;
       rst : in STD_LOGIC;
       Q : out STD_LOGIC
  );
end component;


signal Q1, Q2, Q3 : STD_LOGIC;

begin

DFF1 : DFF
  port map(
       D => Din,
       Q => Q1,
       clk => clk,
       rst => rst
  );

DFF2 : DFF
  port map(
       D => Q1,
       Q => Q2,
       clk => clk,
       rst => rst
  );

DFF3 : DFF
  port map(
       D => Q2,
       Q => Q3,
       clk => clk,
       rst => rst
  );

DFF4 : DFF
  port map(
       D => Q3,
       Q => Dout,
       clk => clk,
       rst => rst
  );

end shift_reg_block;

Now in order to stimulate this design we need to create a testbench. Following is the testbench for this shift register.

library ieee;
use ieee.std_logic_1164.all;

entity shift_reg_block_tb is
end shift_reg_block_tb;

architecture TB_ARCHITECTURE of shift_reg_block_tb is

    component shift_reg_block
    port(
        Din : in STD_LOGIC;
        clk : in STD_LOGIC;
        rst : in STD_LOGIC;
        Dout : out STD_LOGIC );
    end component;

    signal Din : STD_LOGIC;
    signal clk : STD_LOGIC;
    signal rst : STD_LOGIC;

    signal Dout : STD_LOGIC;

begin

    UUT : shift_reg_block
        port map (
            Din => Din,
            clk => clk,
            rst => rst,
            Dout => Dout
        );

    clk_pro : process
    begin
        clk <= 0;
        wait for 5 ns;
       
        clk <= 1;
        wait for 5 ns;
       
    end process;
  
    sti_pro : process
    begin
        Din <= 0;
        wait for 10 ns;
       
        Din <= 1;
        wait for 10 ns;
       
        Din <= 1;
        wait for 10 ns;
       
        Din <= 0;
        wait for 10 ns;
       
        Din <= 0;
        wait for 10 ns;
       
        Din <= 1;
        wait for 10 ns;
       
        Din <= 1;  
        wait for 10 ns;
       
        Din <= 0;
        wait for 10 ns;

       
    end process;

end TB_ARCHITECTURE;

configuration TESTBENCH_FOR_shift_reg_block of shift_reg_block_tb is
    for TB_ARCHITECTURE
        for UUT : shift_reg_block
            use entity work.shift_reg_block(shift_reg_block);
        end for;
    end for;
end TESTBENCH_FOR_shift_reg_block;

The simulation waveform is shown below,

simulation of shift register



Read More..

Decoder implementation using the Shift operators in VHDL

| 0 comments |
One of the different method of implementing a decoder in VHDL is to use the shift operators of vhdl language. Using these operator can shorten the code and can be extended easily to higher number of input/output bits. Here it is shown how a 3x8 decoder can be implemented using vhdl shift operator and verified and simulated using the active-hdl VHDL software.

Before going to the implementation readers may want to read other ways of implementing decoder. For this follow the following links-
  • 74LS138 Decoder design using logical gates
  • 74LS138 Decoder design using With Select statement 
  • 74LS138 3x8 decoder design with case construct in vhdl
  • 74LS138 3x8 decoder design using if else construct
In this vhdl tutorial we gonna see how the shift operator in VHDL can be used to implement a decoder. The idea of using shift operator comes from the fact that there is bit shift in the output of the decoder according the input. If we let x be 4 bit input and y be the 8 bit output then one can observe the output y being in the form- 10000000, 01000000, 00100000, 00010000 ...00000001, which shows that 1 is shifted to the right one bit according to the input x. Now x is 4 bit binary but when it is converted to integer then x as integer indicates the number of shift required.

The following VHDL code illustrates how a decoder could be realized using shift operator in vhdl:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity decoder_shift is
    generic (n : positive := 4);
    port(
    x : in std_logic_vector(n-1 downto 0);
    y : out std_logic_vector(2**n-1 downto 0)
    );
end decoder_shift;

architecture decoder_shift_arch of decoder_shift is
constant yout : bit_vector(2**n-1 downto 0) := (0=>1,others => 0);
begin
    y <= to_stdlogicvector(yout sll to_integer(unsigned(x)));
   
end decoder_shift_arch;


In the above as x input is a std_logic_vector it is first unsigned and then to integer. The shifting operater ssl is used to shift the intermediate signal yout. Since shifting operator ssl acts only on bit_vector, intermediate signal yout is defined as bit_vector. After the shifting the bit_vector is converted back to std_logic_vector using the function to_stdlogic_vector and assigned to the original output y.

The advantage of using shift operator for modelling the decoder is that it requires less code lines to implement the decoder. Another advantage is that it can be easily adopted to higher number of input/output bits by changing the generic bit number n declaration.

The code was simulated with active-hdl vhdl software and the waveform of the simulation is shown below.

decoder simulation in vhdl software

Read More..