2nd Stage of the miniEC – Gain Loop

Tags

,

post for September 1st, 2014

SparkysWidgets has released a newer version of the  miniEC (product page) since I last played with this breakout board.  I ordered some of the newer versions awhile back and am finally getting around to giving the miniEC circuit a twirl!

The Goal

The goals of this post are to identify confusions I have with the 2nd stage (Gain stage) of the miniEC circuit.

Thanks to Those That Go Before

.2 VPP 

Ryan notes in his comments on the minieC

Right before the 2nd stage, this wave is turned into a small signal(about .2VPP via voltage divider) this small signal is passed into the (2nd stage) gain stage where the eC probe forms one leg of the gain divider of the op-amp  By treating the SUT as an unknown resistance in a gain loop the amount of current needed to calculate the conductivity is decreased by several factors(at least a 100x reduction)

However, I checked the chips….

Check the Chips

I am finding a big difference between hardware and software development is when attention to detail kicks in.  With hardware, I find attention to detail is extremely important early on.  For example, soldering an SMT given my skill set.  The extra time I take to clean the pads, place the chip in a way that I don’t have to handle the PCB while trying to put hot solder on a pin/pad, making sure to apply flux, cleaning off the residue after soldering is time well spent.  If I don’t do this, I end up removing and re-soldering…removing and re-soldering…With that said, even with all the prep, there are many times when my soldering needs to be redone…particular on iddy biddy sized parts.

I printed out the analog front end of v1.2 of the minieEC schematic (GitHub repository):

AnalogFrontEndMiniEC1_2

and checked the resistors with their values on the breakout board.  

 

Chips on MinieC

I saw two differences which I verified with my DMM (Extech 330):

miniEC2ndStep

  • R7 on the schematic calls for a 100KΩ resistor.  The value on the board is 47KΩ.
  • R9 is 1KΩ on the schematic but on the board it is 3KΩ.

.2 VPP 

Here I am confused.  R8 / R7 are used as a voltage divider to decrease the voltage going into the op amp.  Given the above, the VPP = .2 However, the LTSpice IV model

Wien Bridge Voltage Out and Stage 2 Voltage in after voltage divide

The green sine wave is the output of the Wien Bridge Oscillator step.  The VPP ~= .9V.  The blue sine wave is the input into the op amp used with the EC probe.  The VPP ~= .08V.  Given the resistor values this makes sense – .9*(4700/(4,700+47,000)) = .08V.  Yet the explanation Ryan gave for this stage noted the VPP into the second op amp should be .2VPP.  I am not sure if:

  • the .2VPP is the important value.  I found another EC Circuit (picture of schematic) that noted .2VPP and uses a 1KΩ R for R8 and a 100KΩ R for R7.  The comment near the non-inverting input of the Gain op amp  notes: “should have about .2Vpp input.  If much higher offset is difficult to null out change [R8] & [R7] as needed”

 When these values are plugged in,

VPP When R8 = 1K and R7 = 100K
 
the VPP into the gain op amp is too small – doing the calculation: .9*(1/101) = .008V!  I think this was a typo.  If the VPP is to be .2V, and R7 = 100K, then a value for R8 that will create a .2VPP is 30KΩ.

RightVPPForStage2

 

 The right answer will depend on the results for the E.C.  Is the value within range of those given by the EZO or TDS meter?  That’s something I need to find out.

Gain

R0 in the LTSpice simulation:

EC Probe in LTSpice

is acting as a value for an E.C. reading (see this post for an explanation). an R value of 200Ω is equal to an E.C. reading of 5mS.

When R9 is 1K, the Gain is 1+ 1000/200 = 6.  

R9 is 1K

which is “close enough” to the LTSpice IV results.

R9 is 3K

R9 = 3K

By knowing the Gain, the E.C. can be back calculated.

When R9 is 3K, the Gain is 1 + 3000/200 or 16.  So 16 = 1+3K/R0  -> R0 = 3000/15 = 200 Ω E.C. = 1/200Ω = 5mS.  Given the relationship between the resistors and the Gain, the variable resistor (R0 – representing the probe in the LTSpice model) means the Gain will vary  based on the conductivity of the bath.  The challenge then is to determine a resistor value for R9 that is within +5V and is “large enough” to get “the best” reading it can.

The question for “large enough” is answered by knowing the range of conductivity(1/R).  Given the E.C. values for vegetables and herbs located here,  The E.C. ranges between .8mS and 5mS.  Given this E.C. range, the resistance range is 1,250 to 200.  Using .step with a list command set for 200 and 1250 (see {R} at R0) and R9 at 4K:

Step with list 1250 and 200

results 4K for R9

I’m thinking a good value for R9 is around 4K.  This way, the Vpp is within 5V.

What’s Next

I need to figure out what the “best” values for the resistors are.  This is probably best done using a bread board prototype.  I’m still having trouble prototyping the Wien Bridge Oscillator.  I think my “big mistake” was using a single power supply.  There is some learning gap that I must bust through to get this going.  I should also receive the Healthy pH Shield PCBs this week.  Once I receive these I will solder on the parts and give this rev of the Shield a twirl.

 

Today as always – please find many things to smile about.

Exploring Floating Ground for the Healthy EC Shield Circuit

Tags

,

post for August 31st, 2014

The Healthy EC Shield owes many of its design choices to the great work done by SparkysWidgets miniEC (product page).  While designing the Healthy pH Shield, I struggled with using a charge pump chip to provide V- to the op amp.  During testing the charge pump added a significant amount of noise into the result.  Also, the part was a significant contributor to the BoM.  As I looked for alternatives, Chris walked me through using Floating Ground to offset the sine wave enough such that the design could use a single supply.

The Goal

The goals of this post include:

  • explaining what I mean when I say Floating Ground.  I am finding – like every other field I have some deeper knowledge of – depending on the context of the engineer, a term could very well have different definitions.  In addition, I didn’t have a grasp (perhaps still don’t – but will keep practicing!) on Floating Ground.
  • LTSpice IV modeling of Floating Ground within the Healthy EC Circuit.

Thanks to Those That Went Before

  • Chris Gammell.    He walked me through how to do this.  I hope that I have learned well enough to repeat his guidance accurately. I highly recommend his Contextual Electronics course.
  • Ryan (SparkysWidgets) has Open Sourced his design and has been phenomenal at making sure we can learn from his work.  I hope you get a chance to check out his work.  And no, I do not get any “payback” for recommending SparkysWidgets.  

Floating Ground

Here is a rough schematic of the breadboard prototype I built to demonstrate and understand Floating Ground when working on the Healthy pH Shield.

As I discussed earlier (in this blog post), pH values range from +/-.414V.  The job of the Floating Ground is to raise how the op amp sees Ground – usually Common Ground at 0V – to a V- that is at least .414V above 0V.  By “floating” the ground up this far, all readings coming into the op amp can be measured above 0V.  In this way, a single supply can be used.

The way this was done in the Healthy pH Shield – and what I plan for the Healthy EC Shield if it works – was to start with a 5V power supply and two resistors (10K and 1K) that divided the power such that a Floating Ground of .45V is established (5V*(1/11) = .45).  Now that I had my Floating Ground, I wanted to try it out with a pH reading I might get.  In a previous post I had a table that translated the pH value to a voltage.  I attached a black wire to the GND side of a AA battery and a red wire to the positive end.  Luckily the battery did not blow up.  I attached the GND of the battery to .45V and then divided the voltage using 1MΩ Resistors such that .375V (1.5*(.5/2)=.375) would feed into the non-inverting input of the op amp.  The op amp’s output should be around .825.  

The first op amp I used was the TL072 (data sheet) V-in and Vout read .88V (880mV-450mV = 430mV) instead of .83V (830mV – 450mV = 380mV).  After talking with Chris about this, he noted this is caused by the common mode input voltage range:

notice how the rails go from +/- 11V for a +/-15V power supply.  This speaks to the op amp not being rail-to-rail.  So I am basing my context on rail-to-rail being important for 0-5V rails as noted in this TI document on Op Amp Voltage Ranges).

I changed the op amp to an LMC6041.   Characteristics include:

  • 4 pA Input Bias
  • Rail-to-Rail Output

This is not the same op amp as in the BoM but has the characteristics discussed.  This op amp came in a DIP package – making it easy to use on a breadboard.

Battery

VGND

V+(in)

V-(in)

Out

1.6

.457

.818/.390

.849/.392

.849/.392

pH reading = (.46MΩ/1.92MΩ)*1.6 = .38

At .392, the breadboard results is 12mV more than expected based on the values for the resistors and battery.  This result is better than the previous results I measured with the other op amp.  I assume the next step to check accuracy would be to take more samples and then calculate the standard deviation.  At this point, I assume 12mV is within a range to accommodate aspects of a breadboard setup and the DMM that make it impossible to get exactly accurate readings.

Floating Ground and Healthy EC Shield

The Floating Ground walkthrough makes sense to me for the design of the Healthy pH Shield.  I am not sure how well this technique will work for the Healthy EC Shield.  The next step in my understanding is to create an LTSpice IV model.  The challenge I have here is I am not sure the parameters for op amps model well.  Even when I use models specific for a chip.  

WienBridgeLTSpiceModel

Here are the results of the model without a Floating Ground:

 

Wien Bridge Results

 

 

Pin

