Documente Academic
Documente Profesional
Documente Cultură
A.E.T.
S.l. dr. ing. Ionel Petrescu
Structura cursului
• Notiuni de automatizari
•Structura FPGA
• Schematics
• Simularea circuitelor
• Limbajul VHDL
09:17 2
Notare
Laborator: 40%
Examen: 60%
•Examen partial: 30%
•Examen final: 30%
09:17 3
Obiectivele cursului
Acumularea de cunostinte si abilitati privind:
– Automatizarea proceselor
– Bucle de reglare
– Programarea cu limbajul de descriere hardware
VHDL
– Sinteza si simularea circuitelor electronice digitale
sau sistemelor care pot fi implementate fizic.
– Implementarea programelor scrise in limbajul VHDL,
pe structura reprogramabila FPGA
09:17 4
Cunostinte minime necesare pentru promovarea
examenului
09:17 5
Referinte bibliografice
1. D. Burdia, G.S. Popescu, Proiectare asistata de calculator a circuitelor
electronice, MATRIXROM, 1999
2. G. Toacse, D. Nicula, Electronica Digitala, Teora, 1996
3. G.V. Iana, G. Şerban, L. Ionescu, P. Anghelescu, PROGRAMAREA CU LIMBAJE
DE DESCRIERE HARDWARE, UNIVERSITATEA DIN PITESTI, 2009
4. S. Brown, Z. Vranesic, Fundamentals of Digital Logic With VHDL
Design, University of Toronto, McGraw Hill, 2005
5. D. L. Perry, VHDL Programming by Examle, McGraw Hill, 2002
3. J. Weber, M. Meaudre, Le langage VHDL Cours et exercises, Dumond,
2004
6. IEEE Computer Society, 1076 IEEE Standard VHDL – Language
Reference Manual, IEEE, 2002
7. V. A. Pedroni, Circuit Design with VHDL, Cambrige, MIT Press, 2004
8. P.P.Chu, FPGA Prototyping by VHDL Examples – Xilinx Spartan 3
Version, WILEY, 2008
9. www.xilinx.com
10. www.digilentinc.com
09:17 6
Glosar
CAD - Computer Aided Drafting , Computer Aided Design
ECAD - Electronic Computer Aided Design
CAE - Computer Aided Engineering
VHDL - VHSIC Hardware Description Language
VHSIC - Very High Speed Integrated Circuits
CPLD - Complex Programmable Logic Devices
FPGA - Field Programmable Gate Arrays
ASIC - Application Specific Integrated Circuits
RTL – Register-Transfer Level
HDL - Hardware Description Language
DSP - Digital Signal Processor
GPP - General Purpose Processor
RISC - Reduced Instruction Set Computer
09:17 7
• Automatizare – efectuarea repetitiva a unor
operatii fara interventia umana directa
• Procesele automatizate necesita
senzori/traductoare si/sau actuatori.
2. If verror is SP and
d/dtverror is SP or ZE
then Vmotor is SP.
3. If verror is ZE and
d/dtverror is SP then
Vmotor is ZE.
4. If verror is ZE and
d/dtverror is SN then
Vmotor is SN.
5. If verror is SN and
d/dtverror is SN then
Vmotor is SN.
6. If verror is LN and
d/dtverror is any then
Vmotor is LN.
Exemplu
• Consider the case where verror = 30 rps and
d/dt verror = 1 rps/s.
Functii membre - exemplu
RN
Functia de activare
Implementari
• Relee (digitale)
• Optocuploare (digitale)
• uC/uP
• PLC
• PLD
Proiectare
Curs AET 2
Introducere
12:31 1
– În proiectele electronice de inceput erau folosite componente
analogice care au un preţ relativ redus, însă, dezavantajele
principale ale sistemelor analogice constau în:
– sensibilitate la variaţiile de temperatură,
– îmbătrânirea mai rapidă a componentelor,
– dificultatea de a îmbunătăţi sistemul cu noi caracteristici.
– Sistemele digitale elimină abaterile cauzate de variaţiile de
temperatură, iar îmbunătăţirea caracteristicilor sistemului la un
moment dat se poate realiza foarte uşor prin modificarea
softului procesorului programabil conţinut de sistem.
12:31 2
Principalele circuite digitale complexe sunt:
12:31 4
Uşurinţă
Implementare Consum de Flexibilitate Concluzii
Performanţa Preţ în
pe piaţă putere ulterioară
dezvoltare
ASIC Nesatisfăcător Foarte Bun Foarte Bun Satisfăcător Bun Nesatisfăcător Satisfăcător
Foarte
DSP Foarte Bun Bun Bun Foarte Bun Foarte Bun Foarte Bun
Bun
Foarte
FPGA Bun Foarte Bun Bunr Satisfăcător Bun Bun
Bun
MCU Foarte Bun Satisfăcător Foarte Bun Bun Satisfăcător Foarte Bun Bun
RISC/
Bun Bun Satisfăcător Bun Satisfăcător Foarte Bun Bun
GPP
12:31 5
12:31 6
INTRODUCERE ÎN DOMENIUL CIRCUITELOR LOGICE
PROGRAMABILE
12:31 7
12:31 8
12:31 9
ROM
12:31 10
ROM
• Constituit dintr-o arie de dispozitive
semiconductoare interconectate astfel incat sa
stocheze o matrice de date binare.
• O ROM cu n intrari si m iesiri contine o matrice
de 2n cuvinte de m biti lungime.
• Poate stoca orice tip de circuit combinational.
• Look-up table - stocheaza toate combinatiile
de intrari
12:31 11
Exemplu look-up table
12:31 12
Tipuri de ROM
• Mask programmable ROM
• User programmable ROM (PROM)
• EPROM
• EEPROM
• FLASH
12:31 13
• Unul dintre cele mai folosite circuite logice
programabile a fost memoria de tip ROM
programabilă o singură dată (PROM).
12:31 14
PROM neprogramat
PROM programat
• Plecând de la această arhitectură s-au
dezvoltat ariile logice programabile de tip PLA
(Programmable Logic Array) dedicate
implementării funcţiilor logice.
• Combinarea structurii PLA-urilor cu
tehnologia PROM a avut ca rezultat
dezvoltarea dispozitivelor logice programabile
de tip FPLA (Field Programmable Logic
Array), care au apărut pe piaţă la mijlocul
anilor ’70.
Dispozitive logice programabile
simple
• În general circuitele PLD cu densitate
redusă de porţi logice (PLA şi PAL), sunt
prezente pe piaţă în capsule de 20 sau 44
de pini şi au o densitate cuprinsă între 100
şi 999 porţi logice.
• Se mai numesc circuite logice programabile
simple sau SPLD-uri (Simple PLD).
• Structura de tip arie logică SI-SAU
recomandă folosirea circuitele SPLD pentru
implementarea ecuaţiilor logice sub forma
sumelor de produse.
• Unele dintre îmbunătăţirile recente ale
circuitelor SPLD sunt:
– porturi de intrare/ieşire programabile,
– porturi de intrare/ieşire bidirecţionale,
– registre de configurare mai flexibile şi
– o schemă de clock mai flexibilă.
• Circuitele SPLD sunt mai uşor de utilizat, de
proiectat şi programat.
• Produsele care beneficiază de avantajele oferite
de circuitele SPLD sunt componentele de reţea
care cer performanţe ridicate per ansamblu:
– hub-uri de reţea
– bridge-uri,
– routere.
• Alte produse vizate de SPLD-uri sunt: sunt cele
din zona telefoniei mobile, video game-urilor şi a
hand-held web browserelor.
Programmable Logic Arrays
• m functii cu n variabile
12:31 21
PLA
12:31 22
PLA
12:31 23
• FPLA-urile au un număr fix de intrări, de ieşiri
şi un număr fix de termeni de tipul produs.
• Avantajul oferit de circuitele din această
familie este că atât aria logică de porţi ŞI cât
şi cea de porţi SAU sunt programabile
• Totuşi acest tip de circuite logice
programabile au avut un succes limitat
deoarece aveau viteză scăzută de lucru şi
erau dificil de programat.
• Logica programată a devenit mai populară la
mijlocul anilor 1970 odată cu apariţia ariilor
logice programabile de tip PAL-uri
(Programmable Array Logic).
• Acest tip de arhitectură combină o arie
programabilă de porţi ŞI cu o arie de porţi
SAU fixă (spre deosebire de circuitele PLA la
care atât aria de porţi ŞI cât şi cea de porţi
SAU sunt programabile).
Programmable Array Logic
12:31 26
Programmable Logic Devices/Generic
Array Logic
12:31 27
Complex Programmable Logic Devices
12:31 28
CPLD
12:31 29
Programming Technologies
• Fuse and anti-fuse - OTP
– fuse makes or breaks link between two wires
– typical connections are 50-300 ohm
– one-time programmable
• Flash/EEPROM
– High density
– Process issues
• RAM-based - volatile
– memory bit controls a switch that
connects/disconnects two wires
– typical connections are .5K-1K ohm
– can be programmed and re-programmed easily
(tested at factory)
30
simple programmable function
Fusible link
technologies
Antifuse
technologies
OTP
Mask-programmed device
PROMs
EPROM-based technologies
An EPROM transistor-based memory
cell.
EEPROM-based technologies
FLASH-based technologies
• Similar cu EPROM sau EEPROM, dar cu strat
mai subtire de oxid
Curs 3
FPGA
Technology timeline (dates are
approximate)
Arhitecturi
FPGA Programming Technologies
• Static RAM programming technology
• EPROM/EEPROM/Flash programming
technology
• Antifuse programming technology
SRAM Programming Technology
Programmable Logic Block
Architectures
CLB
9
Look-Up Table–Based Programmable
Logic Blocks
CLB – LUT based
12
LUT - based
13
Logic Blocks Based on Multiplexers and
Gates
MUX - based
16
XILINX Logic Cell
17
Programmable Interconnects
Interconnects in Symmetric Array FPGAs
General-Purpose Interconnect
Interconnects in Symmetric Array FPGAs
Direct Interconnects
Interconnects in Symmetric Array FPGAs
Global Lines
Interconnects in Row-Based FPGAs
Programmable I/O Blocks in FPGAs
Dedicated Specialized Components in
FPGAs
• Dedicated Memory
• Dedicated Arithmetic Units
• Digital Signal Processing Blocks
• Embedded Processors
• Content Addressable Memories
Other Blocks
26
Other Blocks – MAC (multiplier and
adder cell)
27
Other Blocks - Clock managers
28
Other Blocks - Clock managers
• Jitter removal
• Frequency synthesis
• Phase shifting
• Clock multiplication
• Clock division
29
Other Blocks
30
Xilinx FPGA
• Xilinx refers to the “interconnection switches” as the
switch matrix
IOB IOB IOB IOB
IOB
IOB
CLB CLB CLB CLB
SM SM SM
Programmable
Switch Matrix
IOB
IOB
CLB CLB CLB CLB
SM SM SM
IOB
IOB
CLB CLB CLB CLB
SM SM SM
IOB
IOB
CLB CLB CLB CLB
32
FPGAs
• An example of programming an FPGA
x3 f
f1 x1 x2
x1 f 2 x2 x3
x1 0 x2 0
0 1 f x1 x2 x2 x3
f1 f2
0 0
x2 1 x3 0
x2
f1 0
1 x1
f3
1 0/1
f2 1 0/1 f
LUT 0/1
0/1
x2
33
FPGAs
• An example of programming an FPGA
x3 f
f1 x1 x2
x1 f 2 x2 x3
x1 0 x2 0
0 1 f x1 x2 x2 x3
f1 f2
0 0
x2 1 x3 0
x2
f1 0
1 x1
f3
1 0/1
f2 1 0/1 f
LUT 0/1
0/1
x2
34
Configuration Storage Elements
• Static Random Access Memory (SRAM)
– Logical configuration is controlled by the state of
SRAM bits
– FPGA needs to be configured at power-on by another
separated ROM
• Flash Erasable Programmable ROM (Flash)
– Logical configuration is implemented by floating-gate
transistors that can be turned off by injecting charge
onto its gate.
– FPGA itself holds the program
– reprogrammable, even in-circuit
35
36
Curs 4
INTRODUCERE ÎN LIMBAJUL DE
DESCRIERE
HARDWARE – VHDL
• VHDL -> VHSIC Hardware Description
Language (limbajul de descriere hard
VHSIC)
• VHSIC -> Very High Speed Integrated
Circuit.
• set de unelte pentru sinteză (synthesis
tools).
• creeaza structuri de circuite logice direct
din descrierile VHDL comportamentale.
• pot fi proiectate, simulate şi sintetizate atât
circuitele combinaţionale simple cât şi
sisteme complexe cu microprocesor
Design
flow
Modalităţi de proiectare cu circuite
PLD
• Metoda de bază în proiectarea cu circuite
logice programabile cuprinde trei faze:
- descrierea proiectului;
- implementarea proiectului;
- verificarea proiectului.
• Mediul software de proiectare XILINX ISE (Integrated Software
Environment) este utilizat la realizarea şi implementarea completă a
unui proiect pentru structurile programabile de tip XILINX.
Componenta software ISE Project Navigator facilitează crearea
proiectului, organizându-l pe următoarele etape:
– Descriere proiect. Programatorul are posibilitatea să descrie proiectul prin
introducerea de coduri sursă HDL (Hardware Description Language)
pentru limbajele VHDL, Verilog, Abel sau utilizând schematice şi
diagrame cu stări finite;
– Sinteza. În cadrul acestei etape fişierele de tip VHDL, Verilog sau
schematice sunt transformate în fişiere de tip netlist care sunt acceptate
ca fişiere de intrare la etapa de implementare;
– Implementarea. După sinteză, la implementare, proiectul este adaptat şi
transformat din forma logică digitală în forma tehnologică implementabilă
pe structura reconfigurabilă aleasă;
– Verificarea. Poate fi realizată în toate etapele de implementare ale
proiectului. Utilizarea componentelor software de simulare conduce la
verificarea completă a funcţionalităţii proiectului sau a unor porţiuni de
proiect. De asemenea, pot fi realizate şi verificări directe pe circuit, după
programarea acestuia;
– Configurarea. După generarea fişierelor de programare (bitstream file)
proiectantul are posibilitatea programării circuitului reconfigurabil. În
timpul procesului de configurare sunt programate interconexiunile
structurii FPGA alese.
Structura unui cod VHDL
• VHDL este un program program structurat, împrumutându-se unele
idei de la limbajele de programare soft Pascal şi Ada.
• O idee de bază este acea de a defini o interfaţă a modulului hard în
timp ce detaliile interne sunt ascunse.
• Astfel o entitate (entity) VHDL este o simplă declarare a intrărilor şi
ieşirilor modulului în timp ce arhitectura (architecture) VHDL este o
descriere structurală sau comportamentală
detailată a funcţionării modulului.
• Acest concept formează bazele proiectării ierarhice a sistemelor, şi
anume arhitectura entităţii de la nivelul cel mai de sus poate conţine
(instantiate) alte entităţi ale căror arhitecturi sunt “invizibile” de la
nivelurile superioare.
• O arhitectură de la nivel superior poate folosii entităţi de la nivelul
inferior de mai multe ori, iar mai multe arhitecturi de la nivel superior
pot folosii aceeaşi entitate de la nivel inferior fiecare la rândul ei.
Conceptul entitate-arhitectură
Conceptul de ierarhie
Entity – descrie interfata cu lumea
exterioara
entity nume_entitate is
generic(nume generice : type := valori_initiale);
port(nume_porturi : mode tip port);
end entity nume_entitate;
port (
in1, in2 : in bit;
out1 : out bit
);
Entity - Generics
generic (
...list of generic declarations...
);
generic (
gain : integer := 4;
time_delay : time := 10 ns
);
Entity - Constants
• constant : rpullup : real := 1000.0;
• constant a : integer := 1;
constant b : real := 0.123;
constant c : std_logic := ‘0’;
Entity - Exemplu
entity test is
generic (
gain : integer := 4;
time_delay : time := 10 ns
);
Begin
--specificaţii_concurente
BEGIN
ARHITECTURE or_gate OF or_gate IS
g1 : and_gate PORT MAP (a, b, d);
g2 : or_gate PORT MAP (c, d, y); BEGIN
END ex_struct; b3 <= b1 OR b2;
END or_gate;
Curs 5
Limbajul VHDL
Variables
• variable var1 : integer := 0;
variable var2 : integer := 1;
var1 := var2;
Signals
• În cadrul unei arhitecturii se pot definii unul sau mai multe semnale
interne, iar acestea în cadrul unei diagrame logice au corespondent
traseele.
SIGNAL signal_name : signal_type [:= initial_value];
process (a) is
signal na : bit;
begin
na <= not a;
end process;
If-then-else
• if (condition) then
... statements
end if;
• if ( a = b ) then
out1 <= ‘1’;
end if;
If-then-else
• if (condition) then
... statements
else
... statements
end if;
• if ( a = b ) then
out1 <= ‘1’;
else
out1 <= ‘0’;
end if;
If-then-else
if (condition1) then
... statements
elsif (condition2)
... statements
... more elsif conditions & statements
else
... statements
end if;
If-then-else
if (a > 10) then
out1 <= ‘1’;
elsif (a > 5) then
out1 <= ‘0’;
else
out1 <= ‘1’;
end if;
Case
case testvariable is
when 1 => out1 <= ‘1’;
when 2 => out2 <= ‘1’;
when 3 => out3 <= ‘1’;
end case;
case test is
when 0 to 4 => out1 <= ‘1’;
case test is
when 0 => out1 <= ‘1’;
when others => out1 <= ‘0’;
end case;
For
for loopvar in start to finish loop
... loop statements
end loop;
for i in 0 to 7 loop
a(i) <= ‘1’;
end loop;
While and loop
• for i in 0 to 7 loop
if ( i = 4 ) then
exit;
endif;
endloop;
• for i in 0 to 7 loop
if ( i = 4 ) then
next;
endif;
endloop;
• WHILE (day = weekday) LOOP
day := get_next_day(day);
END LOOP;
Functions
function name (input declarations) return
output_type is
... variable declarations
begin
... function body
end
Functions
function mult (a,b : integer) return integer is
begin
return a * b;
end;
package new_functions is
function and10 (a,b,c,d,e,f,g,h,i,j : bit) return bit;
end;
package body new_functions is
function and10 (a,b,c,d,e,f,g,h,i,j : bit) return bit is
begin
return a and b and c and d and e and f and g and h and i and j;
end;
end;
Components
component and4
port ( a, b, c, d : in bit; q : out bit );
end component;
d1: and4 port map ( a => b, b => c, c => a, d => d, q => q);
LIBRARY
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
Curs 6
Boolean algebra
Rules of Boolean algebra
Single-Variable Theorems
Rules of Boolean algebra
Double-Variable Theorems
• Quine–McCluskey
• Karnaugh
Logic gates – gates.vhd
library IEEE;
use IEEE.std_logic_1164.all;
entity gates2 is
port(
a : in STD_LOGIC;
b : in STD_LOGIC;
and_gate : out STD_LOGIC;
nand_gate : out STD_LOGIC;
nor_gate : out STD_LOGIC;
or_gate : out STD_LOGIC;
xnor_gate : out STD_LOGIC;
xor_gate : out STD_LOGIC
);
end gates2;
S = (M D' V) + (M D V') + (M D V)
S = (M AND (NOT D) AND V) OR (M AND D AND (NOT V)) OR (M AND D
AND V)
majority
majority
majority.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity majority4 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : in STD_LOGIC;
f : out STD_LOGIC);
end majority4;
begin
f <= ((b and c and d) or (a and c and d) or (a and b and d)
or (a and b and c));
end Behavioral;
majority_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity majority4_top is
Port ( sw : in STD_LOGIC_VECTOR (3 downto 0);
led : out STD_LOGIC_VECTOR (0 downto 0));
end majority4_top;
end Behavioral;
Curs 7
Circuite logice combinationale (1)
Comparatoare
Multiplexoare si demultiplexoare
Comparator pe 2 biti
Comp2bit.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comp2bit is
Port ( a : in STD_LOGIC_VECTOR (1 downto 0);
b : in STD_LOGIC_VECTOR (1 downto 0);
a_eq_b : out STD_LOGIC;
a_gt_b : out STD_LOGIC;
a_lt_b : out STD_LOGIC);
end comp2bit;
begin
a_eq_b <= (not b(1) and not b(0) and not a(1) and not a(0)) or (not b(1) and b(0) and not a(1) and
a(0)) or (b(1) and not b(0) and a(1) and not a(0)) or (b(1) and b(0) and a(1) and a(0));
a_gt_b <= (not b(1) and a(1)) or (not b(1) and not b(0) and a(0)) or (not b(0) and a(1) and a(0));
a_lt_b <= (b(1) and not a(1)) or (b(1) and b(0) and not a(0)) or (b(0) and not a(1) and not a(0));
end Behavioral;
comp2bit_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity comp2bit_top is
Port ( sw : in STD_LOGIC_VECTOR (3 downto 0);
led : out STD_LOGIC_VECTOR (2 downto 0)
);
end comp2bit_top;
end Behavioral;
multiplexer
Mux_v1.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux21a is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
s : in STD_LOGIC;
y : out STD_LOGIC
);
end mux21a;
Begin
y <= (not s and a) or (s and b);
end Behavioral;
Mux_v2.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux21b is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
s : in STD_LOGIC;
y : out STD_LOGIC
);
end mux21b;
begin
p1: process (a, b, s)
begin
if s = '0' then
y <= a;
else
y <= b;
end if;
end process;
end Behavioral;
Mux_v3.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux21c is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
s : in STD_LOGIC;
y : out STD_LOGIC);
end mux21c;
begin
y <= a when s = '0' else b;
end Behavioral;
Mux_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux21_top is
Port ( sw : in STD_LOGIC_VECTOR (1 downto 0);
btn : in STD_LOGIC_VECTOR (0 downto 0);
led : out STD_LOGIC_VECTOR (0 downto 0)
);
end mux21_top;
begin
a1 : mux21a
port map(
a => sw(0),
b => sw(1),
s => btn(0),
y => led(0)
);
end Behavioral;
Mux 4 to 1
Mux4to1_v1.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux41b is
Port ( c : in STD_LOGIC_VECTOR (3 downto 0);
s : in STD_LOGIC_VECTOR (1 downto 0);
z : out STD_LOGIC);
end mux41b;
begin
z <= (not s(1) and not s(0) and c(0)) or (not s(1) and s(0) and c(1)) or (s(1) and not s(0)
and c(2)) or (s(1) and s(0) and c(3));
end Behavioral;
Mux4to1_v2.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux41c is
Port ( c : in STD_LOGIC_VECTOR (3 downto 0);
s : in STD_LOGIC_VECTOR (1 downto 0);
z : out STD_LOGIC_VECTOR (0 downto 0));
end mux41c;
begin
p1: process(c, s)
begin
case s is
when "00" => z(0) <= c(0);
when "01" => z(0) <= c(1);
when "10" => z(0) <= c(2);
when "11" => z(0) <= c(3);
when others => z(0) <= c(0);
end case;
end process;
end Behavioral;
library IEEE;
Mux4to1_top.vhd
use IEEE.STD_LOGIC_1164.ALL;
entity mux41b_top is
Port ( sw : in STD_LOGIC_VECTOR (3 downto 0);
btn : in STD_LOGIC_VECTOR (1 downto 0);
led : out STD_LOGIC_VECTOR (0 downto 0));
end mux41b_top;
c1 : mux41b
port map(
c(0) => sw(0),
c(1) => sw(1),
c(2) => sw(2),
c(3) => sw(3),
s(0) => btn(0),
s(1) => btn(1),
z => led(0)
);
end Behavioral;
Mux4to1_v3.vhd
Mux_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; begin
entity mux21_top is a1 : mux21a
Port ( sw : in STD_LOGIC_VECTOR (5 downto 0);
port map(
btn : in STD_LOGIC_VECTOR (2 downto 0);
led : out STD_LOGIC_VECTOR (2 downto 0)); a => sw(0),
end mux21_top; b => sw(1),
s => btn(0),
architecture Behavioral of mux21_top is y => led(0)
component mux21a is –v1 );
port(
a : in STD_LOGIC;
b : in STD_LOGIC; b1 : mux21b
s : in STD_LOGIC; port map(
y : out STD_LOGIC a => sw(2),
); b => sw(3),
end component;
s => btn(1),
component mux21b is –v2 y => led(1)
port( );
a : in STD_LOGIC;
b : in STD_LOGIC; c1 : mux21c
s : in STD_LOGIC; port map(
y : out STD_LOGIC
);
a => sw(4),
end component; b => sw(5),
s => btn(2),
component mux21c is –v3 y => led(2)
port( );
a : in STD_LOGIC;
b : in STD_LOGIC;
s : in STD_LOGIC; end Behavioral;
y : out STD_LOGIC
);
end component;
Mux quad 2 to 1
Mux24_v1.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux24a is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
s : in STD_LOGIC;
y : out STD_LOGIC_VECTOR (3 downto 0)
);
end mux24a;
end Behavioral;
Mux24_v2.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux24b is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
s : in STD_LOGIC;
y : out STD_LOGIC_VECTOR (3 downto 0));
end mux24b;
begin
p1: process (a, b, s)
begin
if s = '0' then
y <= a;
else
y <= b;
end if;
end process;
end Behavioral;
Mux24_v3.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux24c is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
s : in STD_LOGIC;
y : out STD_LOGIC_VECTOR (3 downto 0));
end mux24c;
begin
y <= a when s = '0' else b;
end Behavioral;
Mux24_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux24_top is
Port ( sw : in STD_LOGIC_VECTOR (7 downto 0);
btn : in STD_LOGIC_VECTOR (0 downto 0);
led : out STD_LOGIC_VECTOR (3 downto 0));
end mux24_top;
begin
QM1: mux24a port map
(a => SW(3 downto 0), b => SW(7 downto 4), s => BTN(0), y => LED(3 downto 0));
end Behavioral;
Dmux
Dmux.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity dmux is
Port ( a : in STD_LOGIC;
s : in STD_LOGIC_VECTOR (1 downto 0);
y : out STD_LOGIC_VECTOR (3 downto 0));
end dmux;
architecture Behavioral of dmux is
begin
y(0) <= (not s(0)) and (not s(1)) and a;
y(1) <= (not s(0)) and s(1) and a;
y(2) <= s(0) and (not s(1)) and a;
y(3) <= s(0) and s(1) and a;
end Behavioral;
Dmux_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity dmux_top is
Port ( sw : in STD_LOGIC_VECTOR (0 downto 0);
btnC : in STD_LOGIC;
btnL : in STD_LOGIC;
led : out STD_LOGIC_VECTOR (3 downto 0));
end dmux_top;
architecture Behavioral of dmux_top is
component dmux is
port( a : in STD_LOGIC;
s : in STD_LOGIC_VECTOR (1 downto 0);
y : out STD_LOGIC_VECTOR (3 downto 0));
end component;
begin
a1 : dmux
port map( a => sw(0),
s(0) => btnL,
s(1) => btnC,
y(0) => led(0),
y(1) => led(1),
y(2) => led(2),
y(3) => led(3));
end Behavioral;
Curs 8
Circuite logice combinationale (2)
Codoare si decodoare
Encoder
y1 = w3 + w2
y0 = w3 + w1
Priority Encoders
Priority Encoders
Enc.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity enc4to2 is
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
y : out STD_LOGIC_VECTOR (1 downto 0);
v: out STD_LOGIC
);
end enc4to2;
begin
process(x)
begin
y(1) <= x(3) or x(2);
y(0) <= x(3) or (not x(2) and x(1));
v <= x(3) or x(2) or x(1) or x(0);
end process;
end Behavioral;
Enc_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity enc4to2_top is
Port ( sw : in STD_LOGIC_VECTOR (3 downto 0);
led : out STD_LOGIC_VECTOR (1 downto 0);
dp : out STD_LOGIC
);
end enc4to2_top;
begin
E1: enc4to2
port map(
x => sw,
y => led,
v => dp
);
end Behavioral;
Decoder 2to4
Decoder 3to8
Dec3to8_v1.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity dec3to8 is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
y : out STD_LOGIC_VECTOR (7 downto 0));
end dec3to8;
begin
y(0) <= not a(2) and not a(1) and not a(0);
y(1) <= not a(2) and not a(1) and a(0);
y(2) <= not a(2) and a(1) and not a(0);
y(3) <= not a(2) and a(1) and a(0);
y(4) <= a(2) and not a(1) and not a(0);
y(5) <= a(2) and not a(1) and a(0);
y(6) <= a(2) and a(1) and not a(0);
y(7) <= a(2) and a(1) and a(0);
end Behavioral;
Dec3to8_v2.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity dec3to8 is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
y : out STD_LOGIC_VECTOR (7 downto 0));
end dec3to8;
begin
process (a)
variable j : integer;
begin
j := conv_integer(a);
for i in 0 to 7 loop
if (i = j) then
y(i) <= ‘1’;
else
y(i) <= ‘0’;
end if;
end loop;
end process;
end Behavioral;
Dec3to8_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity dec3to8_top is
Port ( sw : in STD_LOGIC_VECTOR (2 downto 0);
led : out STD_LOGIC_VECTOR (7 downto 0));
end dec3to8_top;
end Behavioral;
7-segments display
7seg_v1.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity hex7seg_le is
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
a_to_g : out STD_LOGIC_VECTOR (6 downto 0));
end hex7seg_le;
end Behavioral;
7seg_v2.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity hex7segb is
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
a_to_g : out STD_LOGIC_VECTOR (6 downto 0));
end hex7segb;
architecture Behavioral of hex7segb is
begin
process(x)
begin
case x is
when "0000" => a_to_g <= "0000001";
when "0001" => a_to_g <= "1001111";
when "0010" => a_to_g <= "0010010";
when "0011" => a_to_g <= "0000110";
when "0100" => a_to_g <= "1001100";
when "0101" => a_to_g <= "0100100";
when "0110" => a_to_g <= "0100000";
when "0111" => a_to_g <= "0001101";
when "1000" => a_to_g <= "0000000";
when "1001" => a_to_g <= "0000100";
when "1010" => a_to_g <= "0001000";
when "1011" => a_to_g <= "1100000";
when "1100" => a_to_g <= "0110001";
when "1101" => a_to_g <= "1000010";
when "1110" => a_to_g <= "0110000";
when others => a_to_g <= "0111000";
end case;
end process;
end Behavioral;
7seg_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity hex7seg_top is
Port ( sw : in STD_LOGIC_VECTOR (3 downto 0);
a_to_g : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0);
dp : out STD_LOGIC);
end hex7seg_top;
end Behavioral;
Mux7seg
Mux7seg.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; --7 seg decoder
entity mux7seg is process(digit)
Port ( btn : in STD_LOGIC_VECTOR (3 downto 0); begin
a_to_g : out STD_LOGIC_VECTOR (6 downto 0); case digit is
an : out STD_LOGIC_VECTOR (3 downto 0); when X"0" => a_to_g <= "0000001";
dp : out STD_LOGIC); when X"1" => a_to_g <= "1001111";
end mux7seg; when X"2" => a_to_g <= "0010010";
architecture Behavioral of mux7seg is when X"3" => a_to_g <= "0000110";
signal x: STD_LOGIC_VECTOR(15 downto 0); when X"4" => a_to_g <= "1001100";
signal s: STD_LOGIC_VECTOR(1 downto 0);
when X"5" => a_to_g <= "0100100";
signal digit: STD_LOGIC_VECTOR(3 downto 0);
when X"6" => a_to_g <= "0100000";
Begin
when X"7" => a_to_g <= "0001101";
x <= X"1234";
when X"8" => a_to_g <= "0000000";
an <= not btn;
when X"9" => a_to_g <= "0000100";
s(1) <= btn(2) or btn(3);
s(0) <= btn(1) or btn(3);
when X"A" => a_to_g <= "0001000";
dp <= '1';
when X"B" => a_to_g <= "1100000";
--4 to 1 mux when X"C" => a_to_g <= "0110001";
process(s) when X"D" => a_to_g <= "1000010";
begin when X"E" => a_to_g <= "0110000";
case s is when others => a_to_g <= "0111000";
when "00" => digit <= x(3 downto 0); end case;
when "01" => digit <= x(7 downto 4); end process;
when "10" => digit <= x(11 downto 8); end Behavioral;
when others => digit <= x(15 downto 12);
end case;
end process;
clock
top
BCD – logic gates
BCD - algoritmic
Binary to bcd converter – binbcd8.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.all;
entity binbcd8 is
Port ( b : in STD_LOGIC_VECTOR (7 downto 0);
p : out STD_LOGIC_VECTOR (9 downto 0));
end binbcd8;
begin
for i in 0 to 17 loop
z(i) := '0';
end loop;
z(10 downto 3) := b;
for i in 0 to 4 loop
if z(11 downto 8) > 4 then
z(11 downto 8) := z(11 downto 8) + 3;
end if;
if z(15 downto 12) > 4 then
z(15 downto 12) := z(15 downto 12) + 3;
end if;
z(17 downto 1) := z(16 downto 0);
end loop;
p <= z(17 downto 8);
end process bcd1;
end Behavioral;
mux7segb.vhd
library IEEE; begin
use IEEE.STD_LOGIC_1164.ALL;
s <= clkdiv(20 downto 19);
use IEEE.STD_LOGIC_unsigned.all; dp <= '1';
entity mux7segb is -- set aen(3 downt 0) for blanks
aen(3) <= x(15) or x(14) or x(13) or x(12);
Port ( x : in STD_LOGIC_VECTOR (15 downto aen(2) <= x(15) or x(14) or x(13) or x(12) or x(11) or
0); x(10) or x(9) or x(8);
clk : in STD_LOGIC; aen(1) <= x(15) or x(14) or x(13) or x(12) or x(11) or
clr : in STD_LOGIC; x(10) or x(9) or x(8) or x(7) or x(6) or x(5) or x(4);
aen(0) <= '1';
a_to_g : out STD_LOGIC_VECTOR (6
downto 0);
--Quad 4 to 1 mux
an : out STD_LOGIC_VECTOR (3 downto process(s, x)
0); begin
dp : out STD_LOGIC); case s is
end mux7segb; when "00" => digit <= x(3 downto 0);
architecture Behavioral of mux7segb is when "01" => digit <= x(7 downto 4);
when "10" => digit <= x(11 downto 8);
signal s: STD_LOGIC_VECTOR(1 downto 0); when others => digit <= x(15 downto 12);
signal digit: STD_LOGIC_VECTOR(3 downto 0);
end case;
signal aen: STD_LOGIC_VECTOR(3 downto 0);
end process;
signal clkdiv: STD_LOGIC_VECTOR(20 downto 0);
mux7segb.vhd (cont.)
-- 7 seg decoder --digit select
process(digit)
begin
process(s, aen)
case digit is
when X"0" => a_to_g <= "0000001“;
begin
when X"1" => a_to_g <= "1001111“; an <= "1111";
when X"2" => a_to_g <= "0010010“; if aen(conv_integer(s)) = '1' then
when X"3" => a_to_g <= "0000110“; an(conv_integer(s)) <= '0';
when X"4" => a_to_g <= "1001100“;
end if;
when X"5" => a_to_g <= "0100100“;
when X"6" => a_to_g <= "0100000“;
end process;
when X"7" => a_to_g <= "0001101“; --clk div
when X"8" => a_to_g <= "0000000“; process(clk, clr)
when X"9" => a_to_g <= "0000100“; begin
when X"A" => a_to_g <= "0001000“;
if clr = '1‘ then
when X"B" => a_to_g <= "1100000“;
when X"C" => a_to_g <= "0110001“;
clkdiv <= (others => '0');
when X"D" => a_to_g <= "1000010“; elsif clk'event and clk = '1' then
when X"E" => a_to_g <= "0110000“; clkdiv <= clkdiv + 2;
when others =>a_to_g <= "0111000"; end if;
end case; end process;
end process;
end Behavioral;
Binbcd8_top.vhd
library IEEE; signal x: STD_LOGIC_VECTOR(15 downto 0);
use IEEE.STD_LOGIC_1164.ALL;
signal p: STD_LOGIC_VECTOR(9 downto 0);
entity binbcd8_top is
Port ( mclk : in STD_LOGIC; begin
btn : in STD_LOGIC_VECTOR (3 downto 3); x <= "000000" & p;
sw : in STD_LOGIC_VECTOR (7 downto 0);
led <= sw;
led : out STD_LOGIC_VECTOR (7 downto 0);
a_to_g : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0); B1: binbcd8
dp : out STD_LOGIC); port map (
end binbcd8_top;
b => sw,
architecture Behavioral of binbcd8_top is
p => p
component binbcd8 is );
port(
b : in STD_LOGIC_VECTOR(7 downto 0);
X2: mux7segb
p : out STD_LOGIC_VECTOR(9 downto 0)
);
port map (
end component; x => x,
clk => mclk,
component mux7segb is
clr => btn(3),
port(
x : in STD_LOGIC_VECTOR(15 downto 0);
a_to_g => a_to_g,
clk : in STD_LOGIC; an => an,
clr : in STD_LOGIC; dp => dp
a_to_g : out STD_LOGIC_VECTOR(6 downto 0);
);
an : out STD_LOGIC_VECTOR(3 downto 0);
dp : out STD_LOGIC
); end Behavioral;
end component;
Curs 9
Arithmetic Circuits
Half-Adder
Full-Adder
4-bit adder
Adder4bit.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity adder4bit is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
cf : out STD_LOGIC;
ovf : out STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0));
end adder4bit;
begin
c(0) <= '0';
s <= a xor b xor c(3 downto 0);
c(4 downto 1) <= (a and b) or (c(3 downto 0) and (a xor b));
cf <= c(4);
ovf <= c(3) xor c(4);
end Behavioral;
Mux7sega.vhd
library IEEE;
architecture Behavioral of mux7sega is
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.all; signal s: STD_LOGIC_VECTOR(1 downto 0);
signal digit: STD_LOGIC_VECTOR(3 downto 0);
signal aen: STD_LOGIC_VECTOR(3 downto 0);
signal clkdiv: STD_LOGIC_VECTOR(19 downto 0);
entity mux7sega is
Port ( x : in STD_LOGIC_VECTOR (15 downto 0); begin
clk : in STD_LOGIC;
s <= clkdiv(19 downto 18);
clr : in STD_LOGIC;
aen <= "1111";
a_to_g : out STD_LOGIC_VECTOR (6 downto 0); dp <= '1';
an : out STD_LOGIC_VECTOR (3 downto 0);
dp : out STD_LOGIC); --Quad 4 to 1 mux
process(s, x)
end mux7sega; begin
case s is
when "00" => digit <= x(3 downto 0);
when "01" => digit <= x(7 downto 4);
when "10" => digit <= x(11 downto 8);
when others => digit <= x(15 downto 12);
end case;
end process;
-- 7 seg decoder
process(digit) --digit select
Begin process(s, aen)
begin
case digit is
an <= "1111";
when X"0" => a_to_g <= "0000001“;
if aen(conv_integer(s)) = '1' then
when X"1" => a_to_g <= "1001111“; an(conv_integer(s)) <= '0';
when X"2" => a_to_g <= "0010010“; end if;
when X"3" => a_to_g <= "0000110“; end process;
when X"4" => a_to_g <= "1001100“;
when X"5" => a_to_g <= "0100100“; --clk div
when X"6" => a_to_g <= "0100000“; process(clk, clr)
begin
when X"7" => a_to_g <= "0001101“;
if clr = '1' then
when X"8" => a_to_g <= "0000000“;
clkdiv <= (others => '0');
when X"9" => a_to_g <= "0000100“; elsif clk'event and clk = '1' then
when X"A" => a_to_g <= "0001000"; clkdiv <= clkdiv + 1;
when X"B" => a_to_g <= "1100000"; end if;
when X"C" => a_to_g <= "0110001"; end process;
when X"D" => a_to_g <= "1000010";
when X"E" => a_to_g <= "0110000“; end Behavioral;
when others => a_to_g <= "0111000";
end case;
end process;
Adder4bit_top.vhd
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity adder4bit_top is
Port ( mclk : in STD_LOGIC;
btn : in STD_LOGIC_VECTOR (3 downto 3);
sw : in STD_LOGIC_VECTOR (7 downto 0);
led : out STD_LOGIC_VECTOR (0 downto 0);
a_to_g : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0);
dp : out STD_LOGIC
);
end adder4bit_top;
architecture Behavioral of adder4bit_top is
component adder4bit is
Port ( a : in STD_LOGIC_VECTOR (3 downto 0);
b : in STD_LOGIC_VECTOR (3 downto 0);
cf : out STD_LOGIC;
ovf : out STD_LOGIC;
s : out STD_LOGIC_VECTOR (3 downto 0));
end component;
component mux7sega is
Port ( x : in STD_LOGIC_VECTOR (15 downto 0);
clk : in STD_LOGIC;
clr : in STD_LOGIC;
a_to_g : out STD_LOGIC_VECTOR (6 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0);
dp : out STD_LOGIC);
end component;
A1: adder4bit
port map(
a => sw(7 downto 4),
b => sw(3 downto 0),
s => s,
cf => cf,
ovf => led(0)
);
X2: mux7sega
port map(
x => x,
clk => mclk,
clr => btn(3),
a_to_g => a_to_g,
an => an,
dp => dp
);
end Behavioral;
Half subtractor
full subtractor
• E = 0 – adder
• E = 1 - subtractor
multiplicator
Mult.vhd
Mult_top.vhd
Mult_top.vhd
(cont.)
divider
• 87 / D
div.vhd
Curs 10
entity SRlatch is
Port ( S : in STD_LOGIC;
R : in STD_LOGIC;
clk : in STD_LOGIC;
q : out STD_LOGIC;
notq : out STD_LOGIC);
end SRlatch;
end Behavioral;
D flip-flop
Edge-triggered D flip-flop
Edge-triggered D flip-flop
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Dflipflop is
Port ( clk : in STD_LOGIC;
D : in STD_LOGIC;
q : out STD_LOGIC;
notq : out STD_LOGIC);
end Dflipflop;
end Behavioral;
D flip-flop with set and clear
D flip-flop with set and clear
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity csDflipflop is
Port ( clk : in STD_LOGIC;
set : in STD_LOGIC;
clr : in STD_LOGIC;
D : in STD_LOGIC;
q : out STD_LOGIC;
notq : out STD_LOGIC);
end csDflipflop;
end Behavioral;
D flip-flop with clear
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity dff is
Port ( clk : in STD_LOGIC;
clr : in STD_LOGIC;
D : in STD_LOGIC;
q : out STD_LOGIC);
end dff;
begin
process(clk, clr)
begin
if(clr = '1') then
q <= '0';
elsif(rising_edge(clk)) then
q <= D;
end if;
end process;
end Behavioral;
D flip-flop with asynchronous set and clear
Divizor cu 2
1 bit Register
• load = 0, q store
• load = 1, q = inp0
Reg1bita.vhd
Reg1bitb.vhd
4 bit reg
Reg4bit.vhd
N bit reg
Reg.vhd
Shift reg
Shiftreg.vhd
Ring counter
Ringcount.vhd
Curs 12
FSM
Mealy
process(port_intrare, stare_prezenta)
Begin
case stare_prezenta is
when stare0 =>
if (intrare = … ) then
port_iesire <= <valoare>;
else …
end if;
when stare1 =>
if (intrare = … ) then
port_iesire <= <valoare>;
else …
end if;
when stare2 =>
if (intrare = … ) then
port_iesire <= <valoare>;
else …
end if;
…
when others null;
end case;
end process;
Moore
process(stare_prezenta)
Begin
case stare_prezenta is
when stare0 => port_iesire <= <valoare>;
when stare1 => port_iesire <= <valoare>;
when stare2 =: port_iesire <= <valoare>;
…
when others null;
end case;
end process;
Door lock code
Doorlock_top.vhd
Doorlock_top.vhd (cont.)
Doorlock_top.vhd (cont.)
Doorlock.vhd
Doorlock.vhd (cont.)
Doorlock.vhd (cont.)
Doorlock.vhd (cont.)
semafor
Semafor_top.vhd
Semafor.vhd
Semafor.vhd
(cont.)
Semafor.vhd (cont.)
Clkdiv.vhd