How to convert TI TLV271 spicemodel to run in LTSPICE ?

Status
Not open for further replies.
May 11, 2008
21,609
1,292
126
Hello everybody, i have figured out that LTspice uses a different model description when compared with Texas Instruments opamps.

I would like to simulate the TLV271.
I downloaded the model from the TI website and created a new symbol called TLV271. I made sure it points to a TLV271.lib . Changed the name of the subckt to make it work. I can simulate without any errors, but the values are all wrong. Output rises to 2400Volts. :eek:
When comparing an opamp subckt such as the LT1490 in the LTC.lib, i noticed that LT uses a far more advanced model description. Using google, i found there are model 1 and model 2, spice model descriptions. The TLV271.lib is a model 1 according to the comments in the TLV271 file. I can assume, that LT uses for the LT1490 the model 2 Spice model description.

My question is :
Are there any functioning TLV271 models out there for LTspice ? It is not really an issue, but i just use the TLV271 often and it works fine. Would be fun to play with while using LTspice. I do not want to use TI swcad. I like LTspice more.
 
May 11, 2008
21,609
1,292
126
I also tried the easy way.

Used the opamps2 symbol.
Changed the value to TLV271.
Included a spice directive : ".include TLV271.LIB" .
It seems there is an error in the spice model or it is just not compatible with LTspice. :|
 
Last edited:

PsiStar

Golden Member
Dec 21, 2005
1,184
0
76
I don't carry the SPICE syntax in my head, but just quickly looking thru the TLV271.LIB file I do see some early statements that are unfamiliar to my typical SPICE files. There just are not enough hours in the week!

A couple of those lines have the "poly" function. Is that in LTspice for instance?
 
May 11, 2008
21,609
1,292
126
I don't carry the SPICE syntax in my head, but just quickly looking thru the TLV271.LIB file I do see some early statements that are unfamiliar to my typical SPICE files. There just are not enough hours in the week!

A couple of those lines have the "poly" function. Is that in LTspice for instance?

Well, i asked someone who knows more than me about spice simulating on my work today and he gave a very likely explanation :
There are multiple ways to model behavior of a component.
An opamp can be modeled exactly as a component with lots of resistors and capacitors and lots of transistors. A true accurate model based on the actual inner workings of the opamp. But slow to simulate.
But it is also very common to model a certain component with transconductance descriptions.
For example, multiple voltage dependent current sources (or voltage dependent voltage sources)may be used that expect input on the non inverting input and the inverting input.
Modeling behavior of an opamp but not with full accuracy. It does make the spice modeling a lot faster. But can also allow why the output in the simulation can rise to up to 2400 Volts while using a 10V positive rail.
He suspected that this is the case with the TLV271 spice model.
It will probably work, but the way i used it allowed for strange results.
I will have to do some testing to be sure.

Opamp fundamentals.
http://www.wisc-online.com/objects/ViewObject.aspx?ID=SSE3303

http://synth.stromeko.net/diy/OTA.pdf
 
Last edited:

PsiStar

Golden Member
Dec 21, 2005
1,184
0
76
Yes, behavior modeling is the trend for complex devices as well as protecting IP.

Sounds like you could be headed toward IBIS models which is just the behavior model. Initiated by Intel of course.
 
May 11, 2008
21,609
1,292
126
I would like to officially state that today i labeled myself as an idiot and i bow my head in shame.:oops::$
I found the error i made. The TLV271 is not the problem. It was in my circuit.
http://www.ti.com/product/tlv271

I have build the design from scratch again and it worked.
After that, i started to trace back all the components from the original circuit that did not work and found an error in a label used to connect various parts of the circuit to the voltage rail. Mainly the TLV271 did not receive any voltage on its V+ pin.
Funny thing is that when building a circuit, that is the first thing i measure before testing. Checking if all the voltage rails are connected and everything receives power. After that i start to test the circuit. But when simulating, i assumed the program would give an error if pins are not connected. But it really is a good simulator, it does not provide warnings for wrong connected circuits... :oops::$

I think i need a vacation.

