26 Aralık 2012 Çarşamba

FPGA Training Course Day 2

FPGA Training Course Day 2

1) When we declare I/O's with wire, you have to assign them or you shall do it inline as:

wire input1 = SW[6]; //inline assignment
wire input2, input3, input4;
wire [1:0] select = SW[1:0];
wire out;

assign input2 = SW[7];
assign {input4, input3} = SW[9:8];
assign LEDG[0] = out;

2) reg variables can only be assigned in always block, but they can be defined everywhere.

3) input means wire input, output means wire output; you have to write reg to define it reg type.

4) http://opencores.org/ for various designs...
     http://www.fpga4fun.com/ for fun...
    These two sites are very useful for gathering FPGA projects.

5)Simple ALU:
/*This is the start of TOP Module*/
module DE0_TOP
(

input [9:0] SW, // Toggle Switch[9:0]
output [9:0] LEDG, // LED Green[9:0]
);

ALU alu1(SW[3:0],SW[7:4],SW[9:8],LEDG);
endmodule
/*This is the end of TOP Module*/

module ALU(input [3:0] operand1, input [3:0] operand2, input [1:0] oper, output reg [7:0] result);

wire signed [3:0] opr1 = operand1;//You can define as signed!!!
wire signed [3:0] opr2 = operand2;

always @ (*)
begin
case(oper)
 2'b00: result = operand1 + operand2;
 2'b01: result = operand1 - operand2;
 2'b10: result = operand1 * operand2;
 2'b11: result = opr1 * opr2;
default: result = 8'b0;
endcase
end

endmodule

6) With "Inster Template" you can insert template modules, switch cases etc...

7)File -> New-> Verilog HDL File and you can write a module with .v file. Then you can call this module easily.

8) #( parameter SIZE = 32,
   SURE = 32'd50_000_000 )
you can call  binary_counter #(.SURE (12_500_000))b1(.clk(CLOCK_50),....
module with different parameters if you wish by changing SURE value.
Normal call: binary_counter b1(.clk(CLOCK_50)...
Call with input parameter: binary_counter #(.SURE (12_500_000))b1(.clk(CLOCK_50)...

9) You can define parameters as given example (similat to macros in C,C++):

module binary_counter
#(
// Parameter Declarations
parameter SIZE = 32
)
....

10)  Tools->MegaWizard Plug-In Manager contains libraries. You can use these modules if you need. (There are a lot of useful libs.)

11) In order to create a FPGA logic analyzer in the FPGA chip: Tools->Signal Tap II Logic Analyzer
Choose CLOCK_50; Type: Continuous; Pre-Trigger Position to use a trigger and Trigger condition as 1.
Then Double Click on the blank white area to open Node Finder to add the ports and wires or regs that you want to observe. You can use BUTTON[0] as a trigger for instance. Then Run Analysis, the project will be compiled again and after choosing the right device and the compiled file from the right hand side of the screen, click Program Device and Run Analysis again to see what happens. If you set a trigger, it will keep waiting till you trigger it.

12) You can use Qsys under Tools menu to create your own SoC. This is awesome!..You can write your own code and run in your new machine.

13)From File-> Convert Programming File you can convert .sof files to .pof files to write PROM for always use.

We cover a lot of examples even if I cannot share here. This is the end of Day 2!

25 Aralık 2012 Salı

FPGA Training Course Day1

FPGA Training Course --Day 1--

FPGA is composed of:
  • Logic Blocks
  • Programmable Interconnect Network
  • I/O Blocks
  • Clock Management, DLLs&PLLs
  • Dedicated Multipliers
  • Block RAM (high speed)
  • DSP Resources
  • Microprocessors (ARM, Atom, PPC)
In fact there are no and/or gates existing in fpga. After we make the FPGA design, a LookUp Table ise constructed and the LUT is used afterwards.

Verilog 4-bit Counter:
module counter(CLOCK, DIRECTION,  COUNT_OUT)
input CLOCK;
input DIRECTION;
.
.
.
VHDL is more functional than Verilog, because it also supports Analog side, not just digital one. Verilog is simpler in syntax.
We will write in Verilog and use Altera Quartus II. 
Altera Board drivers are @ /altera/12.1/quartus/drivers/usb_blaster
You should install drivers first.

