In this post I take a step back and write down what the goal of the EC Circuit is and how the Ladybug Shield’s EC circuit implements to these goals.  After doing this, I further analyze the circuit from the perspective of the scenario in which the Ladybug Shield will be used.  I then go on to test the circuit using a breadboard populated with the same parts that will be used on the PCB.  The testing will lead to design changes in the EC Circuit.  Back to the EC Gain loop….

Here’s an image of the all important gain loop in the EC circuit:

EC_SignalDesignLadybugShieldAlpha1

EC Gain Loop

 

To find the EC of a nutrient bath using an EC probe:

  • Find the gain (Vout/Vin)
  • Solve for the probe’s resistor value (ReC)
  • Take the reciprocal (1/ReC) and that’s the EC in Siemens

Thanks to Those That Went Before

I will always be thankful to Chris Gammel.  His Contextual Electronics courses and strong mentorship have opened up my abilities in practicing electronics.  Chris has a terrific ability to engage his students in building circuits and in the process learning quite a bit about electronics.

I learned a lot from Ryan’s – SparkysWidgets – open source minipH and miniEC BoBs for measuring the pH and EC.  On top of the availability of the schematics, Ryan has been exceptionally supportive – answering questions when I am stumped, and providing feedback.

Open Source

The kicad schematics and Arduino Sketches can be found at this GitHub location.

Find the Gain

Gain = Vout/Vin+.  The design already figures out Vout by sending EC_SIGNAL through an ADC.  Vin+ has been assumed to be 100mV.  Problems with this assumption:

  • the 200mV Vpp was sourced from the design of others, not based on acquired knowledge on my part.  Perhaps a larger Vpp is possible.  If so, the final result will be more accurate.
  •  not using a measured value means the Gain will most likely be off.  Since this is a gain, the error is magnified.

A Different Vpp for Vin+

The current design sets the Vpp of Vin+ to +/- 200mV.  Now that I better understand how the EC circuit works, is 200mV the “best” Vpp given the design requirements?

I am designing the Ladybug shield to help grow herbs and vegetables.  From the information in this post on EC values for vegetables and herbs, I will restrain the EC Gain loop to determine EC values between  .5mS to 5mS = .0005S to .005 S.  S = 1/R.  So resistance = 1/S.  The range for the variable resistor in the gain loop representing the EC probe that this circuit must support goes from 2KΩ (1/.0005) to 200Ω (1/.005).

When the resistance is 2KΩ, the Gain = 1 + R10/2K = 1 + 1K/2K = 1.5.  When the resistance is 200Ω, the Gain = 1 + 1K/200 = 6.  To be safe, a maximum amplification of 7 will be used.  The op amp’s rails provide 5V of headroom for the Vpp of the incoming waveform.  The maximum Vpp of Vin+ – 5V/7 = 714mV.  To be a bit more conservative, I will use a Vpp for the shrunken waveform of 500mV (instead of the 200mV I have used up to this point).  The EC readings should be improved with a larger Vin+.

Vin+ will be amplified between between 1.5 and 7 times.  Let’s say the reading is off by 100mV.  At 1.5 times this is 150mV.  At 7 times this is 700mV.  Given the potential for a wide variance – even if we could (calculate) the amplitude of the Wien Bridge Oscillator and then voltage divide, the value can vary based on the environment of the components at the time of measurement.  Instead of adding a fixed value, I am going to add measuring the Vin+ as part of the E.C. calculation.

According the MCP6244 datasheet, given the power supplied to the op amp’s rails: V+ = 5V, V- = 0V, the maximum Vout range = 4.65V(5V-.35V) to .35V(0V+.35V) or 4.3V.  Given the op amp’s headroom of 4.3V, the maximum Vpp of Vin+ = 4.3V/7 = 614mV.  To be a bit more conservative, I will shoot for a Vpp of 500mV for the Vin+ of the EC Gain Loop.  The EC readings should be improved with a larger Vin+ Vpp.

Measure Vin+

I have updated the Ladybug Shield’s design to measure Vin+ along with Vout.  To do this, I added the 75LVC1G53 2:1 analog multiplexer (data sheet):

ECCircuitWithSwitch

In a previous post, I discussed the updated design of the rectifier circuit that the Ladybug Shield will use.  Since this waveform also needs to be converted to DC, it needs to be rectified.  I could copy the rectifier circuit.  However, I’d rather have one rectifier circuit that is reused by the waveforms. This way, if there are problems with rectification they are contained within one rectifier circuit.

I added a 10K pull-up resistor to the ~E pin (pin 2).  This way, the switch is off by default.  The switch is turned on or off by sending a digitalWrite() through an Arduino pin.

