/
m59
/
MukPlis
Обзор
Документация
Войти
/
m59
/
MukPlis
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/DatTemp.vhd
275 строк
10 KB
AndreyM
TU good variant
29 мар 2026, 10:04
29 мар 2026, 10:04
0abc2b4
Код
Авторство
О чём код?
------------------------------------------------------------------------------------------------------------- -- Title : DatTemp -- : ����� ������ � ������������ � �� ���� DS18B20 -- Design : -- Author : Makarov -- Company : -- ------------------------------------------------------------------------------------------------------------- library ieee; use ieee.std_logic_1164.ALL, ieee.std_logic_unsigned.all, ieee.std_logic_arith.all; use ieee.numeric_std.all; entity DatTemp is port( CLK : in std_logic; us1 : in std_logic; us10 : in std_logic; us100 : in std_logic; ms1 : in std_logic; ms10 : in std_logic; ms100 : in std_logic; s1 : in std_logic; RD0 : in std_logic; RD1 : in std_logic; Q : out std_logic_vector(7 downto 0); QT : in std_logic; QT_OUT : out std_logic; STRB_COM : out std_logic; STRB_SKIP : out std_logic; STRB_RD_COM : out std_logic; STRB_RD_DATA: out std_logic; DT : out std_logic; ZT : out std_logic ); end DatTemp; architecture DatTemp of DatTemp is signal temper : std_logic_vector(15 downto 0):="0000000000000000"; signal temp_rg : std_logic_vector(15 downto 0):="0000000000000000"; signal cntr_s : std_logic_vector(1 downto 0):="00"; signal cntr_ms100 : std_logic_vector(3 downto 0):="0000"; signal cntr_ms10 : std_logic_vector(2 downto 0):="000"; signal cntr_ms1 : std_logic_vector(2 downto 0):="000"; signal cntr_us100 : std_logic_vector(2 downto 0):="000"; signal cntr_us10 : std_logic_vector(2 downto 0):="000"; signal stb_res : std_logic:='0'; -- ������ ������ |_| ������� ������, 500 us signal stb_pres : std_logic:='0'; -- ����� 15-60 us ����� Reset, DS18B20 ��������� |_| ��������� ����������� 60-240 us, ������ ����� ����� 1 ms signal stb_skip_com : std_logic:='0'; -- ������ ������ ������� "���������� ROM", 0xCC, 1 ms signal stb_conv_com : std_logic:='0'; -- ������ ������ ������� "Convert Tcommand", 0x44, 1 ms signal stb_tconv : std_logic:='0'; -- ������ Strong pullup DQ �� ����� �������������� (tCONV), 800 ms signal stb_rd_com : std_logic:='0'; -- ������ ������ ������� "Read Scratchpad" �������, 0xBE, 1 ms signal stb_rd_data : std_logic:='0'; -- ������ ������ 9 ����, �� ������ ������ ������ ������ ��� � ������������ signal stb_bit_data : std_logic:='0'; -- 10 us ����� imp_ini_rd signal stb_com : std_logic; -- stb_skip_com or stb_conv_com or stb_rd_com signal ini_0 : std_logic; -- ������ ������� � ������ ������ ������ ������� 10 us signal data_out : std_logic:='0'; -- -- ���� ������ ���� 100 ���, ������ �������: '0' - 70 ���, '1' - 10 ���, ������� ���� �������� ������� -- ���� ������ ���� ���������� ���������� �������� ������� ������ �� ����, ��� ������ '1' ����� ���������� ������� ������� ����� 10 ���, ��� ������ '0' ����� ���������� ������� ������� ����� 70 ��� -- ����� ������ ���� (����� 70 ��� ����� ������ �����) ������ ������ ���������� ���� -- ������ ������ ����� 1 �� -- ������ �����: LSB -- ��� ������ � �� ������ ������������ � ������� 15 us ����� ���������� ������, ������� ������ ����������� ��������� �������� ������ ���� signal cntr_stb_res : std_logic_vector(2 downto 0):="000"; -- ������� ������������ ������� ������, 500 us, �� ms100 signal cntr_slot_wr : std_logic_vector(3 downto 0):="0000"; -- ������� us10 � ����� ����������� �������� ����, ��� ���������� ���������������� ������ �������, �� us10 signal cntr_out_bits: std_logic_vector(3 downto 0):="0000"; -- ������� ���, ���������� �� �� � ������� �������, �� ms100 signal prz_1 : std_logic; -- ������� ������ '1' ���� � ������ �� ������ ����� ������ � ������� ���������� ������� signal prz_0 : std_logic; -- ������� ������ '0' ���� � ������� ���������� ������� signal imp_ini_rd : std_logic; -- �� ����� �������� ������ ������ �� ���� ������ �������, ����� �������� DS18B20 ������ ��������� ��� ������, 16 �������� � �������� 100 us signal cntr_in_bits : std_logic_vector(4 downto 0):="00000"; -- ������� ���, ����������� � ��, ��� ����� � ����������� signal wr_data_dt : std_logic:='0'; -- ������ ���� ������ � �������, ����� 10 us ����� imp_ini_rd begin STRB_COM<=stb_com; STRB_SKIP<=stb_skip_com; STRB_RD_COM<=stb_rd_com; STRB_RD_DATA<=stb_rd_data; PROC_CNTR_ms100: process (CLK) begin if rising_edge(CLK) then if s1='1' then cntr_ms100<="0000"; elsif ms100='1' then cntr_ms100<=cntr_ms100+1; end if; end if; end process PROC_CNTR_ms100; PROC_CNTR_ms10: process (CLK) begin if rising_edge(CLK) then if ms100='1' then cntr_ms10<="000"; elsif ms10='1' then cntr_ms10<=cntr_ms10+1; end if; end if; end process PROC_CNTR_ms10; PROC_CNTR_STB_RES: process (CLK) begin if rising_edge(CLK) then if stb_res='0' then cntr_stb_res<="000"; elsif us100='1' then cntr_stb_res<=cntr_stb_res+1; end if; end if; end process PROC_CNTR_STB_RES; PROC_STB: process (CLK) begin if rising_edge(CLK) then if s1='1' then stb_res<='1'; -- ������ ������ |_| ������� ������, 500 us stb_rd_data<='0'; temp_rg<=temper; elsif cntr_stb_res(2)='1' and cntr_stb_res(0)='1' and us100='1' then -- cntr_stb_res(2)='1' stb_res<='0'; stb_pres<='1'; -- ����� 15-60 us ����� Reset, DS18B20 ��������� |_| ��������� ����������� 60-240 us, ������ ����� ����� 1 ms elsif ms1='1' and stb_pres='1' then stb_pres<='0'; stb_skip_com<='1'; -- ������ ������ ������� "���������� ROM", 0xCC, 1 ms elsif ms1='1' and stb_skip_com='1' and cntr_ms100(3)='0' then stb_skip_com<='0'; stb_conv_com<='1'; -- ������ ������ ������� "Convert Tcommand", 0x44, 1 ms elsif ms1='1' and stb_conv_com='1' then stb_conv_com<='0'; stb_tconv<='1'; -- Strong pullup DQ �� ����� �������������� (tCONV), 800 ms elsif ms100='1' and stb_tconv='1' and cntr_ms100=7 then -- elsif ms100='1' and stb_tconv='1' and cntr_ms100(3)='1' then stb_tconv<='0'; stb_res<='1'; -- ������ ������ |_| ������� ������, 500 us elsif cntr_stb_res(2)='1' and cntr_stb_res(0)='1' and us100='1' then stb_res<='0'; stb_pres<='1'; -- ����� 15-60 us ����� Reset, DS18B20 ��������� |_| ��������� ����������� 60-240 us, ������ ����� ����� 1 ms elsif ms1='1' and stb_pres='1' then stb_pres<='0'; stb_skip_com<='1'; -- ������ ������ ������� "���������� ROM", 0xCC, 1 ms elsif ms1='1' and stb_skip_com='1' then stb_skip_com<='0'; stb_rd_com<='1'; -- ������ ������ "Read Scratchpad" �������, 0xBE, 1 ms elsif ms1='1' and stb_rd_com='1' then stb_rd_com<='0'; stb_rd_data<='1'; -- ������ ������ 9 ����, �� ������ ������ ������ ������ ��� � ������������ elsif cntr_in_bits(4)='1' and us10='1' and stb_rd_data='1' then stb_rd_data<='0'; -- ����� ������ ������ ���� ���� � �� end if; end if; end process PROC_STB; stb_com<=stb_skip_com or stb_conv_com or stb_rd_com; PROC_cntr_out_bits: process (CLK) begin if rising_edge(CLK) then if stb_com='0' or (cntr_out_bits(3)='1' and cntr_out_bits(0)='1' and us100='1') then cntr_out_bits<="0000"; elsif stb_com='1' and us100='1' then cntr_out_bits<=cntr_out_bits+1; -- �� 0 �� 9 end if; end if; end process PROC_cntr_out_bits; PROC_SLOT_WR: process (CLK) begin if rising_edge(CLK) then if stb_com='0' or us100='1' then cntr_slot_wr<="0000"; elsif us10='1' then cntr_slot_wr<=cntr_slot_wr+1; -- �� 0 �� 9 end if; end if; end process PROC_SLOT_WR; ini_0<='0' when cntr_slot_wr=0 and stb_com='1' and cntr_out_bits(3)='0' else '1'; prz_0<='0' when cntr_slot_wr<8 and stb_com='1' and cntr_out_bits(3)='0' and prz_1='0' else '1'; data_out<=ini_0 and prz_0; prz_1<='0' when cntr_out_bits=0 else '1' when (cntr_out_bits=1 and stb_rd_com='1') or cntr_out_bits=2 or (cntr_out_bits=3 and stb_conv_com='0') or (cntr_out_bits=4 and stb_rd_com='1') or (cntr_out_bits=5 and stb_rd_com='1') or (cntr_out_bits=6 and stb_rd_com='0') or (cntr_out_bits=7 and stb_conv_com='0') else '0' when stb_com='1' else '1'; PROC_cntr_in_bits: process (CLK) begin if rising_edge(CLK) then if us100='1' and stb_rd_data='1' then imp_ini_rd<='1'; elsif us1='1' then imp_ini_rd<='0'; end if; if stb_rd_data='1' and imp_ini_rd='1' and cntr_in_bits(4)='0' and us1='1' then cntr_in_bits<=cntr_in_bits+1; -- �� 0 �� 9 elsif stb_rd_data='0' then cntr_in_bits<="00000"; end if; end if; end process PROC_cntr_in_bits; PROC_WR_DATA_DT: process (CLK) begin if rising_edge(CLK) then if imp_ini_rd='1' then stb_bit_data<='1'; -- elsif us10='1'then stb_bit_data<='0'; -- end if; if stb_bit_data='1' and us10='1' then wr_data_dt<='1'; else wr_data_dt<='0'; end if; end if; end process PROC_WR_DATA_DT; PROC_WR_DATA_TEMP: process (CLK) begin if rising_edge(CLK) then if wr_data_dt='1' then temper<=(not QT) & temper(15 downto 1); end if; end if; end process PROC_WR_DATA_TEMP; ZT<='0' when stb_res='1' else '0' when stb_com='1' and cntr_slot_wr(3)='0' and cntr_out_bits(3)='0' else '0' when imp_ini_rd='1' else '1'; DT<='0' when stb_res='1' or imp_ini_rd='1' else '1' when stb_tconv='1' else '0' when imp_ini_rd='1' else data_out; Q<= temp_rg(7 downto 1) & stb_rd_data when RD0='1' else temp_rg(15 downto 8) when RD1='1' else "ZZZZZZZZ"; QT_OUT<='0' when stb_res='1' else '0' when stb_com='1' and cntr_slot_wr(3)='0' and cntr_out_bits(3)='0' else data_out; end DatTemp;