[Basic VHDL] arithmetic operation

One of the common errors that many beginners will experience at the first time when they use vhdl is:: ERROR:HDLCompiler:1731 which means that : found '0' definitions of operator "+", cannot determine exact overloaded matching definition for "+". Let see what the root cause of this error is and how to fix it:

In VHDL, we cannot use arithmetic operation on std_logic or std_logic_vector data type directly. Let consider below code snippet:

[Basic VHDL] Type Conversion Functions

VHDL is a very strong-type language, it means that we must supply the arguments of exactly right type to a function or operator. Otherwise, the compiler will give an error message.

Although many functions or operators are overloaded so that you can use the same functions for more than one type of data, in many cases it is a must to do a type conversion.

Many type conversions can be found in the package std_logic_arith in ieee library. Mostly we deal with std_logic_vector, unsigned and integer type.

Below are some common conversion functions, we should memorize because of its convenience:

std_logic_vector to  unsigned: unsigned(x)

std_logic_vector to integer: conv_integer(x)

unsigned to std_logic_vector: std_logic_vector(x)

unsigned to integer: conv_integer(x)

integer to unsigned: conv_unsigned(x,len)

integer to std_logic_vector: conv_std_logic_vector(x,leng)

std_logic_vector to integer: to_integer(unsigned(x));


vhdl, tutorial, type conversion functions, common vhdl conversion function

[Xilinx] Simulation Runtime: How to change default simulation run time

Default simulation run time in Xilinx is 1000ns. Sometimes, we need a bigger time frame to run our simulation. We can easily change this default value into our desired value. It can be done either by ISIM command or window GUI setting.

Below is one of the easy ways to change default simulation run time. ( simulation time )


Step1: From your main working workspace, choose the option "Simulation"


(Click The Image To Enlarge The View)



Step 2: Right click on Simulate Behavioral Model, then choose Process Properties...


(Click The Image To Enlarge The View)



Step 3 : change the default vaule 1000 ns in texbox Simulation Run Time to your expected value:


(Click The Image To Enlarge The View)


Xilinx, Tutorial, Change the simulation run time, Simulation time

[Basic VHDL] Signal Assignments: with/select ; when/else; case/when

In  vhdl, we usually can do the same things in different ways; and, signal assignment is one of the them. There are basically 3 ways to do it. They are look kinda similar and not easy to remember. Let's take a look at these signal assignments.

1- with .... select ..... when
with/select is called officially "selected signal assignment" in vhdl. below is an example of this signal assignment:

1
2
3
4
5
6
7
8
9
 with op select
 
 controls y <= "110000010" when "000000",
     "101001000" when "100011",
     "001010000" when "101011",
     "000100001" when "000100",
     "101000000" when "001000",
     "000000100" when "000010",
     "---------" when others;  

2- When ..... else
It is officially called "conditional signal assignment"  in vhdl. It seems to be a little bit more general than with/select/when. Below is an example of this signal assignment:

1
2
3
4
5
6
7
 y <=      "110000010" when op = "000000" else
   "101001000" when op = "100011" else
   "001010000" when op = "101011" else
   "000100001" when op = "000100" else
   "101000000" when op = "001000" else
   "000000100" when op = "000010" else
   "---------" when others;

3- Case ... when
This statement is always used inside a process. This statement is the same as IF-THEN-ELSE statement. They are equivalent.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 process(op) is begin
  case op is
   when "000000" => controls <= "110000010";
   when "100011" => controls <= "101001000";
   when "101011" => controls <= "001010000";
   when "000100" => controls <= "000100001";
   when "001000" => controls <= "101000000";
   when "000010" => controls <= "000000100";
   when others   => controls <= "---------";
  end case;
 end process;

[Xilinx] Error Fixing: model technology's vsim executable cannot be found

Whenever you have got below error while running simulation:
"model technology's vsim executable cannot be found"

It means that you need to choose a suitable simulator, there are some ways to overcome this. below is one of the easy way to fix this error ( for VHDL ):

Step1: Right click on your main file, and choose Design Properties...:





Step2: a new window will be popped up. Then click on Simulator, then choose ISim as below image:
That is it! try to run your simulation again!



Few words to jot down

The key to life is accepting challenges 
 
Obstacles can't stop you.

Problems can't stop you.

Most of all other people can't stop you.

Only you can stop yourself.

Challenges are what make life interesting;
Overcoming them is what makes life meaningful.

Boring C code ever! - Easy to get error

Khi sử dụng một #define trong C, chúng ta nên chú ý dùng dấu ngoặc trong các biểu thức được define.
Ngoài ra, nếu trước đó ta đã khai báo một biến, sau đó lại define một tên trùng với tên biến đó. Thì từ lúc define đó trở đi, tên được define sẽ được sử dụng cho tới khi ta undef nó ( như ví dụ với M bên dưới)

#include

#define in printf
#define N 100
#define length1 3 + 5
#define length2 (3+5)
void main()
{
    int M = 200;
    int x = 2*length1;
    int y = 2*length2;
    in("\n N= %d M=%d",N,M);
#define M 300
    in("\nM=%d",M);
#undef M
    in("\nM=%d",M);
    in("\n%d",x);
    in("\n%d",y);
}

[Thuật toán cơ bản] Xác định số nguyên tố

Xác định số nguyên tố: ngôn ngữ C

#include
#include

