CONTACT | TEL : 02-728-3440, EMAIL : SALES@ASTRONLOGIC.COM
ASTRON LOGIC RESEARCH AND DEVELOPMENT CO.,LTD.

» WEBBOARD

ใครรู้..ช่วยผมที Sensor SHT15

ใครรู้เกี่ยวกับการใช้งาน SHT15 ช่วยบอกผมทีครับ ว่า code ผมผิดตรงไหน ทำไม่ติดต่อกับเซนเซอร์ไม่ได้ sensor มันไม่ตอบ ACK (ด่วน)

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

entity control_sht1x is
port(
clk_9600Hz : in std_logic;
start : in std_logic;
resetn : in std_logic;
select_type : in std_logic;
sck : out std_logic;
data : out std_logic_vector(15 downto 0);
clk_out : out std_logic;
cdata : inout std_logic
);
end control_sht1x;
architecture ee13 of control_sht1x is
type State_Type is (Idel,StartUp,ResetConnection,TransmissionStart,StateCommand,Measurement,DataSensor,SoftReset,WaitState);
constant temp : std_logic_vector(7 downto 0):="00000011";
constant humi : std_logic_vector(7 downto 0):="00000101";
constant write : std_logic_vector(7 downto 0):="00000110";
constant read : std_logic_vector(7 downto 0):="00000111";
constant reset : std_logic_vector(7 downto 0):="00011110";
constant regiter : std_logic_vector(7 downto 0):="00000000";
signal data_temp : std_logic_vector(15 downto 0):="0000000000000000";
signal command_temp : std_logic_vector(7 downto 0):="00000000";
signal State : State_Type := StartUp;

