Status
Not open for further replies.

#### aguo5520

##### Member
Hi there,

I just found out about Teensy and ordered one for a project I am working on that involves a sensor, which outputs a 4-20 mA analog signal.
I am trying to figure out how to read that analog signal using the Teensy.

To convert the 4-20 mA analog signal into an analog voltage signal, I was thinking that I could simply run the 4-20 mA signal through a 165 Ohm resistor, which would give me a voltage range of 0.66V to 3.3V (4mA*165Ohms = 0.66V to 20mA*165Ohms = 3.3V). From here, I would connect two analog pins of the teensy to both sides of the resistor to obtain the voltage across the resistor and use that as the analog voltage signal. With this voltage signal I can simply calculate the sensor values.

Is this a valid method for using the teensy analog inputs? Is there a better way to do this?

Also, as an electrical engineering student trying to gain more knowledge, can someone tell me how voltage references work and what they are used for in layman's terms?

I appreciate all help!

Thanks,

Alan

A couple things to consider, many 4-20 devices have a failed high option so 165 ohms x 20 ma = 3.3 exactly will not give you any room to detect anything over 20 mA. I would suggest a lower value. Also most systems would use an op amp but since your 4-20mA across the resistor is low impedance this shouldn't be a problem as long as you keep the resistor relativity close to the teensy. You at the very least would want to add some protection to like a 3.3 volt zener diode tied to ground and the voltage signal. and possibly a reverse protection diode. If you used an op amp you then could add another layer of protection.

since 4-20 ma signal devices are current controlled you could also add a resistor in series before the 165 ohm resistor if your loop voltage is high enough. This also applies if you wanted to add a diode in series for polarity protection.

I'd use a 60 ohm resistor and the internal 1.2V reference.

I'd use a 60 ohm resistor and the internal 1.2V reference.

If you did this you would be limiting yourself to 20.00 mA exactly, depends on the application i guess but i have on my work bench now 4 pressure transmitters that full scale over 20 mA; like 20.1mA ect. Also the fail high state on some devices i previously mentioned.

If you did this you would be limiting yourself to 20.00 mA exactly, depends on the application i guess but i have on my work bench now 4 pressure transmitters that full scale over 20 mA; like 20.1mA ect. Also the fail high state on some devices i previously mentioned.

I guess to sum up I would suggest a lower resistance resistor to increase the range like 50 ohms @ 1.2 volts then you have a range to 24ma.

I'd use a 60 ohm resistor and the internal 1.2V reference.

Is this just for greater headroom before the damage-threshold voltage is reached?

IMHO it would be best using an op-amp powered @+/- 3.3V as a current/voltage converter with a 150R resistor in the fb network. This would make sure that you won't overload the teensy's input since it would clip when reaching Vcc and you could use the internal 3.3V reference AND have some headroom...

Thank you guys for your inputs. I'm still trying to wrap my head around what you guys are saying exactly, but I get the gist of it. Right now, I'm going to look for a way to easily and cheapily protect my circuit from reverse polarity.

Can someone tell me exactly how the teensy detects analog voltages? and how does that relate to the "voltage references" in it?

reverse polarity protection is easy to accomplish on 4-20 mA circuts; just place a diode in series with your resistor. Your sense line needs to be between the diode and the resistor. 4-20 mA circuts are current controlled so regardless of the load the current stays the same. the diode will not effect the reading as long as you keep your measurement to a point after the diode and the loop voltage is enough to overcome the added load (most transmitters can handle 500+ ohms at 24 volts). PM me your email and i can email you a schematic. As far as how the ADC works here is a wiki article on it https://en.wikipedia.org/wiki/Analog-to-digital_converter

While Freescale doesn't say much more beyond the fact it's based on successive approximation, it's almost certainly a charge redistribution design. Pretty much all the successive approximation ADCs in modern microcontrollers use this approach.

Here's a short paper from TI about how the technology works.

http://www.ti.com/lit/an/slyt176/slyt176.pdf

