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.

Signed multiplication in Verilog

Status
Not open for further replies.

Aimerbhat

Newbie level 5
Joined
May 14, 2010
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
bangalore
Activity points
1,358
Hi ,

I have 8 numbers like -398.1234 , -14.1898 etc and I have 8 signals generated in the design .
I need to compute

y = c1* x1 + c2 * x2 .... + c8 *x8 ,
where c1 , c2 etc are the constants and x1 , x2 are the signals to the block .

What is the best way to code this ?
since these are floating point numbers , should I multiply them by10, 000 ,
to convert them to integer, do the computation and then again divide by10, 000 ?
If so , dividing by10,000 will not be easy in binary .

Can we declare floating point numbers in verilog, and will the synthesis tool take care of it ?

Thanks ,
Aimer
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,421
Helped
14,442
Reputation
29,148
Reaction score
13,239
Trophy points
1,393
Location
Bochum, Germany
Activity points
284,395
The topic of fixed point numbers has been frequently discussed at Edaboard, you may want to review the respective discussions. Generally, you have to decide about the intended precision and choose a suitable signal bitwidth. Scaling should be done by powers of two, which is nothing but a shift operation with binary numbers. I'm sure, you can figure it out yourself.
 

yanzixuan

Member level 3
Joined
Feb 26, 2009
Messages
65
Helped
10
Reputation
20
Reaction score
6
Trophy points
1,288
Activity points
1,573
Aimerbhat said:
Hi ,

I have 8 numbers like -398.1234 , -14.1898 etc and I have 8 signals generated in the design .
I need to compute

y = c1* x1 + c2 * x2 .... + c8 *x8 ,
where c1 , c2 etc are the constants and x1 , x2 are the signals to the block .

What is the best way to code this ?
since these are floating point numbers , should I multiply them by10, 000 ,
to convert them to integer, do the computation and then again divide by10, 000 ?
If so , dividing by10,000 will not be easy in binary .

Can we declare floating point numbers in verilog, and will the synthesis tool take care of it ?

Thanks ,
Aimer

Hi, seems you want to design a FIR filter.
follow the binary rule, you can multiply then by 2^n(such as 1024) to convert them to integer. after computation, divide it by 2^n.

also, you can declare floating point number in verilog, but only just for simulation.
Synthesis tool can not modify it automatically. if you want implement it on FPGA, i suggest you use the float module from "opencore" or FPGA vendor such as xilinx.
but I thought it's not necessary.

these is anther way to convert real number to binary number: example:
6.125 = 6 + 0.125
6 = 110(binary),

0.125 * 2
0 0.250 * 2
0 0.500 * 2
1 1.000

0.125 = 0.001(binary)

6.125 = 110.001(binary)
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top