Conditioning phototransistor voltage for ADC  - Page 1
Forum section: electronics / projects

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 03:09:29 am
content: I need to 3 very accurate light measurements!I have 3 phototransistors powered from 5v using 3 separate 1m ohm resistors to ground, and the voltage ranges across the three transistors read ranges about 1.0-v2.4v.Like this.I am using anadafruit ADS111516-bit 4-channel adc with a mux for differential measurements. It has a PGA scalable from +/-6.1v to +/-0.25v so voltage range isn't a problem, but I am looking to get as high of resolution as possible and the circuit has to be responsive enough for 800 readings per second.Although it may sound like it, I basically don't know what I'm doing at all with the analog math and conditioning these signals properly. How do I get rid of my 1 volt dc offset? I've played with using an lm324 in different configurations but without success. There is about 0.3v difference between the min/max of the signals I've been compensating for this in software but would like to fix with hardware before the adc for better resolution, where should I be trimming this at? The voltage level going into the phototransistors, the resistor going to ground after the transistor, both? Is there a magic op amp that will solve all my problems? I've heard of reverse bias for phototransistors, should I be doing that? Should I be using differential mode on my ADC? Should I ditch all of this for digital light sensor chips? The math I'm doing with the readings involves making the signals bipolar at their half-voltage range level, could I be doing this in analog with a negative power supply or differential measurement? I have some multiplication, addition, and subtraction math currently running in software that would be nice to do in hardware, I've conclude through research that this is possible but is there a tool for designing analog math? I'm using this data for some cool neural network software that is pretty far along, I've neglected the analog end of my project for far too long, any advice appreciated, thanks!

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 08, 2015, 04:53:58 am
content: 1M?? That sounds like an awful lot, even for ambient IR levels. If the phototransistors can see visible light as well, they'll surely be saturated almost all the time?This problem starts with the same thing any other does: what are you trying to do?If your optics are well shielded and controlled, you may not need much (and 1M resistors might turn out to be suitable). That doesn't sound like what you've got, though.As for offset, it is very easily removed, analog or digital:If your signal remains within the linear range (the transistor never fully turning on or off), then a high-pass filter, with a cutoff frequency below your signal's cutoff, will do. This can be done with or without op-amps in the analog domain, or with some simple DSP math in the digital domain (a single or two pole IIR filter would be the best).If the phototransistor can saturate, you might be better off with a gyrator type circuit. The basic idea is, you'd like to ensure the DC voltage across the phototransistor remains constant. You'd normally need an inductor to implement this (because the impedance of an inductor is nearly zero at DC, thus you can force the transistor voltage to remain constant, even if it's drawing a lot of DC current). A gyrator uses an amplifier to invert a capacitor, so that it acts like an inductor.As you can imagine, a gyrator also acts as a high-pass filter, making your signal path easier. The difference is, if your sensor is saturated (due to interference, like ambient DC illumination), it won't be getting any of your signal at all. Avoiding saturation (preserving the linear range) is the first duty.You'll probably still want a high-pass filter elsewhere in the path, because the gyrator won't have a perfect output, nor will your ADC sense it perfectly.If your signal has a lot of DC (e.g., it's sensing if a door is open or closed, simply based on whether there's IR or not), a filter might be entirely inappropriate! Or if it's pulsed data, a filter may be undesirable, because as more pulses are accumulated, the DC offset gets pushed away, and you start getting bit errors. The best solution for this is to use a modulated pulse, so that the emitter is always turning on and off (keeping the DC level independent of signal), and it's the timing pattern that determines whether data is 1 or 0. Manchester encoding is one of the simplest and most common. The analog version of this is a common radio modulation like AM or FM or PM.If you are expecting a very weak signal (e.g., a TV remote, that might be very close or very distant), it might be worthwhile to take a great many ADC samples, and perform a correlation test on them. This averages out noise and interference, allowing you to lock onto the desired signal alone. At the same time, you can only do as much averaging as your signal's bandwidth allows -- there is a one-to-one tradeoff between noise rejection or bit error rate, and total channel bandwidth.Tim

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 05:41:09 am
content: Thanks Tim! As far as the light level and resistor level, they are in a sealed black box with an led and a spining circle with a gradient on it. 1m is just what happened to work at what I thought to be a reasonable light level, I can get the brightness enough to fully saturate all the sensors, so I should use a smaller resistor and that will help?. I don't know what to do as far as tuning the brightest of the led for the sensors optimum range, it's a 3DU7 Silicon Photo-transistor, I haven't been able to find the actual maker or data sheet, it takes time but I've manually tuned the light for what seems to be a good dynamic range without using lots of power on the led, which has to run without PWM, or I would need chopper op amps and get complicated I think..I do a lot of DSP already, mostly a median of small samples and averaging it with the last few medians, I get good data with very low noise, I do the differential math in code, everything works. You could visualize it as 3 phase offset sinus waves, it's pretty clean, highly responsive, little flat on the dark end, but linear-ish and clean for the most part, I just want more res. My special sauce code takes those 8 bit signals and makes a ~14 bit signal, it's very impressive what it does right now, but if I could get 14 bits out of the sensors it would be quite special. My data currently spans 1v-2.4v, it's good data but it doesn't match well for getting the most resolution out of my adc range, almost entirely because of the dc offset. It's about 11 bits accurate, but I'd like more if possible.How do I easily fix the dc offset without a gyrator? Create and add negative voltage? I could lower the voltage level with the resistor to lower the dc offset but it also lowers the entire sensor range, which just scales everything down, I need to shift the voltage lower. Edit: as usual it seems most of the battle is just finding the name of what you're trying to do. I need a level shifter circuit, I hope I don't need a level shifting ICI found someone asking the same thing but with a different voltage range that got a great answers.Basically I need a point in the right direction on specifically how to wire up an op amp to just do the voltage offset, I don't really need the amplification, there's a programmable gain amp in the adc.Can I do this with an lm324n or do I need something else?

author: mikerj
author_rank: Super Contributor
timestamp: June 08, 2015, 06:19:40 am
content: Quote from: T3sl4co1l on June 08, 2015, 04:53:58 amWhy not use a classic transimpedance amp?

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 06:24:43 am
content: So I should be doing reverse bias with a transimpedence amplifier. Any idea what values to use or how to calculate it on a 5v supply, will the lm324n work for this, what would be a better choice? Would it perform better than level shifting it to a minimum of 0v the way it currently is?I'm using a white led, with a random phototransistor. Should I be using a specific wavelength led with a certain light sensor for best results?

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 08, 2015, 07:44:07 am
content: Quote from: mikerj on June 08, 2015, 06:19:40 amThat can be done, too. If a wide range were needed, the variation in hFE wouldn't matter. Since it's in a closed box with controlled intensity, that's probably a good idea.In which case a proper photodiode should be used. I think a phototransistor in reverse bias (preferably C-B, if B is available) is equivalent, but C-E reversed not so much (what's the typical reverse hFE on a phototransistor?).The main thing a TIA gets you is bandwidth, but I guess that's not a big deal here. Over 10 bits, distortion is a real big issue, which would be helped by that, too.Quote from: ohnoitsaninja on June 08, 2015, 05:41:09 amSo you're doing a good old fashioned tone wheel sort of thing? Maybe not for generating or modulating tones, but... same idea.What about it do you need? Angular position? Frequency? How good is the gradient on the thing? How consistent are the sectors?Very roughly speaking, an average 300 DPI laser print at 1" radius will have around 300 points across a given width or radian. So you'd expect the intensity of that "gradient" (however it's achieved) to have a precision on the order of 1/300ths. Which doesn't need much more than 8 bits to resolve. It might be a lot better than that, for a number of reasons (optics looking at more than just a thin radial slice, averaging the image with focus and blur, controlling the image's density with variable color or halftone patterns), or it might be considerably worse (uneven ink/toner density, uneven substrate (paper?) density, warping and distortion during printing and due to environmental effects (plastic has a high tempco, paper has a high tempco and an even higher humidity co).There are ~6.3 radians around a circle, so your cycle should be divided into about 2000 dots worth of resolution. So you might not expect more than 2000 samples per rotation to matter, or to be able to resolve that closely. Again, give and take the above effects.Even if the disc is commercially printed, I would be dubious about anyone making one, or being able to guarantee the tolerance of one, to better than 10 bits or so. For much the same reasons. The mere geometry of your optics will have a huge effect by then, too.If this is for an encoder application, you're probably better off with encoder strip. This is precisely printed plastic film with nearly microscopic lines on it. You can easily get thousands of pulses per rotation, so the angular position or velocity can be known quite well (2000 lines/rotation is 12 bits of resolution, as you can measure half-steps). A sine wave function can be calculated by software, its position being determined by another reference (such as an additional peg or sensor on the shaft that repeats only 1/rev).If this is for a musical or analytical sort of purpose, the noise floor and harmonic distortion will be insanely difficult to deal with. The above method would also be a fine solution, or something completely different, like low distortion sine wave oscillators in a phase-locked loop (PLL).QuoteSome keywords -- differential amplifier, subtractor, inverter and summer, etc.Generally speaking, anywhere you have an amplifier with a +in and -in, you can put a resistor in front of one pin, and add pull-up or down resistor to +V or GND, and the output will shift in the corresponding direction. Mind that loading the inputs with resistors does shift the gain -- but since your gain isn't terribly well defined to begin with, that probably doesn't matter.QuoteI wouldn't suggest it, not at 5V. TLV2372 might be better. Kind of noisy for your desired number of bits, but I don't see how or why you should need so many.Tim

