How to read mv output voltages from a sensor and store the reading in the EEPROM?
Mooneyguy
Posts: 77
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.
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.
Comments
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.
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.
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?
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.
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.
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.
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.
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.
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.
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.
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?
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 :-(
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.
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.
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?
With regard to the bridge excitation circuit, here is what I mean:
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.
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.
Your scheme to attach the battery clips is fine. I thought you were talking about making the connection using one of these...
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.
There are alternatives, and even a simple transistor will do if isolation is not necessary or dictated by prudence.
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 :-)
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!!