High V

Low V

VPP

output

.466

-.464

.93

non-inverting and inverting

.158

-.160

.318


.318 is roughly 3 times .318.  Given the gain is 3.2, I expected the VPP on output to be 1V.  Perhaps .07V is due to modeling parameters?

Here is the model I used that includes the Floating Ground:

LTSpice Wien Bridge With Floating Ground

Here are the values for the non-inverting/inverting inputs of the op amp (blue) and the op amp’s output: 

Results of Wien Bridge With Floating Ground

Pin

High V

Low V

VPP

output

1.8

.6

1.2

non-inverting and inverting

1.5

.8

.7

What’s Next

I don’t have a grasp on using floating ground on the Healthy EC Shield – so I need to do that.  I also will be trying out SparkysWidgets minieC.  Ryan sent me my order awhile back and I am finally getting around to playing with it!  One challenge is there is no firmware (i.e.: Arduino Sketch) to control the minieC.  Hopefully, I’ll be able to cruft something up.

 

As always – thank you for reading this far.  Please find many things to smile about.

Playing Around with Atlas-Scientific’s EC-EZO Breakout Board

Tags

,

 

Post for August 30th, 2014

The EZO Conductivity Circuit

I had reviewed an older version of Atlas-Scientific’s EC Stamp in this blog post. Since then Atlas-Scientific sent me the latest version – the EC EZO.

The EZO – slick packaging, coated for waterproofing

Information and more documentation can be found at this web site.  The product sheet notes this is the 6th version.  Also, the customer scenario has become more focused from the web site:

“Whether you are manufacturing robots, process equipment, sensor arrays, or handheld equipment, Atlas Scientific™ brings you the power and flexibility of a laboratory grade conductivity meter, designed exclusively for robotics.”

Given these statements, this circuit should be far more accurate than what is most likely “good enough.”  Where “good enough” is helping to grow healthy plants through hydroponics.

Communications between the Arduino and the EZO happen either over UART or I2C.  Since UART is the default and simplest method, I will use UART.

LEDs

The EZO has an RGB LED on the upper left side.  It is useful for determining the status of the board.  The different states  are discussed on page 6 of the data sheet.

Wiring Up

Time to set up the prototype on a breadboard.  Here’s the wiring diagram Atlas-Scientific provides in the data sheet:

EZOWiring

Since the EZO supports I2C, I went ahead and followed the instructions to switch the EZO into I2C mode.

The Firmware

I will be using the Arduino sketch found here.  I like it’s simplicity.  Feed in a command from the data sheet and the firmware sends the command to the EZO stamp.  Any responses are printed on the serial monitor.

Sending an I to the EZO through the serial monitor returned

?I,EC,1.1

Terrific – a NEW YIPPEE moment…the breakout board is working!

The first thing I needed to do was to set the probe to K=0.1 (I discuss K in this post) by typing in K,.1 in the serial monitor.  According to Atlas-Scientific, if the K value of the probe is 0.1, it can accurately measure salt content between 0.0005mS to 50mS – or .5µS to 50,000µS.  

Now I’m all set to calibrate.

But….I am lazily ignoring temperature in calibrations and in readings for this round of learning.  While it is an important step, I assume (perhaps falsely) that while temperature will definitely affect the quality of the E.C. readings, for these tests I am not as interested in accuracy as I am in the general workings of reading E.C. values.

Calibrate

Before reading values for E.C., the firmware on the Arduino is calibrated using a known quantity – in this case a solution with a known amount of salt.  And as with pH, the quality of the probe as well as the amount of salt in a solution will determine how far off calibration the firmware is.

After reading the advice in the data sheet (starting on p. 9), I am going to do a two point calibration: “A two point calibration can be used to monitor the conductivity of water over a wide range.”

On the first page of the data sheet, Atas-Scientific advises: “Calibration required only once per year.”

There are three readings I must take.  Two require solutions that have a known amount of salt.  The probe came with two solutions – has a known amount of salt – 10,500µS and 40,000µS:

AS Calibration Solution

Using the command from p. 21 of the data sheet,  The first command I send to the serial monitor is:

Command

Return String

Discussion

Cal,clear

Pending

 

r

Success

0.00,0,0.00,1.000

 

Cal,dry

Pending

 

r

Success

0.00,0,0.00,1.000

 

Cal,low,10500

Pending

Probe in 10,500µS solution.  Stirred probe and let sit for 1 minute before reading.

r

Success

7162,3867,3.93,1.003

rinsed probe off in filtered water then put in 40,000µS solution.

Cal,high,40000

Pending

 

r

Success

39390,21272,25.09,1.019

 

 

 

 

EC Probe Calibrating

Now I need to figure out what the string returned when the probe was in the 10,500µS (7162,3867,3.93,1.003) solution and in the 40,000µS solution (39390,21272,25.09,1.019). According to p. 16 of the data sheet, the string returned is in the format:

EC,TDS,SAL,SG

The probe read an EC of 7,162 for the 10,500µS solution which translates to 3,867 TDS (Total Dissolved Solids). I ignore the other two readings since I do not use them. It would take me awhile to research what these two numbers mean and I’d rather spend time focusing on E.C. values.

E.C. Level in Nutrient Bath

The next step in this adventure is to fill a nutrient bath and adjust the E.C. level until it is within the range for growing healthy lettuce – the plant I am interested in growing such that every day I have enough lettuce for a fresh salad.  I’d like to say everyone in my family shares my enthusiasm for this accomplishment…but…um…sadly…. yet on to the most tasty lettuce I can grow hydroponically with fancy shmanzy (yah – not a word) electronics thrown in to support my tendencies for laziness.

Dr. Resh is a trusted expert in hydroponics.  From his post on hydroponically growing lettuce:

The EC of most lettuce formulations will be between 1.5 and 2.0 mS.

Other sites note a slightly different level.  I will start off with maintaining an EC level between 1.5 and 2.0mS.

Nutrients

I will be using the Aqua Vega nutrient mix I bought a while back.  I have it on hand based upon a recommendation I received months ago on the /r/hydro subreddit.  The markup on liquid nutrients is phenomenal.  Given what I know from mixing nutrients for my tomatoes, it has to be in the range of 1,000x!  So in the future I will figure out a chemistry and mix that.  Still, it is awfully easy to just use pre-measured/pre-made.  I equate it to eating a frozen dinner to cooking the same meal…

E.C. Level

I’m interested in growing lettuce so I will target the range of E.C. levels for lettuce.  Dr. Resh is a trusted expert in hydroponics.  From his post on hydroponically growing lettuce:

The EC of most lettuce formulations will be between 1.5 and 2.0 mS.

While other sites will note slightly different levels, I will start off with maintaining an EC level between 1.5 and 2.0mS.

Reservoir Setup

I will be using the same reservoir I used to test pH readings, a 3 gallon Rubbermaid bucket I got at a local department store:

3gallonreservoir

I built a prototype hydroponics system that pumps the nutrient path through a hose and out through feeder hoses into 2” net pots.  The hose then cycles the nutrient bath back into the reservoir:

Proto Hardware Setup

The brown box in the middle contains an EZO circuit.  There is also a peristaltic pump attached that I used to automate pH levels.  I will eventually explore automating E.C. additions into the nutrient bath using this pump:

EZO Circuit in prototype

E.C. Readings

I will be adding nutrients until the nutrient bath is within the range of 1.5mS to 1.0mS.  For comparison, I will also take measurements with my TDS tester I got awhile back.  Since E.C. values are converted to TDS, it is unfortunate that the tester I have does not return results in E.C.  I’m assuming that both the EZO and TDS tester convert EC to PPM by multiplying the EC (mS) by 500.

When I multiple .04960mS * 500ppm, the result is a TDS value of 24.8ppm – less than the expected 26 recorded by the probe (see first reading).  I assume the algorithm Atlas-Scientific uses is more sophisticated than just adding 500ppm.  After all – Atlas-Scientific charges a premium for their expertise.  Since TDS will not be a measurement I will be making in the future I will not investigate this discrepency further.

The TDS level for a healthy lettuce range given the E.C. range is 1.5mS to 2mS = 1.5*500 to 2*500 = 750ppm to 1000ppm.  I will now mix up the nutrients and start adding in increments that I think will get me closest to these values without adding too much.  A member of my family just waled past where I was mixing the nutrients and made the comment “smells like pee, are you mixing chemicals again?” …um… The label on the nutes state the dosage to be 20mL/10L or 8mL/gallon.  I’m using a 3 gallon reservoir so the first addition will be around 24mL.  I’ve added 20mL in and turned on the pump to circulate the bath.  I also added a small air stone and air pump I picked up at petco awhile back.  I’ll wait about 15 minutes before measuring the E.C. so that the bath has enough time to mix up the nutrients.  I’ll take 5 readings in sequence to get a feel for the variability of results.  Most likely the smart folks at Atlas-Scientific have applied a smoothing algorithm of some type so my expectation is the E.C. values of the readings will be close together.

State of nute bath

E.C. (EZO) µS

TDS (EZO)ppm

TDS (tester)ppm

no nutes added

49.60

26

20

+20mL (5 readings)

608,607,607,607,607

328,327,327,327,327

335,329,339,346,347

+40mL

1895,1896,1893,1893,1896

1023,1024,1022,1022,1024

 

