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 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.
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.
The Maximum Follow Rate?
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
Reset the Rectifier
Mosfet Pin Config (Datasheet)
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!
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.
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.
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.