Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

problem: multiply two fractional numbers in verilog

Status
Not open for further replies.

mohsen p

Newbie level 1
Newbie level 1
Joined
Apr 17, 2010
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,288
I have to multiply two fractional numbers of 42 bits in verilog. I am using the fixed point (Q12.30). Now my result is wrong.

part of my code:
Code:
module my_name (out,Clk);
    input Clk;
    output reg signed [83:0] out;  //(Q24.60)
    reg signed [41:0] in1;         //(Q12.30)
    reg signed [41:0] in2;         //(Q12.30)
  
    always @(posedge Clk)
        out <= in1 * in2;
endmodule

for example if in1=-2 & in2=-1.89652 then out=3.79304 , but my result is -15956.351736 !!!

in modelsim:
-2 is 42'b111111111110_000000000000000000000000000000
-1.89652 is 42'b111111111110_00011010011111011010111100000
-15956.351736 is 111111111100000110101011_101001011111010010100010000000000000000000000000000000000000 (WRONG)

plz tell me how multiply two fractional numbers.
thanks.
 

hi first of all your value
-1.89652 is 42'b111111111110_00011010011111011010111100000

It should be something like => 111....111_11 1001 0110 0000 1001 0101 0110 1100

since 0.89652 * 2^30 = 962631020)base10 => 11 1001 0110 0000 1001 0101 0110 1100)base_2

does not seem right,
Try doing this
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top