After adding 20mL of nutes and waiting over 15 minutes, the E.C. measured about 607 from the EZO, the TDS measured around 327.  The TDS tester did not read as smooth measurement, ranging from 329 to 349.  The standard deviation of the EZO TDS readings is .4.  The standard deviation of the TDS tester is much higher at 6.76.  The folks at Atlas-Scientific did indeed enhance their firmware with a proprietary E.C. measuring technique that accommodates the not only the noise in the circuit but also the variability across reading from a probe of less quality.

Now that I feel I have a “good enough” comparison between the two meters, I am going to focus only on E.C. readings.

I need to get the E.C. to between 1,500µS and 2,000µS.  It is currently around 607 (+/- .4).  If I target the half way value of 1,750µS, The E.C. needs to be raised by 1,143µS. This is 1.88 times the value of the current reading.  Since 20mL raised the E.C. from 50 to 607 : 557µS or about twice as much nutrients.  This time I’ll add 40mL of nutes and rerun the tests.

After adding an additional 40mL of nutes, the E.C. reading from the EZO was around 1895.  Given my past experience with adding nutrients or adjusting pH (even worse since the pH scale is logarithmic!), I am fine with this being a healthy amount of nutrients to start growing lettuce with.  While not by much, the E.C. readings were a little bit more variable than the first time.  I do not see the slight variability as being significant.

So that’s it for now!

What’s Next

I want to run similar tests with SparkysWidgets minieC (latest version).  And…sigh…I’ll keep redoing the Wien Bridge Oscillator bread board until the darn thing works!

 

Thank you for reading this far.  Please find many things to smile about.

New Soldering Toys in Prep for Soldering the Healthy pH Shield

Tags

Post for August 29th, 2014

While I (anxiously) wait for OshPark to mail me my three copies of my first developer revision of the Healthy pH Board, I’m getting tools and techniques together.  I’m also looking into how I can most efficiently solder multiple boards..

The Goal

The goal of this post is to describe the techniques I plan to use to solder the components onto the Healthy pH Shield PCB.

Thanks To Those That Go Before

  • Chris Gammel.  Chris’s Session 1B Contextual Electronics course helped me make a monumental leap forward in my soldering skills.  The other students were also amazing in their abilities and sharing what they know.  I love being the person who has the most to learn in a class and being able to keep going through the firehose of learning!
  • OshPark for making it possible to inexpensively, easily, and quickly (but of course not quick enough :-) ) to fabricate PCBs!
  • OshStencils for providing a service to create inexpensive stencils.
  • Curious Inventor and EEVBlog for creating some great videos on soldering techniques.

Previous Efforts

We did a lot of soldering of SMD components onto a PCB during Session 1B of Contextual Electronics.  The biggest challenge was soldering the MCP3901 ADC 20-SSOP.  Wow – this is one small part for my soldering skill set!  After much frustration with my soldering iron, I ended up getting an AOYUE 968A+.  While I appreciate the smoke absorber, the hot air soldering iron.  How did I live without it?  

Yet, I am proud of the soldering job I did with the soldering iron and solder:

in order to use an MCP3901 on a breadboard, I decided to order an SSOP to DIP adapter from Sparkfun. I used the soldering method described in this Curious Inventor Surface Mount Soldering 101 video.  I found:

  • holding the part over the pins
  • applying the right amount of solder.  To conquer this, I used a lot of flux on the pads and then just used the solder from tinning the tip.  I found adding any more solder created clumps that took me a LONG time to clean up with a solder wick.
to be the biggest challenges.

A fellow student in my Contextual Electronics course had occasionally used self closing tweezers for holding parts in place.  What a great idea!  I found using self closing tweezers to be a tremendous tool for holding the MCP3901 in place on the SSOP to DIP adapter.

I got these on eBay – although I would advise getting a smaller size.

Happily, the soldering worked and I can now prototype circuits that include the MCP3901.  A definite YIPPEE! moment.

Soldering the Healthy pH Shield

Given my experience and current skill set I’m exploring a few different ways to solder the components onto the Healthy pH Shield.  They share a common point in that I decided the easiest method for me is to use reflow.   This way, my overly shaky hands won’t get as much in the way.

Pieco Paste Press + AOYUE Hot Air Soldering Iron

The biggest challenge I have had with using the hot air soldering iron is getting the right amount of solder onto the teeny-weeny pad.  I started looking for inexpensive methods of solder paste dispensing that was better than my fat thumb pressing on a syringe.  I ended up buy a Pieco Paste Press on Tindie.  I broke my own rule when buying.  I like to ask a support question and see what response I got.  I wrote both a message on Tindie to Pieco as well as tweeted a question to their twitter account.  I did not get a response on either one.  I was surprised.  A big reason I like to buy from “the small guys” is because I have this perhaps unfounded belief they are passionate not only about their product but also their customer.  Having done support for my own company, I can imagine the person or few people to be “really busy” but in my experience I always found time to at least let the person know I don’t have time…

I also bought 10CC of ChipQuik solder paste from digikey.com.

Awhile back I had bought several soldering practice boards from ebay.

Practice Soldering PCB

I tried the Pieco paste press with a 23GA tip.  The solder came out easy enough.  However, I had trouble getting a straight line on a pad like is shown on the Pieco video.  After putting on lots of flux, I tried to “carefully” put the solder paste on the pads.  Hopefully, I will get better over time.  For now,  the best I could do was spread the past along the pads and pins then turn the hot air reflow iron on….

PCB With Solder

I circled the two areas where I used solder wick to pick up the extra solder gluing the pins together.

I thought the solder paste worked well – at least better than the last I got.  More experience and finding out what others use will evolve my choice.  I’ll keep using the Pieco paste press when I do this type of soldering in the future.  Right now I am not overly wowed by the outcome.  However, the lack of precision could very well be on my lack of knowledge and skill in how to best use the paste press.

Stencil + Hot Air Soldering

Once I (geez – it’s hard to wait!) get the dev boards from OshPark, I’m very excited to try out the stencil I just received from Osh Stencils.

 

OshStencil

I’ll be using the technique Dave showed in his EEVblog video #415 – SMD Stencil Reflow Soldering Tutorial.

Another way to get to a stencil….Thanks to a posting from the Amped Hour subreddit, I read this blog post on DIY Stencil.  I hope to try this technique in the future!

Stencil + Oven Reflow

Our local hacker space – Metrix Create Space – has a reflow oven I can lease by the half hour.  If I’m not too lazy, I plan to find my way there and give oven reflow a twirl…

 

So much to learn…

Thank you very much for reading this far.  Please find many things to smile about.

1st Stage of the E.C. Circuit – Wien Bridge Oscillator on a Breadboard

Tags

,

Post for August 28, 2014

As noted in this blog post where I walked through SparkysWidgets’ miniEC, the first stage of the E.C. circuit is a Wien Bridge Oscillator.  The goal of the Wien Bridge Oscillator is to create a low distortion sine wave.  The sine wave is used to inject current into the E.C. probe so that the probe can measure conductivity.

The Goal

The goal of this post is to explore a bread board implementation of the Wien Bridge Oscillator circuit used in the Healthy E.C. Shield (Healthy E.C. Shield project files are available on this GitHub repository).

Thanks To Those That Go Before 

I like to take a moment to reflect on folks who have positively impacted my life by sharing their knowledge.  Certainly I would not be able to write this blog post without advice, guidance, and insight from:

  • The incredible wealth of information that has been shared on the Internet.  THANK YOU.  I grew up in the pre-Internet age where there was very little knowledge sharing.  Learning was focused on one test after another.  Now for most of my learning the only thing stopping me is the quality of my Google Search terms.
  • Chris Gammell.  Chris is the real deal.  He knows his electronics.  He is an incredibly great teacher.  I highly recommend his Contextual Electronics course.  You can start to get to know Chris by listening to The Amped Hour podcast.  
  • Ryan (SparkysWidgets).  Ryan’s work and sharing knowledge on his pH and EC sensors have been the basis of my knowledge of these circuits.  Ryan is an incredibly sharp person who is indefatigable in his effort to share his knowledge.

LTSpice IV Model

Using LTSpice is a great way for me to learn and feel more comfortable with a circuit.  This LTSpice IV model shows the three parts of a Wien Bridge Oscillator:

LTSpice Wien Bridge

  • Bandpass Filter:   A bandpass filter is used to set the frequency at 1.6KHz.  

    I’ve been told a frequency of at least 1 KHz is needed to avoid electrolysis: 

    • based on comments found on this web page:  “If the frequency is high enough (>1khz it seems) the molecules dont have time to move apart before they are pulled in the opposite direction.” 
    • Ryan uses this frequency for the miniEC – which he has tested with. Ryan’s reasoning:Really anything over 1khz should work well, the idea is get into a higher speed AC signal so that you do the least amount of damage to the water chemistry that you are trying to read, Passing DC through salty water breaks down the salts and causes electrolysis.  Both of which are really bad if your intentions are to measure that salt content and not disturb the SUT. 
    The R’s and C’s that make up the bandpass filter has R3 = R6 = 1K and C5 = C6 = 100nF. applying the frequency formula: f = 1/(2∏RC) = 1/(2*3.14*1000*.0000001) ~= 1.6K
  • Start Oscillation:  This post notes a property of Wien Bridge Oscillators:Initially the gain set by R5 and R4 will be just slightly greater than 3, this will allow oscillations to start. The Gain =  1 + 22K/10K = 3.2. 
  • Stabilize:  Once the oscillation gets going it stabilizes to 3 using diodes to reduce the resistance of R5.
