A few days ago (documented in this post), I was testing the Ladybug Shield Alpha 1.  Given what I wanted to test, I felt the best way was to make a test PCB.  I paid Metrix Create:Space $137 to fabricate two test PCBs.  I like to do more than one because it is not uncommon for me to remove the copper from a pin or do something else that makes the PCB useless.  Besides, there is no to just a little cost difference between doing one and two because a big chunk of the cost goes to set up.  Metrix Create:Space’s pricing can be found on this post.  The test PCBs are more easily damaged than those from Osh Park.  I submitted the Gerbers and drill files on Friday and picked up the PCBs Thursday afternoon.  This is definitely a time versus money trade-off.  I am finding making test PCBs in between Osh Park fabrications to speed up the process.  A significant reason is the shorter time between design and test means I don’t forget as much what I am trying to do.  The length of time is not long enough to clean my memory of what the heck I’m attempting to test.

I’m focusing on the part of the EC circuit that prepares the EC’s AC waveform to a DC current that is supplied into the ADC in order to convert to a digital value that an Arduino can read.

After testing the existing circuit, I agree with Dave Jones’ comment about peak detection circuits: “…it doesn’t exactly work like it does on paper.”  🙂

The Goal

The goal of this post is to understand observations I have made while testing the rectifier circuit.  This post presents what was observed, why this behavior happened, and what I will do to fix the behavior.

Open Source

The kicad schematics and layout can be found at this GitHub location

The code for reading the results from the ADS1015 is located here.

Thanks to Those That Went Before

As always, a huge thank you to Chris Gammell for his mentorship and excellent Contextual Electronics courses.  If expectations define what can be achieved, I received an a great gift in that Chris has expectations that we can learn electronics to a high level.  Combined with a great teaching style, My learning has jumped leaps and bounds.

Thanks to Dave Jones for his excellent “Fundamental Fridays” videos, like the one I watched several times so that I got a better idea on what the heck is going on in a rectifier circuit.

What’s Going on?

Through scope and DMM measurements, I’ve been observing two characteristics of the current rectifier design that are not right:

  • The DC value that is fed into the ADC is sometimes at the right value.  But more often the DC value is higher and then drifts (slowly) downwards.
  • The noise at 80mV seems high (I’m still looking into this)

The Op Amp’s Rate of Change in Voltage

Is it the Slew Rate?

Dave Jones does a great job explaining and then showing why the slew rate is an important characteristic of the op amps in this EEVBlog video.  Another good source of information is “The Art of Electronics, 2nd Edition” section 4.15.

I don’t believe the problem is the slew rate of the op amp.
The time it takes for one period of the shrunken waveform is about 600µS.  The frequency ~= 1/.0006S = 1.6KHz (surprise!  This is what I noted in earlier posts).  The Vpp = 216mV, with Vmax at ~100mV.  If it was the slew rate, the op amp’s voltage would slew to the negative rail – which is -2.5V in this case.  If the op amp’s voltage is -2.5V and it needs to get to 100mV in 300µS (half the period of the waveform).  The MCP6244’s datasheet notes the slew rate at .3V/µS.  This means the op amp can increase voltage by .3V/µS*300µS  = 90 V.  So I don’t think it is the slew rate.

The Maximum Follow Rate?

The Art of Electronics (p. 218) talks about the maximum follow rate.  The op amp’s follow rate is the rate at which the output can feed back to the input – the op amp’s vin- is powered by the output (i.e.: it is a voltage follower).  The MCP6244’s voltage follow rate = “output short circuit current”/C = +/-23mA/1µF = .023V/µS.  In 300 µS, the amount of voltage that can flow in is .023V/µS*300µS = 6.9V.  This is enough to accommodate 2.5V + 100mV+ the diodes (2*.6) = -3.7V. So the capacitor does not need to be smaller (although going to .1µF should work) since the follow rate is fast enough.
For now I’ll ignore the noise and focus o the DC value drift.  Dave’s video talks about the voltage droop caused by the capacitor leaking charge.  
If this is so, shouldn’t the values measured by the ADC go down and then back up (keep repeating down and up…)?
I’m still learning about capacitors, but I’m thinking the excess voltage is due to the interaction with the capacitor.

NO THANKS to the Memory

There are times when stuff should just be forgotten.  In this case, it is the capacitor holding on to a previous charge after discharge.  As pointed out in this app note from Analog Devices:

Dielectric absorption…causes a capacitor which is quickly discharged and then open-circuited to appear to recover some of its charge. 

Dave Jones’ video also explains this unwanted phenomenon in the EEVBlog #490 video.

Well dandy.  Ceramic capacitors have a high dialectic absorption.  I think this is what I was seeing when the charge was drifting up.  The ceramic capacitor was holding on to it’s charge.

Scrolling down the app note, there is a table which shows capacitors made out of polypropylene are inexpensive and have a low (0.001% – 0.02%) dialectic absorption.  Ceramic capacitors – in contrast – have a <0.1% dialectic absorption.  Polypropylene capacitors are a better fit for the rectifying circuit.

OK, Now What?

