OpenCores
URL https://opencores.org/ocsvn/dallas_one-wire/dallas_one-wire/trunk

Subversion Repositories dallas_one-wire

[/] [dallas_one-wire/] [tags/] [arelease/] [DS1821_2.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 bretthowar
library ieee;
2
use ieee.std_logic_1164.all;
3
use ieee.std_logic_arith.all;
4
use work.protocol_pkg.all;
5
--use work.decode_pkg.all;
6
use work.timer_pkg.all;
7
 
8
entity DS1821 is
9
  port
10
  (
11
        master_clk, master_rst          : IN std_logic;
12
        clk                                             : INOUT std_logic;
13
        tempValid                                       : OUT std_logic;
14
        reset, read1, write1            : INOUT std_logic;
15
        DQ1                                             : INOUT std_logic;
16
        rddata1                                 : INOUT std_logic_vector(7 downto 0);
17
        wrdata1                                 : INOUT std_logic_vector(7 downto 0);
18
        ready1                                  : INOUT std_logic
19
 
20
        --useg                                          : OUT std_logic_vector( 0 to 6 );
21
        --lseg                                          : OUT std_logic_vector( 0 to 6 )
22
  );
23
end entity;
24
 
25
architecture DS1821Controller of DS1821 is
26
 
27
component one_wire is
28
        port (
29
                clk, reset, read, write : IN std_logic;
30
                DQ                                      : INOUT std_logic;
31
                rddata                          : INOUT std_logic_vector(7 downto 0);
32
                wrdata                          : IN std_logic_vector(7 downto 0);
33
                ready                           : INOUT std_logic);
34
end component;
35
 
36
--component seg_decode is                       --this component is only needed for debugging
37
--      port(
38
--              value                           : IN std_logic_vector (3 downto 0);
39
--              output                          : OUT std_logic_vector (0 to 6));
40
--end component;
41
 
42
component clk_divider is
43
        port(
44
        clk                                             : IN    std_logic;
45
        oneus_plus                              : INOUT std_logic);
46
end component;
47
 
48
        type states is (init, sendCommStatProg, sendCommStatVal, init1, sendConvTempComm, init2, sendReadTempComm, readTemp);
49
        signal state                            :states;
50
        signal next_state                       :states;
51
 
52
begin
53
        temperaturemap1: one_wire port map(clk, reset, read1, write1, DQ1, rddata1, wrdata1, ready1);
54
        clkdivider: clk_divider port map(master_clk, clk);                      --clock divider to make this work with 25.175Mhz
55
        --usegdecode: seg_decode port map(rddata1(7 downto 4), useg);           --seven seg decoder for debugging
56
        --lsegdecode: seg_decode port map(rddata1(3 downto 0), lseg);           --seven seg decoder for debugging
57
 
58
        process ( clk, master_rst )
59
        begin
60
                if master_rst = '0' then
61
                        wrdata1 <= wrdata1;
62
                        write1 <= write1;
63
                        read1 <= read1;
64
                        tempValid <= '0';
65
                        reset <= '1';
66
                        next_state <= init;
67
                        state <= init;
68
                elsif rising_edge( clk ) then
69
                        state <= next_state;
70
                        case state is
71
                                when init =>
72
                                        write1 <= '0';
73
                                        read1 <= '0';
74
                                        reset <= '1';
75
                                        tempValid <= '0';
76
                                        next_state <= sendCommStatProg;
77
                                when sendCommStatProg =>
78
                                        reset <= '0';
79
                                        if ready1 = '1' then
80
                                                wrdata1 <= "00001100";                  --send 0Ch = Configure the register command
81
                                                write1 <= '1';
82
                                                next_state <= sendCommStatVal;
83
                                        end if;
84
                                when sendCommStatVal =>
85
                                        write1 <= '0';
86
                                        if ready1 = '1' then
87
                                                wrdata1 <= "01000010";                  --send 42h = Write this value into the register
88
                                                write1 <= '1';
89
                                                next_state <= init1;
90
                                        end if;
91
                                when init1 =>
92
                                        write1 <= '0';
93
                                        read1 <= '0';
94
                                        if ready1 = '1' then
95
                                                reset <= '1';
96
                                                next_state <= sendConvTempComm;
97
                                        end if;
98
                                when sendConvTempComm =>
99
                                        reset <= '0';
100
                                        --write1 <= '0';
101
                                        --tempValid <= '0';
102
                                        if ready1 = '1' AND reset <= '0' then
103
                                                wrdata1 <= "11101110";                  --send EEh = Begin Conversions
104
                                                write1 <= '1';
105
                                                next_state <= init2;
106
                                        end if;
107
                                when init2 =>
108
                                        if read1 = '1' then
109
                                                read1 <= '0';
110
                                                tempValid <= '0';
111
                                        end if;
112
                                        write1 <= '0';
113
                                        if ready1 = '1' then
114
                                                reset <= '1';
115
                                                tempValid <= '0';
116
                                                next_state <= sendReadTempComm;
117
                                        end if;
118
                                when sendReadTempComm =>
119
                                        tempValid <= '1';
120
                                        reset <= '0';
121
                                        write1 <= '0';
122
                                        if ready1 = '1' AND reset <= '0' then
123
                                                tempValid <= '1';
124
                                                wrdata1 <= "10101010";                  --send AAh = Read Temp Command
125
                                                write1 <= '1';
126
                                                next_state <= readTemp;
127
                                        end if;
128
                                when readTemp =>                                                --starts reading the temperature
129
                                        write1 <= '0';
130
                                        tempValid <= '1';
131
                                        if ready1 = '1' then
132
                                                read1 <= '1';
133
                                                tempValid <= '0';
134
                                                next_state <= init2;
135
                                        end if;
136
                                --when holdTemp =>                                              --For now I just hold the temp steady after one read
137
                                --      read1 <= '0';
138
                                --      if ready1 = '1' then
139
                                --              tempValid <= '1';
140
                                --              --ftemp <= rddata1 * "00001001";
141
                                --      end if;
142
                                --      next_state <= holdTemp;
143
                                when OTHERS =>
144
                        end case;
145
                end if;
146
        end process;
147
end architecture;
148
 
149
PACKAGE TEMPERATURE_PKG IS
150
                COMPONENT DS1821
151
                END COMPONENT;
152
END TEMPERATURE_PKG;

powered by: WebSVN 2.1.0

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