In the end, i can still say i learned something.
Because i now know how to make my own libraries with non LT components.
I have now a little understanding of the spice modeling description.
And i now know that LT spice will not always warn about errors in the circuit.
It will just calculate while producing results with errors.
In all honesty, i know the circuit works before even simulating, but sometimes it is just nice to do it. And it makes for easy screenshots to add in a document. To add with measurement screenshots taken with the oscilloscope on the actual physical circuit.
And my beloved TLV271, i can use it in my simulation. :wub:
In the end, everything is always great. ():)
 
Last edited:
May 11, 2008
21,609
1,292
126
LTspice sure works great, i just added a component from analog devices.
The AD8211 current shunt monitor. ^_^
http://www.analog.com/en/specialty-amplifiers/current-sense-amplifiers/ad8211/products/product.html

A short example coarse about how to measure current with an MCU :
The AD8211 is great when used with a resistor with a value that is (with a little imagination) a power of 2. For example, 0.16 Ohms.
The AD8211 has an amplification of 20V/V. This means that it will amplify the voltage difference between the input pins with 20. 20 is with a little imagination also a power of 2.
Thus we can say the output voltage = 0.16*20*I.
If we would convert this to a digital value with an ADC, we have an ADC count. Now, why do i keep mentioning that power of 2.
Well, when the AD value is normalized and scaled because the MCU is a 32 bit (or a 16 bit) MCU, it is easy to normalize the value and scale it. Meaning multiply it by 100 or 1000. A 32 bit register can hold values signed from -2*10^9 to 2*10^9.
0.16 will become 16 when properly done and 20 will become 2 when properly done. This means that the value only needs to be shifted instead of using multiplication or division.
Shifting 1 bit position to the left is multiplying by 2.
Shifting 1 bit position to the right is dividing by 2.

This speeds up and makes the calculating for an embedded MCU a lot easier.

I want to measure 20mA to 1A.
Take note that i am discarding offset and calculation errors for a moment.
But since the MCU also sets the trip level by use of DAC, i have some leverage to calibrate away a reasonable amount of offset and measurement errors.

The 20mA limit i have because the output of the AD8211 has an average limit of 0.05 Volt low voltage. It will not get lower than that meaning i cannot measure any lower then 0.05 Volts. Everything below 0.05 is noise and can be discarded without proper tricks. Also 20mA is low enough for the intended purpose.
Thus i get 0.02A*0.16*20 = 64mV.
Or 1A*0.16*20 = 3200mV.
ADC = 10 bit = 3.3 / 1023 = 3.2mV. (ADC resolution = reference voltage divided by 1023 = [2^10] - 1)

To measure 20mA :
64mV / 3.2mV = 20 ADC counts.

To measure 1A
3200mV / 3.2mV = 1000 ADC counts.
If i use mA units. I do not even have to calculate in this example.
But in practice i have to add or subtract some offset and measurement error.
If i convert this value into ascii, i only have to shift a comma (and do leading zero suppression )to display mA.

With these values, it is very easy to measure currents.
Measuring lower currents
Of course, if we would use an extra resistor of for example 1.6 Ohms we could measure theoretically as low as 2mA. I = 64mV / (20 * 1.6)
If we would use 16 Ohms, we could measure theoretically as low as 200uA.
It is logical that the maximum measurement (full scale) goes down as well.
Changing measurement range could be done, by using 3 modern Nmosfets with a very low RDson (5milliOhm) And switch current sense resistors 0.16 / 1.6 /16 Ohm.
Use a software trick to do autoranging (ADC full scale or 0 is changing the currently selected resistor for another one.) It all depends on what the requirements are and the limits of creativity.


I made a small linear power supply simulation in LTspice that will be controlled by an MCU.
The current trip point to shutdown can be set as well.
Why do i go through all this trouble, you are thinking ?
I have this wish list for a power supply i have the components for but not the time. But i am slowly getting there...
It is one part of 4 individual sections (all electrically isolated) in one 19 inch casing.
large 4 line 20 character display.
0 to 5Volts. 20mA to 1A current trip / current source.
0 to 12 Volts. 20mA to 1A. current trip / current source.
0...12 Volts , -12Volt . 20mA to 1A. current trip / current source.
0...45 Volts. 20mA to 4A. current trip / current source.
 
Last edited:
May 11, 2008
21,609
1,292
126
Of course, for greater measurement accuracy, a delta sigma ADC is much better to use than standard SAR (succesive approximation) ADC. When chosen properly, scaling and normalizing is still easy.
But when speed is more important than accuracy or accuracy is good enough, the SAR will do fine, which is for the intended purpose the case. The measurements on the LCD are indicative only and are not used for experimental setup.
 
