Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sensirion SHT7x interface in VHDL?

Status
Not open for further replies.

stelik

Newbie level 3
Joined
Mar 31, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,306
sht71 0000000000000000

Does anyone have code or know anything on interfacing a Sensirion SHT71 (or SHT75) sensor in VHDL? In particular, I am using a Xilinx Coolrunner-II CPLD. I have found various sample codes online (like from the Sensirion's website) as well as assembly codes and such, but nothing in VHDL. I have tried for days, but I haven't even been able to synthesize my code!

If anyone has any info, that would be great. Thanks in advance!

Below is my code:

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity getdata is
    Port ( clk : in  STD_LOGIC; --500 KHz clock
           twi : inout  STD_LOGIC;  --P139
           i2c : inout  STD_LOGIC;
			  data : out std_logic_vector(19 downto 0);
           clk_twi : out  STD_LOGIC; --P140
           clk_i2c : out  STD_LOGIC);
end getdata;

architecture Behavioral of getdata is
	signal counter_timing	: std_logic_vector(18 downto 0) := "0000000000000000000";
	signal counter_comms		: std_logic_vector(2 downto 0) := "000";
	signal timingclk  		: std_logic := '1'; --1 Hz clock
	signal clk_comms			: std_logic := '1'; --100 KHz clock
	signal temp 				: std_logic_vector(7 downto 0) := "00000011"; --code for measure temperature
	signal humidity 			: std_logic_vector(7 downto 0) := "00000101"; --code for humidity measurement
	signal data_temp 			: std_logic_vector(15 downto 0) := "0000000000000000";
	signal data_humidity 	: std_logic_vector(15 downto 0) := "0000000000000000";
	signal ack 					: std_logic := '0';
	signal start				: std_logic := '0';
	signal measure				: std_logic := '0';
	signal count				: std_logic_vector(1 downto 0) := "00";
	signal count2				: std_logic_vector(3 downto 0) := "0000";
	signal send					: std_logic := '0';
	signal ackq					: std_logic := '0';
	signal receive				: std_logic := '0';
	signal ackt					: std_logic := '0';
begin
	
	slowclock: process (clk)
		 begin
			--if rising_edge(clk) then
			if clk'Event and clk='1' then
					counter_timing <= counter_timing + 1;
					counter_comms <= counter_comms + 1;
					if counter_timing = "1111010000100011111" then
						timingclk <= not timingclk;
						counter_timing <= "0000000000000000000";
					end if;
					if counter_comms = "100" then
						clk_comms <= not clk_comms; 
						counter_comms <= "000";  
					end if;
			end if;
	end process;
	
	
	
	
	retrieve: process(clk,clk_comms,timingclk)
		begin
			--Unless the sensor is taking a measurement, output the 100 KHz clock to clk_twi and clk_i2c
			if measure = '0' then
				clk_twi <= clk_comms;
				--clk_i2c <= clk_comms;
			else
				ack <= twi;
				if ack = '0' then
					measure <= '0';
					receive <= '1';
				end if;
			end if;
			
			--if rising_edge(timingclk) then
			if timingclk'Event and timingclk = '1' then
				start <= '1';
				twi <= '1';
				--i2c <= '1';
			end if;
			
			--Send the start sequence
			--if start = '1' and falling_edge(clk) then
			if start = '1' and clk'Event and clk='1' then
				count <= count + 1;
				count2 <= count2 + 1;
				if count = "10" then 
					twi <= '0';
					count <= "00";
				end if;
				if count2 = "1100" then
					twi <= '1';
				count <= "00";
				count2 <= "0111"; --Set up counter to send temperature command
				start <= '0';
				send <= '1';
				end if;
			end if;
			
			--if send = '1' and falling_edge(clk_comms) then
			if send = '1' and clk_comms'Event and clk_comms = '1' then
				if count2 = "1111" then
					send <= '0';
					twi <= '1';
					ackq <= '1';
					ack <= twi;
				else
					twi <= temp(conv_integer(count2));
					count2 <= count2 - 1;
				end if;
			end if;
			
			--if ackq = '1' and ack = '0' and rising_edge(clk_comms) then
			if ackq = '1' and ack = '0' and clk_comms'Event and clk_comms = '1' then
				measure <= '1';
				ackq <= '0';
			--elsif ackq = '1' and ack = '1' and rising_edge(clk_comms) then
			elsif ackq = '1' and ack = '1' and clk_comms'Event and clk_comms = '1' then
				measure <= '0';
				ackq <= '0';
			end if;
			
			--if receive = '1' and rising_edge(clk_comms) then
			if receive = '1' and clk_comms'Event and clk_comms = '1' then
				if count2 = "0111" and count = "01" then
					count <= count - 1;
				else
					data_temp(conv_integer(count2)) <= twi;
					count2 <= count2 - 1;
					if count2 = "0111" then
						ackt <= '1';
						receive <= '0';
					elsif count2 = "1111" then
						receive <= '0';
					end if;
				end if;
			end if;
			
			--if ackt = '1' and falling_edge(clk_comms) then
			if ackt = '1' and clk_comms'Event and clk_comms = '1' then
				twi <= '0';
				ackt <= '0';
				receive <= '1';
				count <= "01";
			end if;
				
			data(19 downto 12) <= data_temp(7 downto 0);
			--data(11 downto 0) <= data_humidity(11 downto 0);
	end process;
end Behavioral;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top