I recently modified the EC circuit to read both Vin and Vout of the EC gain loop. This way the Ladybug Shield would provide the closest readings for the Gain (Vout/Vin). Once the gain is known, the resistance of the EC probe in the nutrient bath can be measured. Once the probe’s resistance is known it is a small skip to calculate the Conductivity of the nutrient bath.
Thanks To Those That Went Before
- Chris Gammell advised me on how to think about and debug this challenge. Chris is an excellent teacher/mentor. I have learned A LOT from his Contextual Electronics courses and his mentorship. THANK YOU.
- Ryan (SparkysWidgets) open sourced the minipH and miniEC. This effort has allowed me to gain a jump start in my understanding of the electronics behind pH and EC circuits. Besides that, Ryan is an exceptionally smart, kind person who readily shares his knowledge and has provided me with excellent advice. THANK YOU.
- Laen and the people/company at OshPark. I have become an advocate of OshPark. They are a model of the most excellent service/support providing quality product at a reasonable price and turn around time. THANK YOU.
The kicad schematic and layout are located at this GitHub location. The schematic to view for this post is the Rectifier schematic.
I recently started measuring both Vin and Vout of the EC gain loop.
For weeks I have been poking at really understanding why I am seeing readings from the ADC start high and eventually drift down to the right value when these events occurred:
- switch MUX to take Vout readings
- turn FET on for around 4 ms to drain the capacitor
- switch MUX to take Vin readings
Challenge 1: Start high, Go low
Vin readings start out high (say around 900mV) and eventually (after hundreds – say 2000 readings) stabilize at an expected value (say around 250mV).
I stumbled around mumbling what I thought was going on. The problem was I didn’t have “the smoking gun.” I didn’t have proof of what was going on until….until…I gained a better understanding of how to use a scope!
Chris advised me what to look for:
On channel 1, monitor the gate voltage of the FET.On channel 2, monitor the input to the buffer (the output from the rectifier circuit).
If you trigger on channel 1 going high, you can see the behavior the FET is causing (hopefully draining the cap).
(RIGHT THERE – the cost of Contextual Electronics paid off !)
Ah yes…just like any great detective knows…figuring stuff out is about figuring out what to look for and then finding it.
After figuring out the difference between “Auto” “Normal” and “Single” triggering I realized what I wanted was to set my scope on Normal triggering. Personally, I found (find?) how triggering works confusing at first. But well worth learning :-).
And look at that:
The blue line follows the FET as it transitions from OFF (low) to ON (high). When the FET is on, the cap is discharging. The yellow line starts reading the rectified Vout and then switches to Vin at about the time the FET is set to HIGH. It turns out the cap discharges in about 25µS. With the FET on HIGH, the cap is kept discharged.
I then set a trigger to happen when the FET went to LOW using an Arduino sketch that executed one after each other:
The scope showed the capacitor was fully discharged within the time it took the Arduino sketch to execute the digitalWrites():
Given the small amount of time it takes to discharge the cap, a digitalWrite(FET,HIGH) immediately followed by a digitalWrite(FET,LOW) gives more than enough time to discharge the cap (about 80µS for the code to execute while it takes about 25µS for the cap to discharge).
Challenge 2: Settling Down
Another challenge I was facing with ADC readings was slightly higher readings right after turning the FET OFF. So I took another scope measurement. This time I ran an Arduino Sketch that:
byte S = HIGH;
Serial.println(“send VOUT for 1 seconds”);
S = LOW;
Serial.println(“Switch to VIN”);
//turn FET on and off to discharge the capacitor
Serial.println(“send VIN for 6 seconds”);
The focus is on the reading for Vin between the two readings for Vout. When the MUX switches to VIN, it takes about 3 seconds for VIN to stabilize. I’ll add a delay(300); after switching to Vin and discharging the cap.
What this post is about for me is a better understanding of how to use a scope to get a better peek into what is going on within the innards of the analog part of the circuit. WHOA! I am excited to have learned this…hopefully I will start applying my new found debugging/viewing skills and shorten my bumblings when it comes to debugging what is a mysterious world for me – the analog circuit…
Thanks for reading this far. Please find many things to smile about.