Last edited:
May 11, 2008
21,609
1,292
126
Since i am kind of a perfectionist, i did not like the for me only limitation the AD8211 has. It would be nice to be able to measure as low as possible. Preferably a resolution of 1 mA would do fine for an indication. But the output would not go lower then 0.05 Volt or in worst case not lower then 0.1 Volt.
And i do not want to switch between shunt resistors. That is a serious issue.

It really is a nice IC.
The common mode input range exceeds ground level (-2V)and up to 65 Volt.
Since i am connecting the shunt resistor with this ic before the regulator series pass element, it always receives a steady voltage.
The output swings form 0.05 V (0.1 V worst case) to 4.95 V.
The maximum voltage difference between the inputs must be 250mV. Since i use a resistor of 0.16 Ohm and a maximum current of 1A, i have 160mV. Well within specification.

But i have to solve the issue of the output not going lower then 0.1 V worst case with a design trick. I have to circumvent it with using creativity. I must come up with an idea, test it and see if it works and meet all specified criteria...

AD8211_fbs.gif



There are ways to circumvent this issue. Some examples :

kirchoff1.jpg

Current offset.
I could add an internal current load to create a current offset. Then there would always flow enough current through the shunt resistor to keep the output above the 0.1 Volt. Subtracting in software the offset current from the measured current value is all we need to do to get the current that flows towards the output. This is Kirchoff first law. That is one possibility.


adc.jpg

Another way is to change the reference levels of the ADC.
An Analog to digital converter has a reference. A SAR ADC for example has a low reference level and a high reference level. The low reference level usually represents the lowest value the ADC can measure and convert for value 0, meaning all bits are set to 0. With the used 10 bit ADC this would also mean all bits are set to logic 0. The high reference level usually represents the highest value the ADC can measure and convert as all bits set to logic 1. the value 1023 with a 10 bit adc. Unfortunately, often when we do this we sacrifice i/o pins when an ADC is used integrated inside a MCU. We also sacrifice some measurement range.

Often it is also not possible to change the reference low input (fixed to ground level) but it is often possible to change the reference high level.

The third way is also a way.
negative.jpg

What if i would not connect the GND pin of the AD8211 to ground level.
But to a negative voltage rail. I do not need much, -0.1V is enough for worst case scenario. What happens is that we shift the lowest level of the output towards ground by shifting the GND pin to -0.1Volt. The output level will not drop, and since we only need an output level of 3.3 V maximum there is enough freedom since the output voltage level of the AD8211 can go up to 4.95V.
But we still need to use this with the current load from the first example to create an offset current to let a minimum current flow to compensate for the 0.1 V. The advantage is that we have more range with the ADC. Because with proper offset current adding, 0V means 0mA towards the output.


I will just use the current offset subtraction trick.
From the above example in the other post :
Rshunt = 0.16 Ohm * 20 * 1mA = 3.2mV. This means the output should rise
3.2mV for every 1mA. At 3.2mV per mA (3,3V/1023), and 3,3 V being 1023 means i have 1023mA full scale for a 10bit ADC. But i also need a little calibration space to compensate for offset errors of the ADC and the circuit.
That 23mA i need to create an offset. I want to measure 1A full scale.
But if the AD8211 output voltage level can not go lower then 0.1V, i have a problem. Why ? because i have in the most optimistic scenario, 23 *3.2mV = 73.6mV to create a range from 0mA to 1000mA measurement range.
What will happen is that with 0.1 V, i will not reach 1000mA full scale, i will reach less. 0.1V/3.2mV = 31,25mA. 1023mA- 32mA (rounded figure) = 991 mA full scale. I have to hope for an AD8211 with an low output level of 0.05V. Then i have enough freedom to calibrate away by subtraction or addition any measurement error. Of course assuming that the entire circuit is linear from input to output.

And the fun is that this all can be tested with LTspice too. Tomorrow i will have actually 3 ADC8211 in my possession to play with when i have the time.
 
Last edited:
May 11, 2008
21,609
1,292
126
I finally had the time to play with the AD8211. Created a small protopcb with resistor and decoupling capacitor. The AD8211 i used, came as low as 34mV with a 22000 Ohm load. Thus with a simple potentiometer i can create a small 20mA current offset to keep the output above the minimum voltage level.

