Difference between revisions of "CasperTutorial01"

From AstroBaki
Jump to navigationJump to search
Line 120: Line 120:
 
"sim\_out" ports. We will see later how to use a {\bf Scope} block to monitor lines.
 
"sim\_out" ports. We will see later how to use a {\bf Scope} block to monitor lines.
  
\subsubsection{Connecting the Blocks Together}
+
\subsubsection{Wire the Blocks}
  
 
Draw wires between blocks by clicking on the output of a block and dragging the line over to the input of another block.  You may want to refer to the figure at the beginning of this section to remember how they should look wired up.
 
Draw wires between blocks by clicking on the output of a block and dragging the line over to the input of another block.  You may want to refer to the figure at the beginning of this section to remember how they should look wired up.
Line 158: Line 158:
 
and "counter\_value" to represent the control and output registers, respectively.
 
and "counter\_value" to represent the control and output registers, respectively.
  
Also note that the software registers have sim\_in and sim\_out ports. The
+
{\bf Software Registers} have sim\_in and sim\_out ports. The
input port provides a means of simulating this register's value (as would be
+
sim\_in input port provides a means of simulating how this register's value might be set by the CPU. The sim\_out output port provides a means to monitor the register's FPGA-assigned value, as it might be read by the CPU.
set by the PPC) using the sim\_in line. The output port provides a means to
 
simulate this register's current FPGA-assigned value.
 
  
For now, set the sim\_in port to constant one using a Simulink-type constant.
+
\subsubsection{Add a Constant}
This will enable the counter during simulations.
+
 
 +
For now, set the sim\_in port to 1 using a {\bf Constant} block from {\it Simulink Library Browser $\rightarrow$ Simulink $\rightarrow$ Sources}. This will simulate the counter being enabled.  
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig17.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig17.png}\end{figure}
  
During simulation, we can monitor the counter's value using a scope:  
+
\subsubsection{Add a Scope}
 +
 
 +
We can monitor the value of the output register's sim\_out port by adding using {\bf Scope} from {\it Simulink Library Browser $\rightarrow$ Simulink $\rightarrow$ Sources}:  
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig18.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig18.png}\end{figure}
  
\subsubsection{Add the counter}
+
\subsubsection{Add a Counter}
  
 
You can do this either by copying your existing counter block (copy-paste, or
 
You can do this either by copying your existing counter block (copy-paste, or
ctrl-click-drag-drop) or by placing a new one from the library.
+
ctrl-drag-drop) or by placing a new one from the library.
  
Configure it with a reset and enable port as follows:
+
Configure it with a reset and enable port:
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig19.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig19.png}\end{figure}
  
  
\subsubsection{Add the slice blocks}
+
\subsubsection{Add Two Slice Blocks}
  
Now we need some way to control the enable and reset ports of the counter. We
+
We could control the enable and reset ports of the counter using two separate software registers,
could do this using two separate software registers, but this is wasteful since
+
but this is wasteful; each register has 32 bits, and we only need two.
each register is 32 bits anyway.
+
We'll use a single register and slice out one bit for enabling the counter,
 
+
and another bit for resetting it. Either copy your existing {\bf Slice} block
So we'll use a single register and slice out one bit for enabling the counter,
+
(copy-paste, or ctrl-drag-drop) or add two more from
and another bit for resetting it. Either copy your existing slice block
 
(copy-paste it or hold ctrl while dragging/dropping it) or add two more from
 
 
the library.
 
the library.
  
 
The enable and reset ports of the counter require boolean values (which
 
The enable and reset ports of the counter require boolean values (which
Simulink interprets differently from ordinary 1-bit unsigned numbers).
+
Simulink interprets differently from 1-bit unsigned numbers).
Configure the slices as follows:
+
Configure the slice for the enable port as:
 
 
Slice for enable:
 
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig20.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig20.png}\end{figure}
  
Slice for reset:
+
and the slice for the reset port as:
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig21.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig21.png}\end{figure}
  
 +
\subsubsection{Wire the Blocks}
  
\subsubsection{Connect it all up}
+
Connect all these blocks together as per the diagram at the beginning of this section.  
 
+
To neaten things up, consider
Now we need to connect all these blocks together. To neaten things up, consider
 
 
resizing the slice blocks and hiding their names. Their function is clear
 
resizing the slice blocks and hiding their names. Their function is clear
 
enough from their icon without needing to see their names.
 
enough from their icon without needing to see their names.
  
Do so by right-clicking and selecting Format $\rightarrow$ Hide Name. You could do this
+
Do so by right-clicking and selecting {\it Format $\rightarrow$ Hide Name}. You could do this
with the counter too, but it's not a good idea with the software registers,
+
with the counter too, but it's not a good idea with the software registers.
because otherwise you wouldn't know how to address them when looking at your
+
You want to know how to address them by looking at your
diagram.
+
diagram!
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig22.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig22.png}\end{figure}
  
\subsection{Adder}
+
\subsection{Adding Two Numbers}
  
 
To demonstrate some simple mathematical operations, we will create an adder. It
 
To demonstrate some simple mathematical operations, we will create an adder. It

Revision as of 13:07, 26 March 2010