| 1 |
145 |
lanttu |
-------------------------------------------------------------------------------
|
| 2 |
|
|
-- Title : Port blinker
|
| 3 |
|
|
-- Project : Funbase
|
| 4 |
|
|
-------------------------------------------------------------------------------
|
| 5 |
|
|
-- File : port_blinker.vhd
|
| 6 |
|
|
-- Author : Juha Arvio
|
| 7 |
|
|
-- Company : TUT
|
| 8 |
|
|
-- Last update: 2011-12-05
|
| 9 |
|
|
-- Version : 0.1
|
| 10 |
|
|
-- Platform :
|
| 11 |
|
|
-------------------------------------------------------------------------------
|
| 12 |
|
|
-- Description: Counts up and inverts output when reaching the limit value.
|
| 13 |
|
|
-- Then start over again.
|
| 14 |
|
|
-------------------------------------------------------------------------------
|
| 15 |
|
|
-- Revisions :
|
| 16 |
|
|
-- Date Version Author Description
|
| 17 |
|
|
-- 20.10.2011 0.1 arvio Created
|
| 18 |
|
|
-------------------------------------------------------------------------------
|
| 19 |
|
|
-- Funbase IP library Copyright (C) 2011 TUT Department of Computer Systems
|
| 20 |
|
|
--
|
| 21 |
|
|
-- This source file may be used and distributed without
|
| 22 |
|
|
-- restriction provided that this copyright statement is not
|
| 23 |
|
|
-- removed from the file and that any derivative work contains
|
| 24 |
|
|
-- the original copyright notice and the associated disclaimer.
|
| 25 |
|
|
--
|
| 26 |
|
|
-- This source file is free software; you can redistribute it
|
| 27 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
| 28 |
|
|
-- Public License as published by the Free Software Foundation;
|
| 29 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
| 30 |
|
|
-- later version.
|
| 31 |
|
|
--
|
| 32 |
|
|
-- This source is distributed in the hope that it will be
|
| 33 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
| 34 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
| 35 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
| 36 |
|
|
-- details.
|
| 37 |
|
|
--
|
| 38 |
|
|
-- You should have received a copy of the GNU Lesser General
|
| 39 |
|
|
-- Public License along with this source; if not, download it
|
| 40 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
| 41 |
|
|
-------------------------------------------------------------------------------
|
| 42 |
|
|
library ieee;
|
| 43 |
|
|
use ieee.std_logic_1164.all;
|
| 44 |
|
|
use ieee.std_logic_arith.all;
|
| 45 |
|
|
use ieee.std_logic_unsigned.all;
|
| 46 |
|
|
|
| 47 |
|
|
entity port_blinker is
|
| 48 |
|
|
generic (
|
| 49 |
|
|
SIGNAL_WIDTH : integer := 32
|
| 50 |
|
|
);
|
| 51 |
|
|
port (
|
| 52 |
|
|
clk : in std_logic;
|
| 53 |
|
|
rst_n : in std_logic;
|
| 54 |
|
|
|
| 55 |
|
|
ena_in : in std_logic;
|
| 56 |
|
|
val_in : in std_logic_vector(SIGNAL_WIDTH-1 downto 0);
|
| 57 |
|
|
port_out : out std_logic
|
| 58 |
|
|
);
|
| 59 |
|
|
|
| 60 |
|
|
end port_blinker;
|
| 61 |
|
|
|
| 62 |
|
|
architecture rtl of port_blinker is
|
| 63 |
|
|
|
| 64 |
|
|
signal port_level_r : std_logic;
|
| 65 |
|
|
signal val_cnt_r : std_logic_vector(SIGNAL_WIDTH-1 downto 0);
|
| 66 |
|
|
|
| 67 |
|
|
begin
|
| 68 |
|
|
|
| 69 |
|
|
port_out <= port_level_r;
|
| 70 |
|
|
|
| 71 |
|
|
--
|
| 72 |
|
|
-- Count upwards until reaching the value in the input
|
| 73 |
|
|
--
|
| 74 |
|
|
process (clk, rst_n)
|
| 75 |
|
|
begin
|
| 76 |
|
|
if (rst_n = '0') then
|
| 77 |
|
|
port_level_r <= '0';
|
| 78 |
|
|
val_cnt_r <= (others => '0');
|
| 79 |
|
|
|
| 80 |
|
|
elsif (clk'event and clk = '1') then
|
| 81 |
|
|
|
| 82 |
|
|
if (ena_in = '0') then
|
| 83 |
|
|
val_cnt_r <= (others => '0');
|
| 84 |
|
|
else
|
| 85 |
|
|
if (val_cnt_r = val_in) then
|
| 86 |
|
|
port_level_r <= not(port_level_r);
|
| 87 |
|
|
val_cnt_r <= (others => '0');
|
| 88 |
|
|
else
|
| 89 |
|
|
val_cnt_r <= val_cnt_r + 1;
|
| 90 |
|
|
end if;
|
| 91 |
|
|
end if;
|
| 92 |
|
|
|
| 93 |
|
|
end if;
|
| 94 |
|
|
end process;
|
| 95 |
|
|
|
| 96 |
|
|
end rtl;
|