Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Behavioral model for a two out of five detector

Reply
Thread Tools

Behavioral model for a two out of five detector

 
 
bigmoe88 bigmoe88 is offline
Junior Member
Join Date: Feb 2010
Posts: 4
 
      02-10-2010
Hey everyone, I am having trouble writing a behavioral model for a two out of five bit detector. Y is always undefined when I simulate it, what am I doing wrong? Here is the code:

Code:
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity two_five is                         -- Begin entity
     port(
       A, B, C, D, E: in std_logic;
       Y: out std_logic
          );
end entity two_five;                       -- End entity
-------------------------------------------------

architecture beh of two_five is            -- Begin architecture
signal sig: std_logic_vector (4 DOWNTO 0);
signal cnt: std_logic_vector (1 downto 0) := "00";
begin
    sig <= A&B&C&D&E;
    process (sig)
      begin
        for i in 0 to 4 loop
          if sig(i) = '1' then
            cnt <= cnt + 1;
          end if;
        if cnt = "10" then--count = 2 then
        Y <= '1';
      else Y <= '0';
      end if;
    end loop;
    end process;
end beh;
 
Reply With Quote
 
 
 
 
sridar sridar is offline
Member
Join Date: Jun 2007
Posts: 52
 
      02-11-2010
Change cnt declaration to variable or try to code using logical equation.

with 5 bit vector, the possible values of less than two 1's are
00000
00001
00010
00100
01000
10000

eq =not( (a.b.c.d.e)+(a.b.c.d.E)+(a.b.c.D.e)+(a.b.C.d.e)+(a .B.c.d.e)+(A.b.c.d.e) )


Quote:
Originally Posted by bigmoe88
Hey everyone, I am having trouble writing a behavioral model for a two out of five bit detector. Y is always undefined when I simulate it, what am I doing wrong? Here is the code:

Code:
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity two_five is                         -- Begin entity
     port(
       A, B, C, D, E: in std_logic;
       Y: out std_logic
          );
end entity two_five;                       -- End entity
-------------------------------------------------

architecture beh of two_five is            -- Begin architecture
signal sig: std_logic_vector (4 DOWNTO 0);
signal cnt: std_logic_vector (1 downto 0) := "00";
begin
    sig <= A&B&C&D&E;
    process (sig)
      begin
        for i in 0 to 4 loop
          if sig(i) = '1' then
            cnt <= cnt + 1;
          end if;
        if cnt = "10" then--count = 2 then
        Y <= '1';
      else Y <= '0';
      end if;
    end loop;
    end process;
end beh;
 

Last edited by sridar; 02-11-2010 at 06:39 AM..
Reply With Quote
 
 
 
 
bigmoe88 bigmoe88 is offline
Junior Member
Join Date: Feb 2010
Posts: 4
 
      02-11-2010
Ok, so I tried that and got the same result, also, Y gets '1' only when there are exactly two out of five are high.

Here is the current code:

Code:
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity two_five is                         -- Begin entity
     port(
       A, B, C, D, E: in std_logic;
       Y: out std_logic
          );
end entity two_five;                       -- End entity
-------------------------------------------------

architecture beh of two_five is            -- Begin architecture
signal sig: std_logic_vector (4 DOWNTO 0);
begin
    sig <= A&B&C&D&E;
    process (sig)
      variable count: integer;
      begin
        count := 0;
        for i in 0 to 4 loop
          if sig(i) = '1' then
            count := count + 1;
          end if;
        if count = 2 then
        Y <= '1';
      else Y <= '0';
      end if;
    end loop;
    end process;
end beh;
 
Reply With Quote
 
sridar sridar is offline
Member
Join Date: Jun 2007
Posts: 52
 
      02-12-2010
Hi, I am getting the correct result when I simulate the code. BTW, which synthesis and simulation tools are you using.


Quote:
Originally Posted by bigmoe88
Ok, so I tried that and got the same result, also, Y gets '1' only when there are exactly two out of five are high.

Here is the current code:

Code:
library ieee;
use ieee.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity two_five is                         -- Begin entity
     port(
       A, B, C, D, E: in std_logic;
       Y: out std_logic
          );
end entity two_five;                       -- End entity
-------------------------------------------------

architecture beh of two_five is            -- Begin architecture
signal sig: std_logic_vector (4 DOWNTO 0);
begin
    sig <= A&B&C&D&E;
    process (sig)
      variable count: integer;
      begin
        count := 0;
        for i in 0 to 4 loop
          if sig(i) = '1' then
            count := count + 1;
          end if;
        if count = 2 then
        Y <= '1';
      else Y <= '0';
      end if;
    end loop;
    end process;
end beh;
 
Reply With Quote
 
bigmoe88 bigmoe88 is offline
Junior Member
Join Date: Feb 2010
Posts: 4
 
      02-12-2010
I am using QuestiaSim-64 6.4c. I am not synthesizing it, I am just simulating it with a force file. Here are the contents of the force file:

force A 0 0, 1 10 ns -repeat 10 ns
force B 0 0, 1 20 ns -repeat 20 ns
force C 0 0, 1 30 ns -repeat 30 ns
force D 0 0, 1 40 ns -repeat 40 ns
force E 0 0, 1 50 ns -repeat 50 ns
 
Reply With Quote
 
bigmoe88 bigmoe88 is offline
Junior Member
Join Date: Feb 2010
Posts: 4
 
      02-14-2010
Ok, so I got it working finally the other day. I created a new project and copied the code into a new file and it all worked well. Have no idea what caused such odd behavior. Thanks so much for your help.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
LPG gas detector , smoke detector fire alarm system wholesale and OEM zcsecurity VOIP 3 09-20-2010 12:27 AM
LPG gas alarm detector, smoke detector fire alarm system OEM zcsecurity VOIP 1 09-20-2010 12:16 AM
what's the differences between the behavioral model and the RTLmodel? risingsunxy@googlemail.com VHDL 7 03-10-2006 02:22 PM
EDK Modelsim Behavioral Simulation Error hansman VHDL 3 01-30-2004 09:05 AM
Hard Disk Drive behavioral model Stephane Guyetant VHDL 0 10-02-2003 09:52 AM



Advertisments
 



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 47 48 49 50 51 52 53 54 55 56 57