diff options
author | tgingold <tgingold@users.noreply.github.com> | 2022-12-24 08:56:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-24 08:56:55 +0100 |
commit | 26bb3c572eaffafafd8de8ef09b8acc34f91656f (patch) | |
tree | 2d70696f4f8bb78f9a4fda7a6d596775fdf080cc /testsuite/pyunit/dom/examples/SimpleEntity.vhdl | |
parent | 8845f761ed2299e595afd5eee2444fed7fb79639 (diff) | |
parent | 5d9897770cb16494c6379cce85ed5935532c0cd1 (diff) | |
download | ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.tar.gz ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.tar.bz2 ghdl-26bb3c572eaffafafd8de8ef09b8acc34f91656f.zip |
Merge pull request #2265 from Paebbels/paebbels/DOM-with-documentation
pyGHDL.dom with Documentation
Diffstat (limited to 'testsuite/pyunit/dom/examples/SimpleEntity.vhdl')
-rw-r--r-- | testsuite/pyunit/dom/examples/SimpleEntity.vhdl | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/testsuite/pyunit/dom/examples/SimpleEntity.vhdl b/testsuite/pyunit/dom/examples/SimpleEntity.vhdl new file mode 100644 index 000000000..8acc3ddb5 --- /dev/null +++ b/testsuite/pyunit/dom/examples/SimpleEntity.vhdl @@ -0,0 +1,57 @@ +-- Author: Patrick Lehmann +-- +-- A generic counter module used in the StopWatch example. +-- +library IEEE; +use IEEE.std_logic_1164.all; +use IEEE.numeric_std.all; + +use work.Utilities.all; + +-- Generic modulo N counter +-- +-- This component implements a generic modulo N counter with synchronous reset +-- and enable. It generates a wrap-around strobe signal when it roles from +-- MODULO-1 back to zero. +-- +-- .. hint:: +-- +-- A modulo N counter counts binary from zero to N-1. +-- +-- This component uses VHDL-2008 features like readback of ``out`` ports. +entity Counter is + generic ( + MODULO : positive; -- Modulo value. + BITS : natural := log2(MODULO) -- Number of expected output bits. + ); + port ( + Clock : in std_logic; -- Component clock + Reset : in std_logic; -- Component reset (synchronous) + Enable : in std_logic; -- Component enable (synchronous) + + Value : out unsigned(BITS - 1 downto 0); -- Current counter value + WrapAround : out std_logic -- Strobe output on change from MODULO-1 to zero + ); +end entity; + + +architecture rtl of Counter is + -- Synthesizable and simulatable variant of a generic counter. + + -- Internal counter value + signal CounterValue : unsigned(log2(MODULO) - 1 downto 0) := (others => '0'); +begin + process (Clock) + begin + if rising_edge(Clock) then + if ((Reset or WrapAround) = '1') then + CounterValue <= (others => '0'); + elsif (Enable = '1') then + CounterValue <= CounterValue + 1; + end if; + end if; + end process; + + Value <= resize(CounterValue, BITS); + WrapAround <= Enable when (CounterValue = MODULO - 1) else '0'; +end architecture; |