author: Kalvin
author_rank: Super Contributor
timestamp: June 08, 2015, 08:13:00 am
content: Referring to this application note:https://physlab.lums.edu.pk/images/1/10/Photodiode_circuit.pdfWhy not do it properly like Figure 13. Or you could get more dynamic range using a log-amplifier like in figure 5. The log amplifier prefented here is sensitive to the temperature changes, so it may matter or not in your application. These are just basic circuit ideas, you may need to tweak the circuits to meet your application needs. If you have a bipolar power supply or you create a virtual ground at the midpoint of the power supply, it should be quite easy to trim out any offset current using a trimpot or using a microcontroller's PWM outputs as simple DACs.

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 08:26:35 am
content: Thanks for your concerns Tim, but I've found optical/mathematical/dsp solutions around your mentioned problems, It currently works at *cough* well over 10 bit resolution on this bad res data, I hope to soon disclose everything about it. The tech has the scaling capability to supply resolution higher than anyone would ever need, sorry you did all that dpi mathInstead of a gradient it could be simply half black, half white, if the sensors are far enough from the circle and the optics are right, it's the same as a gradient to the sensor and none of those printer things matter, you don't even need a printer. I'll take care of all the math part of my application, I promise I have down, I just need to offset this damn 1v voltage

author: tggzzz
author_rank: Super Contributor
timestamp: June 08, 2015, 08:35:37 am
content: Quote from: ohnoitsaninja on June 08, 2015, 03:09:29 amIt would help if you defined what you mean by "accurate".A few of examples... It could require that the circuit's response has to be tracable back to national/international metrology standards. Do you need to accurately model the eye's response? Do you need the output to be stable over days/weeks/ months.I've seen a very expensive piece of equipment that had an accuracy specification of 0.1dB (which nobody cared about), and a stability/repeatability of 0.001dB (which was necessary).

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 08:47:52 am
content: Analog accuracy isn't really the question here, my signals between the range of 1v-2.4v are great signals but all of the bits of my ADC from 0v-1v are being wasted. If it were shifted to 0v-1.4v, I could fit the signal perfectly into the available 15-bits(the 16th bit is signed for differential readings) of my adc. The actual lux accuracy isn't important. I have this adc sitting millimeters away from the sensors, all metal shielded, no light bleeds into the 'box' and and everything is precision mounted, so I know high precision is attainable. The sensors themselves in their current wiring configuration have the speed and stability needed for the design requirements. So really the only thing I need help with is to shift(not scale) this voltage down closer to 0v.Regardless of the lux accuracy, all that really matters is that for every position of the wheel, the combination of values between the 3 sensors is a different number which can be mapped to be perfect within the repeatable accuracy of the sensors.

