SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
Universidade Federal de Santa Catarina
         Centro Tecnológico – CTC
    Departamento de Engenharia Elétrica
                                            http://gse.ufsc.br




“EEL7020 – Sistemas Digitais”


     Prof. Eduardo Augusto Bezerra
           Eduardo.Bezerra@eel.ufsc.br




         Florianópolis, agosto de 2012.
Sistemas Digitais



Processos implícitos e explícitos




           EEL7020 – Sistemas Digitais   2/37
Processos implícitos e explícitos


Processos implícitos:
• Atribuições com sinais em paralelo (exemplo: LEDR <= SW);
• Atribuições com seleção (with / select) e comparação (when)
• Componentes instanciados (component / port map);

Processos explícitos:
• Definidos com a palavra reservada process.




                           EEL7020 – Sistemas Digitais          3/37
Processos implícitos e explícitos
LIBRARY IEEE;                              LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;               USE IEEE.STD_LOGIC_1164.ALL;
ENTITY implicito IS                        ENTITY explicito IS
PORT (                                     PORT (
   a, b : IN STD_LOGIC;                       a,b : IN STD_LOGIC;
   y : OUT STD_LOGIC                          y : OUT STD_LOGIC
);                                         );
END implicito;                             END explicito;
ARCHITECTURE logic OF implicito IS         ARCHITECTURE logic OF explicito IS
    SIGNAL c : STD_LOGIC;                     SIGNAL c : STD_LOGIC;
BEGIN                                      BEGIN
    c <= a AND b;                             PROCESS (a, b)
    y <= c;                                   BEGIN
END logic;                                        c <= a AND b;
                                              END PROCESS;
                                              PROCESS (c)
• Soluções equivalentes;                      BEGIN
• Exemplo adaptado de material                    y <= c;
  educacional da Altera.                      END PROCESS;
                                           END logic;
                                 EEL7020 – Sistemas Digitais                4/37
Processos implícitos e explícitos
LIBRARY IEEE;                             LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;              USE IEEE.STD_LOGIC_1164.ALL;
ENTITY implicito IS                       ENTITY explicito IS
PORT (                                    PORT (
   a, b : IN STD_LOGIC;                      a,b : IN STD_LOGIC;
   y : OUT STD_LOGIC                         y : OUT STD_LOGIC
);                                        );
END implicito;                            END explicito;
ARCHITECTURE logic OF implicito IS        ARCHITECTURE logic OF explicito IS
    SIGNAL c : STD_LOGIC;                    SIGNAL c : STD_LOGIC;
BEGIN                                     BEGIN
    c <= a AND b;                            PROCESS (a, b)
    y <= c;                                  BEGIN
END logic;                                       c <= a AND b;
                                                 y <= c;
                                             END PROCESS;
• Soluções NÃO SÃO equivalentes;          END logic;
• Exemplo adaptado de material
  educacional da Altera.

                                EEL7020 – Sistemas Digitais                5/37
Processos implícitos – revisão de atribuição condicional

architecture x of y is                        architecture x of y is
begin                                         begin

  q <= a when sela = ‘1’ else                   with sel select
       b when selb = ‘1’ else                   q <= a when “00”,
       c;                                            b when “01”,
end x;                                               c when “10”,
                                                     d when others;
                                              end x;




                          EEL7020 – Sistemas Digitais                  6/37
Processos explícitos – comparação e seleção
                                        architecture explicito of y is
architecture implicito of y is          begin
begin
                                           process (sela, selb, a, b, c)
   q <= a when sela = ‘1’ else             begin
        b when selb = ‘1’ else               if sela=‘1’ then
        c;                                      q <= a;
                                             elsif selb = ‘1’ then
end implicito;                                  q <= b;
                                             else
                                                q <= c;
                                             end if;
                                            end process;

                                        end explicito;
                             EEL7020 – Sistemas Digitais                 7/37
Processos explícitos – comparação e seleção
                                        architecture explicito of y is
 architecture implicito of y is         begin
 begin                                   process (sel, a, b, c, d)
    with sel select                      begin
    q <= a when “00”,                        case sel is
         b when “01”,                            when “00” =>
         c when “10”,                                    q <= a;
         d when others;                          when “01” =>
 end implicito;                                          q <= b;
                                                 when “10” =>
                                                         q <= c;
                                                 when others =>
                                                         q <= d;
                                             end case;
                                          end process;
                                        end explicito;
                             EEL7020 – Sistemas Digitais                 8/37
Estudo de caso: uso de processo explícito para
implementar registrador com reset assíncrono,
            clock e sinal de enable




                  EEL7020 – Sistemas Digitais     9/37
Deslocamento de vetor de entrada 1 bit à esquerda (1/2)
-- sr_in recebe palavra de N bits (vetor de N bits). A cada
-- pulso de clock, a palavra em sr_in é deslocada 1 bit para a
-- esquerda, e copiada para sr_out, também de N bits.
library ieee;
use ieee.std_logic_1164.all;

entity desloc_1_bit_esq is
 generic ( N : natural := 64 );
 port      ( clk     : in std_logic;
              enable : in std_logic;
              reset  : in std_logic;
              sr_in  : in std_logic_vector((N - 1) downto 0);
              sr_out : out std_logic_vector((N - 1) downto 0)
           );
end entity;
                         EEL7020 – Sistemas Digitais      10/37
Deslocamento de vetor de entrada 1 bit à esquerda (2/2)
architecture rtl of desloc_1_bit_esq is
  signal sr: std_logic_vector ((N - 1) downto 0); -- Registrador de N bits
