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.

Multiplication of float/real value in VHDL

Status
Not open for further replies.

arunprasadvr3

Newbie level 3
Joined
Aug 8, 2018
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
Hello,
I need to implement this exprestion in VHDL

Answer=((0.21*255)+(0.72*100)+(0.07*90))

Can anybody help me how to multiply the float values and roundoff the final answer
 

Hi,

your whole expression is just a constant value: 131.85. No need to calculate anything in VHDL.

Klaus
 

VHDL can do the calculation for real variables or constants, need to convert the integer constants to real

e.g.

Code:
constant answer : real := (0.21*255.0)+(0.72*100.0)+(0.07*90.0);
or
Code:
constant answer : integer := to_integer(round((0.21*255.0)+(0.72*100.0)+(0.07*90.0)));

Real variables aren't synthesizable, depending on what you want to achieve, you'll refer to float or fixed point data type.
 

Hi,
For understanding I have given constant value.

But the real expression is

Answer=((0.21*R)+(0.72*G)+(0.07*B))

R, G, and B are input for the module


Thanks,
Arun
 

Hi,

now it´s a complete different situation.

Are you sure you need the output as "float"?
I´d avoid it.

Try to use integer or fixed point multiplication.

Klaus
 

Hi,
I don't need output as float. I need the output as "integer"

Arun
 

Hi,

integer...
Signed/unsigned? 8bit, 16 bit, 32 bit?

***

I´m no specialist in VHDL.
Thus here my "hardware style" explanation:

depending on what accuracy you need I recommend to replace it with integer multiplication.

Example:
0.21 x R

expand it by 2^16 = 65536

0.21 * 65536 * R / 65536

now combine:
(0.21 * 65536) * R / 65536

and make this an integer value (or let the compile do the job)
(0.21 x 65536) = 13763
--> 13773 * R / 65536

The hardware just calculates "13773 * R" (integer 16 bit x 16 bit multiplication)
and the "/65536" is just a shift 16 bits to the right. ... which indeed is replaced as "wiring" (it takes bits 0..15 of the result instead of bits 16..31)

Klaus
 

    V

    Points: 2
    Helpful Answer Positive Rating
It looks like you want to convert RGB->grayscale.
You can do this without floating values at all.


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
process(clk_pix)
begin
    if rising_edge(clk_pix) then
        grayPixel <= (x"4c"*redSignal + x"97"*greenSignal + x"1C"*blueSignal); --weighted color
    end if;
end process VideoEdition;
 
--output video signals
OUT_vid_data(23 downto 16) <= grayPixel(15 downto 8); --red channel
OUT_vid_data(15 downto 8) <= grayPixel(15 downto 8); --green channel
OUT_vid_data(7 downto 0) <= grayPixel(15 downto 8); --blue channel


The source:
https://miscircuitos.com/video-processing-fpga-zybo-using-vhdl/
 

    V

    Points: 2
    Helpful Answer Positive Rating
For understanding I have given constant value.

But the real expression is

Answer=((0.21*R)+(0.72*G)+(0.07*B))

R, G, and B are input for the module
I think you are still learning to ask clear questions.

As far as I understand now, you want synthesizable VHDL. In- and output is 8 bit unsigned. The resolution of the fixed point factors need to be still defined, 8 bit could be a first guess. The code can be comfortably implemented using IEEE fixed point library or with elementary numeric_std operations. The latter similar to what KlausST suggested, converted to legal VHDL syntax.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top