+ Post New Thread
Results 1 to 5 of 5
  1. #1
    Newbie level 1
    Points: 16, Level: 1

    Join Date
    Mar 2018
    Posts
    1
    Helped
    0 / 0
    Points
    16
    Level
    1

    VHDL Multiplying by a fraction

    Hello,

    I am working on an FPGA design where a 20 bit signal is transferred from one component to another component, where a procedure is performed using the 20-bit signal. The calculation performed in the procedure is multiplying the 20 bit signal by 0.00034, or 680/2000000, and then placing this value into a signal of the integer type. However this generates a negative slack for the transfer of data between the register of the 20 bit signal in the first component, and the register of the integer signal in the second component. When I look at the data path in the timing report, it seems that the bulk of the delay is due to the calculation performed in the second component. Is there a less time consuming way to perform the calculation? The calculation in the procedure looks like this at the moment:

    Code:
    -- Calculates distance in centimeters
    	PROCEDURE calculate_distance 
    	(
    		SIGNAL p_counter_data_in	:	IN std_logic_vector(19 downto 0);
    		SIGNAL p_distance_data_out : OUT integer
    	) IS
    		
    	BEGIN
    	
    		p_distance_data_out <= to_integer(unsigned(p_counter_data_in) * 680/2000000);
    	
    	END calculate_distance;

    •   Alt13th March 2018, 16:25

      advertising

        
       

  2. #2
    Super Moderator
    Points: 29,073, Level: 41
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    6,687
    Helped
    1604 / 1604
    Points
    29,073
    Level
    41

    Re: VHDL Multiplying by a fraction

    What frequency?
    What technology?

    I don't use fractions in my multiplications, so I'm not sure how many bits that will use in synthesis. I normally define any fractions with a parameter (Verilog) with a defined bit width and treat them as scaled integers, I never let the tools decide how many bits. In this case did the tools define it as 32-bits?



    •   Alt13th March 2018, 16:38

      advertising

        
       

  3. #3
    Full Member level 5
    Points: 1,992, Level: 10

    Join Date
    Nov 2013
    Location
    Germany
    Posts
    268
    Helped
    27 / 27
    Points
    1,992
    Level
    10

    Re: VHDL Multiplying by a fraction

    Quote Originally Posted by Sofus View Post
    Hello,

    I am working on an FPGA design where a 20 bit signal is transferred from one component to another component, where a procedure is performed using the 20-bit signal. The calculation performed in the procedure is multiplying the 20 bit signal by 0.00034, or 680/2000000, and then placing this value into a signal of the integer type. However this generates a negative slack for the transfer of data between the register of the 20 bit signal in the first component, and the register of the integer signal in the second component. When I look at the data path in the timing report, it seems that the bulk of the delay is due to the calculation performed in the second component. Is there a less time consuming way to perform the calculation? The calculation in the procedure looks like this at the moment:

    Code:
    -- Calculates distance in centimeters
    	PROCEDURE calculate_distance 
    	(
    		SIGNAL p_counter_data_in	:	IN std_logic_vector(19 downto 0);
    		SIGNAL p_distance_data_out : OUT integer
    	) IS
    		
    	BEGIN
    	
    		p_distance_data_out <= to_integer(unsigned(p_counter_data_in) * 680/2000000);
    	
    	END calculate_distance;
    Can you use the microprocessor to do this multiplication part and output the result in integer??



    •   Alt13th March 2018, 17:58

      advertising

        
       

  4. #4
    Advanced Member level 5
    Points: 36,062, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,589
    Helped
    1924 / 1924
    Points
    36,062
    Level
    46

    Re: VHDL Multiplying by a fraction

    Can you use the microprocessor to do this multiplication part and output the result in integer??
    This would be pretty pointless, as its a pretty straightforward fixed point multiplication

    to the OP: Be careful with your operators. If you did (680/2000000) you would get 0, but actually you're getting (unsigned(p_counter_data_in) * 680) / 20000000.
    The divide in this circuit is what is failing the timing. You should really convert 680/20000000 to some kind of offset integer, that you can then shift after the operation. This means no divider is needed. Something like this:

    p_distance_data_out <= to_integer(unsigned(p_counter_data_in) * ( (680*(2**16)) /2000000) ) / (2**16);

    This should ensure the calculation is a simple A*B, rather than the (A*B)/C you had before.


    1 members found this post helpful.

  5. #5
    Advanced Member level 5
    Points: 20,802, Level: 35
    barry's Avatar
    Join Date
    Mar 2005
    Location
    California, USA
    Posts
    4,008
    Helped
    868 / 868
    Points
    20,802
    Level
    35

    Re: VHDL Multiplying by a fraction

    If you insist upon using non-power-of-two division, have you considered using an IP core or DSP block?



--[[ ]]--