begin
  process (clk, reset)
  begin
    if (reset = '0') then          -- Reset assíncrono do registrador
       sr <= (others => '0');
    elsif (rising_edge(clk)) then -- Sinal de clock do registrador (subida)
       if (enable = '1') then      -- Sinal de enable do registrador
          -- Desloca 1 bit para a esquerda. Bit mais significativo é perdido.
          sr((N - 1) downto 1) <= sr_in((N - 2) downto 0);
          sr(0) <= '0';
       end if;
    end if;
  end process;
  sr_out <= sr;
end rtl;


                                EEL7020 – Sistemas Digitais             11/37
Deslocamento de vetor de entrada 1 bit à esquerda

          Valor de entrada em sr_in = 93H

           1    0   0       1        0         0       1   1
           7    6    5      4         3         2      1   0



 1
 X         0    0   1       0        0         1       1   0    0
           7    6    5      4         3         2      1   0

           Valor de saída em sr_out = 26H


                         EEL7020 – Sistemas Digitais           12/37
Tarefa:
mini-calculadora com multiplicação e divisão por 2




                   EEL7020 – Sistemas Digitais       13/37
Tarefa – Descrição Textual
• Alterar a mini-calculadora desenvolvida nas aulas anteriores, de
  forma a realizar a “multiplicação por 2” e a “divisão por 2”.

• Utilizando um registrador de deslocamento, projetar um circuito
  para realizar operações de divisão por 2 (shift right).

• Utilizando um registrador de deslocamento, projetar um circuito
  para realizar operações de multiplicação por 2 (shift left).

• Substituir o componente que realiza a função F = not A pelo novo
  componente que realiza a multiplicação por 2.

• Substituir o componente que realiza a função F = A xor B pelo novo
  componente que realiza a divisão por 2.
Atenção!! Nesse novo circuito existem dois componentes que utilizam
apenas um operando, e dois componentes que utilizam dois
operandos. É preciso alterar a FSM para se adequar a essa situação!!

                            EEL7020 – Sistemas Digitais         14/37
top_calc.vhd




                                                            F=A+B
                             Registrador
                                           Q




                                                                                                              Registrador
                        D
                    8                                  8                                                 D
                                                                                               F(7..4)                              Decod.
                        EN                                               8                                                  Q
                                                                                                                                4       7-seg
                                                                                                         EN
                                                   8
                                                                                           4
                                                                                                                                                                   HEX1




                                                             F= A or B
                                                       8
                                                                         8   F1
                                                                                  00
                                                       8
                                                                             F2
Operandos                                                                         01
                                                                                               F(3..0)




                                                                                                              Registrador
                                                                                           F
SW(7 downto 0)                                                               F3   Mux                    D
                                                                                  10       8      4
                                                                                                                            Q        Decod.
                                                                             F4   11                                            4       7-seg
                                                                                                         EN




                                                             F=A/2
                                                                                       2
                                                                                                                                                                   HEX0
                                                                                  sel
                                                       8                 8
                                                                                           8



                                                                                               F(7..0)




                                                                                                                                         Registrador
                                                                                                                                    D
                                                             F=A*2



                                                                                                                                                       Q
                                                                                                                                    EN
                                                                                                                                                            8
                                                       8                 8


                                                                                                                                                           LEDR(7 downto 0)




                 Enable_1                      Clock       Reset    Seleção da operação
                                                              EEL7020 – Sistemas Digitais                            Enable_2                                   15/37
TOPO

                                                                                          HEX1


     Operandos
     SW(7 downto 0)
                          8


                                                                                          HEX0




                                                                                         LEDR
                                                                  2                (7 downto 0)


                               Enable_1                       Seleção   Enable_2

       Reset KEY(0)
    Clock CLOCK_50
                              Rst                            FSM
                              Clk      Máquina de estados com a função de
      Enter KEY(1)            Enter    “controlador” do fluxo de operações
Operação SW(17..16)           Operacao     realizadas pela calculadora.
                      2
                                    EEL7020 – Sistemas Digitais                       16/37
Outros templates com
processos explícitos do Quartus II




            EEL7020 – Sistemas Digitais   17/37
Quartus II – Templates de descrições VHDL com processos




                       EEL7020 – Sistemas Digitais   18/37
Basic Positive Edge Register with Asynchronous Reset and Clock Enable

process (<clock_signal>, <reset>)
begin
   -- Reset whenever the reset signal goes low, regardless
   -- of the clock or the clock enable
   if (<reset> = '0') then
        <register_variable> <= '0';
   -- If not resetting, and the clock signal is enabled,
   -- update the register output on the clock's rising edge
   elsif (rising_edge(<clock_signal>)) then
               if (<clock_enable> = '1') then
                       <register_variable> <= <data>;
               end if;
   end if;
end process;

                            EEL7020 – Sistemas Digitais        19/37
Basic Positive Edge Register with Asynchronous Reset

process (CLK, RST)
begin
   -- Reset whenever the reset signal goes low, regardless
   -- of the clock
   if (RST = '0') then
        Q <= '0';
   -- If not resetting update the register output
   -- on the clock's rising edge
   elsif (CLK’event and CLK = ‘1’) then
              Q <= D;
   end if;
end process;



                            EEL7020 – Sistemas Digitais   20/37
Binary counter (1/2)
-- Binary counter
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity binary_counter is
 generic (MIN_COUNT : natural := 0;
            MAX_COUNT : natural := 255);
 port (
       clk       : in std_logic;
       reset    : in std_logic;
       enable : in std_logic;
       q: out integer range MIN_COUNT to MAX_COUNT
       );
