Difference between revisions of "CasperTutorial01"
From AstroBaki
Jump to navigationJump to searchLine 40: | Line 40: | ||
\subsubsection{Add Xilinx System Generator and XSG Core Config blocks} | \subsubsection{Add Xilinx System Generator and XSG Core Config blocks} | ||
− | All CASPER designs must have two blocks: a System Generator and an XPS Core Config. | + | All CASPER designs must have two blocks: a {\bf System Generator} and an {\bf XPS Core Config}. |
+ | Go to Simulink Library Browser $\rightarrow$ Xilinx Blockset $\rightarrow$ Basic Elements and drag a {\bf System Generator} block onto your new model: | ||
+ | |||
+ | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig3.png}\end{figure} | ||
− | + | You should not configure the {\bf System Generator} block directly; add an | |
− | + | {\bf XSG Core Config} block from Simulink Library Browser $\rightarrow$ BEE\_XPS System Blockset to do it for you: | |
− | XSG Core Config block from Simulink Library Browser $\rightarrow$ BEE\_XPS System Blockset to do it for you: | ||
− | \begin{figure}[h!]\centering\includegraphics[scale=.5]{ | + | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig4.png}\end{figure} |
All hardware-related (possibly board-specific) blocks are yellow and can be found in this BEE\_XPS | All hardware-related (possibly board-specific) blocks are yellow and can be found in this BEE\_XPS | ||
library. Blocks relating to Digital Signal Processing (DSP) are found in the CASPER DSP library and have other colors. | library. Blocks relating to Digital Signal Processing (DSP) are found in the CASPER DSP library and have other colors. | ||
− | + | Double click on the XSG core config block that you just added. Set it for | |
+ | "ROACH: SX95t" with "sys\_clk" as the clock source: | ||
− | + | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig5.png}\end{figure} | |
− | |||
− | |||
− | |||
For the curious, the available clocking options include: | For the curious, the available clocking options include: | ||
\begin{itemize} | \begin{itemize} | ||
− | \item sys\_clk: use | + | \item sys\_clk: use on-board 100MHz crystal connected to the FPGA |
\item sys\_clk2x: use frequency-doubled version of sys\_clk generated using a Phase Locked Loop (PLL) set by a Digital Clock Manager (DCM) on the FPGA | \item sys\_clk2x: use frequency-doubled version of sys\_clk generated using a Phase Locked Loop (PLL) set by a Digital Clock Manager (DCM) on the FPGA | ||
\item arb\_clk: use clock generated from sys\_clk using a DCM (rounded to nearest integer within range of DCM's abilities) | \item arb\_clk: use clock generated from sys\_clk using a DCM (rounded to nearest integer within range of DCM's abilities) | ||
Line 67: | Line 67: | ||
\end{itemize} | \end{itemize} | ||
− | \ | + | \subsection{Flashing an LED} |
− | + | To demonstrate the basic use of hardware interfaces, we will implement a flashing LED by adding the following circuitry to our model: | |
− | + | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig13.png}\end{figure} | |
− | |||
− | |||
− | |||
− | |||
− | + | With the FPGA running at 100MHz, the most significant bit (msb) of a 27-bit | |
+ | counter will toggle every 0.745 seconds. We can output this bit to one of the four | ||
+ | green LEDs on the | ||
+ | ROACH. | ||
− | \ | + | \subsubsection{Add a Counter} |
− | + | Drag a {\bf Counter} into your design from Simulink Library Browser $\rightarrow$ Xilinx Blockset $\rightarrow$ Basic Elements. Double-click it and set the parameters for a | |
− | + | free-running, 27-bit, unsigned counter: | |
− | free running, 27 | ||
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig7.png}\end{figure} | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig7.png}\end{figure} | ||
− | \subsubsection{Add a | + | \subsubsection{Add a Slice} |
− | + | To select the most significant bit (MSB) of the counter, we need to add a | |
− | + | {\bf Slice} block to your model from Simulink Library Browser $\rightarrow$ Xilinx Blockset $\rightarrow$ Basic | |
− | Elements | + | Elements. |
Double-click on the newly added slice block. There are multiple ways to select | Double-click on the newly added slice block. There are multiple ways to select | ||
− | which bit(s) you want. In this case, | + | which bit(s) you want. In this case, it is simplest to index from the |
− | upper end and select the first bit. | + | upper end (MSB) and select the first bit. Set your slice to be 1 bit wide with 0 offset from the top bit: |
− | |||
− | |||
− | |||
− | Set | ||
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig9.png}\end{figure} | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig9.png}\end{figure} | ||
− | + | You could also have indexed | |
+ | from the least significant bit (LSB) with an offset of 26. | ||
− | + | \subsubsection{Add a GPIO} | |
− | Set it to use ROACH's LED bank as output | + | Drag in a {\bf gpio} (General Purpose Input/Output) block from Simulink Library Browser $\rightarrow$ BEE\_XPS System Blockset. This block is used to interface your Simulink design to specific pins on the FPGA chip. |
+ | Set it to use ROACH's LED bank as output with GPIO bit index 0 (i.e. the first LED): | ||
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig11.png}\end{figure} | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig11.png}\end{figure} | ||
− | \subsubsection{Add a | + | \subsubsection{Add a Terminator} |
− | + | This is optional, but to prevent warnings about unconnected outputs, you can connect unused outputs to a {\bf Terminator} block from Simulink Library Browser $\rightarrow$ Simulink $\rightarrow$ Sinks: | |
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig12.png}\end{figure} | \begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig12.png}\end{figure} | ||
− | + | Only Xilinx blocks (blue with an "X" logo, from Simulink Library Browser $\rightarrow$ Xilinx Blockset) compile to hardware. Blocks from the Simulink Library Browser $\rightarrow$ Simulink library are usually white, and they never compile into hardware; they are for simulation only. These blocks are not to be confused with {\bf Subsystems}, which can appear as white blocks, but are hierarchical elements that contain other blocks, including Xilinx blocks that compile to hardware. | |
− | |||
− | |||
− | |||
− | |||
− | For this reason, you need to use | + | Blocks from the Xilinx Blockset library use a different data type than the rest of Simulink. For this reason, you need to use yellow {\bf Gateway} blocks (from Simulink Library Browser $\rightarrow$ Xilinx Blockset) whenever connecting them to other |
− | Simulink-provided | + | Simulink-provided, simulation-only blocks. Many of |
− | the | + | the yellow blocks in the BEE\_XPS System Blockset, like the GPIO block, do this for you with "sim\_in" and |
− | "sim\_out". We will see later how to use a | + | "sim\_out" ports. We will see later how to use a {\bf Scope} block to monitor lines. |
− | \subsubsection{ | + | \subsubsection{Connecting the Blocks Together} |
It is a good idea to rename your blocks to something more sensible, like | It is a good idea to rename your blocks to something more sensible, like | ||
counter\_led instead of just counter. Do this simply by double-clicking on the | counter\_led instead of just counter. Do this simply by double-clicking on the | ||
name of the block and editing the text appropriately. | name of the block and editing the text appropriately. | ||
− | |||
− | |||
It is a good time to save this new design. There are some Matlab limitations you should be aware-of: | It is a good time to save this new design. There are some Matlab limitations you should be aware-of: |