w11 - vhd 0.794
W11 CPU core and support modules
Loading...
Searching...
No Matches
clkdivce_tb.vhd
Go to the documentation of this file.
1-- $Id: clkdivce_tb.vhd 1181 2019-07-08 17:00:50Z mueller $
2-- SPDX-License-Identifier: GPL-3.0-or-later
3-- Copyright 2007-2011 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4--
5------------------------------------------------------------------------------
6-- Module Name: clkdivce_tb - sim
7-- Description: Generate usec and msec enable signals (SIM only!)
8--
9-- Dependencies: -
10-- Test bench: -
11-- Target Devices: generic
12-- Tool versions: viv 2016.2; ghdl 0.33
13-- Revision History:
14-- Date Rev Version Comment
15-- 2016-09-10 806 1.0 Initial version (copied from clkdivce)
16------------------------------------------------------------------------------
17
18library ieee;
19use ieee.std_logic_1164.all;
20use ieee.numeric_std.all;
21
22use work.slvtypes.all;
23
24entity clkdivce_tb is -- generate usec/msec ce pulses
25 generic (
26 CDUWIDTH : positive := 6; -- usec clock divider width
27 USECDIV : positive := 50; -- divider ratio for usec pulse
28 MSECDIV : positive := 1000); -- divider ratio for msec pulse
29 port (
30 CLK : in slbit; -- input clock
31 CE_USEC : out slbit; -- usec pulse
32 CE_MSEC : out slbit -- msec pulse
33 );
34end clkdivce_tb;
35
36
37architecture sim of clkdivce_tb is
38
39 type regs_type is record
40 ucnt : slv(CDUWIDTH-1 downto 0); -- usec clock divider counter
41 mcnt : slv10; -- msec clock divider counter
42 usec : slbit; -- usec pulse
43 msec : slbit; -- msec pulse
44 end record regs_type;
45
46 constant regs_init : regs_type := (
47 slv(to_unsigned(USECDIV-1,CDUWIDTH)),
48 slv(to_unsigned(MSECDIV-1,10)),
49 '0','0'
50 );
51
52 signal R_REGS : regs_type := regs_init; -- state registers
53 signal N_REGS : regs_type := regs_init; -- next value state regs
54
55begin
56
57 assert USECDIV <= 2**CDUWIDTH and MSECDIV <= 1024
58 report "assert(USECDIV <= 2**CDUWIDTH and MSECDIV <= 1024): " &
59 "USECDIV too large for given CDUWIDTH or MSECDIV>1024"
60 severity failure;
61
62 proc_regs: process (CLK)
63 begin
64
65 if rising_edge(CLK) then
66 R_REGS <= N_REGS;
67 end if;
68
69 end process proc_regs;
70
71 proc_next: process (R_REGS)
72
73 variable r : regs_type := regs_init;
74 variable n : regs_type := regs_init;
75
76 begin
77
78 r := R_REGS;
79 n := R_REGS;
80
81 n.usec := '0';
82 n.msec := '0';
83
84 n.ucnt := slv(unsigned(r.ucnt) - 1);
85 if unsigned(r.ucnt) = 0 then
86 n.usec := '1';
87 n.ucnt := slv(to_unsigned(USECDIV-1,CDUWIDTH));
88 n.mcnt := slv(unsigned(r.mcnt) - 1);
89 if unsigned(r.mcnt) = 0 then
90 n.msec := '1';
91 n.mcnt := slv(to_unsigned(MSECDIV-1,10));
92 end if;
93 end if;
94
95 N_REGS <= n;
96
97 CE_USEC <= r.usec;
98 CE_MSEC <= r.msec;
99
100 end process proc_next;
101
102
103end sim;
regs_type := regs_init N_REGS
Definition: clkdivce_tb.vhd:53
regs_type := regs_init R_REGS
Definition: clkdivce_tb.vhd:52
regs_type :=( slv( to_unsigned( USECDIV- 1, CDUWIDTH) ), slv( to_unsigned( MSECDIV- 1, 10) ), '0', '0') regs_init
Definition: clkdivce_tb.vhd:46
out CE_MSEC slbit
Definition: clkdivce_tb.vhd:33
USECDIV positive := 50
Definition: clkdivce_tb.vhd:27
CDUWIDTH positive := 6
Definition: clkdivce_tb.vhd:26
out CE_USEC slbit
Definition: clkdivce_tb.vhd:31
MSECDIV positive := 1000
Definition: clkdivce_tb.vhd:28
in CLK slbit
Definition: clkdivce_tb.vhd:30
std_logic_vector( 9 downto 0) slv10
Definition: slvtypes.vhd:42
std_logic slbit
Definition: slvtypes.vhd:30
std_logic_vector slv
Definition: slvtypes.vhd:31