Temperature Sensor Verilog

adcsensortemperature

Hello I have been working on an analog temperature sensor TMP36 and I am trying to get the temperature and display it on the NEXYS3 SSD. I am aware the NEXYS3 does not have an analog pin and I built an analog to digital converter using the TI ADC0804 an 8-bit ADC. The part I need help with is particularly getting the input from the temperature sensor. I do not understand the data sheet well enough to come up with the formula in verilog. The only example I found was for an arduino in the link below

https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor

DATA SHEET

http://www.analog.com/static/imported-files/data_sheets/TMP35_36_37.pdf

I am powering the ADC with 5 volts and need help converting their formula to verilog.

Voltage at pin in milliVolts = (reading from ADC) * (5000/1024)
Centigrade temperature = [(analog voltage in mV) – 500] / 10

Those are the two formulas I need help with. I need an formula equivalent in Verilog. The output to the SSD is an 8-Bit number in other words am only interested in temperatures 0-99 for my project. Thanks any help would be appreciated.

Best Answer

Simple algebra. Plug one of them into the other and simplify:

mv = code * 5000/1024

temp = (mv - 500) / 10

temp*10 = mv - 500

temp*10 = code * 5000/1024 - 500

temp*10 = (code * 5000) / 1024 - 500

(add divisor/2 before performing an integer division for rounding)

temp*10 = (code * 5000 + 512) / 1024 - 500

temp*10 = ((code * 5000 + 512) >> 10) - 500

One multiply, one shift right by 10, one addition, and one subtraction. Then convert to BCD and display it.

However, if you have an 8-bit ADC, you're probably going to want to divide by 256 instead of 1024 (shift right by 8 instead of 10) and add 128 instead of 512.

And here is an algorithm for converting binary to BCD: http://www.eng.utah.edu/~nmcdonal/Tutorials/BCDTutorial/BCDConversion.html

Just run that, split into groups of 4 bits, and drive each digit in the display with one group (after decoding to the proper 7 segment signals, of course).