Results from running the simulation:

  • The op amp output has a VPP ~= 460mV
  • The inverting and non-inverting inputs have a VPP of ~= +/- 163mV.

Bread Board

I am using the LMC6041 op amp and 2 diodes I had purchased earlier from our local electronics store, the NTE519.

Op Amp Pins

I broke the circuit int three sub circuits so that bread boarding would be easier.  I checked the values for the resistors, capacitors, and diodes with my Extech 330 DMM.

Group A Subcircuit

Group A sub circuit goes from the inverting input of the LMC6041(pin 2) to the output of the LMC041 (pin 6)

Group A Subcircuit Wien Bridge

Group B Subcircuit

Group B Subcircuit goes from the inverting input of the LMC6041 (pin 2) to the non-inverting input (pin 3).

Group B Sub Circuit Wien Bridge

Group C Subcircuit

Group C subcircuit goes from the non-inverting input (pin 3) to output (pin 6).

GroupC Subcircuit Wien Bridge

Results

I am using a Rigol DS1052E Scope.  On my first try, I was just getting noise!  Ach!  I removed all wires and components, leaving the op amp’s pin 4 connected to GND and pin 7 connected to +4.68V.  I then checked the voltage on pin 6.  Nothing…hmm…luckily I had gotten two op amps since what can go wrong will go wrong.  The other op amp showed +4.68V on the output pin 6.  Switching over to this op amp….doing the wiring again….and again….

Pin 2 – Inverting Input

Pin 3 – Non-Inverting Input

Pin 6 – Output

Overview of the Healthy EC Shield

Tags

Today’s Post: August 27, 2014

I am building a Healthy EC Arduino Shield.  This shield is a complement to the Healthy pH Shield.  I started using Sketchup in my design workflow – what a terrific 3D modeling application! There are a lot of models for Arduino folks.  I started the image below with a shield and a few components I found within the model library.

Sketchup Of Healthy EC Shield

The Healthy EC Shield will measure the E.C. of a nutrient bath. If more nutrient is needed, the shield will tell a pump to add more nutrients. I am stacking the E.C. Shield on top of the Healthy pH Shield in order for it to use the Healthy pH:

  • The 5V regulated Wall Wart power supply.
  • The Temperature measurement circuit and firmware.

The Goal

The goal of this post is to introduce the design of the Healthy E.C. Shield I am working on.  If I’m really successful some of you will want to share improvements to this work! 

Thanks To Those That Go Before 

For this project I wish to thank:
  • Chris Gammell.   Chris has empowered me with the mind set and abilities I need to build the circuits – going from design to Gerbers.  I would never have been able to build this shield within this timeframe without Chris.  I have a habit of listening daily to passages from Proverbs.  There are many passages about the importance of knowledge. Here’s one that summarizes why paying Chris the small amount of money he requests for what I receive is an honor: Proverbs 8:10 – 11: Take my instruction instead of silver, and knowledge rather than choice gold, for wisdom is better than jewels, and all that you may desire cannot compare with her.  Perhaps the most surprising and wonderful gift Chris has given me is the confidence to do electronics at a level that I did not think was possible within a year.  Chris doesn’t assign a learning profile.  Rather he assumes his teaching and a student’s determination will make it possible to climb most electronic mountains.  This was tested when he had our Contextual Electronics class soldering 0603 SMTs and his creative method for soldering on the MCP3901 on the bench buddy.  Chris brings with him a talented group of individuals who take his course, listen to his podcasts, read his blog posts.  Talented individuals who have taken the time to help me – such as the folks that were in my Contextual Electronics course.
  • Ryan (SparkysWidgets).  I have poured many hours into learning how Ryan put together the schematics for the minipH and miniEC.  If he had not made these open sourced I would not think it possible to design the Healthy pH shield.   Ryan is extremely giving in sharing his supreme knowledge about analog circuits.  I use the minipH within a breadboard prototype to control the pH of a 3 gallon bath.  His work has been instrumental in my understanding of a pH circuit and how to go about designing one.  My goal of building the Healthy pH shield would be far (far) more difficult if Ryan had chosen not to publish the schematics.  Ryan’s additional insights go above and beyond what I could wish for.

Open Source Hardware

I use:

  • LTSpice IV for circuit modeling
  • Sketchup for 3D modeling 
  • kicad for schematic design and board layout.  
The files are located here.  I would GREATLY APPRECIATE feedback/improvements!

Thoughts on the Design

EC Circuit – Op Amp

The EC Circuit (kicad file EC.sch) uses three op amps.  My PoR – it is not uncommon for me to change to another part as I learn more – is to use Microchip’s MCP6244 (data sheet, digikey.com page).  I am concerned this chip might not be available in quantities in the future.  After contacting digikey.com over email and receiving this reply: Thank you for contacting Digi-Key with your inquiry. As far as I can tell neither the manufacturer nor Digi-Key intends to discontinue the MCP6244-E/SL. The part that we have in stock is packaged in tubes. 57 to a tube. That is why there are no price breaks over 100 pieces. If larger quantities are required we also offer the T&R packaging under Digi-Key part number MCP6244T-E/SL-ND. Which can be ordered in multiples of 2600. It is a non-stocking part for us so you obviously need to plan ahead for a manufacturing run. OK, so I’ll keep using the MCP6244 in this design.  I use the MCP6241 in the design of the Healthy pH which gives me the benefit of already being familiar with the chip’s design and pin out.

Input Bias

When I was designing the (first iteration of) the Healthy pH Shield, I took a look at longer look at the acceptable Input Bias (IB) of the op amp to use in the design.  I figured a really low IB would be awesome.  However, it would end up driving up the BoM.  On the other hand, if the IB is too high, it will be impossible to get readings.

At this point I am making a leap of faith in believing the acceptable IB will be similar to a pH meter’s.  I should look at this more closely.  Here is my rationale based on my design of the Healthy pH Shield:

In TI’s app note, the writer notes (1.3):…even a small input-bias current can produce a large voltage error when injected into the very high impedance of a pH electrode…They go on to recommend the LMP7721 (digikey page) which costs $11.17 @ 1 quantity (OUCH!). The IB is indeed low at 3fA.  But is this low of an IB current required?

The resolution required of the pH sensor is .1 pH value.  A pH reading is based on a line from +/-.414 with a (calibrated) slope of 59.16mV when the temperature is 25˚C and the probe is working perfectly.  This gives me an estimate for how much IB can be tolerated in the Lettuce Buddy design.  The circuit needs to detect differences of at most 5.9mV.  I’ll allow 2.5mV noise (after calibration and temperature adjustment). Using I=V/R and assuming R = 500MΩ, IB = 2.5mV/500MΩ = .0025V/500,000,000Ω = 0.000000000005A = 5pA.  If I assume the output impedance of the probe is 1GΩ, the maximum acceptable IB is 2.5pA.Thus any op amp with an IB <= 2.5pA will work.

Offset Voltage

I’m less concerned about the input offset voltage.  The Input offset voltage will get calibrated out.  To calculate the slope, the probe is calibrated by measuring readings in a solution that is at 10pH and then 7 pH.  The slope is then calculated between these two points.  This gives a value “around” 59.16mV – based on the quality/age of the probe, the temperature of the bath, and  the offset voltage.

Use Three Op Amps

While the part I am using has 4 op amps, I will only be using 3.  The concern here is there might be voltage leakage on the (inverting and non-inverting) inputs of the op amp.  The voltage could leak its way through the op amp.  By doing so, the readings are no good.  This is why a 10K pull down resistor is placed between the inverting and non-inverting inputs of the third op amp in EC.sch.

Measuring Conductivity

An E.C. value tells us how conductive a nutrient solution is.  

As noted in this post on the miniEC circuit – EC is measured in Siemens (S) – a measurement of conductance.  
From information in this post:
Conductivity is an index of how easy it is for electricity to flow. In water, it is the ions that pass electricity from one to the next. This means that the more Na+ and Cl- contained in water the more electricity is carried, and the higher the conductivity.

Conductance comes from the separation of NA+ and CL- ions when salt (NaCl) is placed in water.

Conductivity is the inverse of R.   Plugging in Ohms law, V = IR, V/R = I, V*C=I, C=I/V.  

Thus one goal of the E.C. hardware and firmware is to find out the amount of resistance in the nutrients and convert it to an E.C. value.

Given an E.C. value, we can go to a chart that gives us a range of acceptable values for a particular plant.

To illustrate the application of E.C/Conductivity in hydroponics, I took the recommended E.C. range from this web page for popular plants:

Plant

E.C. (mS)

R (Ω)

Lettuce

0.8 – 1.2

1,250 – 833

Tomato

2.0 – 5.0

500 – 200

Cucumber

1.7-2.5

588 – 400

Basil

1.0 – 1.6

1,000 – 625

The better the conductivity, the lower the resistance.  Tomatoes seem to have one of the best conductivities.  I’m guessing this means there are more nutrients (or denser?) for tomatoes. 

Choosing a Probe to Match the Conductivity

A term that comes up with E.C. measurement is K (the cell constant).  According to this post:

