Teensy 3.0, looking for ADC absolute measurement tips :)

Status
Not open for further replies.

Tomek

Well-known member
EDIT; The scope of this thread changed, and I realized I should split the threads. The original thread was asking for basic ADC tips because I was looking to use a resistor ladder in a measurement application where I desired some accuracy. Later, I moved towards a solution that does not require as much resolution, but instead deals with transistor switching logic and flying capacitors. I do still need some advice on that, if anyone is willing http://forum.pjrc.com/threads/26516...witching-advice-many-thanks?p=53767#post53767. But I realized I should delineate the threads because the scope is very different, but the original thread [this one] still has some great advice for the original idea. Thank you for reading!


Hello! I'm a ME student and not entirely knowledgeable about signals.

The general point of my thread is that:

I am going to use my Teensy 3.0 to measure 18 voltages in series, of about 1.4V and 2.8V (after a divider), hopefully to #.## accuracy & resolution. Ultimately, the exact values don't matter as much as the relative accuracy between the 18 voltages. On the digital scale, I have a fairly large amount of time to take these measurements; 1-2 seconds would be a fair amount of time for the process to take. I'm hoping to learn some tips and things to understand about voltage measurements, so that I can make this setup with some chance of reasonable measurements.

The bigger picture of my system:
The teensy will be controlling about 3A and 42V through 18 modules in series a foot or two away from the teensy. I'll be using a DC integrated H-bridge to periodically (every 30 minutes) reverse the voltage direction. Since I can't measure 42V, or any of the voltages (it's 42-IR1-IR2-IR3-IR4 for each module in series), at each module tap I'll need a resistor divider. This divider will be calibrated in the software; since this is a one-time or two-time thing it's not a big deal to borrow a high quality meter and calibrate the resistor dividers.

I will also need to have a second stage scale that takes the voltages from the dividers, to get a positive reading from the negative voltage. Meaning, (Vreading[sometimes negative]) --- R1 ----MEASURE --- R1 ---- Vref. And knowing Vref, and my measurement, I should be able to calculate Vreading, which is half of the times a negative voltage. Before this stage, I will have a buffer op-amp, because the signals coming from the resistor dividers will be fairly high impedance. I am also thinking about using transistors to direct the voltages from the dividers to the { opamp+ negative voltage scaling component.} The reason for this is that it's easier & cheaper for me to have 18 transistors, than it is to have 18 sets of opamps, references, and scaling systems.

(sidenote, I'll be doing these measurements at certain temperatures, measured with a temp meter, and do certain calculations, and then hopefully print them out with a thermal printer.)

What I've considered so far:
Use a dedicated reference voltage for the ADC. Be very serious about this. (I read this on the forums)
Even though you have a dedicated reference voltage, make sure to substantially filter the teensy power from the 42v switched mode supply. (read this on this forum)
Add a 0.1uF cap on the voltage measurement (maybe this is not needed, since I have a cap?) (read on different forum)
*Pay attention to whatever other suggests people offer.* (will be doing)

I've also considered, and rejected:
Floating capacitor measurements to bypass the resistor divider. I don't quite understand enough of the theory of a floating capacitor voltage, despite the effort at learning and the fact it sounds reasonable in theory...I just dont quite understand if it actually works.
Inverting voltage ICs (I can't find enough information for the newb to learn)
Inverting op amps (complicated and only gaining 1 bit of resolution, by avoiding the 1:1 scale. Introduces complexity of using diodes, which I still haven't found out if their voltage drop is consistent/accurate.)
Other potential solutions that I dont know enough about...(also rejected.)


My reasons for hoping I'll get the accuracy I want.
Assume we have a Vref of 3v. At 14 bit resolution (assume I can get that much from teensy, because I can take slow measurements), I have 16384 steps. That's 0.000183V. Double that because of the negative to positive scaling. Then multiply it by 15 because we have a big voltage scaling for some of the measurements. So my resolution would be 0.00549V....and I only care about x.xx....So by my newbie rationale, I might be ok with resolution, as long as I can sort the potential accuracy problems.

What's left:
Please fill in the gaps. Let me know if there are things I should think about on my pcb (don't keep things too tight? Besides that? Have a ground plane? Besides that?)



I suspect that what I'm asking to do, merely because I have a reasonable amount of time to do it, is not new to anyone familiar with electronics. My solution might not be the perfect one, but it seems to be the best solution for me, after considering some other options. But I'm here to find out if there are any glaring problems to my plan, before I invest the many more hours it will take me to get further.
 
Last edited:
I have done a fair bit of experimentation with the ADC on Teensy 3 previously: http://forum.pjrc.com/threads/15718-Interesting-observation-on-the-ADC-of-Teensy-3-0

Bottom line, the ADC values are approximately 4 ADC units apart at 12 bit sampling. I am using a 2.5V external Vref (TL1431). I'm not sure exactly your application and your required accuracy, but note that even when measuring the same source voltage, there are various values across the various channel, so your required accuracy might be limited.
 
I have done a fair bit of experimentation with the ADC on Teensy 3 previously: http://forum.pjrc.com/threads/15718-Interesting-observation-on-the-ADC-of-Teensy-3-0

Bottom line, the ADC values are approximately 4 ADC units apart at 12 bit sampling. I am using a 2.5V external Vref (TL1431). I'm not sure exactly your application and your required accuracy, but note that even when measuring the same source voltage, there are various values across the various channel, so your required accuracy might be limited.


Hi Darkness, I appreciate your response. I apologize for needing clarity, but I am not quite sure what you mean by 4 ADC units apart at 12-bit sampling. That phrase might mean something standard for most people, but I am not familiar with the terminology. Do you mean that successive sampling of the same signal at 12-bits still results in +/- 4 ADC units? To me, I am not quite sure how to understand that, as it sounds like noise which might be dependent on the system being measured more than the teensy. I assume it could be helped with good noise stabilization, and higher levels of averaging.

But I suppose you might have meant something different.

As for the second part (which might just be a repeat of the first part), if it's of any worth, in my system I can funnel all the measurements through a single ADC channel on the teensy3.0. My other measurements (on different channels), involving a few temp sensors, are not so important.
 
I'm sorry if I confused you, there are two issues here.

Firstly, there is noise in successive sampling on any single channel (let's say I use A0 and successively sample a single voltage source, say 1.5V. In my case, I was using a NiMH battery. Yes, it is not exactly the most stable voltage source, but at least it's DC... ;-p). If using a 12-bit sampling, the valid ADC values are between 0 to 4095. If you look at the result on post #22, say under A0, the ADC values ranges from 2209 to 2240. That is a span of 31 ADC values. Translating the result to my AREF of 2.5V, every ADC unit is 2.5 / 4095 = 0.61 mV. A span of 31 ADC units means that the value has a span of 31 x .61 = 19 mV. The standard deviation would be much lesser than that. All the raw data are there if you want to do some statistical analysis.

Next, there are channel differences when reading the same source voltage. If you look across A0 to A9, you will see that the average reading across all 10 channels on the same voltage source are not the same. There are approximately up to 4 ADC units apart. The standard deviation across all channels are approximately the same hence it seems like it's an inherent characteristics that every channel has a slight DC bias resulting in those subtle differences. However, note that we are only talking about 4 x .61 = 2.4 mV between channels. For my application, that is not an issue. In your case where you are measuring relative differences, I'm not sure of the accuracy that you need and whether such biases are tolerable.

I have also tried different strategies (reading the same channel successively before switching channels, reading every channel once and cycling them through, discarding initial values when switching channels, etc.) but I could not eliminate the bias.

Since you are going to read all the various voltage sources through a single ADC channel, then I guess you would only need to take care of the noise issue. Sampling across 1000 readings should more or less take good care of that since you have 1 to 2 seconds in between, assuming that the voltage source is fairly stable/slowly varying, such that a time averaging would not cause an issue in your application.
 
Last edited:
Woah, thankyou. In fact, your post with the niCD discharging (I recall that; assume it was yours) was where I got a few pointers already. I will try to go through it again and pick up more details.

What you described was very interesting (and I think I understand now). Mostly, getting an understanding of the reading biases is fairly important to me, because these things do not come intuitively. The good thing is, as noted, a lot of the problems do not need to be fully understood, since my application is not very sensitive to time, and so I can average many measurements.


As a clarification, my reading would be more like all 18 of them in 1-2 seconds, though it's a fairly loose standard, since anything will be better than the 10 seconds it takes with the manual method. If I can only get 2.2k/s sampling (that rings a bell, from some other post), that suggests I'd only be able to average a couple hundred readings.
 
I'm fairly curious how you intend to multiplex 18 voltage sources into a single channel. You mentioned something about transistors. Won't you need 18 outputs to individually control them?
 
I'm fairly curious how you intend to multiplex 18 voltage sources into a single channel. You mentioned something about transistors. Won't you need 18 outputs to individually control them?


Yes, I will need 18 outputs to control them. I haven't actually counted it out, but I think i should have enough. 1 for voltage measurements, 2 for two temp sensors, two for H-bridge IC, about 4 for the thermal printer, 18 for simple multiplexing (for simplicity, I don't think I'll do anything besides a simple multiplexing. If I draw it out [my brain isnt very expansive] I suspect I could multiplex with fewer than 18 transistors using some sort of pyramid, but, I would end up over-complicating the code). Anyway, that's 27 of the 32 available pins.


*Edit, I'm not actually sure if it's possible to select 18 sources into 1 channel with fewer than 18 outputs. My brain reminds me that it's possible (has some memory of it being possible) but if I try and do it in my head, I don't see how it can be done. This is mostly not important, though; off topic.
 
Last edited:
One thing to note is that outputs 24 to 33 requires you to solder the outputs directly to the solder pads. I'm not exactly sure how you intend to mount the board, but if you are using a breadboard for your prototyping, it may be quite a squeeze with a mass of wires running out from underneath. ;-)

The other thing to note is the settling time of the transistors when you turn them on and off while multiplexing the channel. This would obviously limit your sampling rate way way below the 2k samples/sec that you quoted.
 
Oomph. So I've been gone for a long time. This project was put on the back burner because a different project wasn't working well, and school.

Now I have the chance to work on this again.

I'm thinking, however, that this novel new (to me) concept of floating capacitors might be a smarter way to be measuring this. I haven't found a lot of information on the web about using floating capacitors to measure voltage differentials.

However, it seems to me, that if I charge a small ceramic cap between say my 54v mark, and my 57v mark, and I disconnect the connections between the cap and those marks, and then reconnect the previously-54v mark to ground, and then sample the previously-57v side of the capacitor, then I should see "3v" without having to make an absurd resistor ladder. I suspect I might have to deal with a few more transistors, but that's not too shocking. I would have to learn what kind of transistors to use since I've only ever used power mosfets before and that's kinda overkill/not necc the best for this application.

Does anyone know if floating capacitors can be used in the way I described?
 
Here is what I would consider doing, having been down your path somewhat... In my limited experience, it makes a lot more sense to use a analog front end like the MCP39XX series from Microchip. It can handle all the conversions, offers 24-bits of resolution, 16 ENOB, etc. right out of the box. You can use analogwritefrequency to drive the OSC1 input from your teensy 3, eliminating the crystal and the capacitors for the MCP unit. FWIW, I am running mine with 2048x oversampling at 1.4ksps times two channels using a 12MHz clock rate on the MCP. Try getting similar performance out of the SAR ADC built into the Teensy - it won't be easy, it won't be cheap, and I doubt it will be anywhere near as accurate.

If galvanic isolation of AC is a consideration, simply apply small power transformers to do that job for you. If not, use a couple of precision resistor chips with low drift rates (25PPM or less). Yes, you will have to deal with SPI, but they do offer chips with quite a few channels - look for the 3-phase units.

In my experience, the cost of the MCP-based solution is lower, the performance is much better than doing all the work to get the Teensy chip happy, but you will have to read their application guides for power meters as well as the datasheets carefully to understand how to use these chips.
 
Last edited:
I would agree. A high performance dedicated ADC chip can easily beat the built-in ADC, which has to work on the same silicon as an ARM processor and lots of on-chip peripherals.

Even with lots of averaging, it's tough to get better than about 13 bits from the on-chip ADC.
 
Hi folks!

Thanks for the two responses.

After I finish some things at work, I will try to update my first page/post to reflect recent new ideas. If the floating capacitor solution (two replies up) would work as I hope, then I would effectively reduce my required resolution down to 12ish bits. I really just need about .01 voltage accuracy, which I hope for with <.005 resolution.

I will look into the dedicated chip but I suspect some downsides might exist for a noob like me. Particularly, limited communication protocol experience, and basically any other Newb excuse :). I will read the datasheet though and see what I can learn about how that chip series works.
 
I made a new thread, because I realized I was getting off topic from the original title of this thread. I hope this was O-K

ok! wow, a year later. I've a new chance to work on this, since things never panned out last time and other projects (plus school) took over. I've some more ideas about how the problem might be solved, but mostly it's just a slightly better idea of the previous ideas.

MAJOR CHANGES
I'm now scaling down the plan so that I switch 9 modules in series across 36V. I'm still driving the circuit +/- 36V DC though, so there's a switch every so often (driven by motor H-bridge chip.)

Major obstacle to most ideas: darn! negative voltages! urg. I'm still struggling to deal with the fact that I need to drive the modules (which are peltier/thermoelectric units) in both directions. So at some point everything that might see "0-36V" starts to see "negative 0-36V" That's obviously a major difference and messes with my transistor understanding and most chips. I wish there was some way that I could think of, and it almost feels like there must be, to switch the entire circuit (teensy + 9 modules) in voltage direction, in such a way that I end up still seeing a positive voltage, but the peltier module is seeing current flow in the opposite direction.

Current leading contenders:

Two high voltage MUXes --> ?op amp differential ? --> switch to allow settling ---> ADC
  • Pros:
  • mux deals with many switches
  • op amp buffers signal and scales to 0-5Vdc

  • Cons:
  • I don't really have op-amp experience. Dont know if this will be feasible or accurate.
  • Will have to determine how to communicate with a high voltage mux chip (MAX378 maybe?)
  • I don't know if reversing the voltage will be a problem. the mux should actually be OK, as long as it reverses something else as gnd.

LTC-6802 Linear technologies battery series monitor
  • Pros:
  • integrated package! awesome, nice, great specs. 12bit ADC. etc etc

  • Cons:
  • How will I deal with 'negative' voltages?
  • LTC-6802 is hard to communicate with! There's a potentially dead and non-working but maybe working arduino github project: https://github.com/chrishonson/openBMS. can I maybe utilize that?
  • Will the chip, designed for Lipo batteries, tolerate my attempt to use it as a sort of ADC unit?

Voltage dividers! Scale 0-36v to 0-3V
  • Pros:
  • really simple. I can calibrate away most problems.
  • Teensy ADC will give me enough resolution for my application, even with scaling things down.

  • Cons:
  • What would be a 3.3V signal on one side, once the voltage is switched, becomes a 33V signal. Urg, I have no clue how to deal with the 'negative' voltage. I say negative in quotations because it's not really negative compared to my supply, but it's reversed through the circuit,. by an H-bridge. Maybe I can use a diode?

Finally, perhaps my leading contender:
This crazy flying capacitor business. Since the module number has been reduced to 9, I actually can deal with switching things with the ~20ish pins it would take. but it won't be easy, it seems.
(my biggest problem): I don't know enough about types of transistors i might use that I can turn on and off with the teensy to control the circuit. Presumably I can't just use mosfets because direction of the voltage will change, but perhaps I actually could still use a P-channel mosfet to switch the lines and another transistor to allow the teensy to switch the p-side. I'd really like to know more about NPN transistors though to see if the would simply be enough. As draw in the attached circuit I've just show switch symbols, which does kind of point out that I could use a wonky series of low power relays if I'm desperate. Perhaps I need to research optocouplers and use some back-to-back as they describe (minimal reading so far on my end) for AC currents. Originally the attached circuit was hand-drawn, but I just threw it into KiCad now because if anyone is looking at this the last thing they should have to struggle with is deciphering my hand-drawing...


Thanks for any suggestions or input. At this point I'm mainly looking at two things
(1) Is this flying capacitor solution feasible? Am I missing something major?
(2) What can I use for the 'switches' in my circuit? So that I can control these things from the teensy. I have some experience with P-mosfets, and think they might work along with a NPN to pull down the P-mosfets gate from high to low. But I don't think I've fully thought through the whole voltage-switching thing, and how the mosfet is direction-ally dependent. I think something else might be better. I'm not sure what.
BasicSchematic.jpg



Edit: More reading on my part, I think optocoupler would not really work. What I see to want is something like an SSR. I wasn't sure if they exist as cheaper smaller components, since I've only seen them as the larger 10-25A kind. I think I may have found the right type of part, though. I went to octopart.com, and found G3VM-61H1 and G3VM-61H1 by Omron, and I think they might work. Since they're rated for AC loads, I don't see why they should cause a problem. They aren't cheap, $2 and $4, when I need some ~20 of them for this circuit, but at least I know there's "something" that should work. Not sure yet if something else is better.
 
Last edited:
I see this is an old thread but thought you may still be looking for a solution.

My thoughts on analog when all else fails is a voltage to frequency circuit. You can get a great resolution reading frequency. the circuit you make will determine input voltage.
 
I see this is an old thread but thought you may still be looking for a solution.

My thoughts on analog when all else fails is a voltage to frequency circuit. You can get a great resolution reading frequency. the circuit you make will determine input voltage.


Hi Kevin!

Thanks for the tip and I'll keep it in mind next time I'm working on a similar project. It's not what comes to mind, in part because I'm a mechanical engineer masquerading in EE shoes. I assume I can google "voltage to frequency circuit" and find some typical analog processes for doing that.

One of the tricks I tended to find with anything like that, is unless the circuit could run referencing just the adjacent modules, then I would have to have chips that could tolerate the full voltage range, which is quite high (bipolar 56V) for most cheap chips. Or, if they could tolerate it (many op amps that could) they were less precise (the wider range op amps had less precision and tolerances.)

The floating capacitor method I want to add, worked really well. I'm was pretty damn excited, though it had bumps and odd starts. I definitively had some wiring and code issues early on. I also had one grounding issue that was a terror to find. I also removed a saftey zener that was causing some bleeding and distorting the measurement. But overall, thing seems to be good.

It has been hard to make quantitative proof that it works precisely, but I did benchmark with passive components (resistors) and a precision resistance meter, though my actual device is meant for testing some active devices (thermoelectric modules.)
 
Status
Not open for further replies.
Back
Top