Lookup table simulation problems
CASTalk.com Forum Index CASTalk.com
Discussion of DSP, FPGA, storage and embedded system.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web castalk.com
Lookup table simulation problems

 
Post new topic   Reply to topic    CASTalk.com Forum Index -> FPGA
Author Message
Elder Costa
Guest





Posted: Fri Dec 10, 2004 4:07 pm    Post subject: Lookup table simulation problems Reply with quote

Hello.

I am using Xilinx ISE Foundation 6.3i. I am trying to implement a sine
lookup table (targeted at either SpartanIII or VirtexII) but I am
getting a strange result when running functional simulation (testbench
bellow) with Modelsim: instead of showing the first element from the
array on the output after the first rising edge it shows the 12th.
Everithing happens as if I had initialized the address counter with 11
instead of 0. I know I am making a basic mistake but I cannot figure
out where or why.

--------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity sintab20 is
Port (
i_Clk : in std_logic;
i_En : in std_logic;
i_Addr : in integer range 0 to 19;
o_DataOut : out std_logic_vector(17 downto 0)
);
end sintab20;

architecture Behavioral of sintab20 is
subtype t_ROM_DATA is std_logic_vector(17 downto 0);
type t_ROM_TYPE is array (natural range <>) of t_ROM_DATA;
constant k_SinTab20x1: t_ROM_TYPE(19 downto 0) :=
(
"000000000000000000",
"001001111000110111",
"010010110011110010",
"011001111000110111",
"011110011011110000",
"011111111111111111",
"011110011011110000",
"011001111000110111",
"010010110011110010",
"001001111000110111",
"000000000000000000",
"110110000111001001",
"101101001100001110",
"100110000111001001",
"100001100100010000",
"100000000000000001",
"100001100100010000",
"100110000111001001",
"101101001100001110",
"110110000111001001"
);

begin
process (i_Clk)
begin
if rising_edge(i_Clk) then
if (i_En = '1') then
o_DataOut <= k_SinTab20x1(i_Addr);
end if;
end if;
end process;
end Behavioral;

-------------

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;

ENTITY sintab20_tb IS
END sintab20_tb;

ARCHITECTURE behavior OF sintab20_tb IS

COMPONENT sintab20
PORT(
i_Clk : IN std_logic;
i_En : IN std_logic;
i_Addr : IN integer range 0 to 19;
o_DataOut : OUT std_logic_vector(17 downto 0)
);
END COMPONENT;

SIGNAL i_Clk : std_logic;
SIGNAL i_En : std_logic;
SIGNAL i_Addr : integer range 0 to 19;
SIGNAL o_DataOut : std_logic_vector(17 downto 0);
constant k_PERIOD : time := 20 ns;

BEGIN

uut: sintab20 PORT MAP(
i_Clk => i_Clk,
i_En => i_En,
i_Addr => i_Addr,
o_DataOut => o_DataOut
);
-- *** Test Bench - User Defined Section ***
i_En <= '1';
-- clock
process
begin
for i in 0 to 40 loop
i_Clk <= '0';
wait for k_PERIOD/2;
i_Clk <= '1';
wait for k_PERIOD/2;
end loop;
wait;
end process;

-- address counter
process
begin
i_Addr <= 0;
wait for k_PERIOD*2;
for i in 0 to 40 loop
if i_Addr < 19 then
i_Addr <= i_Addr + 1;
else
i_Addr <= 0;
end if;
wait for k_PERIOD;
end loop;
wait;
end process;
-- *** End Test Bench - User Defined Section ***
END;

--------------


TIA for your comments.

Elder.
Back to top
Mike Treseler
Guest





Posted: Fri Dec 10, 2004 11:56 pm    Post subject: Re: Lookup table simulation problems Reply with quote

Your main test process executes in zero sim time.
Consider synchronizing the process as shown below.

-- Mike Treseler
--_______________________________________


library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity sintab20 is
port (
i_Clk : in std_logic;
i_En : in std_logic;
i_Addr : in integer range 0 to 19;
o_DataOut : out std_logic_vector(17 downto 0)
);
end sintab20;

architecture Behavioral of sintab20 is
subtype t_ROM_DATA is std_logic_vector(17 downto 0);

type t_ROM_TYPE is array (natural range <>) of t_ROM_DATA;

constant k_SinTab20x1 : t_ROM_TYPE(19 downto 0) :=
(
"000000000000000000",
"001001111000110111",
"010010110011110010",
"011001111000110111",
"011110011011110000",
"011111111111111111",
"011110011011110000",
"011001111000110111",
"010010110011110010",
"001001111000110111",
"000000000000000000",
"110110000111001001",
"101101001100001110",
"100110000111001001",
"100001100100010000",
"100000000000000001",
"100001100100010000",
"100110000111001001",
"101101001100001110",
"110110000111001001"
);

