Difference between revisions of "CasperTutorial01"

From AstroBaki
Jump to navigationJump to search
Line 219: Line 219:
  
 
To demonstrate some simple mathematical operations, we will create an adder. It
 
To demonstrate some simple mathematical operations, we will create an adder. It
will add two numbers on demand and output the result to another software
+
will add numbers in two CPU-controllable registers and output the result to another software
register. Almost all astronomy DSP is done using fixed-point (integer)
+
register. As will be the case for most DSP in FPGAs, this adder will use fixed-point (integer)
notation, and this adder will be no different.
+
data types.
  
We will calculate a+b=sum\_a\_b.
+
We will calculate $a+b=sum\_a\_b$.
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig23.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig23.png}\end{figure}
  
\subsubsection{Add the software registers }
+
\subsubsection{Add Three Software Registers }
  
Add two more input software registers. These will allow us to specify the two
+
Add two more input {\bf Software Registers} to specify the  
numbers to add. Add another output register for the sum output.  
+
numbers to add, and one more output {\bf Software Register} for returning the sum.  
 
+
You may either copy your existing software register blocks or drag them in from the {\it BEE\_XPS Blockset} library.
Either copy your existing software register blocks (copy-paste or holding ctrl
+
Set the I/O direction to "From Processor" on the first two, and "To Processor" on the
while dragging/dropping it) or add three more from the library. Set the I/O
 
direction to From Processor on the first two and set it to To Processor on the
 
 
third one.
 
third one.
  
\subsubsection{Add the adder block }
+
\subsubsection{Add an AddSub Block}
  
Locate the adder/subtractor block, Xilinx Blockset $\rightarrow$ Math
+
Drag into your design the adder/subtractor block: {\it Xilinx Blockset $\rightarrow$ Math
$\rightarrow$ AddSub and drag one onto your design. This block can optionally
+
$\rightarrow$ AddSub}. This block can  
perform addition or subtraction. Let's leave it set at it's default, for
+
perform addition or subtraction. Its default configuration is for addition, and we'll leave that way:
addition.
 
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig24.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig24.png}\end{figure}
  
The output register is 32 bits. If we add two 32 bit numbers, we will have 33 bits.
+
Now we have an interesting problem.  The two input registers are 32 bits wide, and when we add them, we need 33 bits to guarantee that we can hold the full sum.  However, our output register has only 32 bits.
 
 
 
There are a number of ways of fixing this:
 
There are a number of ways of fixing this:
  
 
\begin{itemize}
 
\begin{itemize}
 
     \item limit the input bitwidth(s) with slice blocks
 
     \item limit the input bitwidth(s) with slice blocks
     \item limit the output bitwidth with slice blocks
+
     \item limit the output bitwidth with slice blocks, accepting that the sum may overflow and wrap
     \item create a 32 bit adder.
+
     \item saturate the sum at the maximum/minimum values that can be represented with 32 bits.
 
\end{itemize}
 
\end{itemize}
  
 
Since you have already seen slice blocks demonstrated, let's try to set the
 
Since you have already seen slice blocks demonstrated, let's try to set the
AddSub block to be a 32 bit saturating adder. On the second tab, set it for
+
AddSub block to be a 32-bit saturating adder. On the second tab, set it for
user-defined precision, unsigned 32 bits.
+
user-defined precision, unsigned 32 bits. Change overflow to "saturate":
 
 
Also, under overflow, set it to saturate. Now if we add two very large numbers,
 
it will simply return $2^{32} -1$.
 
  
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig25.png}\end{figure}
 
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig25.png}\end{figure}
  
\subsubsection{Add the scope and simulation inputs}
+
Now, when the sum exceeds the maximum value that can be represented with 32 bits, this adder will return $2^{32} -1$.
  
Either copy your existing scope and simulation constants (copy-paste or
+
\subsubsection{Add a Scope and Constants}
ctrl-drag) or place a new one from the library as before. Set the values of the
 
simulation inputs to anything you like.
 
  
\subsubsection{Connect it all together}
+
Add a {\bf Scope} and two {\bf Constant}. The constants are for simulation; set the values to anything you like.
  
Like this:
+
\subsubsection{Wire the Blocks}
  
\begin{figure}[h!]\centering\includegraphics[scale=.5]{tut1_fig26.png}\end{figure}
+
Connect the blocks as per the diagram at the beginning of this section.
  
 
\section{Simulating}
 
\section{Simulating}

Revision as of 13:28, 26 March 2010