Continue to Site

# Dealing with the real varaibles in verilog

Status
Not open for further replies.

#### Alisha.kunder

##### Newbie level 1
i hv written the program of gauss siedel for 3 by 3 matrix in verilog....
i dont know how to define the value 0.005 in verilog...
its giving an error when i am defining it using real variables.
i read ur post which says real values are not synthesisable...but i am not able to find a solution for it.. please help me wid this.

prog:

module gss_seidel(sol0,sol1,sol2,matrx00,matrx01, matrx02, matrx10, matrx11, matrx12,matrx20, matrx21, matrx22);

output [7:0]sol0,sol1,sol2;
input [7:0]matrx00,matrx01, matrx02, matrx10, matrx11, matrx12,matrx20, matrx21, matrx22;
wire [7:0]r,s,m,p1,p2,p3;
reg matx[2:0][3:0];
reg solutions[2:0];
integer i,j,k;
reg [7:0]result, diff, pivotalrow, pivotalelement, t;
real maxdiff;
always@(matrx00,matrx01, matrx02, matrx10, matrx11, matrx12,matrx20, matrx21, matrx22)
begin
$display("\n GAUSS-SEIDEL ITERATIVE METHOD\n\n"); matx[0][0]= matrx00; matx[0][1]= matrx01; matx[0][2] = matrx02; matx[1][0]= matrx10; matx[1][1]= matrx11; matx[1][2]= matrx12; matx[2][0]= matrx20; matx[2][1]= matrx21; matx[2][2]= matrx22; for(i=0; i<3; i=i+1) begin pivotalelement=matx; pivotalrow=i; for(j=pivotalrow+1; j<3; j=j+1) if (pivotalelement < matx[j]) begin pivotalelement = matx[j]; pivotalrow=j; end for(j=0;j<=3; j=j+1) begin t=matx[j]; matx[j]=matx[pivotalrow][j]; matx[pivotalrow][j]=t; end end /* using Gauss-Seidel iterative method */ maxdiff = 5E-4; k=0; while(maxdiff>=5E-4) begin k=k+1; maxdiff = 0; /* rowwise scanning, substituting estimates of (nofequations-i) unknowns to get Xi in the ith row */ for(i=0; i<3; i=i+1) begin result=matx[3] ; /* columnwise scanning, to get the solution of ith unknown in ith row */ for(j=0; j<3; j=j+1) if(i!=j) result= result-matx[j]*solutions[j]; result=result/matx ; diff=solutions-result; if(diff>maxdiff) maxdiff = diff; solutions=result; end /* end of outer for loop */$display("\n\n No. of iterations= %d", k) ; /* gives the no. of iterations performed */

for(j=0; j<3; j=j+1)
$display(" %f",solutions[j]) ; /* current estimated solutions will be printed */$display(" %f",maxdiff);

end /* end of outermost while loop */

$display("\n\n\n"); /* printing solutions */ for(i=0; i<3; i=i+1)$display(" X%d = %f \n", i, solutions) ;

end

assign p1 = solutions[0],
p2 = solutions[1],
p3 = solutions[2];

endmodule

ERROR:Xst:2228 - "gss_seidel.v" line 31: Unsupported Real variable.

Verilog is not a programming language it is a hardware description language. What you've written is a program (something you would do in a testbench) that is not synthesizable as it can not be realized in hardware. Even without using real types the for loops won't unravel correctly in hardware.

You're coming from a purely SW background, right? You need to switch to a hardware mindset and think in terms of physical registers/gates/memories/etc. You also have to keep in mind parallelism. If you can't draw a diagram of the design with registers and such then you won't be able to describe it properly in an HDL.

Alisha.kunder

### Alisha.kunder

Points: 2
you must first determine if the fixed or floating point representation makes sense.

for example, a decimal could be written as 0.2. This would also be "two tenths". 2 is an integer. As the metric system shows, there is no reason why "a tenth" can't be pulled into the units place. eg 0.123m = 123 mm. The latter is again an integer.

thus, something like 0.123 * 0.4 could be done as (123m * 400m) / (1000*1000). The latter step may not be needed in all cases as you might not need to know the exact value, just a comparison. You would also use power-of two representations instead of base-10 decimal.

floating point also has a non-uniform scale that is useful for scientific computing, but uses more resources.

i hv written the program of gauss siedel for 3 by 3 matrix in verilog....
i dont know how to define the value 0.005 in verilog...
its giving an error when i am defining it using real variables.
i read ur post which says real values are not synthesisable...but i am not able to find a solution for it.. please help me wid this.

prog:

module gss_seidel(sol0,sol1,sol2,matrx00,matrx01, matrx02, matrx10, matrx11, matrx12,matrx20, matrx21, matrx22);

output [7:0]sol0,sol1,sol2;
input [7:0]matrx00,matrx01, matrx02, matrx10, matrx11, matrx12,matrx20, matrx21, matrx22;
wire [7:0]r,s,m,p1,p2,p3;
reg matx[2:0][3:0];
reg solutions[2:0];
integer i,j,k;
reg [7:0]result, diff, pivotalrow, pivotalelement, t;
real maxdiff;
always@(matrx00,matrx01, matrx02, matrx10, matrx11, matrx12,matrx20, matrx21, matrx22)
begin
$display("\n GAUSS-SEIDEL ITERATIVE METHOD\n\n"); matx[0][0]= matrx00; matx[0][1]= matrx01; matx[0][2] = matrx02; matx[1][0]= matrx10; matx[1][1]= matrx11; matx[1][2]= matrx12; matx[2][0]= matrx20; matx[2][1]= matrx21; matx[2][2]= matrx22; for(i=0; i<3; i=i+1) begin pivotalelement=matx; pivotalrow=i; for(j=pivotalrow+1; j<3; j=j+1) if (pivotalelement < matx[j]) begin pivotalelement = matx[j]; pivotalrow=j; end for(j=0;j<=3; j=j+1) begin t=matx[j]; matx[j]=matx[pivotalrow][j]; matx[pivotalrow][j]=t; end end /* using Gauss-Seidel iterative method */ maxdiff = 5E-4; k=0; while(maxdiff>=5E-4) begin k=k+1; maxdiff = 0; /* rowwise scanning, substituting estimates of (nofequations-i) unknowns to get Xi in the ith row */ for(i=0; i<3; i=i+1) begin result=matx[3] ; /* columnwise scanning, to get the solution of ith unknown in ith row */ for(j=0; j<3; j=j+1) if(i!=j) result= result-matx[j]*solutions[j]; result=result/matx ; diff=solutions-result; if(diff>maxdiff) maxdiff = diff; solutions=result; end /* end of outer for loop */$display("\n\n No. of iterations= %d", k) ; /* gives the no. of iterations performed */

for(j=0; j<3; j=j+1)
$display(" %f",solutions[j]) ; /* current estimated solutions will be printed */$display(" %f",maxdiff);

end /* end of outermost while loop */

$display("\n\n\n"); /* printing solutions */ for(i=0; i<3; i=i+1)$display(" X%d = %f \n", i, solutions) ;

end

assign p1 = solutions[0],
p2 = solutions[1],
p3 = solutions[2];

endmodule

ERROR:Xst:2228 - "gss_seidel.v" line 31: Unsupported Real variable.

Hi Alisha.kunder,

Like permute says you can do by scaling the numbers. One more solution is fixed point format(2'c m.n Format). You decide first what is the fixed point format of your input and output(2'c m.n Format).For that just go through the below link,It may helpful to you.
http://x86asm.net/articles/fixed-point-arithmetic-and-tricks/.