cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
live4perfection
Adventurer
Adventurer
11,520 Views
Registered: ‎04-24-2015

Multiply Floating Point to Std_logic_vector in VHDL

Jump to solution

 

Hello ,

 

 I have 32 bit std_logic_vector signal and want to multiply it by floating point .

 

e.g

         signal Input : std_logic_vector (31 downto 0 );

         signal number = 0.2 ;

 

         signal Output: std_logic_vector (31 downto 0 );

 

 

          Output <= 0.2 * Input ;

 

 What can be the best solution to do this kind of multliplication ? i have read somewhere that floating point arithmetic operation is not synthesisble so better to use fixed point numbers . How to do it ?

 

 It would be appreciated if anyone can tell me the proper idea to do that sort of operation .

 

 Thanks

 

 

0 Kudos
1 Solution

Accepted Solutions
muzaffer
Teacher
Teacher
16,669 Views
Registered: ‎03-31-2012

You don't need DMA for this purpose. It would be slow & efficient but you can create a ful AXI FP block and connect it to one of the master ports on the Zynq PS/PL interface directly (or through a simple interconnect).

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

View solution in original post

0 Kudos
19 Replies
yenigal
Xilinx Employee
Xilinx Employee
11,515 Views
Registered: ‎02-06-2013

Hi

 

You can use the Floating point IP for this.

 

Check below link and the documentaion tab for the product guide.

 

http://www.xilinx.com/products/intellectual-property/floating_pt.html

Regards,

Satish

--------------------------------------------------​--------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful.
--------------------------------------------------​-------------------------------------------
0 Kudos
syedz
Moderator
Moderator
11,507 Views
Registered: ‎01-16-2013

Hi,

 

As suggested by @yenigal you can use floating point which is the best case.

Also check if the information in below link is helpful.

http://www.ece.rochester.edu/~parihar/pres/Pres_FP-Multipliers.pdf

 

--Syed

 

--------------------------------------------------​--------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.

Give Kudos to a post which you think is helpful.
--------------------------------------------------​-------------------------------------------

---------------------------------------------------------------------------------------------
Kindly note- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

Did you check our new quick reference timing closure guide (UG1292)?
---------------------------------------------------------------------------------------------
0 Kudos
muzaffer
Teacher
Teacher
11,480 Views
Registered: ‎03-31-2012
do you intend to interpret 'input' as 32 bit single precision floating point number? If so you need to use FP IP in some form. There is VHDL FP library which was distributed a while back but I am not sure whether Vivado can synthesize it. The other option is to use Xilinx FP IP as others have mentioned.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
live4perfection
Adventurer
Adventurer
11,475 Views
Registered: ‎04-24-2015