Like all ADCs, the conversion is really a ratio between the signal you're measuring and the known reference voltage. Nearly all IC voltage references use "bandgap" circuits. Details here:

https://en.wikipedia.org/wiki/Bandgap_voltage_reference

Hi all,

I got some great advice and help from people so far.
I have another pretty basic question that I'm trying to figure out now:

I'm using Adafruit's SmartMatrix SD Shield v3 and I can't figure out how to properly wire my 4-20mA output to the teensy..

This is the schematic for the Shield:

http://docs.pixelmatix.com/SmartMatrix/photos/TeensyManualWiring.jpg

Could someone just help me figure out which part of this schematic is the analog input? I can't figure out which analogRead(PIN) is used for each pin on the SD shield board.

Thanks,
Alan

Connection between 4-20mA sensors and AGND Analog Ground

Hello,

I would like to connect several 4-20 mA sensors to Teensy, see attached schematic.
Is it correct to connect the 50 ohm resistors to AGND (Analog Ground), shown with green color on the schematic?
Is there a limit for the allowed current on the AGND pin? For instance if I connect 5 or 10 sensors there could be up to 100 or 200 mA.

Raphaël

This will work, but it is not fail safe. When one of the 50Ohm resistors (which are intended to convert the 4 to 20mA current into a 200 to 1000mV voltage) breaks, the Teensy will see 12V at its input and go up in smoke.

What I'd do to protect the Teensy is shown in the picture below. I'd use a 150Ohm resistor to obtain a 600mV to 3V range, divide it down by the 1k8 / 1k2 resistor network to obtain 240mV to 1.2V corresponding to optimal resolution with the 1.2V ARef. In case of over-voltage (150Ohm resistor broken), less than 4mA would flow through the 1N4148 diode into the +5V rail. The unity gain (voltage follower) op amp finally decouples the sensor input from the pulsed input load of the SAR ADC.

@Theremingenieur

Thank you for the schematic, it looks nice
I will probably try this circuit with a LM258 op amp.

I have two questions:
• Is it better to use a diode between the "+" input and the +5V rail as shown in your diagram, rather than a 5V Zener diode between the "+" input and the ground rail? (see attached schematic)
• Should I connect all "ground" points to AGND pin of the Teensy?

I for one try to avoid Zeners because the Zener effect is not 'binary' and changes with temperature. A simple (dual)diode like the BAT54S is my preferred solution to avoid (mild) under- or overvoltages.

Yes you can use AGND for your analog front-end. GND and AGND on the Teensy are connected by a ferrite bead to avoid digital interference. So make sure the external sensor doesn't pick up digital noises (e.g. because it has a long wire).

What thereminingenieur didn't mention is that you need rail-to-rail opamps for this. I often use MCP6402T-E's for this. They are excellent and economical rail-to-rail opamps. Attached what I use for 5V->3.3V analog input.

Also bear in mind that Thereminingenieurs effective resistance over which the voltage builds up is about 143 Ohms, because the divider is in parallel to the shunt.

The negative supply of the opamp does NOT go to AGND, but to "normal" GND.

A Zener diode to ground with its leak currents, higher temperature coefficient, and other side-effects is not recommended. That's why I choose the simple diode towards +V solution which has proved to do its job under similar conditions (analog CV in- und outputs in synthesizers, even when musicians accidentally try to feed these into outputs instead of inputs, and so on).

Also bear in mind that Thereminingenieurs effective resistance over which the voltage builds up is about 143 Ohms, because the divider is in parallel to the shunt.

That is correct and gives slightly lower readings (by about 4.8%) which doesn't matter since the results can easily be scaled in the software.

Last edited:
What thereminingenieur didn't mention is that you need rail-to-rail opamps for this. I often use MCP6402T-E's for this. They are excellent and economical rail-to-rail opamps. Attached what I use for 5V->3.3V analog input.
View attachment 7732

Sorry, that was self-understanding for me. These MCP6402 look interesting but unfortunately, these don't exist in DIP package which makes them unusable for old farts like me... (still hand soldering LM358s...)

@ Epyon, Ben and Theremingenieur