dipl/sections/vhdl_intro/vhdl_intro.tex

98 lines
3.5 KiB
TeX
Raw Permalink Normal View History

2020-03-22 18:54:41 +01:00
\documentclass[../../Diplomschrift.tex]{subfiles}
2019-12-10 15:32:02 +01:00
\begin{document}
2020-03-30 15:18:16 +02:00
\section{A short introduction to VHDL}
2020-03-30 20:54:36 +02:00
\label{app:vhdl-intro}
2019-12-10 15:32:02 +01:00
Designing a processor is a big task, and it's easiest to start very small. With software projects, this is usually in the form of a ``Hello World'' program - we will be designing a hardware equivalent of this.
2020-03-30 15:18:16 +02:00
\subsection{Prerequisites}
2019-12-10 15:32:02 +01:00
Other than a text editor, the following Free Software packages have to be installed:
\begin{savenotes}
\begin{description}
2020-03-22 18:54:41 +01:00
\item[\icode{ghdl}\cite{ghdl}] to analyze, compile, and simulate the design
\item[\icode{gtkwave}\cite{gtkwave}] to view the simulation waveform files
\item[\icode{yosys}\cite{yosys}] to synthesize the design
2020-03-27 12:49:50 +01:00
\item[\icode{ghdlsynth-beta}\cite{ghdlsynth-beta}] to synthesize the design
2020-03-22 18:54:41 +01:00
\item[\icode{nextpnr-xilinx}\cite{nextpnr-xilinx}] to place and route the design
\item[\icode{Project X-Ray}\cite{prjxray}] for FPGA layout data and bitstream tools
\item[\icode{openFPGALoader}\cite{open-fpga-loader}] to load the bitstream onto the FPGA
2019-12-10 15:32:02 +01:00
\end{description}
\end{savenotes}
2020-03-30 15:18:16 +02:00
\subsection{Creating a design}
2019-12-10 15:32:02 +01:00
A simple starting design is an up/down counter. The following VHDL code describes the device:
2019-12-10 15:32:02 +01:00
2020-03-27 14:20:22 +01:00
\lstinputlisting[
style=vhdlstyle,
label={lst:counter},
caption={Counter entity},
title=\texttt{counter.vhd},
]{vhdl/counter.vhd}
2019-12-10 15:32:02 +01:00
In order to test this design, a test bench has to be created:
2020-03-27 14:20:22 +01:00
\lstinputlisting[
style=vhdlstyle,
label={lst:counter-tb},
caption={Counter test bench entity},
title=\texttt{counter_tb.vhd},
]{vhdl/counter_tb.vhd}
2019-12-10 15:32:02 +01:00
2020-03-30 15:18:16 +02:00
\subsection{Simulating a design}
2019-12-10 15:32:02 +01:00
2020-03-27 14:20:22 +01:00
\begin{lstlisting}[
style=terminal,
label={lst:counter-sim-commands},
caption={Commands required to simulate the counter design}]
2019-12-10 15:32:02 +01:00
# analyze the design files
ghdl -a --std=08 *.vhd
2019-12-10 15:32:02 +01:00
# elaborate the test bench entity
ghdl -e --std=08 counter_tb
2019-12-10 15:32:02 +01:00
# run the test bench, saving the signal trace to a GHW file
ghdl -r --std=08 counter_tb --wave=counter_tb.ghw
# open the trace with gtkwave (using the view configuration in counter_tb.gtkw)
gtkwave counter_tb.ghw counter_tb.gtkw
2019-12-10 15:32:02 +01:00
\end{lstlisting}
\begin{figure}
\includegraphics[width=\textwidth]{counter_gtkwave.png}
2020-03-29 18:05:21 +02:00
\caption{Screenshot of the counter test bench waveform in GTKWave}
\end{figure}
2020-03-30 15:18:16 +02:00
\subsection{Synthesizing a design}
An additional Xilinx Design Constraints (XDC) file is required to assign the signals to pins on the FPGA:
2020-03-27 14:20:22 +01:00
\lstinputlisting[
label={lst:counter-constraints},
caption={Counter design constraints file},
title=\texttt{counter.xdc},
]{vhdl/counter.xdc}
2020-03-27 14:20:22 +01:00
\begin{lstlisting}[
style=terminal,
label={lst:counter-synth-commands},
caption={Commands required to synthesize the counter design}]
# synthesize with yosys
yosys -m ghdl.so -p '
ghdl --std=08 counter.vhd -e counter;
synth_xilinx -flatten;
write_json counter.json'
# place and route the design with nextpnr
nextpnr-xilinx --chipdb xc7a35tcsg324-1.bin --xdc counter.xdc --json counter.json --fasm counter.fasm
# convert the FPGA assembly to frames
fasm2frames.py --part xc7a35tcsg324-1 counter.fasm counter.frames
# convert the frames to a bitstream
xc7frames2bit --part-name xc7a35tcsg324-1 --frm-file counter.frames --output-file counter.bit
# upload the bitstream to the FPGA
2020-03-22 18:54:41 +01:00
openFPGALoader -b arty counter.bit
\end{lstlisting}
The current value of the counter is displayed in binary on the eight LEDs on the board. When switch 0 (enable) is in the high position, the counter can be advanced using button 0, with the direction set by switch 1. Button 1 resets the counter to zero.
2019-12-10 15:32:02 +01:00
\end{document}