MSP430 ADC poor stability - Page 1
Forum section: electronics / general

author: Simon123
author_rank: Regular Contributor
timestamp: December 15, 2014, 08:39:22 pm
content: Hello!I have written a simple ADC - Serial voltage readout monitor.But the problem is poor stability, sometimes numbers are jumping around like crazy.I'm using energia for programming.I have already moved analogreference() from loop to setup, and it improved a little bit, but still not stable.void setup(){analogReference(INTERNAL1V5);Serial.begin(9600);}void loop(){int sensorValue = analogRead(A4);int voltage = sensorValue * (1500 / 1023.00) ;Serial.println("Ubatt");Serial.print(voltage);Serial.println(" mV");int sensorValue1 = analogRead(A3);int voltage1 = sensorValue1 * (1500 / 1023.00 ) ;Serial.println("Iload");Serial.print(voltage1);Serial.println(" mA");}

author: colotron
author_rank: Contributor
timestamp: December 15, 2014, 09:43:19 pm
content: Hi there. I not use energia but have some experience with msp430.First, which microcontroller/launchpad are you using?.I thought to take a look at the Energia source code to see how it implements analog functions (https://github.com/energia/Energia/blob/master/hardware/msp430/cores/msp430/wiring_analog.c, analogRead function) , but I need to know which microcontroller/launchpad is being used first.First thing that call my attention, a fixed settling time is being used. How is your analog input connected/what kind of analog signal are you measuring?. If for example you are using 2Meg resistors for a voltage divider to monitor a coin battery (you said Ubatt in your code...). , the source resistance will be to high and the acquisition time used by default in Energia insufficient.Are both numbers voltage and current jumping?, or voltage only?.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: December 15, 2014, 09:49:33 pm
content: What does "jumping around like crazy" mean? What settling time are you using? What kind of voltage are you measuring? What is its output impedance?

author: dannyf
author_rank: Super Contributor
timestamp: December 15, 2014, 10:31:56 pm
content: You need to make sure first that it isn't an issue of source signal or expectation.Typically, it is due to the ADC being too fast. Check the code against the datasheet.

author: Simon123
author_rank: Regular Contributor
timestamp: December 15, 2014, 10:36:44 pm
content: Thanks for response.Ubatt is just some thing, i will change(it actualy isnt measuring battery voltage).This part will go to voltage divider and i should get 0-1V on the output of divider and something like 0-5V on the input.The current thingie is actualy measuring voltage as well, but it is connected to shunt and op amp.Idk whats my input impedance, the wires go straight to the micro.Everything i measure is DC.Jump around like crazy b, it changes +-10mV, but sometimes it goes even higher.Whats settling time? It takes sample and prints it out every second or so, if thats what that is.The settling time comes from another part of the code(i didnt copy it here cuz its ok) which uses serial terminal as input to output data on some digital pins.As voltage source i used RIGOL 3 channel power supply-modern digital type one.I don't think ADC is to fast at 1s sampling time.Oh and im using 430G2452 or 430G2553 which i also have.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: December 15, 2014, 10:48:31 pm
content: Quote from: Simon123 on December 15, 2014, 10:36:44 pmNot input impedance, output impedance. If you're pulling off of a voltage divider, what are the resistors being used? Do you have a cap to help stabilize the voltage before the uC?Quote from: Simon123 on December 15, 2014, 10:36:44 pmThat's really not that crazy. The msp doesn't have a precision ADC. On a 1.5V range, you're looking at about 1.5mV/LSB. The error on the ADC can be +/- a couple LSB, so you're already looking at +/- 3mV or so even with a perfect source and perfect sampling. In addition to that, how clean is the output of that power supply and are there any noise sources nearby? How is the MSP being powered (voltage, capacitance, etc.)?Quote from: Simon123 on December 15, 2014, 10:36:44 pmThat's not what it means. I recommend familiarizing yourself with the datasheet:http://www.ti.com/lit/ug/slau144j/slau144j.pdfIn particular, section 22, it's only about 25 pages. What we're asking is how the ADC clock and sample-and-hold is configured (see section 22.3.1). Also see section 22.2.5, which talks about timing considerations.

author: dannyf
author_rank: Super Contributor
timestamp: December 15, 2014, 11:05:01 pm
content: -10mV-For a typical 10bit ADC, fluctuations of 10 lsb or less are not unusual, and 4 lsb or less are common.If your ref is 5v, each lsb is about 5mv.Your issue looks to be unrealistic expectations.

author: Simon123
author_rank: Regular Contributor
timestamp: December 15, 2014, 11:24:43 pm
content: Ok, thanks. Ill read that pdf tomorow, when ill have time and reply.If what i am trying to do are just unrealistic expectations, maybe ill just leave it like that.There is no smothing, but i already tried it and it didn't help.The output impedance of one thing is like 60k, for the other one ill have to check.I am powering the thing from that usb board thing.Noise sources->a lot(power cords, internet cable everywhere and stuff...

author: suicidaleggroll
author_rank: Super Contributor
timestamp: December 15, 2014, 11:33:10 pm
content: Quote from: Simon123 on December 15, 2014, 11:24:43 pmWith a 60k output impedance on the source, you need a sample time of at least 12.8 uS (see section 22.2.5.1 in the earlier pdf). You'll need to check your ADC clock source, clock divider, and sample-and-hold settings to make sure you're not violating that limit.

author: dannyf
author_rank: Super Contributor
timestamp: December 16, 2014, 12:29:04 am
content: (Super) high impedance (we are talking about Mohm or more) is only an issue if you are attempting to measure fast signals.For slow moving DC, it is not that big of an issue in the <Mohm range and can be cured with a small capacitor on the adc's input pin to prevent errors caused by charge transfer. Something like 1nf+ would be more than enough, and I typically use 0.1uf to simplify BOM.For fast signals, you may have to resort to opamps / buffers.

author: colotron
author_rank: Contributor
timestamp: December 16, 2014, 11:23:09 am
content: Quote from: Simon123 on December 15, 2014, 11:24:43 pmOk, I don't think the problem is acquisition time. It was the first thing come to mind not having information about the setup.As said above, 10 LSB error is not so bad, could be better?, maybe; try an accurate external reference (internal reference error is more or less +/-10mV - msp430g2553 datasheet-page 38), input cap on analog input, cleaner supply (msp430g2553 dip version doesn't have separated supply pin AVCC).What about a software issue?int voltage1 = sensorValue1 * (1500 / 1023.00 ) ;are you sure that this arithmetic doesn't overflow, or there aren't any problems mixing integers and floats? (test: do a table with sensorvalue as input and see if the calculation is right for all possible values).The large variation applies only to voltage1 or to sensorValue also?.

author: Simon123
author_rank: Regular Contributor
timestamp: December 16, 2014, 06:39:12 pm
content: Thanks!I installed 1nF caps directly under the uC socket, and now its more accurate.I have also changed to larger voltage reference 2.5V.And i alsochanged that int voltage and int voltage1 to (250/1023.00), cuz i dont need extreme resolution anyways.Now it moves like +-2 if it does, but usualy stays prety stable.