eletrÔnica digital i · 2018. 9. 19. · programação utilizando vhdl professor dr. michael klug...

21
Prof. Michael ELETRÔNICA DIGITAL I DE10-LITE Programação Utilizando VHDL Professor Dr. Michael Klug 1

Upload: others

Post on 19-Jan-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

Prof. Michael

ELETRÔNICA DIGITAL I

DE10-LITEProgramação Utilizando VHDL

Professor Dr. Michael Klug

1

Page 2: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

2

Comparativo Linguagens• Linguagem de Programação x HDL

Prof. Michael

Supondo que cada instrução leve 20nsentre 40 e 60ns para conclusão

Apenas atraso10ns

Page 3: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

3

VHDL

• VHDL: VHSIC Hardware Descriptor Language– VHSIC: Very High-Speed Integrated Circuit

• Desenvolvida para descrever hardware, não sendo umalinguagem sequencial

– Linguagens de alto nível como C ou Java são naturalmentesequenciais

• Linguagem concorrente: instruções VHDL são todasexecutadas ao mesmo tempo (execução paralela)

Objetivo Principal: linguagem utilizada para modelar circuitos/sistemas digitais.

Prof. Michael

Page 4: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

4

VHDL

• Regras Gerais:– VHDL is a hardware-design language: When you are working with

VHDL, you are not programming, you are “designing hardware”;

– Case Sensitivity: VHDL is not case sensitive;

– White Space: VHDL is not sensitive to white space (spaces andtabs);

– Comments: comments begin with the symbol “--” (two consecutivedashes)

Prof. Michael

Page 5: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

5

VHDL

• Regras Gerais:– Identifiers: refers to the name given to various items (variable names

and function names)• Identifiers can only contain a combination of letters (A-Z and a-z), digits (0-9) and

the underscore character (“ ”).• Identifiers must start with an alphabetic character.• Identifiers must not end with an underscore and must never have two consecutive

underscores.

Prof. Michael

Page 6: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

6

VHDL• Regras Gerais:

– Reserved Words

– Parentheses

Prof. Michael

Page 7: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

7

Fluxograma / Passos• Typical FPGA CAD flow

Prof. Michael

Page 8: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

8

Fluxograma / Passos• Passos Básicos:

Prof. Michael

Page 9: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

9

Estrutura de um Programa VHDL

Prof. Michael

Page 10: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

10

Programação VHDL• VHDL Standard Libraries:

– IEEE Standard 1164– Once these packages have been included, you will have access to a

very large set of goodies: several data types, overloaded operators, various conversion functions, math functions and so on.

Prof. Michael

Page 11: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

11

Programação VHDL• Entity: lista as várias entradas e saídas do circuito (cria umacaixa preta cuja função a ser executada é definida pela“architecture”)

Prof. Michael

Page 12: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

12

Programação VHDL• Tipos mais utilizados:

Prof. Michael

bit Assume valores ‘0’ ou ‘1’.x: in bit;

bit_vector Vetor de bits.x: in bit_vector(7 downto 0);x: in bit_vector(0 to 7);

std_logic x: in std_logic; std_logic_vector x: in std_logic_vector(7 downto 0);

x: in std_logic_vector(0 to 7);boolean Assume valores TRUE ou FALSE

Page 13: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

13

Programação VHDL• STD_LOGIC:

– Definida pela biblioteca IEEE– Pode assumir nove valores

Prof. Michael

‘U’: não inicializada ‘Z’: alta impedância‘X’: desconhecida ‘W’: desconhecida fraca‘0’: valor ‘0’ ‘L’: ‘0’ fraca (Low)‘1’: valor ‘1’ ‘H”: ‘1’ fraca (High)‘-’: Don’t care.

• Tipos definidos pelo usuárioExemplos:type logic_level is ( ´0´, ´1´, ´X´, ´Z´ )type octal is ( ´0´, ´1´, ´2´, ´3´, ´4´, ´5´, ´6´, ´7´ )

Page 14: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

14

Programação VHDL• Architecture: Describes what the circuit actually does. In otherwords, the VHDL architecture describes the internalimplementation of the associated entity.

OBS: VHDL coding style used inside the architecture body has a signicant effect on the way the circuit is synthesized (how the circuit 

will be implemented inside an actual silicon device).

Prof. Michael

Page 15: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

15

Programação VHDL• Expressões: realizadas sobre objetos do mesmo tipo.

– As operações possíveis são as seguintes:

• Concatenação: aplicável sobre caracteres, strings, bits,vetores de bits e arrays.Exemplos: “ABC”  & “xyz”   resulta em: “ABCxyz”

“1001”  & “0011” resulta em: “10010011”Prof. Michael

Page 16: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

16

Exemplo: VHDL

• Exemplo: implementar o circuito abaixo na FPGA utilizandoVHDL

• Criação de um Projeto– Crie um projeto utilizando os passos descritos na aula de programação pro

diagrama esquemático.– Nomeie o projeto como light (nomes da Entity e do projeto iguais)

Prof. Michael

Page 17: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

17

Exemplo: VHDL• Descrição de um sistema digital usando VHDL

– Crie um arquivo VHDL em File->New->VHDL File

Prof. Michael

Page 18: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

18

Exemplo: VHDL– Edite o arquivo escrevendo o código abaixo:

– Salve o arquivo como light.vhd

– Para os demais passos siga as instruções da aula de programaçãocom esquemáticos (compilar, definir pinos, ...).

– Efetue a programação na placa FPGA DE10-lite e teste ofuncionamento lógico do circuito.

Prof. Michael

Page 19: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

19

RTL Viewer• Visualização a nível de implementação lógica:– File -> Netlist Viewers -> RTL Viewer

Prof. Michael

Page 20: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

20

Definição de Sinais– Em diversos projetos é necessário definir pontos de sinal “dentro” do

bloco do circuito– Não são entradas nem saídas!!!– Úteis como ponto de referência (muitas conexões dentro do bloco)– Chamados de nós internos ou sinais locais– Entradas e saídas estão disponíveis para outros blocos, porém

sinais locais são reconhecidos apenas dentro desse bloco

EXEMPLO: Implemente o circuito abaixo utilizando o ponto m comosinal.

Prof. Michael

Page 21: ELETRÔNICA DIGITAL I · 2018. 9. 19. · Programação Utilizando VHDL Professor Dr. Michael Klug 1. 2 Comparativo Linguagens •LinguagemdeProgramaçãoxHDL Prof. Michael Supondo

21

Definição de SinaisCódigo VHDL:

Prof. Michael