Shop OBEX P1 Docs P2 Docs Learn Events
ADC0834 & LM34 vs. Offset — Parallax Forums

ADC0834 & LM34 vs. Offset

FalconFalcon Posts: 191
edited 2011-10-25 11:05 in BASIC Stamp
Hello,

I'm using four of the LM34 to measure the temperature of water at several different locations in my home. I've been through the Industrial Control text where I used the ADC0831/LM34 combo to develop a temperature reading. Instead of using four of the ADC0831, I bought the ADC0834 and used an example from Activity #4 (page 26) of the Experiments with Renewable Energy text to get the '0834 up and running. That code is as follows
' ----- For ADC0834 4-Channel Multiplexed A/D Converter -------------------
  A2dChipSel   PIN     0                     ' A/D Converter Chip Select(P0)
  A2dDataIn    PIN     1                     ' A/D Converter Data Input(P1)
  A2dClk       PIN     2                     ' A/D Converter Clock(P2)
  A2dDataOut   PIN     3                     ' A/D Converter Data Output(P3)


  A2dMuxId0    CON     %1100                 ' A/D MUX IDs for Ch 0..3
  A2dMuxId1    CON     %1110                 ' Bit 3 = 1,  start bit
  A2dMuxId2    CON     %1101                 ' Bit 2 = 1,  single (1)/diff (0)
  A2dMuxId3    CON     %1111                 ' Bit 1 odd / sign, Bit 0 select

  a2dMuxId     VAR     Nib                   ' A/D Channel MUX ID to shift out
  a2dResult0    VAR     Byte                  ' 8-bit result of A/D conversion
  a2dResult1    VAR     Byte                  ' 8-bit result of A/D conversion
  a2dResult2    VAR     Byte                  ' 8-bit result of A/D conversion
  a2dResult3    VAR     Byte                  ' 8-bit result of A/D conversion
'--------------------------------------------------------------------------
'  Main Routine
'--------------------------------------------------------------------------

Main:
DO
'  a2dMuxId = A2dMuxId1                       ' Set A/D to convert Ch 0
  GOSUB A2D                                  ' Do the conversion
'  ch1 = a2dResult                            ' 8-bit result into ch0

DEBUG DEC a2dResult0, "  "
DEBUG DEC a2dResult1, "  "
DEBUG DEC a2dResult2, "  "
DEBUG DEC a2dResult3, CR
PAUSE 500
LOOP




'--------------------------------------------------------------------------
'  A/D Converter Routine
'--------------------------------------------------------------------------
'
'  Enter with a2dMuxId as the channel to convert
'  Return with 8-bit result in a2dResult (msb,6,5,4,3,2,1,lsb)
'
'--------------------------------------------------------------------------

A2D:                                         ' Initialize signals
  HIGH A2dChipSel                            ' Disable A/D ChiP SELEct
  LOW A2dDataIn                              ' Initial state of data in
  LOW A2dClk                                 ' Initial state of clock
  a2dResult0 = 0                              ' Clear the 8-bit result

'A2D_Start_Conversion_Ch0:                        ' Start the conversion process
  LOW A2dChipSel                             ' Enable A/D chip select

'A2D_Shift_Out_Channel_ID:                    ' Shift out the Channel ID value
  SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId0\4]

'A2D_Shift_In_Result:                         ' Shift in the result
  PULSOUT A2dClk,10
  SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult0\8]
  HIGH A2dChipSel                            ' Disable A/D chip select
'  a2dResult0 = a2dResult0*2

'  A2D:                                         ' Initialize signals
  HIGH A2dChipSel                            ' Disable A/D ChiP SELEct
  LOW A2dDataIn                              ' Initial state of data in
  LOW A2dClk                                 ' Initial state of clock
  a2dResult1 = 0                              ' Clear the 8-bit result



'A2D_Start_Conversion_Ch1:                        ' Start the conversion process
  LOW A2dChipSel                             ' Enable A/D chip select

'A2D_Shift_Out_Channel_ID:                    ' Shift out the Channel ID value
  SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId1\4]

'A2D_Shift_In_Result:                         ' Shift in the result
  PULSOUT A2dClk,10
  SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult1\8]
  HIGH A2dChipSel                            ' Disable A/D chip select
  a2dResult1 = a2dResult1*2

'  A2D:                                         ' Initialize signals
  HIGH A2dChipSel                            ' Disable A/D ChiP SELEct
  LOW A2dDataIn                              ' Initial state of data in
  LOW A2dClk                                 ' Initial state of clock
  a2dResult2 = 0                              ' Clear the 8-bit result