begin
process(clk_9600Hz,resetn,start,cdata)
variable clkreset : integer range 0 to 17 := 0;
variable clkCommand : integer range 0 to 17 := 0;
variable clkstart : integer range 0 to 8 := 0;
variable clkdata : integer range 0 to 35 := 0;
variable time_up : integer range 0 to 1920 := 0;
variable time_11ms : integer range 0 to 105 := 0;
variable time_320ms : integer range 0 to 3071 := 0;
variable cdata_temp : std_logic := '1';
begin
if resetn = '0' then
State <= StartUp;
elsif clk_9600Hz'Event and clk_9600Hz = '1' then
if select_type = '1' then
command_temp <= humi;
else
command_temp <= temp;
end if;
case State is
when StartUp =>
if time_up < 1920 then
time_up := time_up + 1;
State <= StartUp;
else
time_up := 0;
State <= Idel;
end if;
when Idel =>
sck <= '0';
cdata <= '1';
clk_out <= '0';
if start = '1' then
State <= ResetConnection;
clkreset := 0;
clkCommand := 0;
clkstart := 0;
clkdata := 0;
else
State <= Idel;
end if;
when ResetConnection =>
cdata <= '1';
case clkreset is
when 0 => sck <= '1';
when 1 => sck <= '0';
when 2 => sck <= '1';
when 3 => sck <= '0';
when 4 => sck <= '1';
when 5 => sck <= '0';
when 6 => sck <= '1';
when 7 => sck <= '0';
when 8 => sck <= '1';
when 9 => sck <= '0';
when 10 => sck <= '1';
when 11 => sck <= '0';
when 12 => sck <= '1';
when 13 => sck <= '0';
when 14 => sck <= '1';
when 15 => sck <= '0';
when 16 => sck <= '1';
when others => sck <= '0';State <= TransmissionStart;
end case;
clkreset := clkreset + 1;
when TransmissionStart =>
case clkstart is
when 0 => sck <= '0';cdata <= '1';
when 1 => sck <= '1';cdata <= '1';
when 2 => sck <= '1';cdata <= '0';
when 3 => sck <= '0';cdata <= '0';
when 4 => sck <= '1';cdata <= '0';
when 5 => sck <= '1';cdata <= '1';
when 6 => sck <= '0';cdata <= '1';
when 7 => sck <= '0';cdata <= '1';
when others => sck <= '0';cdata <= '0';State <= StateCommand;
end case;
clkstart := clkstart + 1;
when StateCommand =>
case clkCommand is
when 0 => sck <= '1';cdata <= command_temp(7);
when 1 => sck <= '0';
when 2 => sck <= '1';cdata <= command_temp(6);
when 3 => sck <= '0';
when 4 => sck <= '1';cdata <= command_temp(5);
when 5 => sck <= '0';
when 6 => sck <= '1';cdata <= command_temp(4);
when 7 => sck <= '0';
when 8 => sck <= '1';cdata <= command_temp(3);
when 9 => sck <= '0';
when 10 => sck <= '1';cdata <= command_temp(2);
when 11 => sck <= '0';
when 12 => sck <= '1';cdata <= command_temp(1);
when 13 => sck <= '0';
when 14 => sck <= '1';cdata <= command_temp(0);
when 15 => sck <= '0';
when 16 =>
sck <= '1';
cdata_temp := cdata;
if cdata_temp = '0' then
State <= Measurement;
end if;
when others =>
sck <= '0';
cdata_temp := cdata;
if cdata_temp = '0' then
State <= Measurement;
else
State <= waitState;
end if;
end case;
clkCommand := clkCommand +1;
when Measurement =>
sck <= '0';
clk_out <= '0';
cdata_temp := cdata;
if cdata_temp = '0' then
State <= DataSensor;
else
if time_320ms < 3071 then
time_320ms := time_320ms + 1;
State <= Measurement;
else
time_320ms := 0;
State <= waitState;
end if;
end if;
when DataSensor =>
case clkdata is
when 0 => sck <= '1';data_temp(15) <= cdata;
when 1 => sck <= '0';
when 2 => sck <= '1';data_temp(14) <= cdata;
when 3 => sck <= '0';
when 4 => sck <= '1';data_temp(13) <= cdata;
when 5 => sck <= '0';
when 6 => sck <= '1';data_temp(12) <= cdata;
when 7 => sck <= '0';
when 8 => sck <= '1';data_temp(11) <= cdata;
when 9 => sck <= '0';
when 10 => sck <= '1';data_temp(10) <= cdata;
when 11 => sck <= '0';
when 12 => sck <= '1';data_temp(9) <= cdata;
when 13 => sck <= '0';
when 14 => sck <= '1';data_temp(8) <= cdata;
when 15 => sck <= '0';
when 16 => sck <= '1';cdata <= '0';
when 17 => sck <= '0';
when 18 => sck <= '1';data_temp(7) <= cdata;
when 19 => sck <= '0';
when 20 => sck <= '1';data_temp(6) <= cdata;
when 21 => sck <= '0';
when 22 => sck <= '1';data_temp(5) <= cdata;
when 23 => sck <= '0';
when 24 => sck <= '1';data_temp(4) <= cdata;
when 25 => sck <= '0';
when 26 => sck <= '1';data_temp(3) <= cdata;
when 27 => sck <= '0';
when 28 => sck <= '1';data_temp(2) <= cdata;
when 29 => sck <= '0';
when 30 => sck <= '1';data_temp(1) <= cdata;
when 31 => sck <= '0';
when 32 => sck <= '1';data_temp(0) <= cdata;
when 33 => sck <= '0';
when 34 => sck <= '1';cdata <= '1';
when others =>
sck <= '0';
State <= StartUp;
clk_out <= '1' ;
data <= data_temp ;
end case;
clkdata := clkdata + 1;
when waitState =>
sck <= '0';
cdata <= '1';
if time_11ms < 105 then
time_11ms := time_11ms + 1;
State <= waitState;
else
time_11ms := 0;
State <= Idel;
end if;
when others =>
sck <= '0';
cdata <= '1';
clk_out <= '0' ;
State <= StartUp;
end case;
end if;
end process;
end ee13;

จากคุณ : wut ตั้งกระทู้นี้เมื่อ 20:14 [05/09/2008]

ร่วมด้วยช่วยกันตอบครับ
ชื่อ :
E-Mail :
คำตอบ :







คลิกเพื่อแทรกรูป