Shop OBEX P1 Docs P2 Docs Learn Events
ADC Conversions & driving SSR's — Parallax Forums

ADC Conversions & driving SSR's

RussHRussH Posts: 35
edited 2010-12-01 21:48 in BASIC Stamp
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.

Comments

  • RussHRussH Posts: 35
    edited 2010-11-29 14:06
    Anyone?

    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.:confused:
  • FranklinFranklin Posts: 4,747
    edited 2010-11-29 16:10
    OK, let's start here.
    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.
    You won't get 12v out of the stamp so you will need a transistor or a MOSFET. I'm not where I can pull up the datasheets so I cant answer the other question but if you put some DEBUG statements to display intermediate values you might find your problem.
  • RussHRussH Posts: 35
    edited 2010-11-29 20:44
    Thanks, I am aware that the Stamp wont provide 12V, the SSR is a 3-24 VDC primary. The spec given is 7.5mA @ 12V. I plan to use 5V regardless of whether I use a transistor or not.

    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.
  • stamptrolstamptrol Posts: 1,731
    edited 2010-11-30 05:13
    Have you tried putting a known voltage value into the adc to see if the numbers make sense?

    Or, have you measured the voltage out of the temperature sensor at a known temperature?
  • FranklinFranklin Posts: 4,747
    edited 2010-11-30 09:06
    Thanks, I am aware that the Stamp wont provide 12V, the SSR is a 3-24 VDC primary. The spec given is 7.5mA @ 12V. I plan to use 5V regardless of whether I use a transistor or not.
    If the specs were different than what you posted then why did you ask?
  • $WMc%$WMc% Posts: 1,884
    edited 2010-11-30 12:08
    RussH wrote: »
    Thanks, I am aware that the Stamp wont provide 12V, the SSR is a 3-24 VDC primary. The spec given is 7.5mA @ 12V. I plan to use 5V regardless of whether I use a transistor or not.

    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.
    '
    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.
  • MoskogMoskog Posts: 554
    edited 2010-11-30 12:22
    RussH wrote: »
    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....

    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?
  • MoskogMoskog Posts: 554
    edited 2010-11-30 12:51
    I am into a similar project (not beer, just normal water heaters) and need to track temperatures at five different places. (I'm not using BS2, but the propeller but thats not the issue here) I am using 5 LM35 and also five ADC0831. All five ADC's are tuned with one 10k pot each to give that ref-voltage of 2,55V or as close as I could get.
    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.
  • RussHRussH Posts: 35
    edited 2010-11-30 20:28
    My plan of attack is to force the input of the ADC to 5V and see what the output is, then force it to ground, and see what the output is. I will also measure the voltage out of the LM34 in boiling water, and in ice, and see what I get. This should let me know where I stand, and I can recalc my conversion and see.
    If the specs were different than what you posted then why did you ask?

    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.
    How are You going to get the LM34 in the process(beer)?

    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)
    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 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.
    1600 x 1200 - 275K
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-12-01 00:50
    I agree that there is a problem with the display routine. For example,
    DEBUG DEC dFaren0 DIG 3, ".", DEC3 dFaren0
    
    When the raw result0 is 265 in snow, the math for dFaren value come out to 32330. That is 32.330 degF. But the left side of the display routine only picks off one digit to the left of the decimal and prints 2.330, not 32.330. Isn't that what you were observing?

    I recommend,
    DEBUG DEC dFaren0/1000, ".", DEC3 dFaren0
    
    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?
    calibration0 CON  -11   ' LM34 reads 1.1 degF too low (example).
    mVolts0 = result0 ** 14464 + result0   ' ** gives better precision than */
    dFaren = mVolts0 - calibration0   ' subtract calibration error in 1/10ths
    DEBUG DEC dFaren0/10, ".", DEC1 dFaren0 ' display to 1/10ths degF
    
  • RussHRussH Posts: 35
    edited 2010-12-01 17:36
    Isn't that what you were observing?

    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.
    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!

    Not going to be a problem ;) Unless I decide I need an "instant chiller". 0 degrees F is way below the suggested serving temps I deal with. Thanks for the heads up.
  • RussHRussH Posts: 35
    edited 2010-12-01 21:25
    Thank you so much Tracy,

    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.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-12-01 21:48
    Let me know when the brewski is ready to be tapped!
Sign In or Register to comment.