end entity;
                         EEL7020 – Sistemas Digitais   21/37
Binary counter (2/2)
architecture rtl of binary_cunter is
begin
   process (clk)
         variable cnt: integer range MIN_COUNT to MAX_COUNT;
   begin
         if (rising_edge(clk)) then
                if (reset = '1') then
                        -- Reset counter to 0
                       cnt := 0;
                elsif enable = ‘1’ then
                       cnt := cnt + 1;
                end if;
          end if;
          -- Output the current count
          q <= cnt;
   end process;
end rtl;
                         EEL7020 – Sistemas Digitais     22/37
Basic Shift Register with Asynchronous Reset (1/2)
-- One-bit wide, N-bit long shift register with asynchronous reset
library ieee;
use ieee.std_logic_1164.all;

entity basic_shift_register_asynchronous_reset is
 generic ( NUM_STAGES : natural := 256 );
 port      ( clk      : in std_logic;
              enable : in std_logic;
              reset   : in std_logic;
              sr_in   : in std_logic;
              sr_out : out std_logic
           );
end entity;


                               EEL7020 – Sistemas Digitais           23/37
Basic Shift Register with Asynchronous Reset (2/2)
architecture rtl of basic_shift_register_asynchronous_reset is
  type sr_length is array ((NUM_STAGES-1) downto 0) of std_logic;
  signal sr: sr_length;         -- Declare the shift register
begin
  process (clk, reset)
  begin
    if (reset = '1') then
       sr <= (others => '0');
    elsif (rising_edge(clk)) then
       if (enable = '1') then
          -- Shift data by one stage; data from last stage is lost
          sr((NUM_STAGES-1) downto 1) <= sr((NUM_STAGES-2) downto 0);
          sr(0) <= sr_in;
       end if;
    end if;
  end process;
  sr_out <= sr(NUM_STAGES-1);
end rtl;
                            EEL7020 – Sistemas Digitais         24/37
Four-State Mealy State Machine (1/5)
-- A Mealy machine has outputs that depend on both the state and the
-- inputs. When the inputs change, the outputs are updated immediately,
-- without waiting for a clock edge. The outputs can be written more than
-- once per state or per clock cycle.

library ieee;
use ieee.std_logic_1164.all;

entity four_state_mealy_state_machine is
 port (
       clk      : in std_logic;
       input    : in std_logic;
       reset   : in std_logic;
       output : out std_logic_vector (1 downto 0)
       );
end entity;
                              EEL7020 – Sistemas Digitais           25/37
Four-State Mealy State Machine (2/5)
architecture rtl of four_state_mealy_state_machine is
  -- Build an enumerated type for the state machine
  type state_type is (s0, s1, s2, s3);
  signal state : state_type;         -- Register to hold the current state
begin
     process (clk, reset)
     begin
        if (reset = ‘1’) then
            state <= s0;
        elsif (rising_edge(clk)) then
        -- Determine the next state synchronously, based on
        -- the current state and the input
               case state is
                   when s0 =>
                      if input = '1' then state <= s1;
                      else                 state <= s0;
                      end if;
                                EEL7020 – Sistemas Digitais             26/37
Four-State Mealy State Machine (3/5)
              when s1 =>
                  if input = '1' then        state <= s2;
                  else                       state <= s1;
                  end if;
              when s2 =>
                  if input = '1' then        state <= s3;
                  else                       state <= s2;
                  end if;
              when s3 =>
                  if input = '1' then        state <= s3;
                  else                       state <= s1;
                  end if;
        end case;
      end if;
end process;


                            EEL7020 – Sistemas Digitais     27/37
Four-State Mealy State Machine (4/5)


-- Determine the output based only on the current state
-- and the input (do not wait for a clock edge).
   process (state, input)
   begin
        case state is
                  when s0 =>
                     if input = '1' then
                             output <= “00”;
                     else
                             output <= “01”;
                     end if;




                             EEL7020 – Sistemas Digitais   28/37
Four-State Mealy State Machine (5/5)
             when s1 =>
                 if input = '1' then        output <= “01”;
                 else                       output <= “11”;
                 end if;
             when s2 =>
                 if input = '1' then        output <= “10”;
                 else                       output <= “10”;
                 end if;
             when s3 =>
                 if input = '1' then        output <= “11”;
                 else                       output <= “10”;
                 end if;
         end case;
       end process;
end rtl;


                           EEL7020 – Sistemas Digitais        29/37
Four-State Moore State Machine (1/4)
-- A Moore machine's outputs are dependent only on the current state.
-- The output is written only when the state changes. (State
-- transitions are synchronous.)

library ieee;
use ieee.std_logic_1164.all;

entity four_state_moore_state_machine is
 port (
       clk      : in std_logic;
       input    : in std_logic;
       reset   : in std_logic;
       output : out std_logic_vector (1 downto 0)
       );
end entity;

                             EEL7020 – Sistemas Digitais           30/37
Four-State Moore State Machine (2/4)
architecture rtl of four_state_moore_state_machine is
  -- Build an enumerated type for the state machine
  type state_type is (s0, s1, s2, s3);
  signal state : state_type;         -- Register to hold the current state
begin
     process (clk, reset)
     begin
        if (reset = ‘1’) then
            state <= s0;
        elsif (rising_edge(clk)) then
        -- Determine the next state synchronously, based on
        -- the current state and the input
               case state is
                   when s0 =>
                      if input = '1' then state <= s1;
                      else                 state <= s0;
                      end if;
                                EEL7020 – Sistemas Digitais             31/37
