Shop OBEX P1 Docs P2 Docs Learn Events
Is getting a steady result from Analogin possible? — Parallax Forums

Is getting a steady result from Analogin possible?

eagletalontimeagletalontim Posts: 1,399
edited 2009-01-11 23:56 in General Discussion
I decided to try a different route with the temperature sensor and test the resistance between both leads of the sensor using the ANALOGIN command. If there is a better approach to reading the resistance, please let me know! Right now, I cannot get a steady reading and I am wondering what I can do to stabilize it. Currently, the readings are jumping between 57 and 61 within 1 second. At 70°, the resistance of the sensor is roughly 20K. For hotter temps, the resistance goes up. I am wanting to take that value and convert the ANALOGIN results to display the temperature on 3 7 segment displays. I have RC.0 and RC.1 wired like the ANALOGIN example but I changed the 10k to a 100k which seemed to give a wider range and the cap is a .001uf.

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-12-14 18:00
    ok.....is there any way to simply read the resistance of something and display the results? I have tried the RCTIME command and it is not working at all for some reason. I simply want to have a circuit that I can put a 10K resistor in and the chip will tell me 10000 or if I swap the 10k with a 33k, it will say 33000. I have tried debugging and watching the output, but it always varies. Most of the time, I get ~21,000 to ~50,000 and sometimes i get 0 to ~4000 with the exact same circuitry. Basically i need the chip to work like a digital ohm meter and display STEADY results. Any ideas?
  • Shawn LoweShawn Lowe Posts: 635
    edited 2008-12-14 19:37
    rctime will not show you the resistance, but I'm sure you could calculate the resistance if you had a capacitance that was accurate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Shawn Lowe


    When all else fails.....procrastinate!
  • BeanBean Posts: 8,129
    edited 2008-12-14 21:55
    Try increasing the cap value to a 0.01uF or a 0.1uF.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • BeanBean Posts: 8,129
    edited 2008-12-14 21:55
    Try increasing the cap value to a 0.01uF or a 0.1uF.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-12-19 23:42
    ok, I changed the cap to a .1uF and I bought a thermistor at radioshack hoping to get a steadier reading and actually knowing what the resistance is at a certain temp. The package says it is 10k ohms ± 1% at 25° Celsius. I currently have the chip programmed with the ANALOGIN using RC0 and RC1 as the 2 pins used. It is wired with one 10K across RC0 and RC1 and the thermistor on RC1 to the 5V side of the 7805 VR. Is there something I need to change to get this to work correctly?
  • BeanBean Posts: 8,129
    edited 2008-12-20 13:59
    ANALOGIN measures a variable VOLTAGE. The thermistor is a varing resistance. I would recommend using RCTIME to measure it.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-12-20 15:17
    I tried using RCTIME and it kept jumping around with huge random numbers from 0 to 60,000+ [noparse]:([/noparse]
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-12-20 15:42
    well dang...i found that I had a bad connection with the thermistor on the test board [noparse]:([/noparse] I got it fixed now and it is reading 35 at room temperature with a 100 ohm resistor in place of the 220 ohm. Can someone help me figure out how to convert this to actual room temperature?

    here is my code :
    DEVICE         SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ         4_000_000
    ID        "Temp"
    
    InPin         PIN     RC.0
    DigCtrl     PIN     RA
    Segs         PIN     RB
    MaxDigit     CON     4
    a         VAR     Word
    digPntr     VAR     Byte 
    display     VAR     Byte(MaxDigit)
    digit        VAR    WORD
    digit1        VAR    WORD
    tmpB1         VAR     Byte
    tmpB2         VAR     Byte
    tmpB3         VAR     Byte
    tmpB4         VAR     Byte
    
    INTERRUPT 200
    ISR_Start:
    
    Next_Digit:
      INC digPntr                     ' point to next digit
      IF digPntr = MaxDigit THEN '             check pointer
        digPntr = 0                 ' wrap if needed
      ENDIF
    
    Update_Segs:
      Segs = %00000000                 ' blank segments
      READ DigMap + digPntr, DigCtrl         ' update digit control
      Segs = display(digPntr)             ' output new segments
    
    ISR_Exit:
      RETURNINT
    
    PROGRAM Start
    
    Start:
      DigCtrl = %1111                 ' disable all digits
      TRIS_A = %0000                 ' make dig pins outputs
      TRIS_B = %00000000
      Segs = %00000000
    
    Main:
      HIGH InPin                    ' charge capacitor
      PAUSEUS 250                    ' for 250 usecs
      RCTIME InPin, 1, a                    ' read pot (2 us units)
      tmpB2 = a_LSB / 100                 ' get hundreds digit
      tmpB1 = __REMAINDER                 ' save 10's and 1's
      READ SegMap + tmpB2, display(2)         ' get segment map 100's
      tmpB2 = tmpB1 / 10                 ' get 10's digit
      tmpB1 = __REMAINDER                 ' save 1's
      READ SegMap + tmpB2, display(1)         ' get segment map for 10's
      READ SegMap + tmpB1, display(0)         ' get segment map for 1's
    
    
      GOTO Main
    
    SegMap:                                         ' segments maps
      DATA  %00111111                               ' 0
      DATA  %00000110                               ' 1
      DATA  %01011011                               ' 2
      DATA  %01001111                               ' 3
      DATA  %01100110                               ' 4
      DATA  %01101101                               ' 5
      DATA  %01111101                               ' 6
      DATA  %00000111                               ' 7
      DATA  %01111111                               ' 8
      DATA  %01100111                               ' 9
    
    DigMap: ' digit select map
      DATA %11111110
      DATA %11111101
      DATA %11111011
      DATA %11110111
    
    
  • BeanBean Posts: 8,129
    edited 2008-12-20 16:45
    The resistance of thermistors is not linear. It's not going to be easy to conver the thermistor reading to a temperature.
    Why not just use a digital temperature sensor ? Like the DS1620, these return the temperature directly in digital format.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    "The welfare of the people in particular has always been the alibi of tyrants." ~ Camus
    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-12-20 16:56
    well, i am kind of broke and have limited resources around. I have an account at radioshack so i can buy things on credit tongue.gif They don't have a DS1620 so I have to work with what I can get my hands on. I was hoping to just use the thermistor but the way it sounds, it is impossible [noparse]:([/noparse]
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-12-20 17:18
    Go back to ANALOGIN.· The forward voltage across a silicon diode changes by 1mV per degree Celsius.

    Post Edit -- A current regulator/source, which can be made from·components·available from RS (a resistor and an LM317 or a 7805, or a transistor and a couple of resistors), would be beneficial but not essential.· Noise, poor regulation, questionable construction and so on·will result in shakey readings [noparse][[/noparse]G-I-G-O].·

    Post Edited (PJ Allen) : 12/21/2008 6:49:12 PM GMT
  • Basic JimBasic Jim Posts: 106
    edited 2008-12-20 17:47
    Hi,

    This may be time consuming but I got around a similar situation by building a cross-reference table. I compared what my test thermometer said to what a lab thermometer said and entered the readings in a table. When reading the temp. it would get the info. from the table and display it. If you gather readings in cold temp, warm temp. and· hot temp. Enter the lab Thermometers reading in a table. When you see how the curve behaves it is fairly easy to fill in the gaps in the missing areas. When it was done it was very reliable. There are mathematical formulas that you can use but this way it is customized to you particular part. Also, I'm not a good programmer to work the formula into a routine. A cross-reference table is the way that worked best for me.

    Hope this helps,

    Jim W.



  • max72max72 Posts: 1,155
    edited 2008-12-21 15:52
    If you Google around you can find circuits to linearize a Thermistor.
    For instance http://www.ecircuitcenter.com/Circuits/therm_ckt1/therm_ckt1.htm is a good starting point.
    There is also an article here:
    http://www.science-logic.net/renneberg-lehmann-ecctd07.pdf

    Massimo
  • tommytommy Posts: 84
    edited 2009-01-11 23:25
    --- to lessen jumping around when displaying successive readings from almost any analog device, I simply add up either sixteen or 256 readings in a row, then take the average, and display that.·· To average sixteen readings, take the answer and shift it right four times.· "Dividing" by 256 is even easier:

    --- assuming the reading is returned in a byte, add them up to a word value

    >> mov loop_value 256

    >> get_reading

    >> add your_answer to low_byte

    >> if no carry, skip the next line

    >> inc high_byte

    >> dec loop_value and if not zero jump back up to get_reading

    your high_byte is now the average of 256 readings.· no actual division is required.· the low_byte is ignored. your answer will still not be rock-steady: ·my thermometer changes every thirty seconds or so, but never jumps two degrees.· your·display will be very much closer to what you were expecting.

    tommy
    ·
  • kwinnkwinn Posts: 8,697
    edited 2009-01-11 23:56
    I have used a thermistor to measure and control temperature by calculating the temperature from the voltage across the thermistor with a constant current through it. The formula is fairly simple (T=a+bx+cx^2). To calculate a, b, c, you need 3 to 5 temperature/voltage measurements over the temperature range you are covering using a calibrated thermometer.
Sign In or Register to comment.