Tutorial 1: Simple AND Gate (Schematic Design)
  • For our board: Cyclone III EP3C16F484
  • Start Altera Quartus  II and create a new project.
  • Click new -> Select Block Diagram/Schematic File
  • Click Symbol Tool and select /primitives/logic/and2
  • Draw your logic design.
  • Double click Analysis&Elaboration
  • Under Assignments Tab: Select "Pin Planner" to choose your I/O's.
  • Open the schematic of board and look for the necessary pin names coressponding to switches and leds. (e.g. For an and gate : input1: PIN_H5, input2: PIN_J6 and output PIN_J1.
  • Now time to compile it.
  • Under the Task Window. If everthing is fine, double click "Compile Design". Now just one step: Programming the FPGA board.
  • Your board has to be plugged in and drivers have to be installed.
  • Under Tools menu open "Programmer", Hardware Setup must be your USB-Blaster and Mode: JTAG
  • Just Click "Start".








Note that from File->Create/Update, you can create hierarchical design.

Verilog Design...
Verilog Module:
module ALU (output [3:2] Result, output Cout, output equal, input [3:0] In1, ...); 
 this looks like a struct or class definition correspondingly in C, C++ or Java languages. In order to connect to componets, use "wire".

1)Structural Style
module mux_4_to_1 (Out, In0, In1, In2, In3, Sel1, Sel0)
output Out;
input In0, In1, In2, In3, Sel1, Sel0;
wire NotSel0, NotSel1;
wire Y0, Y1, Y2, Y3
not (NotSel0, Sel0);
not (NotSel1, Sel1);
and( Y0, In0, NotSel1, NotSel0);
.
.
endmodule

2)Data Flow Style ->Using assign
3)Behaviral Style ( better and easy to write ) ->Using always

Verilog - Numbers -> <size> <radix> <value>
3'b001 -> 3 bit binary number; 8'hAB -> 8bit Hexadecimal 0xAB; 124
Binary->b or B; Octal->o or O; Decimal-> d or D; Hexadecimal ->h or H

Verilog has 4 valued logic system -> (0, 1, z, x) z: High impedance, x: Don't care
Two kinds of variables: wire and reg.
Bus example: 
reg[31:0] a; //32 bit wide reg type bus
wire [7:0] b; //8 bit wide wire type buse
wire temp; //1 bit net type signal
Operator example:
reg [7:0] temp = b01001100;
b=&temp; //temp[0]&temp[1]&temp[2]......

Blocked and Non-Blocked Assignments
Non-Blocked:
always @ (*)
    begin
          b<=0; c<=0;
          b<=a+a;
     end

Blocked:
always @ (*)
    begin
          b=0; c=0;
          b=a+a;
     end

Note that in an always block, you have to choose blocked or non-blocked, just one of them.
Note that in every branches of if/else blocks, you have to re-assign all values which you assigned before. If you don't, you cause latches. FPGA does not have latches.

Verilog-Synchronous Logic: (posedge, nededge)
D-FlipFlop Example:
module DFF(input d,clk,output reg q);
always @ (posedge clk)
begin
     q<=d;
end
endmodule

Verilog Example (Altera DEO Board)
module DE0_TOP
(
//////////////////////// Clock Input ////////////////////////
input CLOCK_50, // 50 MHz
input CLOCK_50_2, // 50 MHz
//////////////////////// Push Button ////////////////////////
input [2:0] BUTTON, // Pushbutton[2:0]
//////////////////////// DPDT Switch ////////////////////////
input [9:0] SW, // Toggle Switch[9:0]
//////////////////////// 7-SEG Dispaly ////////////////////////
output [6:0] HEX0_D, // Seven Segment Digit 0
output HEX0_DP, // Seven Segment Digit DP 0
output [6:0] HEX1_D, // Seven Segment Digit 1
output HEX1_DP, // Seven Segment Digit DP 1
output [6:0] HEX2_D, // Seven Segment Digit 2
output HEX2_DP, // Seven Segment Digit DP 2
output [6:0] HEX3_D, // Seven Segment Digit 3
output HEX3_DP, // Seven Segment Digit DP 3
//////////////////////////// LED ////////////////////////////
output [9:0] LEDG // LED Green[9:0]
);

//=======================================================
//  REG/WIRE declarations
//=======================================================

//=======================================================
//  Structural coding
//=======================================================
//assign LEDG[3:0] = SW[3:0] & SW[7:4];// This ANDs switches...
//port by order
and_structural and1(SW[0],SW[4],LEDG[0]);
and_structural and2(SW[1],SW[5],LEDG[1]);
and_structural and3(SW[2],SW[6],LEDG[2]);
//port by name
and_structural and4(.q(LEDG[3]),.a(SW[3]),.b(SW[7]));
endmodule

//STRUCTURAL
module and_structural(input a,b, output q);
   and u1(q,a,b);
endmodule

In task bar, click NetListViewer- RTL viewer to see as a schematic:















