0

I have this code in my project.

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

library ieee_proposed;
use ieee_proposed.fixed_pkg.all;

entity sfixed_test is
 port(x1 : in integer :=20;
        x2 : in integer := 23;
        N : out sfixed( 8 downto -8));

end sfixed_test;

architecture Behavioral of sfixed_test is
    signal Ni,Nii,No,Noo,nb :integer;

signal Niii : sfixed(4 downto -20);
    signal Nn : sfixed(4 downto -20);
signal N1max : integer := 34;
    signal N1min : integer := 14;
    signal N2max : integer := 56;
    signal n2min : integer := 0;

begin


    Ni <= x1-N1min;
    Nii <= N1max-N1min;
    Niii <= to_sfixed(Ni/Nii,Niii);


    No <= x2-N2min;
    Noo <= N2max-N2min;
    Nn <= to_sfixed(No/Noo,Nn);

end Behavioral;

I want to convert result value from my division operation, but the value of Niii and Nn is zero went i try running my code in simulator. And te result of my project is not correct. Please to helping me.

Thank you

  • 1
    If you need floating point, don't declare all of your variables as integer. – Ken White Jan 16 '19 at 21:13
  • Your code has semantic errors (e.g. Niii and Nn are declared twice both as integers and sfixed), it can't be simulated. Remove the integer declarations. There's also no assignment to N. There may be more errors, ` sfixed(3 downto -40);` doesn't appear to have a large enough integer part for your default values of x1 and x2. –  Jan 16 '19 at 21:27
  • @user1155120 i have already change my code, but i'm still have zero value in niii and nn. – Ida Royani Jan 16 '19 at 23:01
  • So, what values do you expect? As Ken White points out indirectly integer division gives integer results (Ni/Nii or 6/20 = 0; No/Noo or 23/56 = 0). You really want to do sfixed division not conversion of the integer quotient. Convert the dividend and divisor to sfixed first noting arithmetic operations will effect the result length. –  Jan 17 '19 at 00:11
  • thank you for helping me everyone. – Ida Royani Jan 17 '19 at 09:32

0 Answers0