Sem 5‎ > ‎VHDL LAB‎ > ‎

E2: Write a program to take an input serial bit stream and outputs a '1' whenever the sequence "01010" occurs overlap must also be considered.

posted Nov 17, 2012, 11:18 PM by Neil Mathew
Although compiled, untested. :/


SOURCE CODE:

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
 
library IEEE;
use IEEE.STD_LOGIC_1164.all;       
use IEEE.std_logic_arith.all;
 
entity pattern_find_en is
        port( Sin: in bit; -- serial input bit
                  Sout: out bit); -- outputs 1 if "01010" occurs
end pattern_find_en;
 
 
architecture arch of pattern_find_en is
signal temp: bit_vector(4 downto 0); -- can be variable too
begin
        
        process( Sin )
        variable count: integer := 0;   
        begin
                
                -- At first, it fills up till 5 input bits are available for check.
                -- shifts values towards the right, and keeps adding the new bit for check
                        
                        if count=0 then
                                temp(0) <= Sin;
                                count:=count+1;
                        elsif count < 5 then
                                temp <= temp srl 1;
                                temp(0) <= Sin;
                                count:=count+1;
                        else
                                temp <= temp srl 1;
                                temp(0) <= Sin;
                        end if;
                                
                -- the check
                
                if temp = "01010" then
                        Sout <= '1';
                else 
                        Sout <= '0';
                end if;
        end process;
end arch;
 





Comments