rgebru wrote:
> I started using the Analog devices AD7814 and I'm having trouble
> understanding how to interface it to the Spartan 3 board. Does
> anyone have any suggestions to get me started? I could REALLY use the
> help!! Thanks!!
>
Less talk, more action !
Check that your temp sensor works like this one (Max6627) but it
shouldn't be a difficult task to adapt the code if it doesn't :-)
Bert Cuzeau
-- ------------------------------------------
-- MicroWire Temp Sensor (c) Bert Cuzeau --
-- ------------------------------------------
-- do not use without prior written consent
-- from the author.
-- Check with info at alse-fr dot com
-- ------------------------------------------
-- With on-the-fly Bin -> BCD conversion.
-- Has been tested on the new Altera MaxII board. Worked 1st try.
--
-- Note : Bin -> BCD conversion is simplified, okay up to +/- 99 included.
-- Note that we handle the negative values !
-- TEMP_CSN : out std_logic;-- Temp Sensor SPI Select
-- TEMP_SCK : out std_logic;-- Temp Sensor SPI Clock
-- TEMP_SDO : inout std_logic;-- Temp Sensor SPI Data
SPI_i: block
begin
-- DO NOT DO THIS below : you won't get a pullup and the input will disappear !
--TEMP_SDO <= 'H'; -- we don't drive it
-- This is okay :
TEMP_SDO <= 'Z'; -- we don't drive it
-- don't forget the pullup in the pin assignment ! (or on your board)
process (Clk, Rst)
variable BitCnt : integer range 0 to 16;
begin
if Rst='1' then
WrTemp <= '0';
TEMP_CSN <= '1';
TEMP_SCK <= '0';
Sign <= '0';
stSPI <= spiBoot;
BitCnt := 0;
FPGA_uW_SIOr<= '0';
TempH <= (others=>'0');
TempL <= (others=>'0');
elsif rising_edge (Clk) then
WrTemp <= '0';
FPGA_uW_SIOr <= TEMP_SDO or TEMP_SDO;
case stSPI is
when spiBoot =>
if Tick4us='1' then
stSPI <= spiIdle;
end if;
when spiIdle =>
TEMP_CSN <= '1';
TEMP_SCK <= '0';
if Cnt05s(Cnt05s'high) = '1' then -- read temperature ~ 2 times / s
TEMP_CSN <= '0';
TempH <= (others=>'0');
TempL <= (others=>'0');
BitCnt := SPi_Nbits;
stSPI <= spiRead1;
end if;
when spiRead1 =>
if Tick4us='1' then
TEMP_SCK <= '1'; -- rising edge
stSPI <= spiRead2;
if BitCnt = SPi_Nbits then
Sign <= FPGA_uW_SIOr; -- Shift the sign in...
else
if TempL < 5 then
TempH <= TempH(2 downto 0) & '0'; -- no carry
TempL <= TempL(2 downto 0) & (FPGA_uW_SIOr xor Sign);
else
TempL <= "-"(TempL,5) (2 downto 0) & (FPGA_uW_SIOr xor Sign);
TempH <= TempH(2 downto 0) & '1'; -- carry
end if;
end if;
BitCnt := BitCnt-1;
end if;
when spiRead2 =>
if Tick4us ='1' then
TEMP_SCK <= '0';
if BitCnt /= 0 then
stSPI <= spiRead1;
else -- No more bit
TEMP_CSN <= '1';
if Cnt05s(Cnt05s'high) = '0' then
WrTemp <= '1'; -- signal we want to display the temp
stSPI <= spiIdle;
end if;
end if;
end if;
end case;
end if;
end process;
end block;