An intuitive guide to Sigma-Delta ADC
bartgrantham
Posts: 83
Hello, everyone. I've been lurking on and off for a few months and I've started to play with my "Propeller DIP Plus Kit" that I acquired a few years ago. I have a number of projects that I am excited to try out, but one of the most interesting to me is the use of the counters to do sigma-delta ADC.
Forwarning: I am a software engineer and I know a bit about electronics, but I can't look at a circuit diagram and get an intuitive sense for how it behaves like I can for code. So, I'm still a beginner.
With that in mind, I'm wondering if someone would be willing to help me "grok" the sigma-delta circuit and code described at the end of AN001 (the counters app note). In return, once I've understood in a way that is intuitive to me I'll write up a nice page with illustrations and animations explaining it for other newbies.
I understand parts of it. For example, after much reading today I learned that the twin 1nf caps are to keep the input near the triggering voltage (a "capacitive divider"...cool). And what the asm does is totally straightforward, but I'm still a little puzzled as to why it is subtracting from the previous value. I suspect it's because my understanding of the process is incomplete or incorrect.
I'm still reading through the forum archives, particularly the long (helpful and detailed) thread at http://forums.parallax.com/showthread.php?t=97510. But I'm sure I'm going to have questions that could only really be explained by an expert.
BTW, for the sake of context my ultimate goal would be to implement a peak-follower for doing guitar to MIDI in a COG (already purchased the Oct 2009 issue of EPE thanks to another thread), but I want to understand SG-ADC before I tackle interfacing with the miniscule voltages of a guitar pickup.
Thanks in advance for any help you guys can provide!
Forwarning: I am a software engineer and I know a bit about electronics, but I can't look at a circuit diagram and get an intuitive sense for how it behaves like I can for code. So, I'm still a beginner.
With that in mind, I'm wondering if someone would be willing to help me "grok" the sigma-delta circuit and code described at the end of AN001 (the counters app note). In return, once I've understood in a way that is intuitive to me I'll write up a nice page with illustrations and animations explaining it for other newbies.
I understand parts of it. For example, after much reading today I learned that the twin 1nf caps are to keep the input near the triggering voltage (a "capacitive divider"...cool). And what the asm does is totally straightforward, but I'm still a little puzzled as to why it is subtracting from the previous value. I suspect it's because my understanding of the process is incomplete or incorrect.
I'm still reading through the forum archives, particularly the long (helpful and detailed) thread at http://forums.parallax.com/showthread.php?t=97510. But I'm sure I'm going to have questions that could only really be explained by an expert.
BTW, for the sake of context my ultimate goal would be to implement a peak-follower for doing guitar to MIDI in a COG (already purchased the Oct 2009 issue of EPE thanks to another thread), but I want to understand SG-ADC before I tackle interfacing with the miniscule voltages of a guitar pickup.
Thanks in advance for any help you guys can provide!
Comments
Usin a SM QFP with the components right by the Prop is always recomended (I have tried the DIP40 and B/Board and got nowhere). I suppose that not clocking it at 80MHz would help but obviously at the expence of sample rate.
This doc from Microchip may help:
"Make a Delta-Sigma Converter Using a Microcontrollers
Analog Comparator Module"
http://ww1.microchip.com/downloads/en/AppNotes/00700a.pdf
"
...the idea of the top cap (in addition to the bottom cap) is to create a super-fast capacitive voltage divider which keeps the integrator voltage at a constant ratio of VDD to VSS, since the logicthreshold voltage is a function of the same. NOT having the top cap actually"injects" VDD noise by not cancelling it. This can be verified by removing the top cap (or the bottom cap)and hearing the difference."
Source: http://forums.parallax.com/showthread.php?t=119773&highlight=noise+chip+gracey
http://forums.parallax.com/showthread.php?t=115952&highlight=115264
http://forums.parallax.com/showthread.php?t=97510&highlight=Troubles+Sigma-Delta
http://forums.parallax.com/showthread.php?t=84176&highlight=u%26gt%3BTroubles+Sigma-Delta
Those discussions became pretty esoteric at times!
For example the business with the capacitor divider is secondary. It will work almost as well with a single capacitor connected to Vss. The main role, to "keep the input near the triggering voltage", is done by the resistor connected to the bpin of the cog counter. It is a "charge balancing" scheme. Can I bring in a crude analogy? You can think in terms of a water tank that needs to be kept half full of water (charge). Water drains out or comes in slowly from some external source. You take the role of the cog counter, and all you can do is watch the level (Apin) in the tank and either pour in one bucket of water or take one out. You have to do that at regular timed intervals. Either one in or one out (no intervals of just sitting back!) If there is no external source or sink, then you will end up taking one out and then putting one in at alternate time steps, and that holds the tank close to half full. However, if water is entering from the external source, you'll end up taking out proportionately more than you put in, say two out for every one in. Vice versa for water draining out The proportionality is exact. Obviously the rate that you put water in or take it out has to balance exactly with the rate of the external flow. (thus "charge balancing") Count the number of buckets put in in comparison to the number of time intervals, that is the digital result. If the total sampling interval is, say, 2048 clock cycles, then an output value of 1024 means the it was that half and half situation where there is no external inflow or outflow.
This is primarily measuring flow, or current. External pressure (EMF) can push a current, but that depends on additional factors like resistance in the external pipes. It is possible to measure EMF, and it is often described with a resistor to an external voltage source. Since the voltage at the cog's apin is maintained at a constant level, it becomes easy to calculate the current that will pass through a resistor from an external voltage. Just remember it is current that is the primary variable.
The subtraction in the asm code is due to the fact that the count of added charge packets (phsa) is allowed to increase more or less continuously, rather than being reset to zero at the beginning of each new timed interval. So to get the result, the code has to subtract the starting phsa value for each timed interval from its value at the end of the interval.
A voltage source has to terminals showing a difference in potential, that is: a voltage. Even if you short circuit the output. Don't say: that is not possible. Or you will be confused. It is possible to have a voltage source, because this is, what we start with. It is not possible to create a short circuit, for this "short circuit" has to reflect the voltage from the voltage source. This is only possible if the short circuit has an finite resistance, so I high current will flow from the voltage source. Or if the SC has a little inductance, what is always the case due to the wiring, even if the "wire" is a screwdriver. In this case, there is a dI/dt necessary to allow a voltage to be applied.
What I want to say: If I assume something, that is not possible, it is still allowed to assume it. But it is not valid to assume something else, incompatible with the first assumption.
Then there is a current source. It is not possible to have the terminals of a current source not connected to a current conducting circuit. For: the current source delivers a current and doesn't care for the voltage necessary to drive this current. If there is a short circuit, there will be no voltage. If there is an open circuit: this is incompatible, for it will result in infinite voltage. So: you never can break an closed loop, incorporating a current source.
But why do we not experience that in every days life: we can open or close switches as we like it! YES, but in real life is not current or voltage source, only items, that behave similar, within limits.
Why I wrote this?
A simple resistor is the same moment a current and a voltage source! And setable! If you drive a current through an resistor, he will deliver a voltage and if you apply a voltage, he will run a current. Strange? Yes!
How can I make a resistor a current source:
Connect the resistor to an empty capacitor of close to infinite capacity. Then this resistor will feed a current into the capacitor proportional to the voltage applied to the resistor. The resistor is a voltage controlled current source. As long as the capacitor doesn't change his voltage.
If the capacitor has a limited capacity, every charge will create a voltage. Therefor the voltage on the resistor will be a little different and the current will be a little less.
What we do now is: whenever we detect, that the capacitor changes his voltage a little bit, we balance his charge and voltage to zero by inserting or removing one or two electrons ;-). Counting the amount of compensation events (in filling or removing), we now no the charge per time, the current, entering from the current source, and therefor, as the current is proportional to the voltage, we know the voltage, applied to the resistor.
By the way: The compensation is done be applying voltage pulses to a second current source, a second simple resistor. As the pulses are generated by a low impedance switch (a nearly perfect voltage source), they can be feed in parallel to a low pass, and the low pass output voltage is the inverse of the input voltage!
And: if you connect to the compensation output another diode and capacitor, you can generate a negative, unstabilized supply voltage, for example to drive an operational amplifier.
What we see: the world is created by perfect voltage and current sources and non perfect short circuit, having some stray inductance, stray capacity and stray resistance!
Bob, excellent collection of threads and docs, thank you. I had skimmed a few of these, but will spend some serious study time this weekend.
ErNa, I'm still wrapping my head around what you're saying conceptually, but I thank you in advance for the enlightment whenever it comes.:smilewinkgrin:
Tracy, your explanation was outstanding, thank you. I appreciate that the "electrons as water, wires as water hose" analogy only goes so far in teaching electronics, but this really helped clear up some muddiness in my understanding. The reason for the subtraction was painfully obvious once you pointed it out. Thanks.
One of the challenges that I have in learning electronics is that it's so hard to get a intuition about the behavior of these systems of components at such enormous speeds and tiny resistance/capacitance/voltage/current ratings. I'm just going to think out loud, please correct me if I'm off track...
So if Apin receives a 0 for one clock cycle it means that the voltage is somewhere between 1.65V and 0V, and the next clock cycle will have Bpin outputting a 1. Now, on the next clock cycle, suppose Apin would still be receiving a 0, but now Bpin is driving that voltage back above the threshold. On the third cycle Bpin is outputting 0, Apin is back to sensing a below-threshold voltage as a 0, and we're back where we started. So AFAICT the system should just be oscillating back and forth between the two states, or perhaps I'm missing a step. Or maybe that's exactly what would happen if everything happened instantaneously, but this is all happening at very high speed, and as someone pointed out the RC combination acts as a low-pass filter (does it really?), so the the set of components doesn't react fast enough and this oscillation doesn't happen.
I guess I can see conceptually how having Bpin == !Apin delayed by a cycle causes Bpin to "bump" the voltage back and forth around the threshold in proportion to the input, but what happens at the 80MHz time scale is where I get lost.