'A2D_Start_Conversion_Ch2:                        ' Start the conversion process
  LOW A2dChipSel                             ' Enable A/D chip select

'A2D_Shift_Out_Channel_ID:                    ' Shift out the Channel ID value
  SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId2\4]

'A2D_Shift_In_Result:                         ' Shift in the result
  PULSOUT A2dClk,10
  SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult2\8]
  HIGH A2dChipSel                            ' Disable A/D chip select
  a2dResult2 = a2dResult2*2

'  A2D:                                         ' Initialize signals
  HIGH A2dChipSel                            ' Disable A/D ChiP SELEct
  LOW A2dDataIn                              ' Initial state of data in
  LOW A2dClk                                 ' Initial state of clock
  a2dResult3 = 0                              ' Clear the 8-bit result



'A2D_Start_Conversion_Ch3:                        ' Start the conversion process
  LOW A2dChipSel                             ' Enable A/D chip select

'A2D_Shift_Out_Channel_ID:                    ' Shift out the Channel ID value
  SHIFTOUT A2dDataIn,A2dClk,MSBFIRST,[a2dMuxId3\4]

'A2D_Shift_In_Result:                         ' Shift in the result
  PULSOUT A2dClk,10
  SHIFTIN A2dDataOut,A2dClk,MSBPRE,[a2dResult3\8]
  HIGH A2dChipSel                            ' Disable A/D chip select
  a2dResult3 = a2dResult3*2
'A2D_End:
  RETURN                                     ' Return to calling routine


I need to adjust the Zero Offset and Range to improve the resolution. The ADC0834 Range "adjustment" seems to be similar to the 0831 in that a 10k pot can be used to adjust the voltage to Vref.
However, the ADC0834 does not have the Vin pin used to set the Zero Offset on the 0831.

The initial version of the above code produced readings of 40 for each LM34. I thought that might have been reasonable if I had chosen the LM35 (Celcius) but it wasn't even close to the temperature in my office where I'm mocking this circuit up on a breadboard. I added the following statements after each LM34 "read" to multiply by 2 and got a more reasonable reading but I'm still not sure if it's correct.

a2dResult0 = a2dResult0*2
a2dResult1 = a2dResult1*2
a2dResult2 = a2dResult2*2
a2dResult3 = a2dResult3*2

So, how is the Zero Offset set on the ADC0834?

Did I miss something on the datasheet?

Activity #4 of the Experiments with Renewable Energy text does describe the Span setting but only discusses Zero Offset in terms of differential measurements. Is this not adjustable on the ADC0834? I don't think the differential option will perform the same funtion as Zero Offset.

falcon

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-10-24 13:45
    Falcon,

    Looking at the Process (Industrial) Control text it seems the differential input was used to hel create an offset. In that case .7V with the VREF set to .5V gives a .7V to 1.2V span. The ADC0831 has the differential inputs, however the ADC0834 does not. Instead the ADC0834 can use two inputs as a differential input. Of course if you do that you'll be limited to two (2) inputs with zero offsets. The ADC0838 would give you four (4) differential inputs, however if you're using the LM34, I would recommend just providing an accurate voltage reference of 2.56V. What this will do is provide a step (LSB) resolution of 0.01V which is the resolution of the LM34 anyway. This will give you a full scale range of 0 degrees F through 256 degrees F. So as long as you don't expect the temperature to drop below 0F or go above 256F this is an ideal solution. If your range is different, please post it and I will see if there is a better solution for your setup.
  • FalconFalcon Posts: 191
    edited 2011-10-24 15:44
    Chris,
    0 to 256 F is more than enough. I'm measuring hot and cold water to and in my home. I was most concerned about the resolution. I thought I read that it would be only 1.22 deg F. .5 deg F would be sufficient. So I can stay with the ADC0834 instead of switching to the 0838.
    I began researching the DS18B20 sensor but my remote Stamp that gathers the data is a BS2 and the One-wire is (I think) required for the DS18B20.

    Thanks a lot,

    falcon
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2011-10-25 11:05
    Falcon,

    Accuracy with this sensor is a bit subjective to me...it seems to be more accurate at around room temperature (able to do 0.5F resolution) but less accurate across the range (up to 1.5F). Because of that the average accuracy is 1 degree F which corresponds to the 0.010V resolution. It is possible to scale the range or even reduce it to increase resolution, however since that accuracy is not consistent across even this range I wouldn't bother. Now, if you have a sensor that can do 0.5F resolution and want to see that on the ADC you have to cut the range in half or use an ADC with more bits. The way it stands you would have 1 degree accuracy. Nice round numbers. =)
Sign In or Register to comment.