The LT1490 opamp is ideal to create a good linear power supply with a Nmosfet series pass element for regulation. Advantage is that no negative power supply is needed to reach 0V. A small mcu driven step up boost circuit is all that is needed to provide the LT1490 with the necessary higher voltage to produce the needed gate source voltage for the nmosfet. The LT1490 functions up to 44Volts.
Higher voltages need a design trick such as using the +V rail as the ground for the opamp (lifted power supply.)

Nmosfets used for non switching audio applications are ideal to use for this purpose. For example the ALF08N16V.
8A, 160V.

GE3TO24705-40.jpg



EDIT:
Woops . This mosfet is intended for the 0...45V/0.02...4A section.

For the 0...12V/0.02...1A section and the 0...5V/0.02...1A section a smaller mosfet will do fine.
IRF520N
 
Last edited:
May 11, 2008
21,609
1,292
126
When sleepy it is common to make an error.:\
The current through a resistor is voltage dependent. Although the current sense resistor and the current offset circuit are placed before the series pass element, the voltage is still going to vary because of a varying load at the actual output. This will also vary the offset current when a resistor is used (I=U/R). And the offset current has to be a constant no matter what the actual output current is.
Thus it is better to create a constant current sink. For example with an (good ol)LM317 from National Semiconductor (Now Texas Instruments), a potentiometer in series with a resistor(combined the 1.25V reference resistor) and a resistor acting as a load for the LM317. For a range of 10 mA to 30 mA it is easy to calculate. 1.25 / 0.01 = 125Ω and 1.25 / 0.03 = ~42Ω.
A resistor of 39Ω in series with a potentiometer of 100Ω will do.
Gives us a range of 39 to 139 Ohm. Will within spec.

Supply voltage will be between 13V and 11V. The LM317 needs 3V minimum. We give it 5V minimum(Because of the 1.25V reference voltage. 0.75 above 3V minimum = experience) . Thus the worst case scenario is 11V - 5V = 6V for the load resistor from the offset circuit. We need to use the highest current to get the highest voltage drop over the load resistor (R=U/I). 6 / 0.03 = 200Ω. Round it up to 180 Ω(E12 range). In reality, 180 * 0.03 = 5.4V. Thus the LM317 will have to withstand a little more. But not an issue.

At 10mA, there will be 1.8V over the load resistor(U = I*R).
The LM317 will have 13V(worst case value) - 1.8V(load resistor) - 1.25(reference resistor) = 9.95V voltage maximum between input and output.
This means that the LM317 will have to dissipate in worst case scenario (P=U*I) 9.95V * 0.01 A = 0.0995W.

At 30mA, there will be 5.4V over the load resistor(U = I *R)
The LM317 will have 13V(worst case value) - 5.4V(load resistor) - 1.25(reference resistor) = 6.35V voltage maximum between input and output.
This means that the LM317 will have to dissipate in worst case scenario (P=U*I) 6.35V * 0.03 A = 0.1905W.

Thus we need a 0.5W model minimum.
From experience, a SOT223 package will do.

The resistor will have to dissipate in worst case scenario 5.4V * 0.03 = 0.162W.
Thus a 0.25W (range) resistor will do.

The reference resistors :
39 * 0.03^2 = (P = I^2*R) = 0.0351W.
A small 0.1W (0603) power range resistor will do for 39 Ohm.
100 * 0.03^2 = (P = I^2*R) = 0.09W.
A small 0.25W potentiometer will do.

For datasheet.
http://www.ti.com/product/lm317

An example of a current load / sink :

lm317-current-regulator.thumbnail.png


Sidenote :
Type ALT+ 937 for the Ω character.
I am not sure this is code table independent though...
 
Last edited:
May 11, 2008
21,609
1,292
126
Sigh... Nobody noticed the errors i made. It does not matter, though... The design rules are not violated.
 

PsiStar

Golden Member
Dec 21, 2005
1,184
0
76
Unless one is working with the similar issue, then what you are asking of us is ... well we can't find the forest for the trees. :\ But perhaps it is helpful for you to explain, then sleep, then you can see? Then I can can say, "glad I could help!" :D
 
Status
Not open for further replies.