FPGARelated.com
Forums

Spartan 3 to tempsensor interface

Started by rgebru March 18, 2005
Hi,

I'm thinkin go of designing a heating/cooling system with VHDL an
need to interface my Spartan 3 board to a real temp sensor. Doe
anyone have an idea of how I can do this?

Thanks!

rgebru wrote:

> Hi, > > I'm thinkin go of designing a heating/cooling system with VHDL and > need to interface my Spartan 3 board to a real temp sensor. Does > anyone have an idea of how I can do this? > > Thanks!!
There are several temperature sensors with i2c interface. They should easily be connected to your board. http://www.google.de/search?hl=en&q=i2c+temperature+sensor Jens
Jens Baumann wrote:
> rgebru wrote: > > > Hi, > > > > I'm thinkin go of designing a heating/cooling system with VHDL and > > need to interface my Spartan 3 board to a real temp sensor. Does > > anyone have an idea of how I can do this? > > > > Thanks!! > > There are several temperature sensors with i2c interface. They should
easily
> be connected to your board. > > http://www.google.de/search?hl=en&q=i2c+temperature+sensor > > Jens
My personal preference is SPI device, eg Analog Devices AD7814. Regards, -rajeev-
Hi,

There is an LM70 (uWire / SPI) Temperature Sensor on our Tornado
board, and the VHDL code for the digital thermometer is free !

http://www.alse-fr.com/Tornado/Torn_Educ_us.pdf

We have also a reference design for the MaxII board with a different
temperature sensor (external transistor as sensor) : Max6627

This kind of interface is about 60 lines of (easy) code...
really simple.

I also wrote behavioral models for the Temperature sensors
so the design can be verified by simulation.

Best regards,

   Bert

rgebru wrote:

> Hi, > > I'm thinkin go of designing a heating/cooling system with VHDL and > need to interface my Spartan 3 board to a real temp sensor. Does > anyone have an idea of how I can do this? > > Thanks!! >
H

thanks so much for the replies..both the Analog devices and the i2
interface seem promising... will let you guys know of my progress :
I haven't started working on it yet. 

To use the temp sensor on the ornado board though wouldn't I have t
use that board? I have to use the Spartan 3 board..

Rut

I started using the Analog devices AD7814 and I'm having troubl
understanding how to interface it to the Spartan 3 board. :(  Doe
anyone have any suggestions to get me started? I could REALLY use th
help!! Thanks!

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!!
I'm not sure if you mean the electrical interface, the programming, or both. Anyway here's my thoughts: If you don't need to power down the sensor, you can ground the DIN pin as shown in figure 4 of the datasheet. For a power supply use the same voltage as the VCCo of the FPGA I/O to avoid interface problems with Vih. It looks like 3.3V and LVTTL or LVCMOS should work. For the programming, you need a state machine that generates the SCLK and CS timing just as shown in figure 2. The best approach is to leave CS high between reads to ensure the AD7814 bits match up with the bit positions shown in the timing diagram. Then all you need is a shift register to pick up the bits at the falling edge of SCLK (to avoid hold time issues). Depending on how you use the temperature, you may also need another parallel register loaded from the shift register when you return CS high. This register would then only change at the end of the reading period and always contain the most recently read temperature. Good luck, Gabor
Hi Gabor

Thanks for the reply.  I'm actually having problems with th
programming part.  Especially displaying the 10bit 2's complemen
temperature readings on my 4 seven segment display. I'm trying t
convert them into binary but for some reason it's not working ver
well.  Do you have a suggestion of how I should read them in? I'm no
using the negative temperature readings and I'm only interested i
temperatures up to 90deg so I can displaly the actual temp on tw
displays and the temperature you want to set on the other 2 displays
 thanks so much for your suggestions!

Rut

rgebru wrote:
> Hi Gabor, > > > Thanks for the reply. I'm actually having problems with the > programming part. Especially displaying the 10bit 2's complement > temperature readings on my 4 seven segment display. I'm trying to > convert them into binary but for some reason it's not working very > well. Do you have a suggestion of how I should read them in? I'm not > using the negative temperature readings and I'm only interested in > temperatures up to 90deg so I can displaly the actual temp on two > displays and the temperature you want to set on the other 2 displays. > thanks so much for your suggestions! > > Ruth
First of all, you want to convert from binary to BCD (2's complement is straight binary when the numbers are positive). Then from BCD to seven-segment. There are several ways to convert binary to BCD. If you had to do it really fast (1 clock cycle) you could use the brute force method using block RAM (1024 x 13) as a look-up table. Since your data is coming in serially at a relatively low clock rate, I assume you don't need to do this. If you have an internal clock running at least 1024 times your sampling rate, the simplest serial method is to load a binary counter with the binary value, then count it down to zero while counting up on a BCD counter (3 divide-by-ten counters in a carry chain). The conversion time would depend on the temperature but the algorithm is simple. An intermediate method takes fewer clock cycles but is a little more tricky. It involves shifting the binary input one bit at a time into a shift register and then performing a "decimal adjust after add" which involves adding a 6 to any digits that either carry out (in the shift register this means 1 in the low bit of the next digit up) or end up with a value greater than 9 after the shift. If you don't pipeline the two operations you'd use 2 clock cycles per input bit for this method or 20 cycles in your case. The shifter / adder would need to be 13 bits long to hold the BCD number. Other methods include serial subtraction of decimal powers (i.e. subtract 1,000 and if there's no borrow, add one to the most significant digit, after a borrow add back 1,000 and then do the same with 100 and the next digit down) or a series of division / remainder operations (i.e. divide by 1,000 and put the result in the high digit, divide the remainder by 100 and put the result in the next digit, divide the second remainder by 10...). Finally converting BCD to 7-segment is a simple look-up table. There should be lots of examples of this around.
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;