Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 0.93 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity up_down_counter is
  6. port (
  7.         clk: in std_logic;
  8.         reset: in std_logic;
  9.         ce: in std_logic;
  10.         up_down: in std_logic;
  11.         z: out std_logic_vector(7 downto 0)
  12.         );
  13.         end up_down_counter;
  14.        
  15.             architecture behavioural of up_down_counter is
  16.        
  17.                 signal count: integer range 0 to 255:= 0; -- "range 0 to 255" very important
  18.        
  19.             begin
  20.         Z <= std_logic_vector(to_unsigned(count,8));   
  21.             process(clk,reset)
  22.                 begin
  23.                     if reset ='1' then
  24.                         count <= 0;
  25.                     elsif rising_edge(clk) then
  26.                         if ce = '1' then
  27.                             if up_down = '1' then
  28.                                 if count = 255 then
  29.                                     count <= 0;
  30.                                 else
  31.                                     count <= count +1;
  32.                                 end if;
  33.                             else
  34.                                 if count = 0 then
  35.                                     count <= 255;
  36.                                 else
  37.                                     count <= count-1;
  38.                                 end if;
  39.                             end if;
  40.                         end if;
  41.                     end if;
  42.             end process;
  43.         end behavioural;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement