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




30 Kasım 2012 Cuma

BackUp Your Linux System with TAR

People using a lot of specific configurations in their Linux systems may want to back up their systems in order not to do the same configurations if system fails.
There are several ways to back up your linux system:
1) The first and the low-level one is "dd" command which dumps the whole disk byte-wise. Since my Ubuntu system was almost 200GB in size, it takes very long time both back-up and restoring.
2)The second option is to use some programs like "CloneZilla". There is a lot of information about usage of these softwares, if you google it.
3)As a Linux user, you can do this just by using TAR command to archive your linux system and reuse it if necessary.

BACK-UP with TAR:
1) Prepare your system before TAR: You can delete all unnecessary files, folders etc for smaller image sizes. You can delete your personal files and internet history not to include them in your back-up image. Do not forget to unmount extra hard-drives mounted un your system(extarnal hdd etc.)
2) After preparation we can take our back-up now.
Open the terminal.
cd /
tar -cvpzf backup.tar.gz --exclulde=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
 We are archiving with "preserve file permisions" options -p- and "gzip" option -z-. Also note that some unnecesary directories are excluded. For instance, /dev directory is a tmpfs directory created by udev at every startup. We do not need it while archiving the system.
After a while, the back-up process will finish. You may see a line saying: "Exiting with failure status due to previous errors". Do not take this message into account. Now you can check whether your backup.tar.gz file is located under root. You can copy the image to another folder or hard-disk if you wish for later usage.


RESTORING
If you are restoring root directory, you shall use a Live CD. Start the system with your Live CD, mount the relevant drive and take care about the correct paths for the commands.
Assuming your backup.tar.gz is located under /home/test, the command is:
tar -xvpzf /home/test/backup.tar.gz -C /
After extraction process do not forget to recreate the directories excluded before:
mkdir /proc /lost+found /sys /mnt /media

Time to reboot your computer to check if restoring is OK!..

If you encounter problems at GRUB boot, check internet for instructions.
https://help.ubuntu.com/community/GrubHowto#Backup,%20Repairing%20and%20Reinstalling%20GRUB

References
https://help.ubuntu.com/community/BackupYourSystem/TAR

21 Kasım 2012 Çarşamba

XML Copy Editor "start-up" Problem in Ubuntu 12.04


Today, I need to use an xml editor for editing some xml files. When I use Ubuntu's Software Center and download "XML Copy Editor", I face with a start-up problem that the program does not start even if you start it from dash or terminal. Its window appears for a second but it stucks.

I've found out a solution to this problem and it really works out! The solution is to compile the source code of XML Copy Editor from scratch.

mkdir ~/compilexmlcopyeditor && cd ~/compilexmlcopyeditor
sudo apt-get purge xmlcopyeditor
sudo apt-get build-dep xmlcopyeditor
sudo apt-get source xmlcopyeditor
cd xmlcopyeditor-
1.2.0.6
sudo dpkg-buildpackage -rfakeroot -us -b
cd ..
dpkg -i *.deb


After the steps above,  in terminal window run the program as below:
xmlcopyeditor <YOUR_XML_FILE>

Bingo!..

References
https://bugs.launchpad.net/ubuntu/+source/xmlcopyeditor/+bug/967087



11 Kasım 2012 Pazar

Sourcey G++ Lite Installation for Mips-GNU-Linux and PATH Adjustment for Fedora and Ubuntu

In order to install mips cross compiler, we firstly have to find mips-4.3-51-mips-linux-gnu.bin.
Go to the directory where mips-4.3-51-mips-linux-gnu.bin is located, open a terminal and write:
$ ./mips-4.3-51-mips-linux-gnu.bin
If you do not have a customization, proceed with Next to the end of the installation through the wizard.
After the installation completes, open a terminal, write "mips" and press TAB to check whether the cross-compiler name completes automatically. If not, we shall add the compiler to PATH.

For Fedora,
$ cd /home/$USER
$ vi .bash_profile
You can also edit .bash_profile with more user friendly text editors as "Gedit".
To the bottom of the file -before #END- :
PATH=$PATH:/opt/Sourcery_G++_Lite/bin
export PATH
Restart your computer to apply the changes.

For Ubuntu
$ gedit .bashrc
To the bottom of the file add the lines below:
PATH="/home/$USER/CodeSourcery/Sourcery_G++_Lite/bin:${PATH}"
export PATH
PATH=$PATH:/opt/Sourcery_G++_Lite/bin

Restart your computer to apply the changes

Now we are able to cross-compile our projects with mips-gnu-linux.

Note: If you are using Ubuntu and encounter a problem during compilation like:
gcc version 4.3.2 (Sourcery G++ Lite 4.3-51) GCC version should be gcc version 4.3.2. please check it!!
make[1]: *** [check_gccver] Error 99 

and compilation fails, you should make some modifications:
Make sure that the symbolic link /bin/sh points to /bin/bash rather than /bin/dash (for Ubuntu 7.04+ dash is the default, check it). To change it run the following command (with root priviledge):
$ sudo rm /bin/sh
$ sudo ln -sf /bin/bash /bin/sh

$ ls -alh /bin/sh

 Try to compile again your project, everything has to be OK now!
 


 
 







10 Kasım 2012 Cumartesi

Ubuntu 12.04 System Configuration for Nvidia Optimus Graphic Card

After proper installation of Ubuntu 12.04, I faced with Graphic card and Power management problems with my Z570 notebook. In this release, I will try to explain how I handled these issues.

If your notebook has a Nvidia Optimus graphic card, this means that your notebook having two graphic cards. One of them is Nvidia and the other one is Intel HD most probably. While you're using Windows 7, the Windows 7 drivers provide a switching between these graphic cards according to performance requirements.

In order to handle this issue, I will advice the readers to follow the instructions at the given web site: https://wiki.ubuntu.com/Bumblebee

There are infinitely many rubbish information about Bumblebee, so using the link above will be enough for this issue. If you encounter a problem like "Cannot find bumblebee and bumblebee-nvidia package", ensure that in UpdatesAvailable-->Settings->Software Source-->OtherSoftware the bumblebee package selections are ticked.

Please do not install any drivers for Nvidia before Bumblebee installation. If you have already installed Nvidia drivers, you shall purge them by:
apt-get purge nvidia-current
rm /etc/X11/xorg.conf
reboot now
In fact, Bumblebee will install nvidia drivers itself. After installation of Bumblebe, you should reboot the system.
After reboot, you should check your Graphics card shown in "System Details". Mine is "Intel® Sandybridge Mobile
x86/MMX/SSE2".
If you have an improper resolution as 640x480, I suggest you to make the changes given below:
In /etc/X11/xorg.conf, look for these two lines :
HorizSync 28.0 - 33.0
VertRefresh 43.0 - 72.0
and replace them with
HorizSync 30.0 - 83.0
VertRefresh 56.0 - 75.0
Reboot or Logout to apply the changes.
Finally, in order to test if your Nvidia Graphic card is working properly in Ubuntu, open the terminal and write the command:
optirun glxspheres 
You can see the similar lines as given below on the terminal:
sezerb@sezerb-Ideapad-Z570:~$ optirun glxspheres
Polygons in scene: 62464
Visual ID of window: 0x21
Context is Direct
OpenGL Renderer: GeForce GT 520M/PCIe/SSE2
97.621786 frames/sec - 108.945913 Mpixels/sec
103.086423 frames/sec - 110.279806 Mpixels/sec
106.882137 frames/sec - 104.728248 Mpixels/sec
 
This is how "optirun" commands work. For instance if you want to use your Nvidia card with firefox, you should write:
optirun firefox 
Bumblebee also sets the power switch of your Nvidia card to OFF if you are not using "optirun" command.
This provides power management and long battery life.
Note: In Bios Configuration menu, one can easily select the switchable graphic card option or the Integrated card option. 
If you do not want to use Nvidia card, you can handle this from Bios.
 
Update @08.12.2012
If you have hybrid graphic cards and if your system allows hardware mux between these cards, you can use also use
vga_switcheroo  (supported by radeon, nouveau) (not supported by nvidia, fglrx)
https://help.ubuntu.com/community/HybridGraphics   
 
References 
 https://wiki.ubuntu.com/Bumblebee
 http://askubuntu.com/questions/201123/screen-resolution-stuck-at-640x480-after-installing-bumblebee