End of first day!..

7 Aralık 2012 Cuma

Do not Install Eclipse, Just Use a "pre-configured" One!

Eclipse is a must for SW developers. It has infinitely many plug-ins helping to users. Today I will deal with using a pre-configured Eclipse in your Ubuntu 12.xx 32-bit system for Subclipse. This post is mostly for myself, but if you have a friend having an Eclipse working with Subclipse, then you do not have to install Eclipse to your system. And you do not need to deal with JavaHL library which is a must for Subclipse plug-in.
If you want to have further information about JavaHL lib, just tune to link below:
http://subclipse.tigris.org/wiki/JavaHL

Steps to Follow:

1) apt-get install libsvn-java # Use sudo in Ubuntu

2) Just get the eclipse folder and "libsvnjavahl-1.so.0.0.0" file from a proper configuration. Note that "libsvnjavahl-1.so.0.0.0" is located at "/usr/lib/i386-linux-gnu/jni/"

3) Copy eclipse folder whereever you want. For instance, I've located it to Desktop. Then copy libsvnjavahl-1.so.0.0.0 file under "/usr/lib/i386-linux-gnu/jni/" directory.

4) Open terminal, make symbolic links to libsvnjavahl-1.so.0.0.0:
 cd /usr/lib/i386-linux-gnu/jni/
 sudo ln -s libsvnjavahl-1.so.0.0.0 libsvnjavahl-1.so
 sudo ln -s libsvnjavahl-1.so.0.0.0 libsvnjavahl-1.so.0

5) Show the JavaHL library path to eclipse. For this step, open the eclipse folder and open eclipse.ini file to edit. 
openFile
-vmargs
-Djava.library.path=/usr/lib/i386-linux-gnu/jni

under -vmargs parameter, write the path as given above.

Now your eclipse is ready to use it with Subclipse plug-in.

As I mentioned above, this post will be really useful for me. For the ones who need a working eclipse configuration with CDT, Subclipse and Android Development Tool (ADT), I can provide an eclipse folder including the javahl lib also.

If you have already installed an eclipse, steps 3 and 4 should be sufficient for you to be able to achieve. I can provide you the "libsvnjavahl-1.so.0.0.0" file.

P.S. Thanks to my enthusiastic friend Sercang spent his time with me while we were trying to make eclipse work!..

6 Aralık 2012 Perşembe

"adb" Does Not Recognize My Android Device in Eclipse IDE.


Today, I will try to solve some problems that I've encountered with while I'm setting up Eclipse IDE for Android Development.
Nowadays it is really easy to configure your system for Android development. In past months, we were downloading an appropriate eclipse version and installing ADT plugin via "Install Software" and finally downloading an appropriate Android SDK for development. Configuration steps may vary for different operating systems. I've done these configurations for my Windows 7, Fedora 13, and my lovely Ubuntu 12.04 LTS. While doing these configurations, I faced with a lot of problems due to different eclipse versions such as "galileo" and "helios". If you do not really care about doing this configuration in your specific Eclipse IDE, you can download  "Android SDK ADT Bundle" from http://developer.android.com/sdk/index.html .
This bundle includes all configurations done with eclipse. Just download, extract and run eclipse!
Now let's look at our said problem: What if your Eclipse configuration does not recognize your Android device?
In Windows, it is really easy stuff, just open Android SDK Manager and download USB driver.
In Ubuntu I've just downloaded Eclipse Helios and latest ADT and SDK revisions. I plugged my Android device and everything was fine!
In my Fedora 13 since I did not want to leave my own Eclipse IDE, I have encountered a lot of problems in configuration stage. Now let's explain this Android recognition problem step by step:

First of all open a terminal and write:
adb devices
If this adb binary is not found, then you should cd to the directory where "adb" located. Hint: It's located in your "../android-sdk-linux/platform-tools/" path.
After this command, you will see
List of devices attached
???????????     device

Check your device vendor ID via "lsusb" command in terminal window.
lsusb
Bus 002 Device 009: ID 04e8:685e Samsung Electronics Co., Ltd
Vendor id is 04e8

Now let's add our device to usb list.
cd /etc/udev/rules.d/
sudo touch 51-android.rules
sudo vi 51-android.rules

Now lets manipulate this file with the line below. (Add this line to file, save and exit)

SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0666", GROUP="plugdev"

!Please be careful to write your Vendorid correctly. After saving and closing the file:

sudo chmod a+r /etc/udev/rules.d/51-android.rules
sudo service udev reload
Now we are ready to use our device with Eclipse IDE for debug purpose. See you soon!..

References
http://developer.android.com/sdk/index.html