void main()
{
int i,n,ngt=1;
printf("Nhap so n = "); scanf("%d",n);
for(i=0;i
(ng_to=1)?printf("%d la so nguyen to",i):printf("%d khong la hop so",i);
getch();
}

Lập trình C: Tìm số nguyên tố
Tìm số nguyên tố dùng C
Thuật toán tìm số nguyên tố dùng C
Thuật toán xác định số nguyên tố dùng C

[Thuật toán cơ bản] A simple algorithm for getting a square root of a number

Thuật toán tính căn bậc 2 dùng ngôn ngữ C / Lập trình C
 
#include
#include
#include

void main()
{
    double a,xn,c;
    printf("\nNhap: ");scanf("%lf",&a);
    xn = a;

    do
    {
        c = xn;
        xn = (xn*xn + a)/(2*xn);
    }while(fabs((xn-c)/c) >= 0.00001);
    printf("\ncan bac 2 sai so: %lf",xn);
    printf("\nchinh sac: %lf", sqrt(a));
}



Thuật toán tính căn bậc hai dùng ngôn ngữ C / Lập trình C
Lập trình C: Tính căn bậc hai
Ngôn Ngữ C: Tính căn bậc 2

Boring C code ever! - solve quadratic equations

( Giải phương trình bậc hai dùng ngôn ngữ C )
Doing all of the calculation in only 1 code line for solving quadratic equation
How boring it is, isn't it :D

#include
#include
#include

void main()
{
    double a,b,c;
    printf("=======================================\n=============== GPTB 2 ================\n=======================================\nNhap du lieu a,b,c cua phuong ax^2 + bx + c = 0\n");
    printf("Nhap a = "); scanf("Nhap a = %lf",&a);
    printf("\n");
    printf("Nhap b = "); scanf("%lf",&b);
    printf("\n");
    printf("Nhap c = "); scanf("%lf",&c);
    printf("\n");

    (a == 0)?((c==0)?((b == 0)?printf("PT vo so nghiem\n"):printf("PT vo nghiem")):((b == 0)?printf("PT vo nghiem\n"): printf("PT co 1 nghiem: %lf",-c/b))):((c != 0) ? ((b == 0) ?(( c< 0) ?printf("PT co nghiem: x = +/-%lf",sqrt(-c/a)):printf("PT vo nghiem\n")):(((b*b - 4*a*c) > 0) ?printf("PT co 2 nghiem: \nx1 = %lf \nx2 = %lf\n",(-b + sqrt(b*b - 4*a*c))/(2*a),(-b-sqrt(b*b - 4*a*c))/(2*a)):printf("PT vo nghiem\n"))):((b == 0)?printf("PT co nghiem x=0"):printf("PT co 2 nghiem x1 = 0 and x2 = %lf",-b/a)));
}


Click on the image to enlarge your view :)

C programing trick!!

What is wrong ??
#include
#include

void main()
{
    printf("%10.0f",-3456);
    getch();
}


There might be some tricks on C programming section in an interview test. Have you ever experienced such kind of trick. If not, above is one of a typical examples which might be on your interview test.

Try to figure out what is going on with above short code !!!

At the first glance, you may ask yourself what is wrong with it. It is just a simple code, nothing wrong with it. But, when you actually run this kind of code. the printing result is not as your expected. It's gonna be 0.

What is the problem here? ---> Try to figure it out by yourself ;)

How to fix that code to run in a proper way ?
--->  it is so easy, isn't it. Just need to put 3456.0 instead of 3456

How to remember a series of number

It is not easy to remember a series of 10 number, isn't it ? But, it will be not difficult when we assign a meaningful word for each pair of number in that series and then build up your own funny story based on those words. Then, you just need to memorize the story in stead numbers.

Below is my own example about this. You can create your own words as well.

However, you need to follow the rule:
1- S,X
2- N
3- M
4- R,Q
5- L
6- G
7- C,K
8- V,D,Đ
9- P,B















(click on the picture to enlarge your view)

Example:
1727629152

=> 17 27 62 91 52: Sợi Tóc bị rơi vào vũng Nước, ngay lập tức nó bị biến thành con Giun. Con Giun đó đang bò thì bị rơi vào tô Bún, tô bún rất nóng làm con giun biến thành con Lươn

Sợi tóc --> Nước --> Giun --> Bún --> Lươn!

How easy it is to remember!

Cover letter! how ?

Step 1: Like many ways to write a traditional letter, we should always start with a greeting. In the cover letter, it is better to start with "Dear".
  • If you know who will receive your letter, just simply write their name. 
    • eg: Dear John,
  • If you don't know exactly who will read the letter, just greet in a general way.
    • e.g: Dear Hiring Manager, . Or, Dear Recruiting Team,
Step 2: After your greeting, you need to write which position you want to apply for. Normally, this will take about one or two sentences in length to mention abou the position.
  • e.g: I am writing this with regard to the position Embeddes Software Engineer which you have mentioned on the website ....
 Step3: Most of the cover letters need about 1 or 2 body paragraph, you should not overwhelm the hiring manager with lot of useless information. In the body paragraph, we just need to answer basic questions, like below:
  • Why am I a qualified candidate for this position?
  • What work experience do I have that fits the job requirements in the company's listing?
  • Why do I want to work for this company specifically?
 Step4: As an short essay, we will need to have a conclusion for it. This is where you will wrap up and discuss how you will proceed with the application.

Step5: End our cover letter with a respecful  closing statement and finish your letter with your full name.
Related Posts Plugin for WordPress, Blogger...