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 call decimal values in verilog

Status
Not open for further replies.

emerson_11

Member level 2
Member level 2
Joined
Jan 23, 2016
Messages
44
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
355
hy
i am working in a image processing based project using FPGA. i want to call my features into addition block which are decimals in the range of 0.1 to 0.9. Can anyone tell me some techniques to convert these numbers into fixed point binary?
 

KlausST

Super Moderator
Staff member
Advanced Member level 7
Joined
Apr 17, 2014
Messages
23,493
Helped
4,757
Reputation
9,535
Reaction score
5,172
Trophy points
1,393
Activity points
155,819
Hi,

simply use "1...9" as integers.
And imagine as there was a "0." before it.

Or use them as integers and divide them by 10...if you really need this.
****

Maybe you need to give a bit more information, why you especially need to know that it is a value between 0 and 1.

Klaus
 

emerson_11

Member level 2
Member level 2
Joined
Jan 23, 2016
Messages
44
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
355
can anyone explain about the roundoff to the nearest power of 2 concept? can i use this for converting my decimals into rounded integer and then into binary
 

ads-ee

Super Moderator
Staff member
Advanced Member level 7
Joined
Sep 10, 2013
Messages
7,941
Helped
1,822
Reputation
3,654
Reaction score
1,807
Trophy points
1,393
Location
USA
Activity points
60,176
Nearest power of two is finding the 2^N that is nearest to your number.

e.g.
Code:
2 => 2^1 (2)
5 => 2^2 (4), or 2^3 (8, for round up)
13 => 2^4 (16)
As you can see this won't help at all for converting between decimals and binary.

BTW in hardware all decimal numbers are stored as binary values, there are no 10 state FFs. So if you look at the following code:
Code:
wire [3:0] a;
assign a = 10;
// 10 in binary is 1010
// a[0] = 1'b0
// a[1] = 1'b1
// a[2] = 1'b0
// a[3] = 1'b1

For your original question the easiest thing to do is scale all your numbers by *10. Using any kind of 2^N scaling will never give you an exact 0.9 value. What you need to do is determine your required integer and fractional bit widths to obtain the accuracy you desire.
 

emerson_11

Member level 2
Member level 2
Joined
Jan 23, 2016
Messages
44
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
355
can you tell me how to choose an effective scaling factor? whether it should be only *10 s or any other number?
 

ads-ee

Super Moderator
Staff member
Advanced Member level 7
Joined
Sep 10, 2013
Messages
7,941
Helped
1,822
Reputation
3,654
Reaction score
1,807
Trophy points
1,393
Location
USA
Activity points
60,176
You scale based on the number of bit of precision you require.
 

Altaero

Member level 4
Member level 4
Joined
Dec 30, 2013
Messages
78
Helped
24
Reputation
48
Reaction score
24
Trophy points
8
Location
St-Petersburg, Russia
Activity points
575
Fixed point arithmetics is absoultely the same as integer arithmetics, in fact it IS integer arithmetics. It's up to you where to put decimal point.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top