Shop OBEX P1 Docs P2 Docs Learn Events
How to read mv output voltages from a sensor and store the reading in the EEPROM? — Parallax Forums

How to read mv output voltages from a sensor and store the reading in the EEPROM?

MooneyguyMooneyguy Posts: 77
edited 2012-01-01 15:05 in Accessories
Related to my post " How to supply a 1 mA input and read mv output proportional to the input current", I see how to supply my input current. Now how do I measure the mv output from the sensor and store it into the EEPROM? I see how to measure many other things, but not voltage.

After reading some of the Nuts and Volts articles, I may now have to amplify the mv output like they show on page 4 of this link http://meas-spec.com/downloads/23_33_Std.pdf and then somehow read the voltage with a ADC somehow? How do I read and store that voltage result? Can someone tell me what device A1 and A2 are on page 4 of the link (looking for something that works pretty good but is low cost)?

Thank you.
«1

Comments

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-04 17:43
    A1 and A2 are operational amplifiers, and in that diagram, they are set up as a differential amplifier using a resistor that is part of the sensor to set the gain. One option you can find at a Radio Shack store is the LM324. It has 4 operational amplifiers in one 14 pin package, so you will have two extra, for 2 bucks! With that, plus two 100kohm resistors, you are set.

    You will also need an analog to digital converter in order to read in the voltage into the microcontroller, and once you have that, it is a matter of using the WRITE command to store the reading in the eeprom.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-04 21:38
    Thanks again Tracy! As you can probably tell I am kind of new to this. There seems to be a lot of analog to digital converters out there. Is there an analog to digital converter device you could recommend to me for this application?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-05 09:41
    Well, you might as well get a 12 bit converter that has good support from Parallax and from the forum. The Parallax part numbers are 604-00060, or 604-00061 or 604-00062 for 2, 4 or 8 input channels respectively. Allow enough channels for expansion!
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-05 14:25
    That sounds like a great idea. I have another question though. Once I get this all working, how do I go from this class room unit that I am learning with, to a small printed circuit board assembly with everything soldered in neatly place so that it can still be programmed? What if I also wanted to change the program in the field? Are all of the parts on the class room board also sold through Parallax?
  • davejamesdavejames Posts: 4,047
    edited 2011-12-05 14:36
    Mooney - does this suit your need?

    http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/catpageindex/2/Level/a/ProductID/122/Default.aspx

    The above requires a separate Basic Stamp module, and an RS232/USB converter unless your computer has a serial port.

    ---or---

    http://www.parallax.com/Store/Microcontrollers/BASICStampDevelopmentBoards/tabid/137/CategoryID/12/List/0/SortField/0/Level/a/ProductID/781/Default.aspx

    The above integrates a BS2, USB interface and a small prototyping area.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-05 19:06
    Very interesting davejames. I will check it out after I get my get the parts for my project and get it working. Thank you.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-06 08:33
    Is there a way I can take 12 VDC from a motorcycle battery and turn it into 9VDC to get rid of the 9VDC battery on the parallax board?
  • davejamesdavejames Posts: 4,047
    edited 2011-12-06 08:43
    Hi Mooney - glad it was informative.

    In answer to your 12V -> 9V question - yes, absolutely. You'll need a 9V voltage regulator. Do a search on "3 terminal voltage regulators", or "7809 regulator". Also, National Semi has app notes with all that you'd need to understand setting up these most valuable devices.

    Let us know of your progress?
  • ercoerco Posts: 20,256
    edited 2011-12-06 16:38
    Mooneyguy wrote: »
    Is there a way I can take 12 VDC from a motorcycle battery and turn it into 9VDC to get rid of the 9VDC battery on the parallax board?

    You're probably better off regulating directly to 5V, unless you need 9V for something else. The 9V input is only there because 9V is a standard size alkaline cell. A BoE or HW board needs 5V to operate; each has another voltage regulator on a to make 5V from the 9V battery. You'll connect your +5V lead to Vdd, and ground (negative connection) to Vss.

    If you do use a 9V regulator and want to use a standard 9V battery connector wire for a quick & easy connection to your board's connector, be aware that the wire colors (black and red) will switch when you make a battery replacement; red will be negative. Work slowly and use your multimeter to constantly check. Others have reversed polarity and fried Stamps from lack of attention.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-06 19:36
    That is an interesting approach. It must be easier to regulate to 5V?

    I recently had a problem with my ping sensor when the 9 VDC battery dropped to about 6.3 VDC. When I changed the 9VDC battery, everything came back to life like normal. I am using a Basic Stamp 2 microcontroller with my Ping.
  • ercoerco Posts: 20,256
    edited 2011-12-06 19:51
    9V batteries, in a word, suck. They have so little amp-hour capacity that it's hard to rate them. And yes, they'll start glitching when their no-load voltage drops below 8V, because they're fairly dead by then and under load, and through the regulator, the applied voltage drops below 5. But your Stamp and PING are all rated at 5V. Any source that delivers 5V at the required current (anything besides a 9V battery) can keep up.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-06 22:38
    Thanks Erco. I think I understand now.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-06 22:52
    I have tried to digest the information over the past couple of days. I ordered the parts needed. Now I tried to detail out the circuit while I wait for my parts to arrive in the mail and believe I am missing some key information for which I am hoping I can gain some insight on. I have attached the schematic that shows where I am at now.

    Q1. How do the pins from the LM324 Quad Op Amp connect to the 12 Bit A/D?
    Q2. After reading the application notes, I wonder if I am missing a filter between the sensor and the A/D, and if my grounds are correct?
    Q3. Measure Systems instrumentation amp is different that the one Microchip suggests (referenced in 604-00062 links) at ww1.microchip.com/downloads/en/appnotes/00694a.pdf (page 8 of 12, AN695). Is there a significant difference between the two schematics?
    Q4. Is there sample code for the Basic Stamp 2 and pin to pin wiring hook ups to connect the 12 Bit A/D to the Basic Stamp 2 EEPROM to store data and then read the data for display?

    I am trying to control a motor based on pressure sensor outputs in this exercise. My background is mostly mechanical but find this microcontroller world very fascinating. I certainly appreciate all the help the forum is providing.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-06 23:45
    You can't hook the LM334 circuit to the +5V Vdd supply. It takes a higher voltage, and I would recommend 9V or 12V. The reason is that the resistance of the bridge circuit (you can read in the data sheet) is around 4400 ohms, but it might be as high as 6000 ohms. If you intend to pass the recommended 1.5 mA of current through the bridge, that will take at least 6.6 V, plus 2V of overhead for the LM334 itself. If you really do want to run it from the 5V supply, then you'll have to run the bridge current at about 0.5 mA and deal with a lower output span.

    The quickest way to connect the LM324 to the ADC would be to connect the two outputs to two neighboring channels. The result will be the difference between the readings. That ADC does not do true differential conversions, but the separate channels might be okay. A 2nd option would be to use another section of that quad op-amp you have to make a differential to single ended converter, and then feed the output of that into one channel of the ADC. Let me know if you want more detail on that option. How fast do you expect the pressure to be changing? A lot in your setup will depend on that.

    I wouldn't worry about adding a filter at this point in the game.

    The circuit in the Microchip docs is another form of differential to single ended amplifier, but not so good for this MSI sensor. The gain setting resistor included in the sensor package is matched to the sensor and is meant for use in that particular circuit.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-07 09:54
    Thanks Tracy. Looks like I will need to put a 9V regulator like you suggested yesterday? Could I use the same regulator to power the Basic Stamp 2? A regulator something like the fixed output regulator in the Fairchild LM7809 data sheet on page 23 of http://www.fairchildsemi.com/ds/LM/LM7805.pdf ? I updated my schematic based on your input (at least I think I did). I have the 12 V motorcycle battery as the source powering the Fixed Voltage Regulator and the ground of the battery going to the ground of the LM7809 and Vss on the Basic Stamp 2.

    I have also added the 3rd op amp of the Quad to create what I think is a 3 op amp instrumentation amplifier like that shown on page 5, figure 5 of http://ww1.microchip.com/downloads/en/AppNotes/00695a.pdf Now the schematic has the output of the third op amp in the quad going to ch 0 of the A/D, the Vref of the 3rd op amp goes to Vref of the A/D, the Basic Stamp 2 Vdd and Vss goes to the Vdd and Vss of the A/D respectively.

    Does the attached schematic look more correct now?

    The pressure change in this application is very slow, something in the order of 2% full scale pressure over 60 seconds once every couple of days. The application is low accuracy but would rather not waste error band unnecessarily.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-07 18:28
    The second stage differential amplifier looks fine. Resistors R1-R4 can all be 100kΩ for a differential to single ended gain of x1. However, the connection from R4 over to Vref on the ADC is incorrect. For a first cut, the bottom of R4 can go to Vss, and Vref on the ADC can go to the +5V power supply, Vdd. Later on, you may want to connect R4 to a small offset voltage, and you may want to be able to adjust Vref to set the scale factor and to improve the resolution. But the two will never be connected together.

    The LM34 circuit is fine, but I would prefer the current source circuit that I had mentioned in your other thread on how to supply 1 mA. That other circuit would use the 4th section of the quad op amp.

    The op-amp and current source should be powered from the 9V supply. The ADC will be powered from 5V, Vdd, same as the Stamp.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-08 00:22
    Thank you. I will change my schematic to incorporate the current source circuit suggested in the other thread and make the fixes you pointed out above. Is it true that I can adjust the current source to obtain 1.5 ma using the 500 ohm pot? The sensors came in today and they only provide 40 mv full scale with 1.5 ma input. Will the fixed voltage regulator work as detailed in my last schematic for the 9V as a supply for the current source. Do you think I need 12 VDC as in your schematic, or will 9 V work fine? In your last sentence above, are you referring to the op-amp and current source detailed in the current source circuit you mentioned in my other thread (how to supply 1ma) with the op-amp actually being the last one available in the Quad Op-Amp?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-08 09:32
    It is filling up the paper more and more!

    The variable resistor you have labeled RL in series with the '7809 should not be there, and the resistor labeled R1 is not necessary either, but a value around R1=100kΩ can help to drain the capacitor when you switch the circuit off.

    This circuit will not draw much current, 20 or 30 mA at most unless you have other loads attached to it. You might use an LM78L09 (smaller TO92 package). The capacitor Co for the LM7809 could be a larger value, something like 1µF.

    The rest looks okay on first glance. You are correct about the 500Ω potentiometer. That adjusts the current from 1 mA to 1.5 mA. The output voltage will be proportional to that current. There are several ways to adjust the range for improved sensitivity: 1) more excitation current 2) more gain in the amplifiers 3) lower reference voltage on the ADC, instead of Vdd=5V. I'd get it working on a breadboard first and see how it turns out. One more thing, while experimenting, add a 1kΩ resistor between the output of A3 and ch0 on the ADC. There is a possibility that the output of the ADC will exceed 5V while experimenting, and the resistor will limit the fault current.

    Do you have an ohmmeter? If so, measure the resistance of your pressure sensor between pins 5 and 6, and between pins 5 and 4, and report back. That will determine whether 9V will do, or if you might need 10V or 12V.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-08 11:50
    Sounds like it is coming together and is starting to get exciting. The bridge resistances measure 4.15 Kohm for pin 5-6 and 3.426 Kohms between 4-5.

    I also notice that Vdd, CS/SHDN, DIN and CLK on my schematic are not hooked up on the ADC yet. Those must be where I read the actual results some how? Can you point me to where to find out how to read and store the info from the ADC?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-08 15:24
    What that resistance means is that if you adjust the bridge current to 1mA, there will be 4.15 volts across the bridge (varies somewhat with temperature). It is just Ohm's law, R * I. That plus the 1.21V from the LM385 brings it to 6.36V at the output of op-amp A4. That gives over 3 volts of headroom for A4, between 6.36 V and the 9V power supply. Good enough. But if you try to push the current up to 1.5 mA, it is borderline and might be better with a 10V supply, but I wouldn't worry about it. Anywhere in the 1mA to 1.5mA range should be fine, combined with gain and adjustments in the amplifier and ADC reference. The outputs from the bridge to the differential amplifier will be centered around approximately 3.3 volts common mode. (1.21 + 4.15/2).
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-09 16:09
    Thank you again for the information. You have been extremely helpful. I have attached a neater revised schematic with all of the changes suggested. Since I had already order the devices, I will tryout the smaller TO92 package you suggested earlier on the my next parts order. I will start my evaluation with the 1 ma input you suggested.

    Can you point me so I can learn how to hook up Vdd, CS/SHDN, DIN and CLK in the ADC and where I might find some sample source code? I am thinking these are the pins I tap into with the Basic Stamp 2 so the outputs can be read, stored, and then used to control devices, true? Obviously I need to hook up what I have first and see an output of some kind on a DVM. In the future, can I replace the Basic Stamp 2 9VDC battery with the output from the Fixed Voltage Regulator in the schematic? That is the reason I selected 9V because I thought it could run the circuit and the Basic Stamp 2.

    I will report back in the next couple of days on the progress - would report faster but I think the wife has me lined up for some painting over the next couple of days or so :-(
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-09 21:55
    For help with the 3108, the first stop can be the Parallax store listing, where you can look for
    Downloads & Resources:
    MCP3208 Example Code (.zip)
    That will suggest how to connect the 4 signal lines from the MCP3208 over to pins on the Stamp. The Vdd power and ground will connect to Vdd and ground on the Stamp. The code should give you basic readings.

    To go beyond thatd try a GOOGLE for:
    MCP3208 basic stamp
    or
    site:forums.parallax.com MCP3208 basic stamp

    You'll find plenty of material to read between brush strokes, ways people have used the chip and the problems they have encountered.

    Yes you can use the 9V supply for the Stamp. Connect the 9V to Vin (NOT to Vdd). 9V to Vin will be regulated on board the Stamp to the 5V Vdd that the stamp itself uses and also the ADC. Power the LM324 op-amp directly from the 9V. I'll take a look at your schematic when I have a chance, have to run now.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-12 09:47
    The schematic looks good. Nice job cleaning it up! There has to be a connection from the battery/9V ground over to the BASIC Stamp Vss ground. Also, you can connect the 9V supply to the Vin pin on the Stamp module. The BASIC Stamp module has its own voltage regulator that will take that 9V and then produce the 5V Vdd for the Stamp and for the ADC.

    I should ask if you will have other things running from the 5V power, especially things like servos that would draw a lot of current? That might change the power supply picture.

    Now that this is coming together, I'm thinking that the reference for current source with A4 could alternatively be derived ratiometrically from the 5V supply, instead of from the LM385 reference diode.
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-12 23:18
    Thanks for the review. I am not real proficient with my AutoCad schematic drawings as you can see. What I meant on my schematic was that the battery/9V ground goes to the Basic Stamp 2 Vss Gnd as noted in the lower far right of the Fixed Voltage Regulator.

    I am still waiting on a few parts to arrive in the mail (should be here later this week). In the mean time, I have been assembling the parts I have right now and studying up on 3 transistor instrument amplifiers, transistor constant current sources with zener diodes (the closest current source I could find in the internet to that you helped me with), and coding for and hook up for the ADC.

    Are you saying that I can simply connect a lead from the 9VDC output of the LM7809 and plug it into any one of the three black Vin sockets at the top of the board and it will replace the 9VDC Alkaline Battery? That would be great. I was going to go to the trouble of connecting the + and - to of the 9V regulator output to the battery terminals. I like your idea much better if I understand it correctly.

    Controlling anything else? In the end all I want to do is read pressure value, compare it to a stored value and then make a decision to close one of two switches to a solenoid that turns on a high current DC motor. The current in the solenoid that comes with the motor runs at about 130 to 150 ma (closer to 130 ma). What is the best what to close the solenoid switches if 150 ma is too high? Is there a special kind of relay I need or can it be done directly from the Basic Stamp Homework Board? I don't really need to control anything else. Although I might like to have an bi-color LED indicate which switch was activated if that is in the current budget (but not required).

    I don't understand how to try out what you suggest in your last sentence. Are you saying that the current source will be fine if I disconnect the LM385-1.2 and leave it open between the bottom of 500 ohm pot and the 10 Kohm resistor?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-13 09:41
    I'd better check the wiring of the homework board before I recommend connecting directly to the Vin socket. You certainly do not by any mistake want to connect 9V to the Stamp Vdd pins or to any of the i/o pins. Your original scheme to go through the snap connector might be better. Be careful when you wire up the snap connector. It will come out in "reverse" as a power source, because the black wire may/will end up being positive and the red wire negative.

    With regard to the bridge excitation circuit, here is what I mean:

    bridge_X2.gif


    The 1.2 volt LM385 reference diode is replaced in this instance by a 3.16kΩ resistor, and the 3.16k/10k divider is connected to the same 5V that supplies the reference pin on the ADC. The power for the op-amp is still 9V. The divider of 3.16k with 10k still provides 1.2 volts to the input of the op-amp, but now the reference is ratio-metric to the ADC reference. What that means is that if the 5V happens to increase or decrease, the excitation to the bridge and the pressure signal input to the ADC follows right along, so the count output from the ADC does not change. That is called "ratiometric" as opposed to "absolute" reference conversion, and in the case of a bridge transducer like this, it is a good thing. Don't worry about changing your plans. Either ratiometric or absolute will work fine until you get down to the level of splitting hairs.
    744 x 352 - 14K
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-13 12:51
    Thanks for the circuit and explanation. I am a little confused on the op amp wiring though. I see in the constant current source drawing above, the op amp goes to the 9V supply and to ground. I am using this fourth op amp from the LM324 for the constant current circuit and the other 3 op amps are used for the instrumentation amplifier. However, the LM324 only has one hook up for Vcc and gnd. Does that mean that each of the instrumentation op amps are also powered by the 9V supply? Is that ok? Here is the pin out of the quad op amp that shows pin 4 & 11 going to Vcc and gnd: http://www.fairchildsemi.com/ds/LM/LM324.pdf . If it is ok to plug into Vin (not Vdd or Vss) that would be a little more clean.

    My intent was to hook the + 9V to where the alkaline battery +9V connects and same for the - connection. I would not think there would be any way to get anything reversed on that, true? The snap connection for the battery is soldered right on to my board with no other black and red wires.

    Regarding my switch question. A switch connected to 12 VDC is used to close a solenoid, which then turns on the DC winch motor. The current that goes through the switch is 130 ma to 150 ma, but the current that runs the motor can be 60Adc depending on pounds of load being worked. All I want to do is use the pressure measurements to close the switch that closes the solenoid. Can you recommend a method to do that? I am thinking even 150 ma might be too much current for my Basic Stamp 2 HomeWork board and might need a relay of some kind perhaps? Obviously it would be better if I could just use a transistor or something to do the switching.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-13 22:57
    All four of the op-amps in the LM324 will be powered from the same 9V applied to pins 4 and 11. Put a 0.1µF capacitor near the chip across those pins.

    Your scheme to attach the battery clips is fine. I thought you were talking about making the connection using one of these...
    clip.jpg

    to bring in the power as kind of a substitute 9V battery. If you do that, you have to watch out for the reversed polarity on the red & black wires.

    The switch connection to the solenoid/winch sounds like a good candidate for an opto-isolated relay. Will the 12V supply be the same motorcycle battery that is running the Stamp and pressure sensor? The simplest option for wiring would be a photoMOS relay (example). This has an LED on the Stamp side, and a circuit with a mosfet transistor that can handle the 150mA/12V on the output side. Stamp lights the internal LED, the switch on the power side closes.

    photomos.gif

    There are alternatives, and even a simple transistor will do if isolation is not necessary or dictated by prudence.
    720 x 540 - 77K
    465 x 152 - 4K
  • MooneyguyMooneyguy Posts: 77
    edited 2011-12-14 10:13
    Thank you. That clears up my quad op amp question nicely. I will add the 0.1uf cap as well. The 12 VDC supply is the same motorcycle battery that is running the Stamp and pressure sensor. The opto-isolated photoMOS relay looks very cool. I just ordered a couple of them.

    I am still clueless on how to create code for the ADC. I think most of my questions center around what the CS/SHDN, Din, CLK and the empty VDD slot are and how they work together using the coding. I have not been able to find much in the line of useful code that has enough explanation for me yet after quite some time searching and reading. I have look at where you pointed me as well as the Parallax forums and Nuts and Volts articles. It seems some of the articles come close, but then the chip is different or the microcontroller is different. My next plan is to go back now to the Parallax manual to see if there are definitions for the pins there with perhaps some info on how to use them to read voltage, and then just try different hunches to see if I can get it to work. I am not giving up though :-)
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2011-12-14 13:03
    Do you have the ADC yet? Once you have it, hook it up on the white plugboard as stated in the MCP3208 demo that you find on the Parallax store page. Oops, I see that the demo may have a typo where it says MCP3204, but the numbers in parentheses are actually the pin numbers for the MCP3208 as noted here:
    ' -----[ I/O Definitions ]-------------------------------------------------
    CS              PIN 0   ' Chip Select   (MCP3208.10)
    Clock           PIN 1   ' Clock         (MCP3208.13)
    DataOut         PIN 2   ' Dout on ADC   (MCP3208.12)
    DataIn          PIN 3   ' Din on ADC    (MCP3208.11)
    

    That means you hook up the Stamp signal p0 with a wire to pin 10 on the MCP3208, Stamp p1 to pin 13 on the MCP3208, and so on. Also of course it also needs the power supply Vss to agnd(14) & dgnd(9) and Vdd to pins Vdd(16) and Vref(15). Run the demo and report back. There is nothing like doing it to learn how it works!!
Sign In or Register to comment.