Four-State Moore State Machine (3/4)
              when s1 =>
                  if input = '1' then        state <= s2;
                  else                       state <= s1;
                  end if;
              when s2 =>
                  if input = '1' then        state <= s3;
                  else                       state <= s2;
                  end if;
              when s3 =>
                  if input = '1' then        state <= s3;
                  else                       state <= s1;
                  end if;
        end case;
      end if;
end process;


                            EEL7020 – Sistemas Digitais     32/37
Four-State Moore State Machine (4/4)

-- Output depends solely on the current state.
   process (state, input)
   begin
        case state is
                 when s0 =>
                      output <= “00”;
                 when s1 =>
                      output <= “01”;
                 when s2 =>
                      output <= “10”;
                 when s3 =>
                      output <= “11”;
       end case;
    end process;
end rtl;
                              EEL7020 – Sistemas Digitais   33/37
Single-port RAM with initial contents (1/4)
-- Single-port RAM with single read/write address and initial contents
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all ;

entity single_port_ram_with_init is
     generic (DATA_WIDTH : natural := 8;
               ADDR_WIDTH : natural := 6);
     port (
       clk : in std_logic;
       addr: in natural range 0 to 2**ADDR_WIDTH - 1;
       data: in std_logic_vector((DATA_WIDTH-1) downto 0);
       we : in std_logic := '1';
       q : out std_logic_vector((DATA_WIDTH -1) downto 0)
       );
end single_port_ram_with_init;
                              EEL7020 – Sistemas Digitais            34/37
Single-port RAM with initial contents (2/4)

architecture rtl of single_port_ram_with_init is
  -- Build a 2-D array type for the RAM
  subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0);
  type memory_t is array(2**ADDR_WIDTH-1 downto 0) of word_t;

 function init_ram return memory_t is
     variable tmp : memory_t := (others => (others => '0'));
 begin
     for addr_pos in 0 to 2**ADDR_WIDTH - 1 loop
         -- Initialize each address with the address itself
         tmp(addr_pos) := std_logic_vector(to_unsigned(addr_pos,
                                               DATA_WIDTH));
    end loop;
    return tmp;
  end init_ram;

                           EEL7020 – Sistemas Digitais         35/37
Single-port RAM with initial contents (3/4)


   -- Declare the RAM signal and specify a default value.
   -- Quartus II will create a memory initialization file (.mif) based on
   -- the default value.

   signal ram : memory_t := init_ram;

   -- Register to hold the address
   signal addr_reg : natural range 0 to 2**ADDR_WIDTH-1;




                              EEL7020 – Sistemas Digitais             36/37
Single-port RAM with initial contents (4/4)

begin
           process(clk)
           begin
               if (rising_edge(clk)) then
                     if (we = '1') then
                          ram(addr) <= data;
                     end if;
                      -- Register the address for reading
                      addr_reg <= addr;
               end if;
            end process;
            q <= ram(addr_reg);
end rtl;



                                  EEL7020 – Sistemas Digitais   37/37

Mais conteúdo relacionado

Mais procurados

Mais procurados (7)

Create your first model for a simple logic circuit
Create your first model for a simple logic circuitCreate your first model for a simple logic circuit
Create your first model for a simple logic circuit
 
Digital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECEDigital System Design Lab Report - VHDL ECE
Digital System Design Lab Report - VHDL ECE
 
Components - Crossing the Boundaries while Analyzing Heterogeneous Component-...
Components - Crossing the Boundaries while Analyzing Heterogeneous Component-...Components - Crossing the Boundaries while Analyzing Heterogeneous Component-...
Components - Crossing the Boundaries while Analyzing Heterogeneous Component-...
 
Introduction to-vhdl
Introduction to-vhdlIntroduction to-vhdl
Introduction to-vhdl
 
ECAD lab manual
ECAD lab manualECAD lab manual
ECAD lab manual
 
Embedded system design psoc lab report
Embedded system design psoc lab reportEmbedded system design psoc lab report
Embedded system design psoc lab report
 
PHP Forum Paris 2012: Magic behind the numbers. Software metrics in practice
PHP Forum Paris 2012: Magic behind the numbers. Software metrics in practicePHP Forum Paris 2012: Magic behind the numbers. Software metrics in practice
PHP Forum Paris 2012: Magic behind the numbers. Software metrics in practice
 

Destaque

Lab1 apresentacao disciplina
Lab1 apresentacao disciplinaLab1 apresentacao disciplina
Lab1 apresentacao disciplina
Eduardo Bezerra
 
Guía integradaactividades 401302_2016-16(04)
Guía integradaactividades 401302_2016-16(04)Guía integradaactividades 401302_2016-16(04)
Guía integradaactividades 401302_2016-16(04)
Andres Peña
 

Destaque (15)

Incursionoenlaculturadigital 140514150203-phpapp01
Incursionoenlaculturadigital 140514150203-phpapp01Incursionoenlaculturadigital 140514150203-phpapp01
Incursionoenlaculturadigital 140514150203-phpapp01
 
Guía de actividades y rúbrica de evaluación tarea 2 y tarea 4
Guía de actividades y rúbrica de evaluación tarea 2 y tarea 4Guía de actividades y rúbrica de evaluación tarea 2 y tarea 4
Guía de actividades y rúbrica de evaluación tarea 2 y tarea 4
 
Lab6 flipflop
Lab6 flipflopLab6 flipflop
Lab6 flipflop
 
