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 convert std_logic_vector to ufixed or sfixed in VHDL?

Status
Not open for further replies.

melexia

Member level 2
Joined
Jun 2, 2008
Messages
43
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,620
Hi all,
I am trying to implement DFT in VHDL. My code takes input from memory in std_logic_vector. But if I want to use CORDIC for sin/cos conversion it requires input in 2Qn format. For time being I have arranged bits in that format but is their any function to convert std_logic_vector to ufixed. Because that bit arrngement is going difficult for further operations.
I know that I can use ieee.proposed.fixed library but for that also I will require variables in ufixed or sfixed format.

Please help, time running out off my hands.

Thanks
 

in the fixed point package, there is a function to convert std_logic_vector to ufixed/sfixed.

function to_ufixed (
arg : STD_ULOGIC_VECTOR; -- shifted vector
constant left_index : INTEGER;
constant right_index : INTEGER)
return UNRESOLVED_ufixed;

there is also a a to_slv function that only takes in a single ufixed or sfixed.

Out of interest, why dont you use sfixed/ufxied for your port inputs rather than std_logic_vector?
 

Thanks, I will definitely try it.
As I am calculating DFT of a signal, input to my code is an output of 8 bit ADC which I will have take as std_logic_vector.
Do u have any suggestion?
 

the output from the ADC is just an 8 bit signal. You can have the top level as ufixed(7 downto 0) if you want.
 

you r right, i can use it like that.
thanks
 

hi, since i want to do the calculation on multiplying 2 data in fixed point. How i want to write the VHDL? what should i put the library package since i cant use sfixed or ufixed all the time?or any suggestion for the complete VHDL? just a simple multiply 2 data like 1.2 X 3.6

thanks
 

you have to use ieee proposed fixed point library which is available with xilinx ise.
This library allows u to convert std_logic to sfixed or ufixed and reverse.
Also multiplication in fixed point is same as that of in std_logic or integer. use '*' for multiplication.
c <= a * b
all has to be of same datatype
 
Now i am using QuartusII to simulate my VHDL. but i cant run the code successful. there are no respond on Library ieee_proposed; i used. Any suggestion?
 

Download the VHDL 93 version of the floatfixlib from here:

**broken link removed**

Just include it in your design like any other design file.

the floatfixlib has become a standard part of the VHDL language in VHDL 2008, but vendors are only just starting to support that standard.

but for multiplication, with a pipline register, here is some sample code that synthesises fine in Quartus, even at the top level.

Code:
library ieee;
use ieee.std_logic_1164.all;

library floatfixlib;
use floatfixlib.fixed_pkg.all;

entity my_mult is
  port (
    clk       : in  std_logic;
    
    a,b       : in  sfixed(3 downto -4);
    c         : out sfixed(7 downto -8)
  );
  
end entity my_mult;
  
architecture rtl of my_mult is
begin
  
  mult_proc : process(clk)
  begin
    if rising_edge(clk) then
      c <= a * b;
    end if;
  end process;
  
  
end architecture rtl;
 
after go through the link provided, which file i should download? is it consists of 11 files? where should i include those files?
the error said that design library "floatfixlib" does not contain primary unit "fixed_pkg" after run the code.
What to do?

thanks
 
Last edited:

you only need to include float_fixed_types_c.vhd and fixed_pkg_c.vhd to use fixed point.

Make sure you get the load order correct.
 
sorry for asking this, where or which directory do i need to include that 2 files?

---------- Post added at 23:08 ---------- Previous post was at 23:02 ----------

thanks trickyDicky. i success run the code. going to do the next step. thanks a lot
 

can i convert sfixed o std_logic_vector ?
 

so if i have a real number should i convert to sfix first then slv
 

real numbers cannot be used in synthesisable VHDL unless it is a constant.
But yes, real -> sfixed -> slv is easiest.
 
thanks i ll use it in testbench only
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top