author: tggzzz
author_rank: Super Contributor
timestamp: June 08, 2015, 08:59:44 am
content: Well, that a little more informative, but it still isn't a usable specification. Adjectives are a big warning sign of inadequacy - numbers are required.For a start, these statements are problematic in isolation and taken together: "Analog accuracy isn't really the question here", "16 bit ADC", "high precision is attainable", "perfect within the repeatable accuracy".Note my signature; it is there for a reason.

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 09:07:45 am
content: The ADC is capable of 15 bits in single ended mode, I don't hope to get 15 bit accurate readings out of it, but before I can do my dsp magic I need to fit the voltage into the adc's 15 bit range, so I have a real 15 bit reading. It doesn't need to be an accurate, noise free 15 bits, it just needs to be 15 bits of potentially accurate information at least, so I could hope to attain maybe a real world 12-14 bits out of the sensors. The dsp magic part reads as many channels worth of sensors as you want to create a single output, this part really is magic, it creates absurdly high readings from even bad data.I understand skepticism, but I've played with this thing for months now. It's level of detecting angular rotation at a radial distance of 1" is above human threshold to rotate something slowly. Plainly, you simply can't touch this thing without it knowing. It's max RPM is limited by sampling speed of the ADC, the DSP, and the settling time of the sensors.WHATS IN THE BOX?p.s. there is no box

author: Kalvin
author_rank: Super Contributor
timestamp: June 08, 2015, 09:17:13 am
content: Using differential measurement mode you could get rid of the 1V offset voltage quite easily - and you could also use the PGA. However, differential mode requires two inputs per channel, so you would need two modules unless you use an analog mux.

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 09:19:08 am
content: I thought I might end up needing more differential channels and ordered 2 adc boardsI just don't know how to best wire up my sensors for differential mode readings, I don't have a negative power supply,my knowledge is mostly in software and I'm not very comfortable on the breadboard!