The cell constant, K, is equal to the distance in cm between the probe’s electrodes divided by the surface area of the electrodes in cm2. For solutions with low conductivities the electrodes can be placed closer together or made larger so that the cell constant is less than one. This has the effect of raising the conductance to produce a value more easily interpreted by the meter. The reverse also applies, in high conductivity solutions, the electrodes are placed farther apart or made smaller to reduce the conductance of the sample. By using the appropriate probe, K=0.1 for low conductivity solutions, K=1 for normal solutions and K=10 for high conductivity solutions, accurate measurements across the full range of conductivity values can be made.

While any conductivity probe can be used with the Healthy EC Shield, I will start out using a conductivity probe with a K value of 0.1 based on the chart provided by Atlas-Scientific (p. 7) and the explanation above (For solutions with low conductivities the electrodes can be placed closer together or made larger so that the cell constant is less than one. This has the effect of raising the conductance to produce a value more easily interpreted by the meter).

K Value

Accurate Reading Range

Resistance Range

0.1

0.0005mS to 50mS

2MΩ to 20Ω

1.0

0.005mS to 200+mS

200KΩ to 5Ω

10

0.01mS to 1S

100KΩ to 1Ω

 

The Side Effects of Injecting a Current

In order to get a reading, an E.C. circuit injects a small amount of current into the nutrient.  A side effect of this is a pH reading taken while the current is being injected will be disturbed.  So don’t take a pH reading at the same time an E.C. reading is taken.  I’ll be handling this in the firmware.

The Importance of Temperature

The firmware must take the temperature of the nutrient bath into account when figuring out the E.C.   I thought this post gives good advice:

The effect of temperature on conductivity readings depends on the solution being measured. The effect is greatest in low ionic strength (low conductivity) solutions. A general rule to follow is there will be a 2% change (increase)/˚C

Adding Nutrients

After the firmware takes a reading, it determines how much (if any) nutrients need to be added to the bath.  One of the things I will be iterating on is when and how long to turn the pump on and off.  My tests will be focused on the range of E.C. values for lettuce.

Next Steps

I have an EZO-EC breakout board from Atlas-Scientific that I am going to test calibrating and getting readings.  A future post will describe what I did.

 


Additional Learnings About the minieC Circuit

Tags

, ,

This post is a follow up to this post – where I dissected SparkysWidgets’ minieC circuit.

Thanks to Those that Go Before

 While this is a short post, It is important to thank exceptional folks whose sharing of their knowledge has greatly benefited my learnings.

  • @SparkysWidgets –  Thank you for your help.  You have been inspirational.  if you are interested in this stuff, PLEASE check this person out!  I will be borrowing heavily from the minieC product and schematic.  
  • The person behind this wonderful post on the electronics behind an EC sensor.
  • Chris Gammel - our very knowledgable and gifted instructor of Contextual Electronics.  A course I would highly recommend if you are interested in turning your prototypes into PCBs and learning tons about electronics along the way.  The more time I spend with Chris, the more I realize what an exceptional person – both in knowledge and in ethics – he is.  Chris is amazing at clarifying circuit concepts!
  • Mike Engelhardt – thank you for LTSpice.  What an exceptional contribution to circuit designers!

Follow Up on minieC Readings

At the end of the post I was curious about the waveform of the digital signal that comes out of the last op amp and then read by the ADC.  I thought it should look like this:

rectifiedACSignal

but it looked more like this:

minieCRectified

I brought this up with Chris during our Google Helpout (note:  I do not get paid for endorsing Chris – quite the opposite – I get a lot of value from Chris and hence pay him – you can sign up to talk with Chris via a google help out.  The link is here).

Chris asked that I try several values for C7 and then several values for R10.  

I tried 10pF, .1µF, 1µF, 10µF, and 50µF.  I ran the simulation twice.  The first time R0 – the substitute for the E.C. Probe – was set at a resistance of 200Ω.  This is about the resistance I would expect for a tomato nutrient bath.  The second time the resistance of R0 was set at 1000Ω – what I would expect for the nutrient path if the plant was lettuce.

SeveralValuesForC7

Here are the results when C7 was set at 10pF, 1µF, and 50µF:

StepSimulationCap

R0=200Ω

R0_1000_SeveralValuesC7

R0 = 1000Ω

As expected, the waveform smoothed out as the value of the capacitor got larger.  The 1µF capacitor is what is used in the minieC design.  The 10pF looks too noisy.  As R0 got larger, the smoothed out voltage value began to give a larger value.  Given this, 1µF seems like a “best” fit for this design scenario.

The next LTSpice simulation I ran was to keep the capacitor at 1µF and plot R10 values for 100Ω, 1KΩ, 10KΩ, and 100KΩ.

The first image set R0 at 200Ω (closer to the tomato range):

DifferetR10R0200

R0 = 200Ω

 In the second simulation I set R0 to 1KΩ – what I expect for lettuce:

SeveralValuesForR10R01000

R0 = 1KΩ

Given the results, it looks like Sparkyswidgets’ choice of 10KΩ for R10 makes sense.

 

That’s it for now.  A simple update to share my LTSpice results to determine the “best” values for smoothing out the DC current going into the ADC without smoothing out the value too much.  It looks like the choices made were the right ones.

 

Calibrating pH using Sparky’s Widgets minipH

Tags

,

I spent a chunk of time understanding the design of SparkysWidgets minipH breakout board.  I posted what I learned here.  My conclusion is – at least at this stage – nice design!  I’ll use SparkysWidgets minipH in my current prototype.

The Goal

The goal of this post is to get the pH readings of the miniPH as accurate as possible.

The Setup

minipHSetup

The pieces in the picture include:

  • the minipH breakout board
  • an Arduino Uno
  • a breadboard
  • jumper wires
  • pH probe and calibration solution from Atlas Scientific.   I had purchased the pH kit earlier and used it to run tests which I documented in this post.
pH Kit

While I consider the price on the high side, I am using the probe and calibration solutions from the kit because Atlas Scientific is known for quality products and I have familiarity and confidence in them based on my prior use.  

The Process

The process to reach the goal will include:

  • Understand results from running Sparky’s Widget’s minipH.ino.
  • Calibrate the readings.
  • Implement any changes to the setup and Arduino sketch that will improve the readings.
  • Document final readings.

Initial Run of minipH.ino

It was very easy to wire the prototype.  All I needed to do was solder headers onto the minipH breakout board so that the Vin, GND, and I2C (SDA and SCL) pins can be wired to the Arduino. 

I ran the sketch when the pH probe was in each of the calibration solutions and took a screen shot of the serial monitor:

pH 4

pH 7

pH 10

I was happy to find the results were reasonable since I hadn’t calibrated yet. 

Evolution of minipH.ino

minipH.ino gives me the basics of what I need to calibrate the pH voltage step and to read the pH.  I will evolve this sketch to:

  • use a state machine to handle input.  This will make the code easier to read and easier to change to different displays.  The first display I will  use is the serial monitor.
  • calibrate based on a weighted average of several readings.
  • determine if the probe needs to be replaced.
  • read the pH.  In this case there is no need to change what Sparky’s Widgets has done.
  • show the info on what was used in calculating the pH voltage step.   I will use what Sparky’s Widget has provided and add to it.
The sketch – minipH_bitknitting.ino –  is located here.

State Machine Input

I based input from a person using this system on the following state machine:

State Valid Keys or Code To Run Next State Outputs
INPUT_CHAR 4,7 CALIBRATE  
  ? HELP  
  p,P CHECK_PROBE  
  r,R READ_PH  
  <any other character> INVALID_ENTRY  
CALIBRATE -> calibrate pH INPUT_CHAR Display new slope
READ_PH -> read pH   Display pH value
HELP -> show help INPUT_CHAR Display inputs
CHECK_PROBE ->check probe INPUT_CHAR Display amount deviation and $ noise in readings
INFO ->show info INPUT_CHAR Display the params used in calculating the pH
INVALID_ENTRY ->print message, go to help HELP Display invalid entry text

Calibration