Lab5 decod 7seg
Lab5 decod 7segLab5 decod 7seg
Lab5 decod 7seg
 
WHAT TO DO WHEN YOU’RE FACED WITH A CAR ACCIDENT
WHAT TO DO WHEN YOU’RE FACED WITH A CAR ACCIDENTWHAT TO DO WHEN YOU’RE FACED WITH A CAR ACCIDENT
WHAT TO DO WHEN YOU’RE FACED WITH A CAR ACCIDENT
 
The Kickass Wall
The Kickass WallThe Kickass Wall
The Kickass Wall
 
2012 feb startup meetup opening slides
2012 feb startup meetup opening slides2012 feb startup meetup opening slides
2012 feb startup meetup opening slides
 
Lab1 apresentacao disciplina
Lab1 apresentacao disciplinaLab1 apresentacao disciplina
Lab1 apresentacao disciplina
 
Lab10 somadores
Lab10 somadoresLab10 somadores
Lab10 somadores
 
Media Trendy 2012 Bernhard Glock - What Inspires Me Most Today After Having L...
Media Trendy 2012 Bernhard Glock - What Inspires Me Most Today After Having L...Media Trendy 2012 Bernhard Glock - What Inspires Me Most Today After Having L...
Media Trendy 2012 Bernhard Glock - What Inspires Me Most Today After Having L...
 
Presentacioncatedraunadista 141205102829-conversion-gate01
Presentacioncatedraunadista 141205102829-conversion-gate01Presentacioncatedraunadista 141205102829-conversion-gate01
Presentacioncatedraunadista 141205102829-conversion-gate01
 
Guía de actividades y rúbrica de evaluación tarea 1 reconocimiento manifies...
Guía de actividades y rúbrica de evaluación tarea 1 reconocimiento   manifies...Guía de actividades y rúbrica de evaluación tarea 1 reconocimiento   manifies...
Guía de actividades y rúbrica de evaluación tarea 1 reconocimiento manifies...
 
Evaluacio aprendo a aprender a modaliad a distancia
Evaluacio aprendo a aprender a modaliad a distanciaEvaluacio aprendo a aprender a modaliad a distancia
Evaluacio aprendo a aprender a modaliad a distancia
 
Guía integradaactividades 401302_2016-16(04)
Guía integradaactividades 401302_2016-16(04)Guía integradaactividades 401302_2016-16(04)
Guía integradaactividades 401302_2016-16(04)
 
Syllabus 401302 2016-16(04)
Syllabus 401302 2016-16(04)Syllabus 401302 2016-16(04)
Syllabus 401302 2016-16(04)
 

Semelhante a Lab9 processos

Clockless design language - ilia greenblat
Clockless design language - ilia greenblatClockless design language - ilia greenblat
Clockless design language - ilia greenblat
chiportal
 
Day2.Combinational Logic
Day2.Combinational LogicDay2.Combinational Logic
Day2.Combinational Logic
Ron Liu
 

Semelhante a Lab9 processos (20)

Vhdl programs
Vhdl programsVhdl programs
Vhdl programs
 
vhdll.docx
vhdll.docxvhdll.docx
vhdll.docx
 
Digital system design lab manual
Digital system design lab manualDigital system design lab manual
Digital system design lab manual
 
Fpga creating counter with external clock
Fpga   creating counter with external clockFpga   creating counter with external clock
Fpga creating counter with external clock
 
Reporte vhdl9
Reporte vhdl9Reporte vhdl9
Reporte vhdl9
 
Digital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDLDigital to analog -Sqaure waveform generator in VHDL
Digital to analog -Sqaure waveform generator in VHDL
 
FPGA Tutorial - LCD Interface
FPGA Tutorial - LCD InterfaceFPGA Tutorial - LCD Interface
FPGA Tutorial - LCD Interface
 
Introduction to Polyhedral Compilation
Introduction to Polyhedral CompilationIntroduction to Polyhedral Compilation
Introduction to Polyhedral Compilation
 
Fpga creating counter with internal clock
Fpga   creating counter with internal clockFpga   creating counter with internal clock
Fpga creating counter with internal clock
 
Combinational Circuits
Combinational CircuitsCombinational Circuits
Combinational Circuits
 
VHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLESVHDL PROGRAMS FEW EXAMPLES
VHDL PROGRAMS FEW EXAMPLES
 
Vhdl
VhdlVhdl
Vhdl
 
Clockless design language - ilia greenblat
Clockless design language - ilia greenblatClockless design language - ilia greenblat
Clockless design language - ilia greenblat
 
Data Flow Modeling
Data Flow ModelingData Flow Modeling
Data Flow Modeling
 
HDL PROGRAMMING-3.pdf
HDL PROGRAMMING-3.pdfHDL PROGRAMMING-3.pdf
HDL PROGRAMMING-3.pdf
 
Day2.Combinational Logic
Day2.Combinational LogicDay2.Combinational Logic
Day2.Combinational Logic
 
Tdm to vo ip 2
Tdm to vo ip 2Tdm to vo ip 2
Tdm to vo ip 2
 
Basic-VHDL-Constructs1.ppt
Basic-VHDL-Constructs1.pptBasic-VHDL-Constructs1.ppt
Basic-VHDL-Constructs1.ppt
 
Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)Verilog lab manual (ECAD and VLSI Lab)
Verilog lab manual (ECAD and VLSI Lab)
 
Vhdl lab manual
Vhdl lab manualVhdl lab manual
Vhdl lab manual
 