I am going to test and evolve the precision rectifier to be the simpler:.

  • change the capacitor from a ceramic to a polypropylene.  I am pretty sure using a .1µF should hold enough charge.  Particularly given the second change I list (reset the rectifier)  I ordered a .1µF and a 1µF from digikey to test.  I haven’t used a polypropylene capacitor before.  It has a different footprint – much larger and with through holes.  Also, polypropylene capacitors cost more than ceramic.  I’m counting on the polypropylene capacitor to make sure readings aren’t higher than they should be (due to the dielectric absorption).
  • reset the rectifier right before asking the ADC for a reading.  
  • simplify the rectifier circuit from an “ultra precision” to a “precision” rectifier.  The precision rectifier is simpler – easier to understand – and given it will be reset before a reading, should work well.
  • Rectify larger signals than the shrunken waveform.   200mV is too small to get accurate readings.  Realistically, given the EC signal goes through a gain loop, this should not be a problem.  However, another challenge I have been noticing is slight variances in the Vpp of the waveform created by the Wien Bridge Oscillator.  I’ll address this in a separate post.

Simplified Precision Rectifier

The first thing I did was draw out the design.  This gave me a visual I could trace the inputs and outputs to get a feel for expected results.  I’m finding figuring out the expected results prior to running tests put me into a better state when observing results with the scope or DMM.  

Reset the Rectifier

I added a MOSFET so the capacitor is reset prior to the Arduino requesting a reading from the ADC.   I remember I had some spare MOSFETs (digikey link) from the Contextual Electronics BenchBudEE project.  A YIPPEE! moment here.  I’m reusing SMTs I have used before and have on hand!
IMG 3262


Mosfet Pin Config (Datasheet)

Since the Arduino asks for a reading, I decided to control the MOSFET’s Gate through an Arduino digital pin.  Since I want to capture the reading at a peak, I wanted to make sure the capacitor had a chance to reset the capacitor.  How long does it take to discharge a .1µF capacitor?
Recalling the formula noted in this SO answer:
since I want dt: dt=C*dV/I   C = .1µF = 1 x 10-7F   I’m thinking the voltage that needs to be discharged will be a maximum of 1V so dv = 1V.  The voltage regulator  I’m using (data sheet) has a maximum output current of 100mA = .1A.  Plugging these values in:
dt = (1X10-7)(1)/.1 = 1 x 10-6 S = 1µS.
The Gate needs to be open for at least 1µS.
Is the amount of time it takes to execute a digitalWrite() longer than 1µS?  If it is, there is no reason to put in a delay() time.  Using the following code:

unsigned long start = micros();
unsigned long end = micros();
Serial.print(“microseconds to execute digitalWrite HIGH:”);

I got 8 µS.  Actually, the granularity of the micros() function is 0-4µs, so the time it takes to execute a digitalWrite is between 4-8 µS.  I’ll use the most conservative 4µS as the amount of time.  4µS is 4 times larger than 1µS.  So there is plenty of time when the circuit is closed to discharge a .1µF capacitor.

Now that the capacitor is drained, the Gate must be open before a reading.  How long does it take to open the Gate?  According to the datasheet, it takes 19.9nS (Turn-Off Delay Time + Turn-Off Rise Time).  Given this fast time and the much slower execution time of Arduino code, I will not put in a delay function.

The code for resetting is:

digitalWrite(gate_pin,HIGH); Discharge the capacitor
digitalWrite(gate_pin,LOW); open the short circuit

Test the Circuit

After several starts, I decided to use the same parts that are in the circuit on the PCB.  This worked out quite well.  It was easier to wire up because the schematic matched the pins on the test circuit.  Since I am using the same chips as I designed for the Shield, I have more confidence the tests reflect what I will see when I order the next round of Shields from OshPark.  An additional benefit is the additions to breadboard parts!


I had gotten the ADC from Adafruit.  The benefit of buying from Adafruit is the additional effort Adafruit put into developing a library for the ADS1015.  They deserve a premium for the tutorial and library. They saved me a lot of time.  The other chips I soldered onto chip footprint -> DIP adapter PCB board, like this one on eBay.  In the future I will prioritize parts not just on price but also footprint.  If the chip uses a standard footprint, I most likely have a DIP adapter PCB board.  This means I can immediately test while I design!


It is easiest to follow this discussion while viewing the pinouts on the kicad schematic found at this GitHub location.  This is for the test board that I discussed in a previous post.  

First Op Amp

The first op amp is used to create a VGND of +2.5V.  The VGND is used by the AWG when supplying the AC Waveform as input to the second op amp.  

Second Op Amp

I am using my trusty Gabotronics to provide the incoming waveform.  Here is the waveform I fed into the second op amp’s non-inverting input and the op amp’s output (before the diode):


The op amp is able to keep up with the voltage rise which means the slew rate is fast enough.   

Analog Results

Here are the results I got from my scope:


CH1 (Yellow) is the input waveform provided by Gabotronic’s AWG feature.  CH2 (Blue) is the output from the rectifier.

Digital Results

The results from reading the ADS1015 through the Arduino: 981.1 mV average of 100 samples +/- 1.2mV.  The standard deviation of 1.2mV points out a small range of values around 981 mV.  The scope shows a VMax of 1.04V.  This is 59mV greater than the 981mV read by the ADC.  What I don’t understand is the ground of the scope.  The Arduino and ADC share the same ground.  However, the scope is not on this ground.  Perhaps this is causing the difference?  I don’t see the difference as being something that requires further investigation because all readings would be referenced to the same ground.

The code I used is located at this GitHub location.

That’s It For Now

The rectifier circuit will be updated to reflect the drawing I detailed during testing.  While initial testing looks like this is a good choice, the shield will need more testing.  More testing will happen after I get updated PCBs from OshPark.  I first need to update the design…and there is one more thing I want to understand…which will be the subject of the next post.



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