Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   VHDL (http://www.velocityreviews.com/forums/f18-vhdl.html)
-   -   if/elsif problem (http://www.velocityreviews.com/forums/t497997-if-elsif-problem.html)

 karlwijk 04-16-2007 02:07 PM

if/elsif problem

Hello, I have a problem with the following construct:

process(clk, reset_n)
begin
if (reset_n = '0') then
out <= '0';
elsif (clk'event and clk = '1') then
if (clear = '1') then
out <= '0';
elsif (set = '1') then
out <= '1';
end if;
end if;
end process;

I have synthesized this for a xilinx. Although the signal "set" is observed to be completely fixed at '0' (in logic analyzer), I get a transition from 0 to 1 on "out". Could it be a glitch on "set" ? Is this a problematic construction for some reason?

 quantum_dot 04-17-2007 04:22 AM

if/elsif statement !

Well, this coding is similar to C programming, and may create a problem in actual hardware. You have not specified all the possible conditions for set/clear. May be you can give this a try :

process(clk, reset_n)
begin
if (reset_n = '0') then
out <= '0';
elsif (clk'event and clk = '1') then
if (clear = '1' and set = '0') then
out <= '0';
elsif (clear = '0' and set = '1') then
out <= '1';
end if;
end if;
end process;

 karlwijk 04-17-2007 05:17 AM

Hi, thanks. Can you explain why my solution creates a problem? Under what signal conditions? Is it, for instance, if you get clear='1' and set='1' at the same time?

Kind regards,
Karl

Quote:
 Originally Posted by quantum_dot Well, this coding is similar to C programming, and may create a problem in actual hardware. You have not specified all the possible conditions for set/clear. May be you can give this a try : process(clk, reset_n) begin if (reset_n = '0') then out <= '0'; elsif (clk'event and clk = '1') then if (clear = '1' and set = '0') then out <= '0'; elsif (clear = '0' and set = '1') then out <= '1'; end if; end if; end process;

 quantum_dot 04-18-2007 05:52 AM

if/elsif problem

Not specifying all the conditions for "clear" or "set" results in a latch condition, which you are not aiming for. This may result in a unpredicted metastable state, which is causing the problem.
:driver:

 All times are GMT. The time now is 01:29 AM.