Lab9 processos

  • 1. Universidade Federal de Santa Catarina Centro Tecnológico – CTC Departamento de Engenharia Elétrica http://gse.ufsc.br “EEL7020 – Sistemas Digitais” Prof. Eduardo Augusto Bezerra Eduardo.Bezerra@eel.ufsc.br Florianópolis, agosto de 2012.
  • 2. Sistemas Digitais Processos implícitos e explícitos EEL7020 – Sistemas Digitais 2/37
  • 3. Processos implícitos e explícitos Processos implícitos: • Atribuições com sinais em paralelo (exemplo: LEDR <= SW); • Atribuições com seleção (with / select) e comparação (when) • Componentes instanciados (component / port map); Processos explícitos: • Definidos com a palavra reservada process. EEL7020 – Sistemas Digitais 3/37
  • 4. Processos implícitos e explícitos LIBRARY IEEE; LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_1164.ALL; ENTITY implicito IS ENTITY explicito IS PORT ( PORT ( a, b : IN STD_LOGIC; a,b : IN STD_LOGIC; y : OUT STD_LOGIC y : OUT STD_LOGIC ); ); END implicito; END explicito; ARCHITECTURE logic OF implicito IS ARCHITECTURE logic OF explicito IS SIGNAL c : STD_LOGIC; SIGNAL c : STD_LOGIC; BEGIN BEGIN c <= a AND b; PROCESS (a, b) y <= c; BEGIN END logic; c <= a AND b; END PROCESS; PROCESS (c) • Soluções equivalentes; BEGIN • Exemplo adaptado de material y <= c; educacional da Altera. END PROCESS; END logic; EEL7020 – Sistemas Digitais 4/37
  • 5. Processos implícitos e explícitos LIBRARY IEEE; LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_1164.ALL; ENTITY implicito IS ENTITY explicito IS PORT ( PORT ( a, b : IN STD_LOGIC; a,b : IN STD_LOGIC; y : OUT STD_LOGIC y : OUT STD_LOGIC ); ); END implicito; END explicito; ARCHITECTURE logic OF implicito IS ARCHITECTURE logic OF explicito IS SIGNAL c : STD_LOGIC; SIGNAL c : STD_LOGIC; BEGIN BEGIN c <= a AND b; PROCESS (a, b) y <= c; BEGIN END logic; c <= a AND b; y <= c; END PROCESS; • Soluções NÃO SÃO equivalentes; END logic; • Exemplo adaptado de material educacional da Altera. EEL7020 – Sistemas Digitais 5/37
  • 6. Processos implícitos – revisão de atribuição condicional architecture x of y is architecture x of y is begin begin q <= a when sela = ‘1’ else with sel select b when selb = ‘1’ else q <= a when “00”, c; b when “01”, end x; c when “10”, d when others; end x; EEL7020 – Sistemas Digitais 6/37
  • 7. Processos explícitos – comparação e seleção architecture explicito of y is architecture implicito of y is begin begin process (sela, selb, a, b, c) q <= a when sela = ‘1’ else begin b when selb = ‘1’ else if sela=‘1’ then c; q <= a; elsif selb = ‘1’ then end implicito; q <= b; else q <= c; end if; end process; end explicito; EEL7020 – Sistemas Digitais 7/37
  • 8. Processos explícitos – comparação e seleção architecture explicito of y is architecture implicito of y is begin begin process (sel, a, b, c, d) with sel select begin q <= a when “00”, case sel is b when “01”, when “00” => c when “10”, q <= a; d when others; when “01” => end implicito; q <= b; when “10” => q <= c; when others => q <= d; end case; end process; end explicito; EEL7020 – Sistemas Digitais 8/37
  • 9. Estudo de caso: uso de processo explícito para implementar registrador com reset assíncrono, clock e sinal de enable EEL7020 – Sistemas Digitais 9/37
  • 10. Deslocamento de vetor de entrada 1 bit à esquerda (1/2) -- sr_in recebe palavra de N bits (vetor de N bits). A cada -- pulso de clock, a palavra em sr_in é deslocada 1 bit para a -- esquerda, e copiada para sr_out, também de N bits. library ieee; use ieee.std_logic_1164.all; entity desloc_1_bit_esq is generic ( N : natural := 64 ); port ( clk : in std_logic; enable : in std_logic; reset : in std_logic; sr_in : in std_logic_vector((N - 1) downto 0); sr_out : out std_logic_vector((N - 1) downto 0) ); end entity; EEL7020 – Sistemas Digitais 10/37
  • 11. Deslocamento de vetor de entrada 1 bit à esquerda (2/2) architecture rtl of desloc_1_bit_esq is signal sr: std_logic_vector ((N - 1) downto 0); -- Registrador de N bits begin process (clk, reset) begin if (reset = '0') then -- Reset assíncrono do registrador sr <= (others => '0'); elsif (rising_edge(clk)) then -- Sinal de clock do registrador (subida) if (enable = '1') then -- Sinal de enable do registrador -- Desloca 1 bit para a esquerda. Bit mais significativo é perdido. sr((N - 1) downto 1) <= sr_in((N - 2) downto 0); sr(0) <= '0'; end if; end if; end process; sr_out <= sr; end rtl; EEL7020 – Sistemas Digitais 11/37
  • 12. Deslocamento de vetor de entrada 1 bit à esquerda Valor de entrada em sr_in = 93H 1 0 0 1 0 0 1 1 7 6 5 4 3 2 1 0 1 X 0 0 1 0 0 1 1 0 0 7 6 5 4 3 2 1 0 Valor de saída em sr_out = 26H EEL7020 – Sistemas Digitais 12/37
  • 13. Tarefa: mini-calculadora com multiplicação e divisão por 2 EEL7020 – Sistemas Digitais 13/37
  • 14. Tarefa – Descrição Textual • Alterar a mini-calculadora desenvolvida nas aulas anteriores, de forma a realizar a “multiplicação por 2” e a “divisão por 2”. • Utilizando um registrador de deslocamento, projetar um circuito para realizar operações de divisão por 2 (shift right). • Utilizando um registrador de deslocamento, projetar um circuito para realizar operações de multiplicação por 2 (shift left). • Substituir o componente que realiza a função F = not A pelo novo componente que realiza a multiplicação por 2. • Substituir o componente que realiza a função F = A xor B pelo novo componente que realiza a divisão por 2. Atenção!! Nesse novo circuito existem dois componentes que utilizam apenas um operando, e dois componentes que utilizam dois operandos. É preciso alterar a FSM para se adequar a essa situação!! EEL7020 – Sistemas Digitais 14/37
  • 15. top_calc.vhd F=A+B Registrador Q Registrador D 8 8 D F(7..4) Decod. EN 8 Q 4 7-seg EN 8 4 HEX1 F= A or B 8 8 F1 00 8 F2 Operandos 01 F(3..0) Registrador F SW(7 downto 0) F3 Mux D 10 8 4 Q Decod. F4 11 4 7-seg EN F=A/2 2 HEX0 sel 8 8 8 F(7..0) Registrador D F=A*2 Q EN 8 8 8 LEDR(7 downto 0) Enable_1 Clock Reset Seleção da operação EEL7020 – Sistemas Digitais Enable_2 15/37
  • 16. TOPO HEX1 Operandos SW(7 downto 0) 8 HEX0 LEDR 2 (7 downto 0) Enable_1 Seleção Enable_2 Reset KEY(0) Clock CLOCK_50 Rst FSM Clk Máquina de estados com a função de Enter KEY(1) Enter “controlador” do fluxo de operações Operação SW(17..16) Operacao realizadas pela calculadora. 2 EEL7020 – Sistemas Digitais 16/37
  • 17. Outros templates com processos explícitos do Quartus II EEL7020 – Sistemas Digitais 17/37
  • 18. Quartus II – Templates de descrições VHDL com processos EEL7020 – Sistemas Digitais 18/37
  • 19. Basic Positive Edge Register with Asynchronous Reset and Clock Enable process (<clock_signal>, <reset>) begin -- Reset whenever the reset signal goes low, regardless -- of the clock or the clock enable if (<reset> = '0') then <register_variable> <= '0'; -- If not resetting, and the clock signal is enabled, -- update the register output on the clock's rising edge elsif (rising_edge(<clock_signal>)) then if (<clock_enable> = '1') then <register_variable> <= <data>; end if; end if; end process; EEL7020 – Sistemas Digitais 19/37
  • 20. Basic Positive Edge Register with Asynchronous Reset process (CLK, RST) begin -- Reset whenever the reset signal goes low, regardless -- of the clock if (RST = '0') then Q <= '0'; -- If not resetting update the register output -- on the clock's rising edge elsif (CLK’event and CLK = ‘1’) then Q <= D; end if; end process; EEL7020 – Sistemas Digitais 20/37
  • 21. Binary counter (1/2) -- Binary counter library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity binary_counter is generic (MIN_COUNT : natural := 0; MAX_COUNT : natural := 255); port ( clk : in std_logic; reset : in std_logic; enable : in std_logic; q: out integer range MIN_COUNT to MAX_COUNT ); end entity; EEL7020 – Sistemas Digitais 21/37
  • 22. Binary counter (2/2) architecture rtl of binary_cunter is begin process (clk) variable cnt: integer range MIN_COUNT to MAX_COUNT; begin if (rising_edge(clk)) then if (reset = '1') then -- Reset counter to 0 cnt := 0; elsif enable = ‘1’ then cnt := cnt + 1; end if; end if; -- Output the current count q <= cnt; end process; end rtl; EEL7020 – Sistemas Digitais 22/37
  • 23. Basic Shift Register with Asynchronous Reset (1/2) -- One-bit wide, N-bit long shift register with asynchronous reset library ieee; use ieee.std_logic_1164.all; entity basic_shift_register_asynchronous_reset is generic ( NUM_STAGES : natural := 256 ); port ( clk : in std_logic; enable : in std_logic; reset : in std_logic; sr_in : in std_logic; sr_out : out std_logic ); end entity; EEL7020 – Sistemas Digitais 23/37
  • 24. Basic Shift Register with Asynchronous Reset (2/2) architecture rtl of basic_shift_register_asynchronous_reset is type sr_length is array ((NUM_STAGES-1) downto 0) of std_logic; signal sr: sr_length; -- Declare the shift register begin process (clk, reset) begin if (reset = '1') then sr <= (others => '0'); elsif (rising_edge(clk)) then if (enable = '1') then -- Shift data by one stage; data from last stage is lost sr((NUM_STAGES-1) downto 1) <= sr((NUM_STAGES-2) downto 0); sr(0) <= sr_in; end if; end if; end process; sr_out <= sr(NUM_STAGES-1); end rtl; EEL7020 – Sistemas Digitais 24/37
  • 25. Four-State Mealy State Machine (1/5) -- A Mealy machine has outputs that depend on both the state and the -- inputs. When the inputs change, the outputs are updated immediately, -- without waiting for a clock edge. The outputs can be written more than -- once per state or per clock cycle. library ieee; use ieee.std_logic_1164.all; entity four_state_mealy_state_machine is port ( clk : in std_logic; input : in std_logic; reset : in std_logic; output : out std_logic_vector (1 downto 0) ); end entity; EEL7020 – Sistemas Digitais 25/37
  • 26. Four-State Mealy State Machine (2/5) architecture rtl of four_state_mealy_state_machine is -- Build an enumerated type for the state machine type state_type is (s0, s1, s2, s3); signal state : state_type; -- Register to hold the current state begin process (clk, reset) begin if (reset = ‘1’) then state <= s0; elsif (rising_edge(clk)) then -- Determine the next state synchronously, based on -- the current state and the input case state is when s0 => if input = '1' then state <= s1; else state <= s0; end if; EEL7020 – Sistemas Digitais 26/37
  • 27. Four-State Mealy State Machine (3/5) when s1 => if input = '1' then state <= s2; else state <= s1; end if; when s2 => if input = '1' then state <= s3; else state <= s2; end if; when s3 => if input = '1' then state <= s3; else state <= s1; end if; end case; end if; end process; EEL7020 – Sistemas Digitais 27/37
  • 28. Four-State Mealy State Machine (4/5) -- Determine the output based only on the current state -- and the input (do not wait for a clock edge). process (state, input) begin case state is when s0 => if input = '1' then output <= “00”; else output <= “01”; end if; EEL7020 – Sistemas Digitais 28/37
  • 29. Four-State Mealy State Machine (5/5) when s1 => if input = '1' then output <= “01”; else output <= “11”; end if; when s2 => if input = '1' then output <= “10”; else output <= “10”; end if; when s3 => if input = '1' then output <= “11”; else output <= “10”; end if; end case; end process; end rtl; EEL7020 – Sistemas Digitais 29/37
  • 30. Four-State Moore State Machine (1/4) -- A Moore machine's outputs are dependent only on the current state. -- The output is written only when the state changes. (State -- transitions are synchronous.) library ieee; use ieee.std_logic_1164.all; entity four_state_moore_state_machine is port ( clk : in std_logic; input : in std_logic; reset : in std_logic; output : out std_logic_vector (1 downto 0) ); end entity; EEL7020 – Sistemas Digitais 30/37
  • 31. Four-State Moore State Machine (2/4) architecture rtl of four_state_moore_state_machine is -- Build an enumerated type for the state machine type state_type is (s0, s1, s2, s3); signal state : state_type; -- Register to hold the current state begin process (clk, reset) begin if (reset = ‘1’) then state <= s0; elsif (rising_edge(clk)) then -- Determine the next state synchronously, based on -- the current state and the input case state is when s0 => if input = '1' then state <= s1; else state <= s0; end if; EEL7020 – Sistemas Digitais 31/37
  • 32. Four-State Moore State Machine (3/4) when s1 => if input = '1' then state <= s2; else state <= s1; end if; when s2 => if input = '1' then state <= s3; else state <= s2; end if; when s3 => if input = '1' then state <= s3; else state <= s1; end if; end case; end if; end process; EEL7020 – Sistemas Digitais 32/37
  • 33. Four-State Moore State Machine (4/4) -- Output depends solely on the current state. process (state, input) begin case state is when s0 => output <= “00”; when s1 => output <= “01”; when s2 => output <= “10”; when s3 => output <= “11”; end case; end process; end rtl; EEL7020 – Sistemas Digitais 33/37
  • 34. Single-port RAM with initial contents (1/4) -- Single-port RAM with single read/write address and initial contents library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all ; entity single_port_ram_with_init is generic (DATA_WIDTH : natural := 8; ADDR_WIDTH : natural := 6); port ( clk : in std_logic; addr: in natural range 0 to 2**ADDR_WIDTH - 1; data: in std_logic_vector((DATA_WIDTH-1) downto 0); we : in std_logic := '1'; q : out std_logic_vector((DATA_WIDTH -1) downto 0) ); end single_port_ram_with_init; EEL7020 – Sistemas Digitais 34/37
  • 35. Single-port RAM with initial contents (2/4) architecture rtl of single_port_ram_with_init is -- Build a 2-D array type for the RAM subtype word_t is std_logic_vector((DATA_WIDTH-1) downto 0); type memory_t is array(2**ADDR_WIDTH-1 downto 0) of word_t; function init_ram return memory_t is variable tmp : memory_t := (others => (others => '0')); begin for addr_pos in 0 to 2**ADDR_WIDTH - 1 loop -- Initialize each address with the address itself tmp(addr_pos) := std_logic_vector(to_unsigned(addr_pos, DATA_WIDTH)); end loop; return tmp; end init_ram; EEL7020 – Sistemas Digitais 35/37
  • 36. Single-port RAM with initial contents (3/4) -- Declare the RAM signal and specify a default value. -- Quartus II will create a memory initialization file (.mif) based on -- the default value. signal ram : memory_t := init_ram; -- Register to hold the address signal addr_reg : natural range 0 to 2**ADDR_WIDTH-1; EEL7020 – Sistemas Digitais 36/37
  • 37. Single-port RAM with initial contents (4/4) begin process(clk) begin if (rising_edge(clk)) then if (we = '1') then ram(addr) <= data; end if; -- Register the address for reading addr_reg <= addr; end if; end process; q <= ram(addr_reg); end rtl; EEL7020 – Sistemas Digitais 37/37