OpenCores
URL https://opencores.org/ocsvn/sincos/sincos/trunk

Subversion Repositories sincos

[/] [sincos/] [trunk/] [vhdl/] [tb/] [clk_rst/] [clk_rst.vhd] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 dk4xp
--! @file
2
--! @brief clock for simulation with selectable frequency and reset with selectable width.
3
 
4
-- (c) jul 2007... Gerhard Hoffmann  opencores@hoffmann-hochfrequenz.de
5
-- Published under BSD license
6
-- V1.0  first published version
7
--
8
--! @details Solution to an everyday problem.
9
--! This module produces a clock for a simulation with selectable frequency
10
--! and a reset signal with selectable width. The duty cycle is 1:1.
11
--! The reset is active from the beginning and removed synchronously shortly
12
--! after a rising clock edge.
13
--! setting verbose to true gives some diagnostics.
14
--
15
-- Make sure that your simulator has a time resolution of at least 1 ps.
16
-- For modelsim, this is set up by the various modelsim.ini files
17
-- and/or the project file (foobar.mpf)
18
 
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
use ieee.numeric_std.all;
23
use ieee.math_real.all;
24
 
25
 
26
 
27
entity clk_rst is
28
  generic (
29
    verbose:         boolean := false;
30
    clock_frequency: real    := 100.0e6;  -- 100 MHz
31
    min_resetwidth:  time    := 12 ns     -- minimum resetwidth, is synchronized to clk  
32
        );
33
  port (
34
    clk: out std_logic;
35
    rst: out std_logic
36
  );
37
end entity clk_rst;
38
 
39
 
40
architecture rtl of clk_rst is
41
 
42
 
43
-- The clock frequency is given in Hz in floating point format.
44
-- compute the equivalent half cycle time.
45
 
46
function frequency2halfcycle(f: real; verbose: boolean) return time is
47
 
48
  variable picoseconds: real;
49
  variable retval:      time;
50
 
51
begin
52
  assert f > 1.0e-10
53
    report "clk_and_rst.vhd: requested clock frequency is unreasonably low or even negative - danger of 1/0.0"
54
    severity error;
55
 
56
  picoseconds := (0.5 / f ) / 1.0e-12;
57
  retval := integer(picoseconds) * 1 ps;
58
 
59
  if verbose then
60
    report "function frequency2halfcycle() in clk_rst.vhd: picoseconds = " & real'image(picoseconds);
61
    report "halfcycle = " & time'image(retval);
62
  end if;
63
 
64
  assert retval > 0 ps
65
    report "frequency2halfcycle(): length of halfcycle truncated to 0 ps. "
66
         & "Set simulator resolution to 1 ps or smaller in modelsim.ini, foobar.mpf or whatever your simulator uses"
67
    severity error;
68
 
69
  return retval;
70
end;
71
 
72
 
73
signal iclk:      std_logic := '0';  -- entity-internal clk and rst
74
signal irst:      std_logic := '1';
75
 
76
constant halfcycle: time    := frequency2halfcycle(clock_frequency, verbose);
77
 
78
----------------------------------------------------------------------------------------------------   
79
begin
80
 
81
--
82
-- generate the internal system clock
83
 
84
u_sysclock: process is
85
begin
86
   wait for halfcycle;
87
   iclk <= '1';
88
 
89
   wait for halfcycle;
90
   iclk <= '0';
91
end process u_sysclock;
92
 
93
 
94
--
95
-- generate internal reset
96
 
97
u_rst: process is
98
begin
99
   irst <= '1';
100
   wait for min_resetwidth;
101
   wait until rising_edge(iclk);
102
   irst <= '0';
103
   wait;    -- forever
104
end process u_rst;
105
 
106
-- make the local signals public
107
 
108
clk <= iclk;
109
rst <= irst;
110
 
111
end architecture rtl;
112
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.