Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee;
- use ieee.std_logic_1164.all; -- Zasrany knihovny - hodnoty, kterych muzou nabyvat ty vektory...
- entity detektor is -- definice pro okolni svet (krabicka, ktera ma vstupy vst,clk,res a vystupy vyst detekce1,detekce2)...
- port(vst,clk : in std_logic; -- deklarace vstupu a jejich typu
- vyst : out std_logic;-- deklarace vystupu a jejich typu - tohle je jen std_logic protoze to neni vektor je to jen 0 nebo 1
- detekce1,detekce2 : out std_logic_vector(4 downto 0)-- deklarace vystupu a jejich typu - vektor tzn neco jako (00001) nebo 10101...
- );
- end detektor;
- architecture det16 of detektor is -- deklarace architektury (funkčnost té entity)..
- signal ps,vnitrnistav :std_logic_vector(4 downto 0); -- deklarace signalu jde to jen tady v begin už ne, jeste se tu muzou deklarovat variables a constant...
- signal pomocne :std_logic_vector(4 downto 0); -- 4 downto 0 znamena, ze to je petibitovy vektor s nejvyssim radem v levo opakem je 0 to 4, tam je nejvyssi rad v pravo...
- begin
- process (vnitrnistav,vst) -- process se spusti automaticky a v zavorkach jsou vždycky sračky, který když se zmeni tak se ten process spusti...
- begin
- case Vnitrnistav is
- when "00000" => vyst <= '0'; if (vst = '1') then ps <= "00001"; else ps <= "00000"; end if; -- tohle je prepsana vyvojova tabulka posloupnosti, vlastně prechodovy funkce
- when "00001" => vyst <= '0'; if vst = '1' then ps <= "00010"; else ps <= "00000"; end if; -- vzdycky je to case kde je aktualni vnitrni stav tady 00001 coz je s1 jakoby.
- when "00010" => vyst <= '0'; if vst = '1' then ps <= "00010"; else ps <= "00011"; end if; -- if funguje stejne jak v C# takze kdyz je x = 1 tak to nastavi ps na 00010 - pristi vnitrni stav...
- when "00011" => vyst <= '0'; if vst = '1' then ps <= "00001"; else ps <= "00100"; end if; -- pokud je x = 0 tak se provadi else a nastavi to ps na jinou hodnotu...
- when "00100" => vyst <= '0'; if vst = '1' then ps <= "00001"; else ps <= "00101"; end if;
- when "00101" => vyst <= '0'; if vst = '1' then ps <= "00110"; else ps <= "00000"; end if;
- when "00110" => vyst <= '0'; if vst = '1' then ps <= "00010"; else ps <= "00111"; end if;
- when "00111" => vyst <= '0'; if vst = '1' then ps <= "01000"; else ps <= "00000"; end if;
- when "01000" => vyst <= '0'; if vst = '1' then ps <= "01001"; else ps <= "00000"; end if;
- when "01001" => vyst <= '0'; if vst = '1' then ps <= "00010"; else ps <= "01010"; end if;
- when "01010" => vyst <= '0'; if vst = '1' then ps <= "00001"; else ps <= "01011"; end if;
- when "01011" => vyst <= '0'; if vst = '1' then ps <= "01100"; else ps <= "00000"; end if;
- when "01100" => vyst <= '0'; if vst = '1' then ps <= "01101"; else ps <= "00000"; end if;
- when "01101" => vyst <= '0'; if vst = '1' then ps <= "00010"; else ps <= "01110"; end if;
- when "01110" => vyst <= '0'; if vst = '1' then ps <= "01111"; else ps <= "00000"; end if;
- when "01111" => vyst <= '0'; if vst = '1' then ps <= "00010"; else ps <= "10000"; end if;
- when "10000" => vyst <= '1'; if vst = '1' then ps <= "00001"; else ps <= "00000"; end if;
- when others => ps <= "00000"; -- tenhle radek podchytava ostatni kombinace promennych ktery tady nejsou v tom seznamu case uvedeny treba 11111.
- end case;
- detekce1 <= vnitrnistav; -- tenhle radek jsem pouzil pro detekci vnitrniho stavu (aktualniho)
- detekce2 <= ps; -- tenhle zase pro detekci pristiho stavu.
- end process;
- process(clk) -- tohle aby to fungovalo tak jak ma tak je to vlastne ten klopny obvod D - process reaguje na zmenu clk
- begin
- if rising_edge(clk) then vnitrnistav <= ps; else vnitrnistav <= vnitrnistav; end if; -- pokud je nabezna hrana signalu clk tak se provede prirazeni ps do vnitrniho stavu... tim se pak zase ale spusti horni process
- end process;
- end det16; -- konec architektury...
- -- prirazuje se (kdekoliv) <= timhle znakem protoze nejakyho picuse napadlo ze = je pouzito pro porovnavani... :D
- -- := tenhle znak znamena prirazeni ale jen pocatecni hodnoty...
Advertisement
Add Comment
Please, Sign In to add comment