Jump to content
Sign in to follow this  
altineller

Energia with TM4C123 battery monitoring ADC problem

Recommended Posts

Hello,

 

I am trying to measure voltage across a voltage diviter with a Tiva-C series boards, and I am consistently getting mis results.

 

I get 0-4096 for 0 to 3.3V. I also have a seperate battery, that goes in to a 100K + 15K voltage divider network and PE_2 is connected to the middle of the voltage divider.

 

It measures 1.1V approximately, when it should be measuring 0.77V. But here is the interesting part. When I use a multimeter to measure the same middle point in the voltage divider, it reads 0.77, and the value from the analog read also converges to 0.77 - then i disconnect the multimeter it will go up to 1.1V back.

 

This brings the question: what is the analog state of this adc pin? does it has to be initialized with pinMode as input, in order to do analogRead?

 

Best regards,

C.A.

Share this post


Link to post
Share on other sites

If I remember correctly you need to use pinMode. You could try with a pot to see if you detect the variations.

But could you explain a bit better? How do you know if it went back up to 1.1V if you disconnected the multimeter? This is measures are all about the voltage divider output correct? I'm guessing the battery is of about 8.5V?

 

Share this post


Link to post
Share on other sites

You may want to try putting an op amp in a unity gain configuration betweem your divider and the ADC. This will isolate and reduce the possible interplay between the divider and ADC while providing a low impedence source to the ADC.

Share this post


Link to post
Share on other sites

So you put the meter across things and the voltage changes? Sounds like you don't have a high-impedance meter.

 

Along the lines of what @@dubnet said, you may want to use an op-amp as a divider instead of resistors. This would effectively isolate the voltage you're measuring from the MCU, if done properly.

Share this post


Link to post
Share on other sites

Hi @@altineller

 

I tried to reproduce your problem on my TM4C123G LaunchPad.  I hooked up the following with a 6V battery (reads 5.9 on my meter).  Is this your circuit?

 

 

VoltageDivider.JPG

 

If so, I was able to get the expected readings using this sketch:

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting...");
}

void loop()
{
  float rawReading;
  rawReading = analogRead(28);
  Serial.print(" Raw Reading = ");
  Serial.print(rawReading);
  float Voltage;
  // NOTE: 3.3 is used for conversion since we are
  // using the default internal voltage reference
  Voltage = 3.3 * rawReading / 4095.0;
  Serial.print("      Voltage = ");
  Serial.println(Voltage); 
}

I did not get different readings when I put my meter across as you reported.  Do you have your circuit grounded to the LaunchPad?  Also, did you convert in your sketch using 3.3V or 6V?  Using 6V would give roughly the number you reported.

 

Hope this helps.

Share this post


Link to post
Share on other sites

@@altineller   You may also want to take a look at the Tiva uC data sheet which has not only the electrical specifications of the ADC but also a diagram that shows the resistance and capacitance sources within the A/D:  http://www.ti.com/lit/ds/symlink/tm4c123gh6pm.pdf

 

The pertinent pages are 1389 to 1391.  You will note that they suggest a voltage source resistance of 500 ohms.  My experience is the lower the source resistance the better with SAR based ADCs.

 

Hope this helps.

Share this post


Link to post
Share on other sites

yes that is the exact circuit. i must have gotten something wrong then in the analog card.

 

could using a lab power supply somehow interfere with the measurement? i will try with a battery now.

 

Hi @@altineller

 

I tried to reproduce your problem on my TM4C123G LaunchPad.  I hooked up the following with a 6V battery (reads 5.9 on my meter).  Is this your circuit?

 

 

VoltageDivider.JPG

 

If so, I was able to get the expected readings using this sketch:

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting...");
}

void loop()
{
  float rawReading;
  rawReading = analogRead(28);
  Serial.print(" Raw Reading = ");
  Serial.print(rawReading);
  float Voltage;
  // NOTE: 3.3 is used for conversion since we are
  // using the default internal voltage reference
  Voltage = 3.3 * rawReading / 4095.0;
  Serial.print("      Voltage = ");
  Serial.println(Voltage); 
}

I did not get different readings when I put my meter across as you reported.  Do you have your circuit grounded to the LaunchPad?  Also, did you convert in your sketch using 3.3V or 6V?  Using 6V would give roughly the number you reported.

 

Hope this helps.

Share this post


Link to post
Share on other sites

@@altineller - Your lab power supply should work...  If you get it to work with a battery then you might try again with the lab supply.

 

@dubnet  

 

You may also want to take a look at the Tiva uC data sheet which has not only the electrical specifications of the ADC but also a diagram that shows the resistance and capacitance sources within the A/D:  http://www.ti.com/li...m4c123gh6pm.pdf

 

