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.

sfixed compare not working [VHDL]

Status
Not open for further replies.

priversek

Newbie level 2
Newbie level 2
Joined
Nov 10, 2013
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
32
Hi

I am having trouble comparing two signed fixed point numbers in VHDL.
Below is code example.


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
signal kot : sfixed(2 downto -30);
signal delta_kot : sfixed(2 downto -30):="000000000000001111111111111111111";
constant half_pi : sfixed (2 downto -30) := to_sfixed(1.57,2,-30);
...
 
 if  ( (kot + delta_kot) > half_pi ) then
   max_reached <= '1';
   ...do something...
 else
   kot <= resize(kot + delta_kot, kot);
 end if;



It looks like compare is not working correctly.
When synthesizing above code I get Warning: "Net <max_reached> does not have a driver."
What am I doing wrong?

I have also tried to cast the signals as signed() on both sides of compare, but then simulation is not working in modelsim, because I receive error: "index value -30 is out of std.standard.natural range 0 to 2147483647".
Please help, I am really stuck here...
Thanks
 

Thats a synthesis warning, meaning the synthesisor has determined that your code is useless and never occurs, and hence removed the max_reached branch.
is max_reached assigned anywhere else?
Does delta_kot ever get assigned anywhere?
are you sure it'ts not overflowing (your code allows values of -2 to +2- 2^-30)
You cannot cast the values directly to signed, because signed only allows +ve indeces (you need to use the to_signed conversion function instead).

Have you testbenched this code?
 

Thats a synthesis warning, meaning the synthesisor has determined that your code is useless and never occurs, and hence removed the max_reached branch.
is max_reached assigned anywhere else?
Does delta_kot ever get assigned anywhere?
are you sure it'ts not overflowing (your code allows values of -2 to +2- 2^-30)
You cannot cast the values directly to signed, because signed only allows +ve indeces (you need to use the to_signed conversion function instead).

Have you testbenched this code?

Ok, here is an example of VHDL code for more information regarding this problem (sfixed accumulator with compare).
I want to accumulate input a, until sum+a becomes grater than half_pi, then assert max_reached.


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library IEEE_PROPOSED;
use ieee_proposed.fixed_float_types.all;
use ieee_proposed.fixed_pkg.all;
 
entity sfixed_compare is
    Port ( a : in sfixed(2 downto -30):="000000000000000000000000001000000";
         max_reached : out std_logic:='0';
            clk : in  std_logic        
           );
end sfixed_compare;
 
architecture Behavioral of sfixed_compare is
 
signal sum : sfixed(2 downto -30);
 
begin
 
compare_process: process(clk)  
 
constant half_pi : sfixed(2 downto -30):=to_sfixed(1.57,2,-30);
    
   begin
           
       if (rising_edge(clk)) then
          if resize(sum + a, sum) > half_pi  then
             max_reached <= '1';
          else
             sum <= resize(sum + a, sum);
          end if;
       end if;
 
    end process;
 
end Behavioral;



I receive this warnings when synthesizing above code:
WARNING:HDLCompiler:746 - "F:\le\xst\ieee_proposed\fixed_pkg_c.vhdl" Line 1470: Range is empty (null range)
WARNING:HDLCompiler:746 - "F:\le\xst\ieee_proposed\fixed_pkg_c.vhdl" Line 1471: Range is empty (null range)
WARNING:HDLCompiler:746 - "F:\le\xst\ieee_proposed\fixed_pkg_c.vhdl" Line 1472: Range is empty (null range)
WARNING:HDLCompiler:314 - "N:/M.53d/rtf/vhdl/xst/src/std_1164.vhd" Line 1025: Choice with meta-value 'U' is ignored for synthesis
WARNING:Xst:647 - Input <a<2:-30>> is never used. This port will be preserved and left unconnected if it belongs to a top-level block or it belongs to a sub-block and the hierarchy of this sub-block is preserved.
WARNING:Xst:647 - Input <clk> is never used. This port will be preserved and left unconnected if it belongs to a top-level block or it belongs to a sub-block and the hierarchy of this sub-block is preserved.
WARNING:Xst:2935 - Signal 'max_reached', unconnected in block 'sfixed_compare', is tied to its initial value (0).
 

Warnings 1,2 and 3 relate to the fixed packages, and are deliberate (you cannot fix them, or at least you should not).
Warnings 4 also ignore.

Is A actually connected to a external signal, or have you just left it unconnected?

Well, max_reached is never set to anything other than '1', so it has no logic in it. If you want it to latch (like you appear to do) you need to give it an initial value or reset value (via a reset).
Also Sum has no initial or reset value.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top