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

Subversion Repositories iicmb

[/] [iicmb/] [trunk/] [src_tb/] [wire_mdl.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sshuv2
 
2
--==============================================================================
3
--                                                                             |
4
--    Project: IIC Multiple Bus Controller (IICMB)                             |
5
--                                                                             |
6
--    Module:  Wire model.                                                     |
7
--    Version:                                                                 |
8
--             1.0,   April 29, 2016                                           |
9
--                                                                             |
10
--    Author:  Sergey Shuvalkin, (sshuv2@opencores.org)                        |
11
--                                                                             |
12
--==============================================================================
13
--==============================================================================
14
-- Copyright (c) 2016, Sergey Shuvalkin                                        |
15
-- All rights reserved.                                                        |
16
--                                                                             |
17
-- Redistribution and use in source and binary forms, with or without          |
18
-- modification, are permitted provided that the following conditions are met: |
19
--                                                                             |
20
-- 1. Redistributions of source code must retain the above copyright notice,   |
21
--    this list of conditions and the following disclaimer.                    |
22
-- 2. Redistributions in binary form must reproduce the above copyright        |
23
--    notice, this list of conditions and the following disclaimer in the      |
24
--    documentation and/or other materials provided with the distribution.     |
25
--                                                                             |
26
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
27
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE   |
28
-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  |
29
-- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE    |
30
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR         |
31
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF        |
32
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS    |
33
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN     |
34
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)     |
35
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE  |
36
-- POSSIBILITY OF SUCH DAMAGE.                                                 |
37
--==============================================================================
38
 
39
 
40
library ieee;
41
use ieee.math_real.uniform;
42
use ieee.math_real.exp;
43
 
44
 
45
--==============================================================================
46
entity wire_mdl is
47
  generic
48
  (
49
    g_resistance_0       :       real       := 1.0; -- In Ohms
50
    g_resistance_1       :       real       := 1.0; -- In Ohms
51
    g_capacitance        :       real       := 1.0; -- In pF
52
    g_initial_level      :       bit        := '0'
53
  );
54
  port
55
  (
56
    sig_in               : in    bit;
57
    sig_out              :   out real;
58
    sig_out_l            :   out bit
59
  );
60
end entity wire_mdl;
61
--==============================================================================
62
 
63
--==============================================================================
64
architecture beh of wire_mdl is
65
 
66
  -- We use picoseconds and picofarads in calculations
67
  constant c_time_delta      : time := 2011 ps;
68
  constant c_time_delta_real : real := real(c_time_delta / 1 ps);
69
 
70
  function to_real(a : bit) return real is
71
  begin
72
    if (a = '0') then
73
      return 0.0;
74
    else
75
      return 1.0;
76
    end if;
77
  end function to_real;
78
 
79
  signal   u_c          : real := to_real(g_initial_level); -- current voltage
80
 
81
begin
82
 
83
  ------------------------------------------------------------------------------
84
  sig_out_proc:
85
  process
86
    variable v_target     : real;
87
    variable v_resistance : real;
88
    variable seed_0       : positive  := 1137938;
89
    variable seed_1       : positive  := 1010110111;
90
    variable random_value : real;
91
  begin
92
    -- Get target voltage
93
    v_target := to_real(sig_in);
94
 
95
    -- Get resistance, depending on target voltage
96
    if (sig_in = '1') then
97
      v_resistance := g_resistance_1;
98
    else
99
      v_resistance := g_resistance_0;
100
    end if;
101
 
102
    -- Calculate next voltage level:
103
    u_c <= v_target - (v_target - u_c)*exp((-c_time_delta_real)/(g_capacitance * v_resistance));
104
 
105
    ieee.math_real.uniform(seed_0, seed_1, random_value);
106
    if (u_c >= random_value) then
107
      sig_out_l <= '1';
108
    else
109
      sig_out_l <= '0';
110
    end if;
111
    wait for c_time_delta;
112
  end process sig_out_proc;
113
  ------------------------------------------------------------------------------
114
 
115
  sig_out <= u_c;
116
 
117
end architecture beh;
118
--==============================================================================
119
 

powered by: WebSVN 2.1.0

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