The pertinent pages are 1389 to 1391.  You will note that they suggest a voltage source resistance of 500 ohms.  My experience is the lower the source resistance the better with SAR based ADCs.

 

OK, I will confess to not understanding that part of the datasheet :unsure: It states that the "analog source resistance", Rs is 500 ohm max.  Just above that there is a line stating that the ADC equivalent input resistance is 2.5 kohms.  And of course there is a footnote h that refers to the diagram below.  The diagram also shows capacitance in the input.  How is this interpreted and how is it used in a practical fashion?  I have set up voltage dividers with resistors in the thousands of ohms range to get me where I wanted to be for analogRead - mostly with the MSP430F5529LP with no problem.  I can see that there would be a problem if there was capacitance (RC filter) and the voltage was changing and you were trying to track it (not the case here?)  Realize that I am not an electrical engineer - just trying to understand.

Share this post


Link to post
Share on other sites

The other dynamic is that as the SAR based A/D does it's conversion and steps through the ladder (be it resistive or capacitive) the input currents change throughout the conversion. As this happens the current through the resistor divider changes as well, which can affect the accuracy of your reading.  That is why a buffer amplifier that presents a high impedence to the divider (drawing very little current from the divider) and simulataneously presents a very low impedence current source to the input of the A/D (typically less than 100 ohms) is a good thing. An Op Amp like an OPA27 configured in unity gain could be a good choice but if your input resistance ever needed to be much larger a fet input based Op Amp might be a better fit since the input resistance is much higher than an OPA27.

Share this post


Link to post
Share on other sites

OK, many thanks. I think I am getting it. Let me try to turn this into some rules I can use...

 

1) if doing one way 5V --> 3V3 logic conversion from a sensor or module to the MCU then keeping the voltage divider resistances in the 100 ohm range is good.

2) if monitoring voltage and it is desireable to minimize current draw from the circuit being monitored then use higher resistance in the divider but use an Op Amp or maybe FET input Op Amp inbetween as a buffer.

 

EDIT: logic conversion does not use ADC - so 1) above is not stated correctly but it does raise the question does any of this apply to digital?

 

Also, are there rules on how much time to allow the ADC to charge? Is this a problem only if you are coming out of a low power mode?

 

I will try putting together a circuit or two and experiment - tried power from a inexpensive DC wall supply and it did work ok although maybe I am getting lucky. I am trying to make it not work so I can fix it

Share this post


Link to post
Share on other sites

OK, I came back to this today and here are the results....

 

Using 2 AA batteries (3.01V per my meter) and 2 M ohm resistors +/- 5% I constructed a voltage divider.  I measured 1.43 V on my meter and 1.04 with the TM4C123G.  When I put my meter on at the same time as the microcontroller the meter read accurately but the microcontroller changed upwards to 1.19V from 1.04  - the strange behavior that @@altineller described.

 

When I changed the voltage divider to two 100 k ohm +/- 1% resistors I read 1.49 V on the meter and 1.29 V from the MCU.  Putting the meter on or off made no difference to the microcontroller.

 

When I changed the voltage divider to a 100k and a 15k +/-  everything worked.  The meter read 0.393V and the MCU showed .39V more or less.  Having the meter on or off made no difference.  This is the same behavior I saw with a 5.9 V battery above.  I get the same behavior with a steady wall power supply.

 

I set the voltage divider back up again with two 100 k resistors.  This time I put a TLV 2462CP Op Amp in unity gain configuration in front of the MCU pin.  I used another 100k resistor as the feedback resistor on the Op Amp based on advice from a book I have that says to set the feedback resistor equal to the source resistance.  Results improved - this time my meter reads 1.49V and the MCU is showing 1.44.

 

So, I "broke it" and then fixed it (pretty much anyway) based on the advice of @@dubnet.

 

Now to try and answer the questions I raised above.  If anyone has better explanations I ready and willing to learn....

 

 

1) if doing one way 5V --> 3V3 logic conversion from a sensor or module to the MCU then keeping the voltage divider resistances in the 100 ohm range is good.

I don't really ever use the TM4C123G - I really only use the MSP430 line and mostly the F5529.   There is a detailed guide from TI on logic conversion for MSP430s, SLAA148:  http://www.ti.com/lit/an/slaa148/slaa148.pdf 

The guide uses some pretty high resistances though in an example.

 

 

2) if monitoring voltage and it is desireable to minimize current draw from the circuit being monitored then use higher resistance in the divider but use an Op Amp or maybe FET input Op Amp inbetween as a buffer.

I'm not even sure what I meant by this now :) .  There is a discussion of this at E2E here:  https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/342579

They state "the higher the source impedance and the smaller the maximum current, the more time you need in the sampling stage to fill the sampling capacitor".   I'll try to keep the source impedance low or use an Op Amp if what I have isn't working....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×