author: tggzzz
author_rank: Super Contributor
timestamp: June 08, 2015, 09:26:36 am
content: Quote from: ohnoitsaninja on June 08, 2015, 09:07:45 amBeware GIGO, of course. And yes, Idounderstand what signal processing canand cannotdo.I have measured my weight many times, and I can therefore state I weigh 66.34940127kg.QuoteWhat skepticism is that? All I noted was that your specifications didn't have much meaning.

author: Kleinstein
author_rank: Super Contributor
timestamp: June 08, 2015, 05:52:54 pm
content: For precise readings photo-diodes are much better than photo-transistors, they are more temperature stable and more linear. The usual circuit is a transimpedance amplifier. The TIA may also contain some low pass filtering. The LM324 is not a good choice - especially with photodiode a TLC274 would be a much better choice, as bias and noise currents are much smaller.For the choice of LEDs usually IR or red leds are the better choice, as Si based detectors are more sensitive to these wavelengths. Red may help to see where the light goes - some paints are not black in IR anymore and can cause some surprise. If there is a significant offset, this indicates some background light. Anyway 1 V offset at 1-2 V Signal does not loose so much. It might help to use modulation, to suppress residual ambient light. With modulation AC coupling may be used to get rid of the offset, without trimming, and the µC internal ADC may be good enough to do decoding at a faster rate and provide resonable resolution through oversampling of the AC signal.The ADS1115 hat only 2 differential inputs - so single ended is the only choice for 3 inputs, and not bad anyway. The 860 SPS is only for a signal channel - reading gets slower if channels are switched.

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 08, 2015, 06:57:02 pm
content: I'll order photodiodes and TLC274s, thanks Kleinstein!The ADS1115 is proving to be indeed too slow, I started using it yesterday, previously I used the (16 bit/12 bit effective?)adc built into the Teensy-LC cortex-m0+. I thought the ads1115 would be a lot better with it's reference but the speed is just too bad. Any better recommendations than to use an ADS1015? I think the adc on the teensy-lc might be capable of better readings if I use a better vref source? The next step up in external adc boards I can find isAd7606, which is pretty bad ass but kinda pricey for how many of these I want to make.AlsoADS1256claiming 24-bit and 30KSPS rate, would this be a good choice for me or is 24-bit just pointless for what I'm doing, even with photodiodes and TIA?A very scary but potentially awesome idea would be toport my code to fpga.This board from TI looks too good to be true at a too good to be true price.Part of my code is to measure the signals deferentially from each other in the 3 possible combinations. To do this with the adc in differential mode, how do I protect the signals from each other, is that what a voltage follower op amp is for? A protective buffer?