begin
process (i_Clk)
begin
if rising_edge(i_Clk) then
if (i_En = '1') then
o_DataOut <= k_SinTab20x1(i_Addr);
end if;
end if;
end process;
end Behavioral;

----------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity sintab20_tb is
end entity sintab20_tb;

architecture sim of sintab20_tb is
-- Fri Dec 10 10:34:08 2004 Mike
-- component ports
signal i_Clk_s : std_logic; -- [in]
signal i_En_s : std_logic; -- [in]
signal i_Addr_s : integer range 0 to 19; -- [in]
signal o_DataOut_s : std_logic_vector(17 downto 0); -- [out]

-- run with waves:
-- vsim sintab20_tb -do "add wave -r /*;run -all;"

signal done_s : boolean;
signal clk_s : std_ulogic;
signal rst_s : std_ulogic;
begin -- architecture sim

-- component instantiation
DUT : entity work.sintab20
port map (i_Clk => i_Clk_s, -- [in]
i_En => i_En_s, -- [in]
i_Addr => i_Addr_s, -- [in]
o_DataOut => o_DataOut_s); -- [out]
i_clk_s <= clk_s;

-- clock generation
tb_clk : process is
constant clk_cy : time := 20 ns;
begin
clk_s <= '0'; -- clk low during rst
if now < clk_cy then
rst_s <= '1'; -- rst high once
else
rst_s <= '0'; -- then low forever
wait for clk_cy/2; -- clk low phase
clk_s <= '1';
end if;
if done_s then wait;
end if;
wait for clk_cy/2; -- clk or rst high phase
end process tb_clk;

main : process (clk_s, rst_s) is
constant last_step_v : natural := 19;
variable step_v : natural;
begin
clked : if rst_s = '1' then
step_v := 1;
elsif rising_edge(clk_s) then
done_s <= step_v > last_step_v;
i_Addr_s <= 0;
enable : if not done_s then
i_En_s <= '1';
i_Addr_s <= step_v - 1;
step_v := step_v + 1; -- step counter
end if enable;
end if clked;
end process main;

end architecture sim;
Back to top
glen herrmannsfeldt
Guest





Posted: Sat Dec 11, 2004 12:48 am    Post subject: Re: Lookup table simulation problems Reply with quote

Elder Costa wrote:

Quote:
I am using Xilinx ISE Foundation 6.3i. I am trying to implement a sine
lookup table (targeted at either SpartanIII or VirtexII) but I am
getting a strange result when running functional simulation (testbench
bellow) with Modelsim: instead of showing the first element from the
array on the output after the first rising edge it shows the 12th.
Everithing happens as if I had initialized the address counter with 11
instead of 0. I know I am making a basic mistake but I cannot figure
out where or why.

I don't see anything, but maybe someone else will.

It would be more usual to make the number of table entries a power
of two, such that mod 360 degrees could be done by ignoring high
order bits. You might see if that works better in your case.

Display both the address and table value. That should help
track down the problem.

-- glen
Back to top
Elder Costa
Guest





Posted: Sat Dec 11, 2004 2:53 am    Post subject: Re: Lookup table simulation problems Reply with quote

glen herrmannsfeldt wrote:
Quote:
I don't see anything, but maybe someone else will.

It turned out it *was* a basic mistake. I should have declared
constant k_SinTab20x1: t_ROM_TYPE(0 to 19)

instead of

constant k_SinTab20x1: t_ROM_TYPE(19 downto 0)

So I was starting with 20th element, not 12th.

Quote:

It would be more usual to make the number of table entries a power
of two, such that mod 360 degrees could be done by ignoring high
order bits. You might see if that works better in your case.

It is not possible in my application, a lock in demodulator at 2.5Msps
using a 125KHz carrier.

Thanks and regards.
Back to top
Elder Costa
Guest





Posted: Sat Dec 11, 2004 2:55 am    Post subject: Re: Lookup table simulation problems Reply with quote

Mike Treseler wrote:

Quote:
Your main test process executes in zero sim time.
Consider synchronizing the process as shown below.

I figured out the problem as I pointed in another message. I will save
your message though as reference as it does contain some stuff I think
will help me.

Thanks and regads.

Elder.
Back to top
glen herrmannsfeldt
Guest





Posted: Sat Dec 11, 2004 4:01 am    Post subject: Re: Lookup table simulation problems Reply with quote

Elder Costa wrote:

(snip regarding sin lookup tables)

Quote:
It would be more usual to make the number of table entries a power
of two, such that mod 360 degrees could be done by ignoring high
order bits. You might see if that works better in your case.

It is not possible in my application, a lock in demodulator at 2.5Msps
using a 125KHz carrier.

Well, it could probably be done with a phase accumulator,
but if the frequencies really are fixed, yes, the 20 element
table is best.

-- glen
Back to top
 
Post new topic   Reply to topic    CASTalk.com Forum Index -> FPGA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




VoIP Electronics Powered by phpBB