Test the Circuit – Calculate EC

Time to wire up the components on a breadboard and check out the circuit.

IMG 3270

 

Rectification Observations

I was wrong in a previous post where I decided I needed a dialectic capacitor.  From my current understanding of circuit analysis, it wasn’t memory being held on by the ceramic capacitor – but the challenge I note below.  The circuit was not able to discharge the potential energy on the last op amp.  I changed the resistor back to a capacitor.

I tried three rectification topologies:

  • input into the ADC at point A (image below)
  • input into the ADC at point B (image below)
  • input into the ADC at point B but added a 470KΩ resistor and 1µF capacitor in parallel.
New Rectifier
The ADC measurements made through an Arduino are listed below in order of lowest standard deviation and closest to expected values (recall I am using a resistor to represent the EC probe’s variable resistance input into the feedback loop):
    • point A. 
    • point B with the added parallel RC.  
    • point B with no additional load

Given my current abilities at circuit analysis, when switching from a higher waveform to a lower waveform, the potential energy needs to be discharged, but there is no load before the ADC.  Introducing the 470KΩ resistor allows discharge.  The capacitor then fills in the holes in between the potential peaks that are exposed from the discharge.  If this is true, It seems the circuit would be better off getting rid of voltage follower (i.e.: the last op amp) op amp since it adds complexity and variability.  On the other hand, the voltage follower op amp buffers the ADC from any surges that might occur between the two op amps.

I ran several tests showing measuring at point A was “good enough” and a better choice than the other two.

 
The design of the Ladybug Shield will remove the second (buffer) op amp from the rectifier circuit.  
 
EC measurements using the ADC and an Arduino sketch will use the Vout DC current following the negative feedback loop of the first op amp.

Arduino Sketch

After (carefully!) wiring up the circuit, I ran the Arduino Sketch found at this GitHub location.  To test the accuracy, I put a 200Ω and then a 2KΩ resistor to simulate the EC Probe’s input.

IMG 3271
It is best to view the Arduino Sketch found here.  The Arduino Sketch calculates the EC by:
  • Asking for the number of readings to take of Vin+ and Vout.  This way, the values can be the average of many values.  
  • reading Vin+

int readVIn(unsigned int num_readings)
{
dischargeCapacitor();
switchTo(VIN);
for (int i=0;i<num_readings;i++) {
int results = readADC();
myStats_Vin.add(results);
}
return myStats_Vin.average();
}

The dischargeCapacitor() function sets the Mosfet’s gate to HIGH which drains the capacitor.  The switchTo() function switches the 2:1 gate to be either read either Vin+ or Vout.  Next comes a loop that reads the ADC for as many readings as I requested to be averages.  A 3rd party library is used to return the average value.

  • reading Vout – very similar to how Vin+ is read.
  • Calculating the Gain = Vout/Vin+
  • Calculating the value for ReC = 1000/(Gain – 1)   [Note: the known resistor is the 1K feedback resistor in the EC Gain loop].
  • Calculating the value for EC in mS = 1/rEC*1000
In the run below, the resistor simulating the EC probe was 200Ω (approximately – the resistor comes from a pack of inexpensive breadboard ready resistors):

Enter number readings:
3
Reading Vin+
239
242
241
Vin+: 240
Reading ECv
1518
1521
1520
| Count: 3** Vin+ ** Average: 240.67| Std deviation: 1.25** ECv ** Average: 1519.67| Std deviation: 1.25
** Gain: 6.33| ReC: 187.65|EC: 5.33mS

I tried several runs with different number of readings up to 1,000.  All gave similar results.  The results for 200Ω is “good enough.”

In this run, I used a 2.2KΩ resistor (again, approximately):

Enter number readings:
3
Reading Vin+
239
246
242
Vin+: 242
Reading ECv
357
359
357
| Count: 3** Vin+ ** Average: 242.33| Std deviation: 2.87** ECv ** Average: 357.67| Std deviation: 0.94
** Gain: 1.48| ReC: 2104.35|EC: 0.48mS

Closing Thoughts

I am comfortable enough with the results to update the Ladybug Shield layout’s EC circuit. I plan to send updated Gerbers to OshPark so that I can reach my goal of using the shield to help me grow the lettuce starts that are starting to collect in my house. I’m very happy with the prototype process that I used. I was able to wire together the same parts to prototype on a breadboard that I use on the Shield. The SMT to DIP PCB boards have been a terrific aid in doing so. I now have parts that I can reuse on future breadboard circuits.

That’s it for now. Please find many things to smile about!

Advertisements