Shop OBEX P1 Docs P2 Docs Learn Events
MCP3204 code questions — Parallax Forums

MCP3204 code questions

kmacken2kmacken2 Posts: 15
edited 2011-03-31 20:02 in Propeller 1
Hi everyone,

Trying to measure temperature using a TH-44004 Tempearture Probe with a MCP3204 adc. Professor provided programs as a template, but it was two different spin programs for using remote sensing, so it was a bit tricky to combined.

The PRI SENS_T linearly interpolates data we have for count to temperature that was calculated just in excel for simplification.

I've attached the spin prorgram of what we've tried so far, and a section at the top with questions for anyone willing to help. I'll probably post more questions later. FYI - new to programming.

Temp_3_29_11.spin

Comments

  • kf4ixmkf4ixm Posts: 529
    edited 2011-03-29 07:46
    What resistance thermistor are you using? When you post your code, i'll take a look and see what i find.
  • kmacken2kmacken2 Posts: 15
    edited 2011-03-29 12:11
    kf4ixm wrote: »
    What resistance thermistor are you using? When you post your code, i'll take a look and see what i find.
    The resistance is 2364.

    Thanks in advance for your help!
  • JonnyMacJonnyMac Posts: 9,233
    edited 2011-03-29 13:09
    What you'll want to do is use the thermistor as part of a voltage divider, the other side using a precision resistor (or good trimmer pot). Measure the voltage at the junction and convert to temperature. Pretty easy, really.
  • kmacken2kmacken2 Posts: 15
    edited 2011-03-29 14:51
    JonnyMac wrote: »
    What you'll want to do is use the thermistor as part of a voltage divider, the other side using a precision resistor (or good trimmer pot). Measure the voltage at the junction and convert to temperature. Pretty easy, really.

    The problem is understanding the code for the adc, never programmed one before. Any tips based on our current program?

    Some things still have to be changed because this was code for a 16-bit 6 channel but actually using a 12-bit 4 channel adc.
  • JonnyMacJonnyMac Posts: 9,233
    edited 2011-03-29 17:14
    Why be burdened with code that don't understand and may not work? If you have the data for the resistance curve of the sensor, writing a program for it should be fairly straightforward. The easiest way to use that element is part of a voltage divider from which you can easily measure the tap.

    There is good code available for the MCP3204 -- I wrote this object:
    -- http://obex.parallax.com/objects/625/

    And you can read about using the MCP3204 in this Nuts & Volts column (I wrote it):
    -- http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp8.pdf

    That article uses joysticks -- think of the your thermistor/resistor combination in similar turns (you're measuring the voltage at the tap).
  • kmacken2kmacken2 Posts: 15
    edited 2011-03-30 14:19
    Hi Jonny,

    Thanks so much for this program. It is much easier for reading the counts from the adc.

    Now we just need to clearly extract the counts. We've run the program and displayed the results in parallax serial terminal, and we're getting the counts read then gibberish like this:

    ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ¬ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ¬ÿÿÿŒÿÿÿŒÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ¬ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿŒÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿŒÿ
    ÿÿŒÿÿÿŒÿÿÿ¬ÿÿÿŒÿÿÿ¬ÿÿÿŒÿÿÿŒÿÿÿ®ÿÿÿ¬ÿÿÿ¬ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ2965
    1: 0
    2: 23
    3: 28
    ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿŒÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿŒÿÿÿ¬ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿŒÿÿÿŒÿÿÿ®ÿÿÿ®ÿÿÿŒÿÿÿ¬ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ¬ÿÿÿ®ÿ
    ÿÿŒÿÿÿ®ÿÿÿŒÿÿÿ®ÿÿÿ¬ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿ®ÿÿÿŒÿÿÿŒÿÿÿ®

    We've looked at this part of the code and are trying to figure out how to get just the count readings to be displayed. What is causing all of the extra text?

    t := cnt
    repeat
    term.tx(HOME)
    term.tx(LF)
    term.tx(LF)
    repeat ch from 0 to 3
    term.dec(ch) ' display channel #
    term.str(string(": "))
    term.dec(adc.read(ch, adc#SE)) ' display channel value (counts)
    term.tx(CLREOL)
    term.tx(CR)
    term.tx(CLRDN) ' terminal clean-up
    waitcnt(t += constant(MS_001 * 100)) ' update every 100ms
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-03-31 07:32
    It looks like either baud rate settings or incorrect or Propeller frequency is incorrect.

    John Abshier
  • kmacken2kmacken2 Posts: 15
    edited 2011-03-31 20:02
    This fixed it! We can easily read the value from the chip now.

    But we are still getting some fluctuation, especially for the temperature sensor. We tried replacing it with a constant voltage supply and seeing the reading, but it wouldn't read the value. And the pressure sensor also fluctuates about between 0 and 10 counts (expecting somewhere close to zero just in normal conditions, right?)

    Yet to test the humidity sensor, that's next.
Sign In or Register to comment.