Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.72 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity example is
  6.   port (Reset      : in  std_logic;
  7.         SysClk     : in  std_logic;
  8.         zbroji     : in  std_logic;
  9.         oduzmi     : in  std_logic;
  10.         ulaz_broj  : in  std_logic;
  11.         oduzima    : out std_logic;
  12.         ucitanPrvi : out std_logic;
  13.         broj1      : out std_logic
  14.         );
  15.  
  16. end example;
  17.  
  18. architecture Behavioral of example is
  19.  
  20.   -- Delayed version of input signals (1 clock cycle delay)
  21.   signal zbroji_d : std_logic;
  22.   signal oduzmi_d : std_logic;
  23.  
  24.   signal zbrojiRE : std_logic;
  25.   signal oduzmiRE : std_logic;
  26.  
  27. begin
  28.  
  29.   -- Generate 1 clock cycle delayed version of
  30.   -- signals we want to detect the rising edge
  31.   -- Assumes active high reset
  32.   -- Note: You should only use the rising_edge macro
  33.   -- on an actual global or regional clock signal. FPGA's and
  34.   -- ASICs place timing constraints on defined clock signals
  35.   -- that make it possible to use rising_edge, otherwise, we have
  36.   -- to generate our own rising edge signals by comparing delayed
  37.   -- versions of a signal with the current signal.
  38.   -- Also, with any respectable synthesizer / simulator using
  39.   -- rising_edge is almos exactly the same as (clk'event and clk='1')
  40.   -- except rising_edge only returns a '1' when the clock makes a
  41.   -- valid '0' to '1' transition. (see link below)
  42.   EdgeDetectProc : process (Reset, SysClk)
  43.   begin
  44.     if Reset = '1' then
  45.       zbroji_d <= '0';
  46.       oduzmi_d <= '0';
  47.     elsif rising_edge(SysClk) then
  48.       zbroji_d <= zbroji;
  49.       oduzmi_d <= oduzmi;
  50.     end if;
  51.   end process EdgeDetectProc;
  52.  
  53.   -- Assert risinge edge signals for one clock cycle
  54.   zbrojiRE <= '1' when zbroji = '1' and zbroji_d = '0' else '0';
  55.   oduzmiRE <= '1' when oduzmi = '1' and oduzmi_d = '0' else '0';
  56.  
  57.   -- Assumes that you want a single cycle pulse on ucitanPrvi on the
  58.   -- rising edege of zbroji or oduzmi;
  59.   ucitanPrvi <= zbrojiRE or oduzmiRE;
  60.  
  61.   -- Based on your example, I can't tell what you want to do with the
  62.   -- broj1 signal, but this logic will drive broj1 with ulaz_broj on
  63.   -- either the zbroji or oduzmi rising edge, otherwise '0'.
  64.   broj1 <= ulaz_broj when zbrojiRE = '1' else
  65.            ulaz_broj when oduzmiRE = '1' else
  66.            '0';
  67.  
  68.   -- Finally, it looks like you want to clear oduzima on the rising
  69.   -- edge of zbroji and assert oduzima on the rising edge of
  70.   -- oduzmi
  71.   LatchProc : process (Reset, SysClk)
  72.   begin
  73.     if Reset = '1' then
  74.       oduzima <= '0';
  75.     elsif rising_edge(SysClk) then
  76.       if zbrojiRE = '1' then
  77.         oduzima <= '0';
  78.       elsif oduzmiRE = '1' then
  79.         oduzima <= '1';
  80.       end if;
  81.     end if;
  82.   end process LatchProc;
  83.  
  84. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement