Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Simulation and realworld problem in design - what is wrong?

 
Thread Tools Search this Thread
Old 04-24-2005, 07:00 PM   #1
Default Simulation and realworld problem in design - what is wrong?


Hi,

(question first asked in comp.arch.fpga, but think it probably suits
this group better since this more a VHDL question than FPGA in general
question)

I wonder why this results in undefined values (further comments in
bottom of post):

----------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following lines to use the declarations that are
-- provided for instantiating Xilinx primitive components.
--library UNISIM;
--use UNISIM.VComponents.all;

entity trigger_level is
Port ( clk : in std_logic;
prescale : in std_logic;
din : in std_logic_vector(7 downto 0);
level : in std_logic_vector(7 downto 0);
rf : in std_logic;
hold : in std_logic;
trig : out std_logic);
end trigger_level;

architecture Behavioral of trigger_level is
type samples_buffer is array(9 downto 0) of
std_logic_vector(7 downto 0);

signal samples : samples_buffer;
begin

process(clk)
begin
if rising_edge(clk) and prescale = '1' and hold = '0' then
-- no reset circuit (not needed) for reducing the number of
slices to 1 instead of 5
for i in 9 downto 1 loop
samples(i) <= samples(i-1);
end loop;
samples(0) <= din;
end if;
end process;


process(clk)
begin
if rising_edge(clk) then
if (rf = '1') then --- falling edge
if (samples(0) < level and samples(9) > level) then
trig <= '1';
else
trig <= '0';
end if;
elsif (rf = '0') then --- rising edge
if (samples(0) > level and samples(9) < level) then
trig <= '1';
else
trig <= '0';
end if;
else
trig <= '0';
end if;
end if;
end process;

end Behavioral;
----------------------------------


The design should be a trigger for an oscilloscope, and I think I have
an error in my design here! The trouble is that I get triggers where I
shouldn't! (or my presampler probably doesn't work, but I think this
simulation told me where the error was!)

The simulation "error" is viewable on my website:
http://www.interrupt.dk/sim.jpg

The trigger is a level/edge trigger that should activate on rising and
falling edges!



And like always: Thanks for helping

Preben Holm


Preben Holm
  Reply With Quote
Old 04-25-2005, 04:59 AM   #2
CODE_IS_BAD
 
Posts: n/a
Default Re: Simulation and realworld problem in design - what is wrong?
hi...
i guess the problem comes as u have declared ur array as a signal.
Now there are two processes, both sensitive to clock edges. And in
1st you r manipulating the array and at the same time in the second u r
using it to check some condition. This may result in simulation
mismatch. I am not very sure but just try to declare both the tasks in
one process and declare ur array as a variable.
Also one question . Why hav u used if .. elsif and else... as there
is only one parameter rf on which ur condition depends then u cud hav
used just if... else..... Have u used it bcoz it is declared as
std_logic and that u want to care for all the other levels? just
explain...



CODE_IS_BAD
  Reply With Quote
Old 04-25-2005, 07:55 AM   #3
Preben Holm
 
Posts: n/a
Default Re: Simulation and realworld problem in design - what is wrong?
> i guess the problem comes as u have declared ur array as a signal.

Problem - why? Signal or variable - what's the difference in this case?
I often use signals because they give me less logic (in the tests I've
made)!

> Now there are two processes, both sensitive to clock edges. And in
> 1st you r manipulating the array and at the same time in the second u r
> using it to check some condition. This may result in simulation
> mismatch.


But in the circuit could this give me any trouble? Is it just simulation
trouble?

> I am not very sure but just try to declare both the tasks in
> one process and declare ur array as a variable.


I'll try that?


> Also one question . Why hav u used if .. elsif and else... as there
> is only one parameter rf on which ur condition depends then u cud hav
> used just if... else..... Have u used it bcoz it is declared as
> std_logic and that u want to care for all the other levels? just
> explain...


I've learned (read somewhere) that I should never use "bit" - rather use
"std_logic"! That's why!


Preben Holm
  Reply With Quote
Old 04-25-2005, 11:31 AM   #4
charles.elias@wpafb.af.mil
 
Posts: n/a
Default Re: Simulation and realworld problem in design - what is wrong?
Your simulator is indicating a setup error for the flip-flop trig, and
trig depends on samples which is synchronous and rf which is probably
asynchronous. Samples also depends on both prescale and hold which are
presumably asynchronous with respect to clk. Any of the signals rf,
prescale or hold will cause real world problems with your design. They
should each be synchronized with clk by using a synchronizer. The
synchronizer many designers use is simply 2 D flip-flops A and B with
A's D input connected to the signal to be synchronized, B's D input
connected to A's output, their clock inputs connected to your system
clock (clk). You use the synchronizer's output instead of the
unsynchronized signal on the input of A. This may or may not cure your
simulation problem (because it is not a perfect solution), but you
should find that the real world circuit now performs properly.

Best regards,

Charles



charles.elias@wpafb.af.mil
  Reply With Quote
Old 04-25-2005, 12:06 PM   #5
ALuPin
 
Posts: n/a
Default Re: Simulation and realworld problem in design - what is wrong?
Some changes maybe: IF-ELSIF-ELSE and additional ELSEs are
not needed. Makes the code more readable.

process(clk)
begin
if rising_edge(clk) then

trig <= '0';

if (rf = '1') then --- falling edge
if (samples(0) < level and samples(9) > level) then
trig <= '1';
end if;

else --- rising edge
if (samples(0) > level and samples(9) < level) then
trig <= '1';
end if;
end if;

end if;
end process;


ALuPin
  Reply With Quote
Old 04-25-2005, 04:28 PM   #6
Preben Holm
 
Posts: n/a
Default Re: Simulation and realworld problem in design - what is wrong?
Well the signal is already synchronized in the whole application.

Therefore I ran a simulation on the module itself with a generated pulse
with the "wizard".

All async. inputs are put into one or more flipflops to cure metastability.


Thanks for answering!


Preben Holm
  Reply With Quote
Old 04-25-2005, 05:25 PM   #7
Mike Treseler
 
Posts: n/a
Default Re: Simulation and realworld problem in design - what is wrong?
Preben Holm wrote:

> The simulation "error" is viewable on my website:
> http://www.interrupt.dk/sim.jpg


Looks like two processes are driving
the testbench signal /trigger_level_tb/trig.
The testbench should only be reading this
signal. Only the DUT instance port map should
drive it.

-- Mike Treseler


Mike Treseler
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

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 38 39 40 41 42 43 44 45 46