ADC Conversions & driving SSR's
Hello,
I am going to be controlling 2 large heaters in a small home brewery using the Basic Stamp Board of Education. Temperature is going to be measured using LM34 Temperature sensors, and the 2 5500W elements will be driven by 40 Amp SSR's.
I think I am having problems with the conversion of ADC output to a usable number. I am using a MCP3202 12 bit ADC to convert the signal from the LM34 temperature sensors to a 12 bit value, and from that I need to find a millivolt equivalent, and finally a temperature. Here is the program I am using to try and display temps from 2 LM34's:
'
[ Program Description ]
' Inputs - 2 LM34 IC's on Channels 0 and 1 of ADC provide analog voltages
' then Debug displays the 12-bit values, voltages and temperatures for each
' channel on the DEBUG terminal. Using a 5 VDC reference the 12-bit values
' should be roughly 0 TO 4096 and the voltage from 0 to 5
'
[ Revision History ]
' N/A
'
[ I/O Definitions ]
CS PIN 13 ' Chip Select (MCP3202.1)
Clock PIN 14 ' Clock (MCP3202.7)
DataOut PIN 9 ' Pin 6 on ADC (MCP3202.6)
DataIn PIN 10 ' Pin 5 on ADC (MCP3202.5)
'
[ Constants ]
Cnts2Mv CON $0139 ' x 1.22 (1.22*256>Hex) (To Millivolts)
Cnts2dF CON $7A00 ' x 122 (122*256>Hex) (To Degrees Farenheit)
'
[ Variables ]
result0 VAR Word ' Result CH0
result1 VAR Word ' Result CH1
mVolts0 VAR Word ' Result0 --> mVolts
mVolts1 VAR Word ' Result1 --> mVolts
dFaren0 VAR Word ' Result0 --> Degrees Farenheit
dFaren1 VAR Word ' Result1 --> Degrees Farenheit
'
[ Init Setup ]
DEBUG CLS, "ADC CH 0 : ", CR, "Volts :", CR, "Degrees :", CR,
"ADC CH 1 : ", CR, "Volts :", CR, "Degrees :"
'
[ Program Code ]
DO
LOW CS ' Enable ADC
SHIFTOUT DataIn, Clock, MSBFIRST, [%1101\4] ' Select CH0, Single-Ended
SHIFTIN DataOut, Clock, MSBPOST, [result0\12] ' Read ADC
HIGH CS ' Disable ADC
mVolts0 = result0 */ Cnts2Mv ' Convert To Millivolts
dFaren0 = result0 */ Cnts2dF ' Convert To Degrees Farenheit
LOW CS ' Enable ADC
SHIFTOUT DataIn, Clock, MSBFIRST, [%1111\4] ' Select CH1, Single-Ended
SHIFTIN DataOut, Clock, MSBPOST, [result1\12] ' Read ADC
HIGH CS ' Disable ADC
mVolts1 = result1 */ Cnts2Mv ' Convert To Millivolts
dFaren1 = result1 */ Cnts2dF ' Convert To Degrees Farenheit
DEBUG HOME, CRSRXY, 11, 0, DEC result0, CLREOL, ' Displays voltages & digital value
CRSRXY, 11, 1, DEC mVolts0 DIG 3, ' for both channels
".", DEC3 mVolts0,
CRSRXY, 11, 2, DEC dFaren0 DIG 3, ' for both channels
".", DEC3 dFaren0,
CRSRXY, 11, 3, DEC result1, CLREOL,
CRSRXY, 11, 4, DEC mVolts1 DIG 3,
".", DEC3 mVolts1,
CRSRXY, 11, 5, DEC dFaren1 DIG 3, ' for both channels
".", DEC3 dFaren1
PAUSE 100
LOOP
The problem is that when I run this, the values I get that should correspond to temperatures are way out. For example, stuffing the sensors into a cup full of snow gives me display values of 2.2 and 3.0 degrees on sensor 1 and 2 respectively, and ~265 and ~272 as ADC bit values. I may have messed up the truncation later on, I am not sure.
The circuit is wired like that on page 183 of the Process Control manual, only with a MCP3202 in place of the ADC0831, and 2 LM34's with 220 Ohm resistors.
Next, I would like to ask whether I should drive the SSR's directly off the Stamp, or if I should use something like a 2N3904 transistor to drive it? The SSR's are claimed to only require 7.5mA / 12VDC to enable.
Any help would be greatly appreciated. I just want to make beer.
I am going to be controlling 2 large heaters in a small home brewery using the Basic Stamp Board of Education. Temperature is going to be measured using LM34 Temperature sensors, and the 2 5500W elements will be driven by 40 Amp SSR's.
I think I am having problems with the conversion of ADC output to a usable number. I am using a MCP3202 12 bit ADC to convert the signal from the LM34 temperature sensors to a 12 bit value, and from that I need to find a millivolt equivalent, and finally a temperature. Here is the program I am using to try and display temps from 2 LM34's:
'
[ Program Description ]
' Inputs - 2 LM34 IC's on Channels 0 and 1 of ADC provide analog voltages
' then Debug displays the 12-bit values, voltages and temperatures for each
' channel on the DEBUG terminal. Using a 5 VDC reference the 12-bit values
' should be roughly 0 TO 4096 and the voltage from 0 to 5
'
[ Revision History ]
' N/A
'
[ I/O Definitions ]
CS PIN 13 ' Chip Select (MCP3202.1)
Clock PIN 14 ' Clock (MCP3202.7)
DataOut PIN 9 ' Pin 6 on ADC (MCP3202.6)
DataIn PIN 10 ' Pin 5 on ADC (MCP3202.5)
'
[ Constants ]
Cnts2Mv CON $0139 ' x 1.22 (1.22*256>Hex) (To Millivolts)
Cnts2dF CON $7A00 ' x 122 (122*256>Hex) (To Degrees Farenheit)
'
[ Variables ]
result0 VAR Word ' Result CH0
result1 VAR Word ' Result CH1
mVolts0 VAR Word ' Result0 --> mVolts
mVolts1 VAR Word ' Result1 --> mVolts
dFaren0 VAR Word ' Result0 --> Degrees Farenheit
dFaren1 VAR Word ' Result1 --> Degrees Farenheit
'
[ Init Setup ]
DEBUG CLS, "ADC CH 0 : ", CR, "Volts :", CR, "Degrees :", CR,
"ADC CH 1 : ", CR, "Volts :", CR, "Degrees :"
'
[ Program Code ]
DO
LOW CS ' Enable ADC
SHIFTOUT DataIn, Clock, MSBFIRST, [%1101\4] ' Select CH0, Single-Ended
SHIFTIN DataOut, Clock, MSBPOST, [result0\12] ' Read ADC
HIGH CS ' Disable ADC
mVolts0 = result0 */ Cnts2Mv ' Convert To Millivolts
dFaren0 = result0 */ Cnts2dF ' Convert To Degrees Farenheit
LOW CS ' Enable ADC
SHIFTOUT DataIn, Clock, MSBFIRST, [%1111\4] ' Select CH1, Single-Ended
SHIFTIN DataOut, Clock, MSBPOST, [result1\12] ' Read ADC
HIGH CS ' Disable ADC
mVolts1 = result1 */ Cnts2Mv ' Convert To Millivolts
dFaren1 = result1 */ Cnts2dF ' Convert To Degrees Farenheit
DEBUG HOME, CRSRXY, 11, 0, DEC result0, CLREOL, ' Displays voltages & digital value
CRSRXY, 11, 1, DEC mVolts0 DIG 3, ' for both channels
".", DEC3 mVolts0,
CRSRXY, 11, 2, DEC dFaren0 DIG 3, ' for both channels
".", DEC3 dFaren0,
CRSRXY, 11, 3, DEC result1, CLREOL,
CRSRXY, 11, 4, DEC mVolts1 DIG 3,
".", DEC3 mVolts1,
CRSRXY, 11, 5, DEC dFaren1 DIG 3, ' for both channels
".", DEC3 dFaren1
PAUSE 100
LOOP
The problem is that when I run this, the values I get that should correspond to temperatures are way out. For example, stuffing the sensors into a cup full of snow gives me display values of 2.2 and 3.0 degrees on sensor 1 and 2 respectively, and ~265 and ~272 as ADC bit values. I may have messed up the truncation later on, I am not sure.
The circuit is wired like that on page 183 of the Process Control manual, only with a MCP3202 in place of the ADC0831, and 2 LM34's with 220 Ohm resistors.
Next, I would like to ask whether I should drive the SSR's directly off the Stamp, or if I should use something like a 2N3904 transistor to drive it? The SSR's are claimed to only require 7.5mA / 12VDC to enable.
Any help would be greatly appreciated. I just want to make beer.
Comments
I've looked at numerous resources on ADC conversion, and I think my factors are correct. Is the problem in my display instructions? I think The problem must be in my display instruction.
I am stumped. Please help, even if you can just point me in the direction.
The main issue right now is the temperature sensing, The debug window gives me ADC bit values, followed by millivolts followed by degrees fahrenheit. The sensor is linear, giving 10 mV/degree F, so the millivolt to degree conversion is just a decimal place shift. The issue is the ADC to mV conversion.
Or, have you measured the voltage out of the temperature sensor at a known temperature?
How are You going to get the LM34 in the process(beer)?
'
I would look at a different sensing element for this liquid application.Like a T/C or RTD.
So your main problem is that the temperature result given in debug window is not correct?
When using ADC0831 we have to use a ref-voltage,usually something like 2,55V to make a linear reading (Like 0,25V on the LM's Vout-pin will give the result 25 degrees on Debug) I'm not familiar with your ADC but could this be an issue in your case, I mean.. is there a ref voltage you need to tune on your ADC?
The problem was not to tune in the ADC's to show the right temp, my problem is that the readings is not stabile, with one second loop the readings can vary from 20-24C. Reading the voltages out of the LM's shows a stabile voltage, also the supply (5V) seems also very stabile. Also the ref-voltage. But I do suspect there are small changings there though, not visible to the voltmeter. To small to be visible but still can affect the ADC. The whole PCB is fed from one single 5V reg (on the Prop proto board) so this reg has a lot of stuff to supply with power, things that is working and consuming currents more or less all the time.
I didnt mean to hijack this thread but post this because it could be an issue in your project too.
I wasn't trying to be rude. What I posted is not different than the spec's for the SSR, but it accepts a range of trigger voltages (3-24), but only gives a current requirement at 12V. I want to be sure that I am not going to overload the Stamp and let the smoke out. I asked because this is a forum, and as far as I know that's what forums are for.
I have 1/4" compression fittings on the kettles, and I have taken a piece of 1/4" copper tube, and silver soldered a little piece of brass round stock into the end. I then potted the LM34's into the tube using an epoxy with high thermal conductivity. It has increased the thermal mass, and lowered response times, but I am dealing with 50 liters (~13 gal) of water, so sensor response times aren't really an issue. They should work well, be easy to clean, and sanitary. (see attachment)
The MCP3202 does not take a Vref, so you can't really 'tune' it. No problem on the hijack, I appreciate the insight. I will have three temp sensors, but only one is really important. I'm not going to be comparing, just monitoring. I have a dedicated 5V supply for the sensors, but I have noticed that the voltage out of the LM34 wanders a bit. I guess I'll have to cross that bridge when I get there. I may need to average out a few readings.
Thanks for all the help, this will definitely get me started on the path.
I recommend, Should print correct. Same syntax for the other temperature and the voltages. Caveat: it does not work for negative temperatures, so don't be surprised if it doesn't work in your ice cream freezer, or in the beer froster!
I'd point out also that the temperature reading definitely does not warrant 3 digits precision past the decimal point. The MCP3202 only measures to 1mV or 0.1 degF (actually, 1.22 mV). Why not convert from raw result0 to mVolts0, then add a calibration offset for each sensor, and then display temperature to tenths of a degree?
That is exactly it. I will give this a shot tonight, and let you know. Thanks. I had a hunch that the problem was in the display.
Not going to be a problem
I calibrated the two sensors to ~32.0 in icy water, and then put them in the kettle. At a hard boil they were reading ~212.4 and ~213.8, which as close as I could hope for.