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.

How to multiply a fixed-point number by a signed integer number in Verilog

mohamis288

Full Member level 2
Full Member level 2
Joined
Mar 1, 2022
Messages
130
Helped
0
Reputation
0
Reaction score
1
Trophy points
18
Activity points
974
I want to multiply an 8-bit fixed-point number by an 8-bit signed integer number in Verilog and we want to have just 8 bits in output. So we want to round our output so that after multiplication, our output must be a signed integer. Unless it will overflow. How can I do that?

Wire [7:0] b0 = 8b'0_0100100;
Input [7:0] input = 8b'10100100;
Assign mul= b0*input;

Is it correct?
 

barry

Advanced Member level 6
Advanced Member level 6
Joined
Mar 31, 2005
Messages
5,990
Helped
1,177
Reputation
2,366
Reaction score
1,321
Trophy points
1,393
Location
California, USA
Activity points
32,589
1) Unless you have some severe constraints, you’re going to have a lot of opportunity for overflow.
2) What’s your fixed point format, 4.4? 6.2?
3) You’ll probably need to do rounding, unless you can live with the truncation error.
4) Im not a verilog person, so I can’t speak to that, but I don’t think your simplistic “b0*input” will work. I think you need to convert both numbers to the same type.
 

FvM

Super Moderator
Staff member
Advanced Member level 7
Joined
Jan 22, 2008
Messages
50,970
Helped
14,629
Reputation
29,534
Reaction score
13,733
Trophy points
1,393
Location
Bochum, Germany
Activity points
291,643
Your variables are actually unsigned, signed has to be declared explicitly. Whe multiplying unsigned with signed, the unsigned variable is treated as signed, thus you need to extend 8 bit unsigned coefficient to 9 bit signed.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top