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

Subversion Repositories onewire

[/] [onewire/] [trunk/] [HDL/] [ds1820_mstr.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 skeptonomi
----------------------------------------------------------------------------------
2
--  <c>2018 william b hunter
3
--    This file is part of ow2rtd.
4
--
5
--    ow2rtd is free software: you can redistribute it and/or modify
6
--    it under the terms of the GNU Lessor General Public License as published by
7
--    the Free Software Foundation, either version 3 of the License, or
8
--    (at your option) any later version.
9
--
10
--    ow2rtd is distributed in the hope that it will be useful,
11
--    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
--    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
--    GNU General Public License for more details.
14
--
15
--    You should have received a copy of the GNU Lessor General Public License
16
--    along with ow2rtd.  If not, see <https://www.gnu.org/licenses/>.
17
-----------------------------------------------------------------------------------  
18
--  Create Date: 5/15/2018
19
--  file: ds1820_mstr.vhd
20
--  description: interfaces to the ds1820 devices on the one wire bus.
21
--  this includes discovering the devices, configuring them, and reading the temperatures
22
--
23
--  The design consists of the following major blocks:
24
--     ow_mstr - low level interface to the one wire bus including byte and bit accesses
25
--     ow_search - discovers devices on the one wire bus, both ds1820 types and others
26
--     ow_temp - configures the ds1820 devices on the bus and reads the temperatures
27
--     ow_idram - a ram for storing the 64 bit long device ids
28
-----------------------------
29
 
30
library IEEE;
31
use IEEE.STD_LOGIC_1164.ALL;
32
use IEEE.numeric_std.all;
33
 
34
-------------------------------------------------------------------------------------
35
-- Entity declaration
36
-------------------------------------------------------------------------------------
37
entity ds1820_mstr is
38
  port (
39
    --global signals
40
          clk              : in    std_logic;
41
    srst             : in    std_logic;  --synchronous reset
42
    stb1us           : in    std_logic;  --1us strobe, used to time transactions
43
    busy             : out   std_logic;  --device is in middle of read,write or init
44
    err              : out   std_logic;  --something went wrong, this is cleared by next command
45
    --controls from upper level of hierarchy
46
        search_stb       : in    std_logic;  --searches for devices on bus
47
    temp_init        : in    std_logic;  --starts initialization of all sensors
48
    temp_conv        : in    std_logic;  --starts temperature conversion on all sensors
49
    temp_read        : in    std_logic;  --starts temperature read from all sensors
50
    --response to upper level of hierarchy
51
    temp             : out   signed(15 downto 0); --temperature of the current sensor
52
    tempidx          : out   unsigned(4 downto 0); --index of the current temp sensor
53
    tempstb          : out   std_logic;                    --temperature available strobe
54
    --one wire bus interface
55
    owin             : in    std_logic;  --one wire input
56
    owout            : out   std_logic   --one wire output
57
    --dio             : inout std_logic
58
  );
59
end ds1820_mstr;
60
 
61
-------------------------------------------------------------------------------------
62
-- Architecture declaration
63
-------------------------------------------------------------------------------------
64
architecture rtl of ds1820_mstr is
65
  --bit module signals
66
  type s16ary is array (integer range <>) of signed(15 downto 0);
67
  signal ow_zbit  : std_logic;
68
  signal ow_rbit  : std_logic;
69
  signal ow_obit  : std_logic;
70
  signal ow_wbit  : std_logic;
71
  signal ow_ibit  : std_logic;
72
  signal ow_rbyte : std_logic;
73
  signal ow_obyte : std_logic_vector(7 downto 0);
74
  signal ow_wbyte : std_logic;
75
  signal ow_ibyte : std_logic_vector(7 downto 0);
76
  signal ow_busy  : std_logic;
77
  signal ow_ppwr  : std_logic;
78
 
79
  --search module signals
80
  signal ows_wbit  : std_logic;
81
  signal ows_obit  : std_logic;
82
  signal ows_rbit  : std_logic;
83
  signal ows_zbit  : std_logic;
84
  signal ows_busy  : std_logic;
85
  signal ows_err   : std_logic;
86
  signal ows_wbyte : std_logic;
87
  signal ows_obyte : std_logic_vector(7 downto 0);
88
  signal ows_idnum : std_logic_vector(4 downto 0);
89
  signal ows_idbit : std_logic_vector(5 downto 0);
90
 
91
  --temp module signals
92
  signal owt_wbit  : std_logic;
93
  signal owt_obit  : std_logic;
94
  signal owt_zbit  : std_logic;
95
  signal owt_busy  : std_logic;
96
  signal owt_err   : std_logic;
97
  signal owt_wbyte : std_logic;
98
  signal owt_obyte : std_logic_vector(7 downto 0);
99
  signal owt_rbyte : std_logic;
100
  signal owt_idnum : std_logic_vector(4 downto 0);
101
  signal owt_idbit : std_logic_vector(5 downto 0);
102
 
103
        signal id_we     : std_logic;
104
        signal id_ibit   : std_logic;
105
        signal id_obit   : std_logic;
106
  signal id_num    : std_logic_vector(4 downto 0);
107
  signal id_bit    : std_logic_vector(5 downto 0);
108
 
109
  --byte module signals
110
  signal ow8_rbit  : std_logic;
111
  signal ow8_wbit  : std_logic;
112
 
113
begin
114
  -------------------------------------
115
  --        signal decoding         ---
116
  -------------------------------------
117
  -- ows is the search module, owt is the temp module
118
  -- rbit, rbyte, wbit, wbyte are the read and write strobes that initiate commands
119
  -- ibit,obit, ibyte, obyte are the bit and byte input and output values
120
 
121
 
122
  -- the following signals are muxed with priorities, allowing both the temperture and search modules
123
  --   (owt and ows) to control the one wire interface. 
124
  ow_rbit <= ows_rbit;
125
        ow_wbit <= ows_wbit when ows_busy = '1' else owt_wbit;
126
  ow_ibit <= ows_obit when ows_busy = '1' else owt_obit;
127
  ow_zbit <= ows_zbit when ows_busy = '1' else owt_zbit;
128
        ow_wbyte <= ows_wbyte when ows_busy = '1' else owt_wbyte;
129
        ow_ibyte <= ows_obyte when ows_busy = '1' else owt_obyte;
130
  ow_rbyte <= owt_rbyte;
131
  id_bit <= ows_idbit when ows_busy = '1' else owt_idbit ;
132
  id_num <= ows_idnum when ows_busy = '1' else owt_idnum ;
133
 
134
 
135
  -------------------------------------
136
  --      one wire controller       ---
137
  -------------------------------------
138
        --ow_mstr - interfaces to the one wire bus, handles reset, rd/wr byte, rd/wr bit
139
        u_onewire : entity work.ow_mstr(rtl)
140
  port map (
141
    --global signals
142
    clk         => clk,
143
    srst        => srst,
144
    stb1us      => stb1us,          -- 1us timing strobe
145
    busy        => ow_busy,         --indicates the one wire interface is busy
146
    init_stb    => ow_zbit,         --sends an init/reset pulse to bus
147
    wrbit       => ow_wbit,         --write a single bit to the bus
148
    inbit       => ow_ibit,         --data bit to write
149
    rdbit       => ow_rbit,         --read a single bit from the bus
150
    outbit      => ow_obit,         --read bit
151
    wrbyte      => ow_wbyte,        --write a byte to the bus
152
    inbyte      => ow_ibyte,        --data byte to write
153
    rdbyte      => ow_rbyte,        --read a byte from the bus
154
    outbyte     => ow_obyte,        --read byte
155
    --one wire bus interface
156
    owin        => owin,            --one wire input
157
    owout       => owout            --one wire output
158
        );
159
 
160
  -------------------------------------
161
  --        search controller       ---
162
  -------------------------------------
163
  --ow_search - searches the one wire bus for all the one wire devices
164
  --  this detects the ds1820 temp sensors and other devices with 64 bit ids
165
  u_ows : entity work.ow_search(rtl)
166
  port map (
167
    --global signals
168
    clk         => clk,
169
    srst        => srst,
170
    start       => search_stb,       --iniitates the ow bus search for devices
171
    busyin      => ow_busy,          --(input) indicates the ow_mstr is busy
172
    busy        => ows_busy,         --(output) indicates the search is busy
173
    error       => ows_err,          --the search algorithm hit a snag
174
    --ow1 & ow8 interfaces
175
    rdbit       => ows_rbit,         --read command to ow1
176
    wrbit       => ows_wbit,         --write command to ow1
177
    zzbit       => ows_zbit,         --reset pulse command to ow1
178
    obit        => ows_obit,         --write value to ow1
179
    ibit        => ow_obit,          --value read from ow1
180
    wrbyte      => ows_wbyte,        --write command to ow8
181
    obyte       => ows_obyte,        --write value to ow8
182
    --id ram interface,
183
    id_num      => ows_idnum,        --current device index (0=31)
184
    id_bit      => ows_idbit,        --current bit index (0-63)
185
    id_rbit     => id_obit,          --bit read from RAM
186
    id_wbit     => id_ibit,          --bit written to RAM
187
    id_we       => id_we             --write enable to RAM
188
 
189
  );
190
 
191
  -------------------------------------
192
  --    temp sensor controller      ---
193
  -------------------------------------
194
  --ow_temp - handles the temperature reading from devices.
195
  --performs initialization, conversion start, and read back of results.
196
  u_owt : entity work.ow_temp(rtl)
197
  port map (
198
    --globals
199
    clk         => clk,
200
    srst        => srst,
201
    busyin      => ow_busy,            --(input) os_mstr is busy
202
    --signals to upper layer hierarchy
203
    init        => temp_init,          --command strobe to initialize sensors
204
    conv        => temp_conv,          --command strobe to start conversions
205
    read        => temp_read,          --command strobe to read the temps
206
    busy        => owt_busy,           --(output) temp module is busy
207
    error       => owt_err,            --indicates temp module error
208
    --temp values output on a muxed bus
209
    temp        => temp,               --output temp value
210
    tempidx     => tempidx,            --temp index
211
    tempstb     => tempstb,            --temp strobe
212
    --ow1 and ow8 interfaces
213
    zzbit       => owt_zbit,           --reset pulse command to ow1
214
    wrbit       => owt_wbit,           --write command to ow1      
215
    obit        => owt_obit,           --write value to ow1
216
    ibit        => ow_ibit,            --value read from ow1
217
    wrbyte      => owt_wbyte,          --write command to ow8
218
    rdbyte      => owt_rbyte,          --read command to ow8
219
    ibyte       => ow_obyte,           --read value from ow8
220
    obyte       => owt_obyte,          --write value to ow8
221
    --id ram interface,
222
    id_num => owt_idnum,               --current device index (0=31)
223
    id_bit  => owt_idbit,              --current bit index (0-63)
224
    id_rbit => id_obit                 --bit read from RAM
225
  );
226
 
227
  -------------------------------------
228
  --              ID RAM            ---
229
  -------------------------------------
230 4 skeptonomi
  -- ow_idram - bit indexed ram, store and recalls the device ids for devices on the ow bus.
231 2 skeptonomi
  --  this is implemented in a seperate module to ensure that it uses a internal ram
232
  --  which greatly reduces the FPGA utilization (saves a lot of FFs and LUTs)
233
  u_idram : entity work.ow_idram(rtl)
234
  port map(
235
    --globals
236
    clk    => clk,
237
    --srst   => srst,
238
    --ram signals
239
    mode       => ows_busy,    --1=search,0=other, used to compute read addresses
240
    idnum      => id_num,      --index of the id to read or write
241
    idbit      => id_bit,      --index of the bit within the id to read or write
242
    we         => id_we,       --write the currently indexed bit
243
    wdat       => id_ibit,     --bit value to write to the currently indexed bit
244
    rdat       => id_obit      --bit value of the currently indexed bit
245
  );
246
 
247
  -- crc8 - computes the CRC for the ow command and responses.
248
  --  not yet implemented
249
  --u_crc : entity work.crc8(rtl)
250
  --port map (
251
  --  clk    => clk,
252
  --  srst   => srst,
253
  --  clken  => stb1us,
254
  --  crcen  => owc_en,
255
  --    crcclr => ow1_init,
256
  --    rdstb  => ow1_rbit,
257
  --    busyin => ow1_busy,
258
  --    din    => ow1_odat,
259
  --    crc    => owc_crc
260
  --);
261
 
262
 
263
  err <= ows_err or owt_err;
264
        busy <= owt_busy or ows_busy;
265
 
266
end rtl;

powered by: WebSVN 2.1.0

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