For a pH probe to match default (ideal) readings, it is assumed there is a voltage change of 59.16mV per pH unit (I’ll refer to the voltage change per pH unit as the pH voltage step.  For example – in the ideal –  a pH of 0 reads 59mV higher (0.414V) than a pH of 1 (0.355V).  One thing that has been stamped in my mind from doing pH explorations is the importance of calibration.  Each pH probe is going to measure the pH differently.  A big factor is how the voltage measurements that come in through the ADC and then converted to a pH value vary from the ideal readings.  Knowing this variance from the ideal readings allows the formula for calculating the pH to be adjusted and hence more accurate.
The sketch has two commands for calibration:
  • 4 – assumes pH probe is in a pH 4 calibrated solution.  Takes the reading and adjusts the pH voltage step to use this reading.
  • 7 – assumes pH probe is in a pH 7 calibrated solution.  Takes the reading and adjust the pH voltage step.
Here is the line of code that adjusts the pH voltage step:
 
params.pHStep = ((((vRef*(float)(params.pH7Cal – params.pH4Cal))/4096)*1000)/opampGain)/3;
 
if you find this line of code confusing – not to worry – check out this post and minipH.ino.
Values to take note of in this equation include:
  • 4096
ADCImage
as shown in the image, an ADC takes in an analog input and puts it into a discrete step.  In the case of a 12 bit ADC – which is used by the minipH – there are 4096 discrete steps – 2^12.  In comparison, the ADC on the Arduino is 10 bit. This means there are 2^10 discrete steps = 1,024 discrete steps.
  • vRef – as the shortened name implies, this is the voltage reference.  It determines the mapping between the analog and digital output.  For example, the vRef of the MCP1541 is a stable 4.096.  When a reading comes in from the ADC, it’s discreet value will be between 0 and 4095.  Which discreet value will be determined by VRef/4096.  4.096 is a great VRef for 12 bit ADCs since 4.096/4096 is 1mV.  When the VRef is 4.93V – for example what I might see when using the USB port on my Mac as a power source, the division is 4.93/4096 = .001203613 – not as even a chunking of the analog into discreet parts.  I’ll discuss this a bit more below.
  • opampGain – recall in my earlier post the first op amp was used to amplify the voltages coming in from the pH probe.  This is what the opampGain is.  In the schematic for the minipH, the op amp gain is 5.68.

 VRef

When I looked closer at the minipH breakout board, I noticed it did not include the MCP1541 as the schematic shows. The schematic seems to not be up to date with the actual minipH breakout board.  OK.  I can’t use the AREF of the Arduino, because AREF assumes the Arduino’s 10 bit ADC is being used.  This means I will use the 5V out of the Arduino as the VRef to the ADC.  Every time I have measured Arduino’s 5V out, it has been higher that 4.096, typically around 4.93.  Yet constantly measuring and adjusting the vRef variable based on DMM readings was a non-starter for me.  I could decide to use 4.93 – assuming this is “close enough” or somehow I could get the actual value of the Arduino’s 5V out.  A Google search and I have found code from a very sharp person that indeed calculates the 5V out.  How terrific is that?  I may not be capable of figuring this code on my own, but happily – this person shared!  See the readVcc() function in minipH_bitknitting.ino.

Output from the readVcc() function and my DMM got the same value – 4.94V for Arduino’s 5V out.  mV results from a few ADC readings when the probe was in the pH 7 calibrating solution:

 

ADC 4.096 4.94
2104 2.10 2.54
2106 2.11 2.54
2124 2.12 2.56
2107 2.11 2.54
2120 2.12 2.56

shows the difference when vRef is left at the default of 4.096 and not what is used when the MCP1541 is not use is about .5mV.  I had this table that maps the pH value to the expected ADC reading (shift column) in my previous post:

pH Signal(s) -(S*Gain) Shift
0 0.414 -2.179 0.339
1 0.359 -1.869 0.649
2 0.309 -1.559 0.959
3 0.249 -1.249 1.269
4 0.189 -0.939 1.579
5 0.129 -0.629 1.889
6 0.069 -0.319 2.199
7 0.009 0.009 2.509
8 -0.069 0.319 2.819
9 -0.129 0.629 3.129
10 -0.189 0.939 3.439
11 -0.249 1.249 3.749
12 -0.309 1.559 4.059
13 -0.369 1.869 4.369
14 -0.419 2.179 4.679

 Using the result from readVcc() gets a value that is closer to what I would expect to be more accurate.

 Op Amp Gain

At first I was surprised to see the opAmpGain set to 5.25 in minipH.ino.   After a closer check at the minipH schematic

minipHSchematicGain

 

the two resistors – R8 and R7 – used for the gain, I found R8 on the PCB to be 200K.  So the OpAmpGain is indeed 5.25 and not 5.7 as calculated in the previous post.

I am using a weighted average of many readings when calculating the pH voltage step.
I decided to take multiple readings and weight them because given the characteristics of the readings to aid in eliminating noise.  One spot where noise occurs when the pH probe takes the reading.  The pH probe is made of glass which isn’t that great in creating an electrical circuit.  This means it has a very high output impedance, typically around or more than 100MΩ. SpakysWidgets notes: “A typical probe has an impedance of anywhere between 50MΩ and 500MΩ, and since 100MΩ*1nA=.1v even having a single stray nano amp can throw our measurement off by almost 2 entire ph units.”  Here is the chunk of code I added to use a weighted average of multiple readings when adjusting the pH voltage step:
  int adc_result;
  unsigned long currentMillis = millis();
  lastpHCalibrationMillis = currentMillis;
  while (currentMillis – lastpHCalibrationMillis < pHReadCalibrationPeriod) 
  {       
    //get a pH reading (assumes pH probe is in a calibration solution)
    adc_result = readADC();
    float last_pH = params.pHStep;
    //modify the mV between pH readngs by the current adc reading
    if( pHCalibrating == 4 ) calibratepH4(adc_result);
    if( pHCalibrating == 7 ) calibratepH7(adc_result);
    //add the new calibration reading to the weighted average.. putting a weight of 70% on latest additions was decided as a starting place…
    params.pHStep  = .7 * params.pHStep + .3*last_pH;
    Serial.print(“pH Slope: “);
    Serial.println(params.pHStep);
    currentMillis = millis();      
  }
  //write the new pH voltage step unit to EEPROM so that it is stored in ‘permanent’ memory
  eeprom_write_block(&params, (void *)0, sizeof(params)); //write these settings back to eeprom

Replacing

 Like tires on our cars, pH probes deteriorate to the point in which they must be replaced.  Or perhaps the pH probe is not up to the job.  But how off should the pH readings be from the ideal before I must use a different pH probe?  Based on information provided in this post:
Generally speaking, when an offset of more than 30 mv (at 7.0 pH) develops or more than 2 minutes is required for a probe to stabilize in a buffer solution a probe has reached end of life or needs reconditioning.
 
Based on this sentence, there are two things I should look at to answer if I need to replace my pH probe:
  • the pH 7 reading of a calibrated solution should be 0mV.  Is the reading > 30mV or <-30mV?
  • are the pH readings within a 2 minute time below an acceptable noise threshold?
I don’t know what the acceptable noise threshold should be.  I’m thinking it should be fairly relaxed to accommodate the inherent noise of the readings.  I’ll start with 10%.  See minipH_bitknitting.ino.
TBD: code

Reading

Sending the ‘r’ or ‘R’ character to the arduino takes a pH reading.  Check out the readpH() function to walk through how the pH is calculated based a reading of the ADC.  

Reflections

My Yippee! Moment came when it appears the minipH probe worked as advertised.  It is a nice, simple design.  I was surprised to find the VREF IC was not there.  However, given the resolution of the readings, using the function to calculate the Vin seems to work fine.

What’s Next

I plan to evolve my knowledge of the minieC sensor using the same methods I used to understand the minipH sensor.  By doing so, I am gaining a practical understanding of the components in the circuit.  With perhaps op amps being the star of the show.   

 

 

Thank you for reading this far.  I hope you find many things to smile about.

 

A Salad a Day – The Charge Pump: -V(Out) and AC Noise

Tags

This post is about figuring out how much -V is being delivered by the charge pump IC to the op amp IC I used  I used in the pH Circuit I breadboarded in an earlier post.

The Goal

The goals of this post include:

  • knowing the -V rail to expect for the op amp I use in the breadboard pH circuit.
  • gaining a solid understanding of AC Coupling as it applies to detecting AC noise coming from the Vout of the Charge Pump.  I cover the Charge Pump and its pins in this post.  The V(out) of the Charge Pump is used to provide -V to the op amp in the pH circuit such that negative pH signals can be read.
  • deciding if the pH circuit needs to evolve to reduce the AC noise that is attached to the V(out).

Thanks To Those That Go Before

These folks have made a tremendous positive impact helping me learn the electronics concepts and practicalities that I needed to complete this prototype of a pH circuit.

  • @SparkysWidgets –  His phSensor schematic and blog post is all you need to get started.  Because I lack the background in electronics, I didn’t understand much of the post at first.  This got me writing out what I learned here.  This person has been exceedingly thoughtful and open with his knowledge.  Kindly (and I assume patiently!) pointing me in the right direction.  Please consider supporting his efforts.
  • Chris Gammell - our very knowledgable and gifted instructor of Contextual Electronics.  A course I would highly recommend if you are interested in turning your prototypes into PCBs and learning tons about electronics along the way.  Chris’s teaching style is exceptional.  He teaches more like a knowledgable guide.  He does first what he expects us to do, examines his mistakes, and constantly seeks and uses feedback from his students.  Chris is exceptional.  His efforts are another I highly recommend support in
  • Gabriel Anzziani – the creator of a very nicely done oscilloscope for the price.  This is the first time I used a scope.  I admire Gabriel’s ability to keep a tool simple. THANK YOU!

Debugging Tools

A challenge I have with using both tools for measuring voltage and current is receiving different readings.  It is becoming too time consuming to properly measure everything.  I will restrict voltage, current, resistor readings to coming from the EX330.  The Oscilloscope will provide a view into the noise around the signal – which means there is a voltage – time relationship / graph.

Test Scenario

To measure the amount of AC noise coming from the V(out) of the MAX1044, I disconnected the TL072 op amp from the MAX1044 on the pH circuit in order to isolate the Charge Pump from the Op Amp.

imageOfBBTestSetup

I then measured the Voltage .  The intent with adding the resistors was to add: no load, around 5mA load, and around a 10mA load.  These current values were chosen because the spreadsheet notes:

They deliver 10mA with a 0.5V output drop.

The words in this sentence lead to potentially different interpretations.  I assumed:

  • “They” means the MAX1044
  • “deliver 10mA” means UP TO 10mA
  • “with a 0.5V output drop” means any load will cause the voltage output drop to be .5 V.  Thus, the maximum value for -V(Out) = power source voltage – .5V.  Meaning a perfect Arduino Uno 5V source allows a -4.5V rail.  In a breadboard prototype the 5V source varies a bit in value – typically from 4.8 to 5.02, so the -V(out) will also vary by this amount.
Sanity check: Since I’m pairing the MAX1044 with the TL072, how much current does the TL072 need?  According to the data sheet for the TL072, Each op amp needs a max of 2.5mA.  There are two op amps, so the max needed is 5mA.  The MAX1044 can deliver this, at a cost of .5V on the -V rail.  I expect a -V rail of around -4.5V.

-V(out) Measured Results

This is what I measured:
Measured Expected Measured
R I I -V(out) Arduino V
470 -0.00745 -.00796 -3.74 4.96
510 -0.00759 -.00788 -4.02 4.96
1000 -0.00437 -.00444 -4.44 4.98
2200 -0.00211 -.00215 -4.72 4.98

I had a set of resistors I’d gotten earlier.  Convenient values to measure included 470Ω, which at 5V has a current of close to 10mA.  As well as 1K, 5mA at 5V.  Based on the data sheet’s statement: They deliver 10mA with a 0.5V output drop.

I saw a drop of 1.22V with a 470Ω resistor and .94V with a 510Ω resistor.  -V(out) gets closer to the Arduino’s 5V input power as the current is lowered.  When the resistor was 1K – which is about the load of the op amp at 5mA – the measured v(out) was -4.44 a voltage drop of -5.4 volts – in close range to: They deliver 10mA with a 0.5V output drop.

I am not sure why the -V(out) is not at the .5V drop for 470Ω and 510Ω.  I am not concerned for the pH circuit since the signal range is +/-.414V – well within the -V(out) range.

I then measured the -V(out) when the MAX1044 is connected to the TL072 and the scope is inputing an AC signal of +/- .414V.  The Voltage source (Arduino) measured 4.92.  I measured -V(out) to be -4.34, a difference of .58V – close to the .5V drop noted in the Max1044 data sheet.  This result seems to be within the range of the expected.

Now I’ll move on to measuring the AC noise on the -V(out) line.

On to AC Noise

Since this is the first time I have measured AC noise, I’m documenting what I did/learned on this process.

How I measured AC Noise

When I first looked at the -V(out) signal coming out of the MAX1044, I didn’t see any noise on the scope.  It turns out it can’t be seen on the scope because the DC signal is hogging up the display and shifting the frequency (y axis).  This seems totally rude to me…but..how to shift the focus back to the AC frequency?  The focus on the DC frequency is referred to a DC bias.  In order to analyze the AC noise, the DC signal needs to be removed from the scope’s probes.  A simple way to remove the DC signal so that I can look at just the AC noise is to use AC coupling.

To measure AC noise I will use the Xminilab oscilloscope.

The Xminilab does not have AC Coupling built in.  I’m glad it didn’t because it gave me the opportunity to get a hands on understanding of what AC Coupling is by building a simple DIY AC Coupler.  Chris figured this out and showed us how to do it in a Contextual Electronics segment.  Here is an image from the scope’s manual:

ACCouplingDIY

Ah – yes…use a capacitor to filter out a signal.  So we all set about and built our AC Coupling “dohicky” which takes the place of the switch.  Here’s mine:

ACCoupler

To get closer to how the circuit will be used, I used the AWG of the Xminilab to add a sine wave as input to the TL072 op amp’s pin 3.  Then I put the wires of the DIY AC Coupler on -V(out) of the MAX1044:

XMiniWithACCoupler

And…no need to wait for it…a YIPPEE MOMENT! I could now see the AC noise on my scope:

I measured the frequency of the AC signal to be 2.7KHz,

ACNoiseFrequency

a high frequency when compared to a 1Hz pH signal’s frequency.

The ∆V =.165V,

ACNoiseOnV-Out

3.7% noise when the -V(out) is -4.34, as measured earlier.

I can think of the following ways to lower the signal noise added by the MAX1044:

  • use a larger capacitor than the 10uF connected between -V(out) and GND
  • use the MAX1044’s BOOST mode.  The data sheet notes: Connecting BOOST to V+ increases the oscillator frequency by a factor of six.  I’m thinking what this means – please let me know if I am wrong – is the MOSFETs in the MAX1044 will open/close at a faster frequency when BOOST is connected into the circuit.  The increased frequency will cut down on AC noise.
I had a 47uF and 470uF capacitors I got as part of a pack.  Here are the measurements I got for AC noise when using each sized cap:
∆V – no BOOST ∆V – BOOST
10uF 0.12 0.06
47uF 0.05 0.05
470uF 0.025 0.025
while a higher capacitor value lowered AC noise when the BOOST pin was not used, there was not much of a difference between using a different capacitor or using BOOST mode.  The results for the 470uF – the largest capacitor – seems to benefit noise reduction on top of using BOOST mode.

Conclusions

I have increased my ability to design a more robust circuit by knowing how to analyze AC noise.  As Chris pointed out to me, even a small amount of noise will cause significant errors in reading.  Particularly since the pH signal has a small amplitude of +/-.414V.  Changes I plan to make in the pH circuit to minimize AC noise include:

  • using the BOOST mode of the MAX1044
  • increasing the capacitor located between -V(out) and GND from 10uF to around 500uF

By making these two adjustments, the ~ 2.6% AC noise of the =-V(out) decreases to ~1.3%.  Adding a higher capacitor should further eliminate the AC noise to ~ .56% based on the measurements I made.  While this is a “one of” measurement on a bread board prototype and every PCB/chip arrangement will vary the results, the general take away I have is to use BOOST mode and a larger capacitor to lower AC noise in the pH signal circuit.

What’s Next

I’m going to let my new found conclusions stew a few days before I update the pH circuit schematic.  Maybe my conclusions are ill-informed.  I am hoping one of you kind readers will point out assumptions or test methods I used that caused me to make incorrect conclusions.  After a few days I will update the pH circuit schematic.  I need to keep making progress on building the BenchBudEE, our project in Contextual Electronics.  Wow – I’m learning A LOT about soldering PCBs.  Another “learn by doing” I am happily lapping up is following the values of a sub-circuit as a solder on more parts.  For example, I’ve been following the schematic for the +12V, adding C’s, R’s, inductors, POTs, LM317 and LM337…after each addition, I check what voltage I get and compare it to what I expected to see.  It is the first time I have a strong look at reading the schematic, comparing that to the board layout, and then checking out the values on the actual PCB!  What an amazing experience.  The other great part here is seems to me that most folks taking the course are more advanced than me.  I LOVE being the least educated/skilled – I learn more and I am lucky that my classmates exuberantly share their techniques.  Chris did a great job setting up the collaborative environment to enable this incredible feedback.  I also want to make progress on the EC circuit.

A Salad A Day – Breadboard prototype of pH Circuit

Tags

, ,

It is time to try out the pH circuit on a breadboard.  

The Goal

The goal of this post is to match the signals on a breadboard circuit to those created from an LTSpice simulation of the pH Circuit.  I haven’t discussed the LTSpice simulation yet.  I hope to do that soon.  Chris uses LTSpice to simulate circuits he goes over with us in the Contextual Electronics course.  Wow – what an exceptionally useful tool!  Through building a simulation in LTSpice, I was able to significantly increase my knowledge of the inputs and outputs of the ICs.  This helped me better understand more aspects of an op amp.  I say more aspects, because I don’t have a strong grasp on all the varieties of ways an op amp can be hooked up.  There is also a concept or two of the inverted op amp that I still scratch my head about.  The best way for me to learn though is to try out what I know, build on that, and add as needed. 

Thanks To Those That Go Before 

These folks have made a tremendous positive impact helping me learn the electronics concepts and practicalities that I needed to complete this prototype of a pH circuit.

  • @SparkysWidgets –  His phSensor schematic and blog post is all you need to get started.  Because I lack the background in electronics, I didn’t understand much of the post at first.  This got me writing out what I learned here.  This person has been exceedingly thoughtful and open with his knowledge.  Kindly (and I assume patiently!) pointing me in the right direction.  Please consider supporting his efforts.
  • Chris Gammell - our very knowledgable and gifted instructor of Contextual Electronics.  A course I would highly recommend if you are interested in turning your prototypes into PCBs and learning tons about electronics along the way.  Chris’s teaching style is exceptional.  He teaches more like a knowledgable guide.  He does first what he expects us to do, examines his mistakes, and constantly seeks and uses feedback from his students.  Chris is exceptional.  His efforts are another I highly recommend supporting.
  • Mike Engelhardt – thank you for LTSpice.  What an exceptional contribution to circuit designers!
  • Gabriel Anzziani – the creator of a very nicely done oscilloscope for the price.  This is the first time I used a scope.  Chris recommended the XMinilab for the course.  I admire Gabriel’s ability to keep a tool simple. THANK YOU!

Debugging Tools

  • DMM – I used a DMM (Digital MultiMeter) to check the power values across the circuit.
  • Simulation – I used LTSpice IV on Windows to simulate the pH Circuit.  The simulation gave me more confidence on what the values should be at the important pin i/o’s in the circuit. 
  • Oscilloscope – I am new to using a scope.  I started with the BitScope 10 Oscilloscope . I found the UI and features to be overly complex and the user’s guide to not provide me with the easiest information to get me going.  Of course, this is most likely my problem because I do not understand not only the software, but how to use the scope.  Chris recommended the Xminilab XScope.  At first I was skeptical if this simple piece of hardware – more like a kit than a product – would help me.  To my  happy surprise I found the Xminilab to be incredibly easy to use and provides only the amount of information that I needed.  Powerful, yet had training wheels for folks like me.

The Circuit

Here is an image of the schematic I created in LTSpice:

PhCircuitDecouplingCapLTSpiceSchenatic Question

 A sine wave of +/- .414 is input into the non-inverting pin of the first op amp.  The output from the first op amp amplifies the signal by 5.681.  The second op amp takes in the amplified signal on its inverting pin. The output of the second op amp inverts and shifts by 2.5 the values of the sine wave.  This sine wave now has values between 0V and 5V, which will be read by the Arduino script.

Parts

I ordered “breadboard friendly” parts from digikey

Mft number

Digikey number

Qty

$

Description

TL072IP

296-14997-5-ND

1

0.70

8-DIP 2 channel TL072 op amp

MCP1541-I/TO

MCP1541-I/TO-ND

1

0.92

Through hole 4.096V VREF

MAX1044CPA+

MAX1044CPA+-ND

1

3.03

8-DIP charge pump

I had the following parts on hand:

Part Quantity
220K R 3
1K R 1
3.3K R 1
47K R 1
10uF C 2

The breadboard prototype differs from the simulation/SparkysWidgets’ schematic:

  • I did not have 3K resistors so I used 3.3K.
  • I did not put in C1 at this point.  I’ll get back to C1 in a bit.

TL072

The TL072 pin out (data sheet): 

TL072

I wanted to make sure that I wired the chip up correctly.  I created this table to give me a better feel for the purpose of each pin and how it maps to the LTSpice simulation:

Pin i/o name i/o description
1 Out Gain op amp pH_Gain
2 V(in-) Gain op amp V_negFeedback
3 V(in+) Gain op amp AWG (Arbitrary Wave Generator, Future: pH signal)
4 V- wired to to pin 5 of the MAX1044 (V- input)
5 V(in+) Shift op amp 5V with 1K and 3.3KΩ = 5*(1/4.3KΩ) = 1.163V
6 V(in-) Shift op amp output of Gain Loop, wired to pin 1
7 Out Shift op amp pH_Shift
8 V+ wired to Arduino 5V power supply (Future: AREF)

 

 

 

 

MAX1044

MAX1044 Inverted Charge Pump (data sheet):

MAX1044

The diagram shows polarized capacitors being used.  I asked Chris if it mattered whether the caps were polarized or not.  He said no – the reason they were polarized was because about 10 years ago (perhaps less) 10uF caps were not available.  I am using electrolytic caps because I have them on hand.

The description of the MAX1044’s pins: 

Pin i/o name i/o description
1 Frequency Boost Connecting BOOST to V+ increases the oscillator frequency by a factor of six. When the oscillator is driven externally, BOOST has no effect and should be left open.
2 CAP+ Connection to positive terminal of Charge-Pump capacitor
3 GND The positive terminal of the reservoir capacitor is connected to this pin.
4 CAP- Connection to negative terminal of Charge-Pump capacitor
5 VOut Negative output V. Connect negative terminal of reservoir capacitor to this pin.
6 LV Low-Voltage Operation. Connect to GND for supply voltages below 3.5V.
7 OSC Oscillator Control Input Connecting an external capacitor reduces the oscillator requency. Minimize stray capacitance at this pin.
8 V+ Power supply voltage input.

I did not use pins 1, 6, and 7. 

Bread Board Results

Here is the pH circuit on the breadboard:

PHBreadBoardLabeled

 

The important i/o points of the signal are the TL072’s pins:

  • 3 – a sine wave is input into the TL072.  A pH signal’s amplitude is +/- .414V
  • 1 – the output of the first op amp.  This is the pH signal that came in on pin 3 amplified by 5.681
  • 7 – the output that is to be read and interpreted by the Arduino.  This takes the output of pin 1, inverts the signal, and then adds 2.5 to each value so that all values are between 0V and 5V.
Successful results are the values at these pins for the simulation and bread board are close enough to feel comfortable the circuit is working as expected.

Input Signal on pin 3

A YIPPEE MOMENT! I was able to set the incoming sine wave to +/- .414V in the simulation.  With the XScope, I could get to +/- .420V.  Reading pin 3 with the scope shows the “close enough” signal going into the breadboard.

PHSignalLTSpice

pin3AWG

Output Signal on pin 1: Amplify pH signal

The output signal  amplifies the pH_signal by 220K/47K + 1 = 5.681.  e.g.: .414*5.681 = 2.359 and -.414*5.681 = -2.359

…and…ANOTHER YIPPEE MOMENT!…the results shown on the scope of the prototype are close enough to the results of the simulation.

 

PH Gain LTSpice

OutputSignalPin1

Output Signal on pin 7: Shift negative values to be above 0V

And…after a day of frustration…YET ANOTHER YIPPEE MOMENT!  The values that will be read from the Arduino:

Ph 5VLTSpice

OutputPin7

Values at Each pH Level

I created a table of the values I should read off the Arduino’s analog i/o pin: 

pH Signal(s) -(S*Gain) Shift
0 0.414 -2.359 0.159
1 0.359 -2.029 0.489
2 0.309 -1.689 0.829
3 0.249 -1.349 1.169
4 0.189 -1.019 1.499
5 0.129 -0.679 1.839
6 0.069 -0.349 2.169
7 0.009 0.009 2.509
8 -0.069 0.349 2.849
9 -0.129 0.679 3.179
10 -0.189 1.019 3.519
11 -0.249 1.359 3.859
12 -0.309 1.689 4.189
13 -0.369 2.029 4.529
14 -0.419 2.359 4.859

The signal goes into pin 1 of the TL072.  The output is amplified by 5.681.  I then inverted the amplified output in preparation for the value that will be the analog input.  The Shift column adds 2.5 to each value.  The values I should read in from the analog i/o pin range from 0.159 for pH 0 to 4.859 for pH 14.

Frequency Response and the .1uF Low Pass Filter

Earlier I noted the prototype did not include the .1uF capacitor that is in the pH schematic.  I didn’t include this capacitor because – while I got the right results for the op amps’ outputs without the cap – the results were very different when I put the cap in the circuit and ran the simulation.  This image shows the pH signal input (pin 3) and the output of the op amp used to apply a gain of 5.681 (pin 1).  When I put the .1uF cap into the circuit, the hard earned 5.681 magnification of the original pH signal disappeared!

HighFrequencyNoGain

No Gain When .1uF Cap in Circuit

Chris explained to me the relationship between wave frequency and amplification.  As the frequency of a wave increases, the amount of amplification decreases.  There is a rather well known plot – the Bode plot – that is used quite a bit in areas where the frequency response is important – such as audio equipment.  Here is the frequency response (Bode plot) for my circuit when an AC analysis is run with the amplitude set to 1:

PHCircuit Freq 1K Cap BodePlot

The first thing to notice on this plot is the Y Axis (amplification of the signal) uses dB to show gain measurements.  Smart people figured out that a dB value = 20*log(vout/vin) = 20*log(Gain on circuit) = 20*log(5.681) = 15.1dB.  Perhaps the same smart folks or maybe their friends also figured out that the cutoff point in which a wave will not be able to be amplified occurs when the frequency is 3dB less than when the frequency of the wave is at 1Hz.  3dB less than 15 db is 12.  That makes the cutoff frequency to be about 7.6Hz.  In order to realize the gain, the simulation needs to be set to less than 7.6.  Also notice how the gain curve goes slightly down before a significant drop off at around the – 3dB.  Thus the full gain is only fully realized when the frequency is 2Hz or less.  A far cry from the 1KHz I naively used as an input into simulating the pH signal!

In this image, the frequency is set to 2Hz:

PHCircuit Freq 2 Cap

Here, the frequency is set to 150Hz:

PHCircuit Freq 150 Cap

Not letting the x-axis change (because of dramatic increase to the frequency), these simulated runs verify the Bode plot.  When the frequency is way small – shown here at 2Hz – the pH signal is amplified the way I want with the .1uF cap in place.  Once the frequency is increased – in this case to 150Hz – the sine wave isn’t magnified.

Wow – a little bit of insight in how a circuit designer would pick the .1uF circuit based on the expected incoming frequency and the requirement of a 5.681 gain!

What’s Next

Before I move on to testing with a pH probe instead of the AWG, I am going to understand signal noise that is occurring because of the ICs.  Chris just taught us about AC coupling and how to DIY an AC coupler for the XScope.  I’m off to do that.  I need to solder an overwhelming amount (at least for me!) SMTs to the Contextual Electronics PCB that we designed in Session 1A and now are soldering together – component by component.  Then I want to go through the same process with understanding and building an EC circuit.

 

THANK YOU for reading this far.

Please find many things to smile about.

 

Follow

Get every new post delivered to your Inbox.