I started searching that IP catalogue and  I had used that very exact Floating Point IP. I added in my Block design and connected via DMA. I set the option "float to Fixed " in that IP (assuming I will send floating point value from SDK ). After generating bitstream, I used the DMA function to send the value float 0.2 to TxBufferPtr, But unfortunately I see only 0 input and 0 output :( So floating point cannot be the input for sending value to DMA. What should I do to complete my required task :(

0 Kudos
muzaffer
Teacher
Teacher
11,466 Views
Registered: ‎03-31-2012
You don't need fixed point option. SDK can generate FP values. You just need to cast them properly when you write them to the buffer.
*((float*)txtbufferptr) = 0.2;
A floating number is just a 32 long bit vector so you can write it to hardware as is.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
live4perfection
Adventurer
Adventurer
11,457 Views
Registered: ‎04-24-2015

Oh Ok... Thanks for that comment.. but should not I set any option in floating point IP ? as it has so many operations so i have to choose one of them " Absolute Value, Accumulaotr, Add/Subtract .... and so on " ....

 

0 Kudos
live4perfection
Adventurer
Adventurer
11,446 Views
Registered: ‎04-24-2015

 & Further, If i select Absolute Value Option, there is no clock port avaialable on IP then, and ultimately it failed to generate bit-stream.

 

What should i do ? Kindly help ..

 

 

Thanks

0 Kudos
muzaffer
Teacher
Teacher
11,419 Views
Registered: ‎03-31-2012
You should select the operation which you need. You earlier said you were trying to multiply by 0.2 so that's what you should select. The connect the 32 bit vector which represents 0.2 to one of the inputs of the multiplier and the 32 bit vector which represents the floating point number to be scaled to the other multiplier input.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
live4perfection
Adventurer
Adventurer
11,414 Views
Registered: ‎04-24-2015

Yes. Thanks for clarify this. But that was the simple case.
Actually in My custom Ip, Output is somewhat like that " --    Output<=  reg1 + ( (reg0 - 1 + reg2) * Float_Input)  ;      

 

so its not simply input*0.2 .  After arithmetic operation on input , then the result will multiply by 0.2 .  So i may be thinking to choose float to float operation to use that floating data into my code.

 

Tell me kindly if  i am wrong.

 

Thanks again for your help.

0 Kudos
muzaffer
Teacher
Teacher
10,590 Views
Registered: ‎03-31-2012
from the looks of it you need an add_sub IP and a multiply IP. You can instantiate these two instances and then use a state machine to drive your signals to their inputs and control the add_sub signal.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
live4perfection
Adventurer
Adventurer
10,575 Views
Registered: ‎04-24-2015

Hy.

 

Just need to ask one thing. Is there any other block that can connect from Zynq PS to Floating Point Operator except DMA ?

 

I dont want to use DMA for connecting Floating Point Operator. Is there any way that Zynq PS can send value to Floating Operator ?

0 Kudos
muzaffer
Teacher
Teacher
16,670 Views
Registered: ‎03-31-2012

You don't need DMA for this purpose. It would be slow & efficient but you can create a ful AXI FP block and connect it to one of the master ports on the Zynq PS/PL interface directly (or through a simple interconnect).

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.

View solution in original post

0 Kudos
live4perfection
Adventurer
Adventurer
10,561 Views
Registered: ‎04-24-2015

 

This is how I had done  : connected GPIO Port of PS to my Floating Point Operator which will go to my PL then. Is it right method for connecting ?

New Bitmap Image (6).bmp
0 Kudos
live4perfection
Adventurer
Adventurer
10,556 Views
Registered: ‎04-24-2015

This is how I had done  : connected GPIO Port of PS to my Floating Point Operator which will go to my PL then. Is it right method for connecting ?

a.png
0 Kudos
muzaffer
Teacher
Teacher
10,540 Views
Registered: ‎03-31-2012
that's one way. I am not sure you need the GPIO.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
live4perfection
Adventurer
Adventurer
10,508 Views
Registered: ‎04-24-2015
0 Kudos
live4perfection
Adventurer
Adventurer
10,373 Views
Registered: ‎04-24-2015

@muzaffer @syedz @yenigal

 
I am still confused regarding fixed point. Ok I will send fixed point number 2 from C code. (2 represents 0.2 float , if ratio is 1/10). This integer 2 will go to FPGA . So I can use that integer 2 in my FPGA ? or I should convert that 2 in 32 bits number ? OR if I use Xilinx FP Ip, so should I use float-fixed conversion ( by sending float value and receiving fixed value at FPGA side)

 

0 Kudos
muzaffer
Teacher
Teacher
10,363 Views
Registered: ‎03-31-2012

Ok I will send fixed point number 2 from C code. (2 represents 0.2 float , if ratio is 1/10). This integer 2 will go to FPGA . So I can use that integer 2 in my FPGA ? or I should convert that 2 in 32 bits number ? OR if I use Xilinx FP Ip, so should I use float-fixed conversion ( by sending float value and receiving fixed value at FPGA side)

 

0.2 is 0x3E4CCCCD in IEEE 754 single precision floating point representation so 0x3E4CCCCD is what you send to your FPGA design which uses a Xilinx FP IP which accepts the single precision inputs. 

Learn about IEEE 754 and see if you can use it for your purposes.

- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos
live4perfection
Adventurer
Adventurer
10,335 Views
Registered: ‎04-24-2015

and is it right that 0.2 will be 00000100 in fixed point ( 8 bits) or 0.5 = 00001000 . So i need to send such fixed point value from SDK not float one.

0 Kudos