author: Kleinstein
author_rank: Super Contributor
timestamp: June 08, 2015, 07:51:42 pm
content: The Photo-diode TIA combination can be linear over a rather large range, so a high resolution might help to cope with data over a wide range of intensities. However simple range switching might do this as well. Before high resolution ADCs got so cheap, using an analog log circuit was a common solution to record data over several orders of magnitude.However at faster reading there will be considerable noise. Also the filter should not give such a large range of intensities. The other point is, that the intensity of LEDs depends on temperature - not much, but enough to limit accuracy. So there is no real need for a high stability reference voltage. An extra channel to monitor the LEDs output might help.The M4 chips offer quite good performance ADCs. Some of the demo boards are damn cheap (also STM32F4...), but usually limited to development purpose. So normally the 12 Bit ADC in the µC might well do it, especially if the LEDs are modulated and oversampling is used. This way I got something like 14 Bit resolution from a 10 Bit ADC in an AVR.Rather cheap (e.g. $2-3) ADCs are MCP3911 and similar (e.g. 2 channel 24 Bit (around 16 Bit effective) up to around 100 kHz). In addition to high resolution the SD ADCs often offer gain switching. There are also 16 Bit variants of the LTC244x at a resonable price.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 08, 2015, 11:32:05 pm
content: Now I'mreallyintrigued. Frankly: how have you proven that your method has such freedom from abberations, distortions, mechanical and electrical tolerances, etc., when you don't even know how to subtract a voltage offset?I don't mean to attack your ignorance. But it does sound like the kind of thing where, you simply don't know what kind of lower-order effectscanbe produced -- a result of using an oversimplified or overly general (and underly filled out) model, usually.For analogy, here's a signal processing scenario:I want a sine wave with zero distortion.Ok, synthesize it with an oscillator.Oh, but the oscillator has distortion, because it's made with amplifiers that aren't perfectly linear. [And other, much more subtle, issues that depend on implementation!]Ok, so let's filter the oscillator. We'll use a low-pass filter, to get rid of the harmonics.We need a high order filter, to attenuate the harmonics thoroughly ("zero" distortion suggests harmonics in the noise floor, maybe -100dB or lower; -60dB in the stop band would be a good start for this filter)The filter requires a lot of inductors and capacitors. We want to use small values and types, to save space.Oh, but small capacitors and inductors are very nonlinear. Our filter could actually create more distortion than it's supposed to remove!A filter that meets the specs might be prohibitively large, precise, and expensive: a perfectly linear filter must be made of linear materials, such as air cored inductors and quality film capacitors (or better). If this were an audio frequency application, the amount of copper required for the inductors (which must be good enough quality, otherwise the filter won't be sharp enough) would be massive.Or maybe we use a digital synthesis method instead. That can be good. Using a 24 bit DAC, the numerical input can be essentially perfect (within 1/2 LSB). The DAC itself, however, need not be as good. Its transfer function might vary with code (INL/DNL), producing both random (noise) and periodic (harmonic) distortions. Moreover, high-precision DACs are often sigma-delta type, which require a long sampling / settling time to achieve their rated accuracy. If this settling time must occur continuously during the waveform, the waveform itself may be skewed. And what if the settling behavior changes depending on code (which it will for a D-S type)? Also, due to the sampling theorem, the DAC output must be perfectly filtered, so in the end, we get the same problem we did before, that it must be filtered.It doesn't end there. The sampling theorem assumes the samples are perfectly equally spaced. If they are not, jitter transforms into noise. If the jitter itself has a periodic component (as it will from a numerically controlled oscillator (NCO) or DDS circuit), the combination of periods (of jitter versus signal) creates a mixture of "spurs", both harmonic and anharmonic, which are difficult to filter.So you can very quickly get into problems, at all stages of the signal chain, due to subtle variations or inconsistencies in their operation. The ideal case typically presented, is only the average case. Many of these subtle errors are undocumented and depend on the architecture (the analog oscillator will never generate spurs; the DDS will never generate a slowly varying AGC error), and can only be predicted with masterful knowledge of the underlying systems.Tim

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 09, 2015, 01:02:29 am
content: If I have an array of signals that are being compared to each other deferentially, if there is a thermal problem it will be likely near equal across the sensors and it doesn't matter. There is no ambient light leaking in. If the led brightness changes over time it will be uniform across the sensor array it will not matter other than to shift the range of the adc sees a little which the DSP doesn't care about.I use an adaptive sampling rate. I'm also not measuring oscillations, I'm measuring essentially a fixed voltage level. It's an absolute encoder dsp that can accurately predict the angle from a single reading of the sensor array. It's like adjusting the shutter speed of a camera, the longer the capture time the higher the accuracy I can read but it's less responsive, hence adaptive sampling rate.I've played with arduinos for a long time (5 years now?) but I've never dabbled much into op amps or other ICs, like I said before I'm a software guy, so sorry if I'm still struggling to offset this voltage after all of everyone's input. I appreciate all of the concern and alternative suggestions, but the technology/software already really, truly, works damn well, but it would work twice as good if I could fix this offset problem. I previously was using 0.10cent LDRs instead of phototransistors and was able to successfully use their long rise and fall times to actually increase the dsp outputs resolution.I'm now back on my teensy-lc without the ads1115, so the sensors are powered off 3.3v, the adc max is 2.56V, and I can tune my sensors output from 1.5v-2.56v. I'm having a hard time figuring out the op amp level shift calculators and knowing which op amps work and don't. I only have 324n and tl082cp on hand, and I'm really desperate to get this offset down.Before I did any of the modeling or figured out the short cut math to do this at high speed, an array of crappy sensors with a high resolution external reference encoder feeding a neural network already confirmed it's possible to make a cheap very high resolution encoder, but I want to run this on a microcontroller not my i7. So while I appreciate hearing thoughts on why it won't work, I already know that it does. Increasing my bit depth isn't an issue, it's merely a preference. The true accuracy is the numberOfSensors * bitsOfAccuracy, I'd like to raise bitsOfAccuracy but it has a limit which you all are keen to point out, but raising numberOfSensors is trivial. The math is quite powerful.

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: June 09, 2015, 01:23:54 am
content: it appears that you want the rotation angle of a graded density disk from several measurements of its transmission of led(s) lighta classic method of removing small DC drifts, offsets in the measurement is to AC modulate the source, synchronously demodulate the received signal - easy to just switch the led(s) on/off and then AC coupling your photodiode amplifier output to the ADC - the synchronous demodulation can be simply subtracting measurements with the led on from the next measurement with led off signalobviously you want to modulate much faster than the disk can rotate and your electronics have to be fast enough not to attenuate the switching frequencythis method is often used when very long term drift, "1/f noise" would be a problemextra photo sensor(s), or better a switchable optical path, that lets you look at the source before and after going through the disk give the ratiometric measurement improvement already suggested

author: tggzzz
author_rank: Super Contributor
timestamp: June 09, 2015, 07:57:25 am
content: Quote from: ohnoitsaninja on June 09, 2015, 01:02:29 amIgnoring the quite remarkable claim in the last sentence, clearly your software is inadequate to the task so I don't understand why you think it "works damn well".I suggest you read, learn and inwardly digest standard texts on basic electronics, low-noise electronics, practical ADCs, and optoelectronics. In particular, ensure you understand what the specifications in the device datasheets mean and why they are there - e.g. "input offset voltage", "INL", "DNL", "1/f corner frequency", "thermal drift" and many others.You might also reconsider calling yourself a "ninja"; it makes me think of the Dunning-Krueger effect.

author: Kalvin
author_rank: Super Contributor
timestamp: June 09, 2015, 09:02:02 am
content: Do you need to sample the detectors at the same time, or would it be enough that you sample then sequentally as fast as possible? If you do not really need the simultanous sampling, the easiest way to get rid of the offset voltage is to add a analog multiplexed to the front of the A/D-converter and run the A/D-converter in differential mode. The differential mode will get rid of the offset voltage by definition. Wire the signal from the detector into the + input of the A/D-converter. Put a 10k trimpot between the power supply and GND (three trimpots, one for each detector), and wire the trimpot wiper to the - input of the A/D-converter.You do not even need the analog multiplexer if you have two A/D-boards so you can run both in differential mode. Just configure the A/D-convertes into differential mode, wire the detector signals to the + inputs of the A/D-channels and the trimpot wipers to - inputs of the A/D-channels. That's it.Ps. You should use multiturn potentiometers. Placing 100nF capacitorc between the wipers and ground will not hurt either.

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 09, 2015, 06:00:43 pm
content: Quote from: tggzzz on June 09, 2015, 07:57:25 amMy software isn't good enough? Without knowing what I'm doing with analog electronics at all, I wrote software that takes $8 in parts and a $12 uC dev board and made an absolute rotary encoder that functions over 12 bit accurate with build quality to match. Go ahead and look how much a commercial one would cost, especially a programmable one with the features I get from the uC, you're looking $600-$1200 usd, so yeah, it works DAMN WELL. The hardware also does lots of cool things I didn't even mention here, because really I didn't want to get into a discussion about if it works or not, because I have first hand experience that it does work, I just needed some help in an area I admit I don't know anything about, instead I'm seeing mostly arrogance of people who think they understand the situation because of electronics specifications, are really missing the big picture of what is taking place here and how my code works, perhaps because they don't know quite as much about computer science like I don't know about electrical engineering. You seem almost mad that someone without your knowledge is capable of doing something you can't.Imagine measuring within a repeatable tolerance the signals that are not looking at a graded wheel, but a complete garbage random pattern wheel. If the combination of sensor outputs is unique for every 0.0001 radian of rotation, the bit depth accuracy is two_pi/0.0001 = 62831, almost 16 bit. This is a gross oversimplification of how it works. Read all the sensors 'simultaniously', and for each sensor you can predict it's value as well as know it's value, the difference being signal error you can measure from just a single sensor sweep, so both each sensor's value and it's error are usable properties. I have achieved and exceeded 0.0001 radian stability when not using a mess of breadboard wires.It's not a perfectly linearly accelerating round circle at this stage, but it's 15 bits worth of unique angles. It's then finally calibrated with high resolution external reference measurement of the angle.My neural network models made external reference verified angle predictions beyond the limit of my external reference which was 14 bit accurate, and this was using LDRs not photo-transistors. It claimed an accuracy of 0.00004 against 1mb of separately logged test data which is over 17 bit on 3 crappy LDRs on a much rougher constructed prototype than what I use now. Anything over 14 bit can't be verified without a better external reference, but the nature of the algorithm is to approximate smoothly the values in between which it is accurate so you can be almost sure that the 15th bit is also accurate when the readings are stable out to 17 bits.Thanks Kalvin, I added the capacitors. There isn't good docs on getting differential reads on the teensy-lc and the ads1115 isn't quite fast enough but I'll get an appropriate differential adc.

author: Kleinstein
author_rank: Super Contributor
timestamp: June 09, 2015, 08:17:56 pm
content: With TIAs to amplify the optical signal, there usually is no more need for differential inputs, at least up to about 16 Bit level. The next step to more accuracy would be measuring the LEDs intensity as well,or using a pattern that is sensitive to intensity ratios only. How good the accuracy gets also depends on the quality of the pattern - this will be the ultimate limit.Using 3 detectors is somewhat odd to me. Usually one needs 2 detectors to resolve a position in closed circle - another 2 could use a second higher period pattern to get a much better resolution - but this would be 4 detectors. With 4 detectors something like 16 Bit resolution should not be so difficult, even if the individual detectors only deliver something like 10 Bit resolution. So under cost aspects a few more cheaper detectors could be easier than few high resolution channels. So maybe 4 phototransitors are better than 3 photodiodes and TIAs - especially if the µC internal ADCs are good enough.

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 09, 2015, 08:27:50 pm
content: Two sensors on opposite sides would mean I can't tell it's absolute position outside of 180 degrees, it would measure the same on two sides. Two sensors less than 180 degrees apart works but the math is weird and one side is higher resolution than the other. My implementation allows me to very quickly scale up or down the number of sensors I'm using, the only change to the code is to tell it the number of sensors to read. 3 is the minimum workable number, so I'm using that while I'm breadboarding for sanity.The quality of the print is an issue, but measuring it is a function of the dynamic range, which is a result of wheel size and sensor optics, not so much the dpi of the printer used. I made the majority of my progress on an earlier prototype that was simply half white paper half black with electrical tape. For what it's worth, this part is going to be laser etched which I haven't honestly looked into but I would expect to be of very high resolution.I'm excited for my new op amps to show up so I can try out the TIA configuration, I wish there was a local store that had real components, it would have profoundly impacted my life.Putting a sensor underneath the LED for measuring it's real brightness is a good idea, as I'd like to change the brightness based on disk speed. I'd like to pwm control the brightness of the led from the uC, but I don't want it to produce any artifacts on the sensors. The teensy also has a dac I could drive the LED from.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 09, 2015, 08:56:04 pm
content: He didn't specify the position of the two detectors.Presumably they would be in quadrature (90 degrees).Tim

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 09, 2015, 09:18:58 pm
content: Quote from: ohnoitsaninja on June 09, 2015, 06:00:43 pmI was going to skip over this, but actually, I'm curious. Do you have a link to such a device? I'd like to see the specs. Have you verified that your device matches or improves all the specs on said device? (Do you have the equipment to even be able to verify it..?)QuoteAh, so you state that:- The noise floor (repeatable signal) is in the N-bit range- The positional accuracy (distortion, etc.) need not be anywhere near thisam I interpreting that correctly?The analog analogy is: take that op-amp I referenced earlier, for example. TLV2372 claims 39 nV/rtHz input referred noise. In a typical gain-of-10 amplifier configuration, that's 390nV/rtHz at the output. Suppose we filter the output to a 20-20kHz bandwidth for audio purposes. The noise will be about 55uV RMS. (Slightly more actually, because noise density rises at lower frequencies. This doesn't cover much bandwidth, so the change should be small, perhaps 60uV RMS total in reality.) That means, for a given input state, you can expect the output to bounce around a +/-150uV range (i.e., 3 sigma, give or take).That doesn't mean your output is absolutely known. The input offset voltage is 2mV typical, over 10 times higher than the noise level. Which means the output will be in a +/-20mV range (again, gain of 10 at work). Now, with a high pass filter, this doesn't matter, but if you were using this for a precision DC measurement, it would affect the sum error in your signal chain. (The noise level near DC would also be a significant impact, effectively looking like the offset voltage is dancing around randomly.)So for a dynamic range of +/-2.5V (i.e., centered in the 0-5V range), you might get as little as 0.15mV of error (AC coupled noise, 14 bit equivalent), or 20mV or more (DC precision, a mere 7 bit equivalent).The amp is also rated for 0.09% THD+N, meaning for an input of +/-0.100V, you might get +1.029V and -0.982V, or whatever, out instead. (I think I'm mangling the definition of THD+N here, but I think it should be in the right order of magnitude.)The distortion will be equivalent to nonuniformity of your encoder wheel. Like I said, depending on printing method, it may be chunky (pixellated), or that may not matter (averaged over the visible sector?), and it may be distorted (the N visible sectors warped in such a way that the angle is resolving to some local offset).As for the optics, an LED at low current is probably limited by shot noise. At low bandwidth (<1kHz), that's probably not a big deal anyway. I don't think LEDs or photodiodes are affected by systematic variations (aside from temperature, which as you say, will cancel out). Still, because the voltage accuracy can end up quite poor, a chopper detection method might be valuable (i.e., modulating the LED between two brightness levels, and taking the synchronous difference in detector levels).Tim

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 09, 2015, 09:41:34 pm
content: My external reference is a camera and printed gray code disk with software I wrote for temporal alignment with the sensor data. So no I don't have specs to hand you.I might not end up with the same tech specs of traditional equivilent bit absolute rotary encoder, but I'm making this for a specific end user that would never dream of using high precision absolute encoders because of their cost. My encoder might not end up being the best for a CNC machine or camshaft sensors, but it does provide cheap functionality that didn't exist previously for completely different markets with different needs.The page I first found for using photo-transistors insisted I use a chopper op amp.I was looking to avoid doing this because I don't understand it very well and what I have already works but it looks like that is the way to go, as well as it being in TIA reverse bias configuration. Returning to this page, it's more insightful than I remembered and covers most of the problems I've had. It doesn't talk about sync with a pulsing led though, which is very much outside my analog knowledge.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: June 09, 2015, 10:09:33 pm
content: "We have investigated ourselves and found no wrongdoing"? (See also "tautology" and related subjects.)It doesn't sound like you have any absolute, calibrated method to resolve better than, say, 10 bits or so. I'd simply say: relax, don't worry about it. Until you can confirm parts-per-million errors on an absolute basis, it's all a lot of hot air and wasted effort to try to resolve anything more.If you're still interested in precision measurements, you should probably start simple, like using voltage dividers and op-amps to create a precision ADC (or multimeter) kind of system. This is relatively easy to calibrate (even the modestly cheap (not the no-name super cheap crap) DMMs carry more than 3 digits of repeatable accuracy), and serves as a good introduction to analog concepts: voltage, current, ratios, op-amp functions, and inevitably... EMC issues like sensitivity to RF and ESD, which necessitate filtering and protection devices. Then you can push it further, into the AC domain, and establish a flat frequency or step response, and do signal analysis (like RMS, or if you want to, frequency detection, FFT, mini-scope readout, etc.).Then you'll have an excellent underpinning to return to your optical encoder system, and with luck, be able to quantify it to much better levels than those expensive commercial parts. Might even be something worth selling -- for a competitive price, of course!Tim

author: ohnoitsaninja
author_rank: Contributor
timestamp: June 09, 2015, 10:19:44 pm
content: Thanks Tim!That is great advice that I hope I have time to follow, I'm really interested in learning more about how to do this properly, but the product is already in an advanced stage of development and I'm focusing on production. I want to make a higher end version later, but it already works superbly well. You might think it's laughable that it's in such a state when I know so little about the circuitry design but the truth is what is sitting on my desk right now is accurate to a minimum of 12 bits and has been every day for weeks. I have visualization tools for showing this, but I usually just use it for it's intended purpose where if it wasn't accurate I would be able to tell. It may not match up perfectly with a precision absolute encoder, but I'm not getting the stepping you would see with a 10-12 bit signal, I get the smoothness of 14+ bit data which is what I need, it seems to be accurate enough, for it's size, it's more accurate than human threshold to turn it, which is it's intended application. No matter the truth of it's specifications, it does it's intended job with a quite pleasant adeptness.Why would you suspect I'm under 10 bits? Do you think my external reference is less than 10 bit accurate? It's readings are higher than 10 bit accurate before calibration to the external reference! I've actually stopped using the external reference calibration because the dsp is so good it outperforms my external reference. This is all on a breadboard with long wires, using 500k pots for calibration. How much improvement can I expect to see moving this to a small pcb with precision resistors and a properly educated fellow such as one of you has put all the right little caps and such in the right spots with better voltage supply? I only needed 12-13 bit accuracy out of this thing, and I'm already above that with my shotty breadboarding.It's really cool what neural networks can do with a variety of sensor data. They can learn the technical specifications of components better than any listed graphs in datasheets because it measures performance characteristics in your application, all you need is an accurate measuring reference. This is why I neither know about or care about much of the technical specifications, the neural network in my head doesn't need to understand it, I've made another to do that for me. For NOW, I just need to understand it well enough to make good hardware, and I made great cheap hardware, although a bit lacking on the electronic components front. Deep learning is here, it's going to do things that makes the magic I claim in this thread look like monkeys using sticks to eat ants. It's theoretically possible to use genetic algorithm and neural networks to redesign the hardware and possibly come up with something that blows all this away, 128 bit accuracy or something stupid high. It is my expectation and hope that things like this are going to be suddenly applied to every aspect of all technology within our lifetimes and things will get really weird. Neural network programming could displace an unprecedented amount of jobs.Take this marvelous piece of engineering for example.As cool as it is, it's design is riddled with human design tendencies like, MORE BLADES! Given the opportunity, genetic algorithm and neural networks wouldn't design a turbine that looked anything like this, and that is probably a really good thing.