Spartan 3 to tempsensor interface

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!

Reply to
rgebru
Loading thread data ...

There are several temperature sensors with i2c interface. They should easily be connected to your board.

formatting link

Jens

Reply to
Jens Baumann

easily

My personal preference is SPI device, eg Analog Devices AD7814.

Regards,

-rajeev-

Reply to
Rajeev

Hi,

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

formatting link

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:

Reply to
info_
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

Reply to
rgebru

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!

Reply to
rgebru

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

Reply to
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

Reply to
rgebru

rgebru wrote:

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.

Reply to
Gabor

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

Reply to
info_

hey,

thanks..I think the displaly problem got solved..although now I'

nervous since I didn't use a complicated algorithm and since I' using the bits 9 downto 2 (positive numbers only and are straigh binary) then I have a process that converts them to bcd..then to th

7 segment display. Now I'm working on simulating the ad7814..whic seemed pretty easy. but for the life of me I can't get it t work..I'm just using a simple process (which you had mentione earlier also) to generate the timing diagram..this is what I'm doin ( obviously it's wrong ) before I interface it to the fpga. I ahv to have the chip with FPGA working by wed :( Talk abou procrastinating..it seemed simple before I started working on it! : entity model7814 i port CS: in std_logic:='Z' SCLK: in std_logic :='0' Dout: out std_logi ) end model7814

architecture Behavioral of model7814 i

CONSTANT N: integer :=16 begi

process (CS,SCLK

begi

if SCLK' event and SCLK= '0' the

if CS

Reply to
rgebru

  1. Why don't you try and understand the code I sent ? It does (I think) all you want to do plus a little extra. It does respect the design rules (it's fully synchronous) It does employ good coding techniques.
  2. Read and re-read (and adopt) :
    formatting link

Your "simple" process is a collection of things "no to do". Wrong domain, wrong sensitivity list, wrong tristate inference ( via clocked process !)....

If you do not start with the basics, you'll find hardware design disgustingly frustrating and a total loss of time. My opinion.

Bert Cuzeau

Reply to
info_

hi

You might want to give me a chance to look at it before you decide

don't want to learn it!! Great, so I'm doing everything wrong. Wel I have something that kinda models the chip(Not what I had poste earlier) will look at yours too obviously. But I don't have much tim to get it working. Everything else except the chip interfacing work so far. thanks

Reply to
rgebru

Thanks everyone for your suggestions, I finally got it to work..

Reply to
rgebru

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.