Hello all!I've red all the documentation I've found about the measuring input voltage and comparing it to internal reference (2.0V). Yet my results with voltage measurements are way off. I'm posting my code below. With accurate multimeter I get the result of 2,958 V. But with ADC I get the result of 145 (8-bit) which turns into 2,27V with my conversion formula:
VCC = 2 * result * (Vref/255) = 2.27V,
Vref = 2.0V.
I've went through all forums I found and it bugges me that I don't find anything wrong with my attempt. Any help?
Ofcourse, what is the step size? or in other way, what is the minimum resolution you can get from your ADC? I think this will answer your question.
Hope this helps.
as I see it, the step size is 4 / 255 V = ~16 mV which is okay for me. Results were the same when I used 10-bit conversion. It seems not to explain why I get 2,27 V when I should get nearly 3 volts.
Do u get 145 every time???????
if you are using 12bit adc then result = 1023*i/p/Vref;
can you explain how u derived this formula??
There is a bug inside the ref module of the serie 6xxx, ADC27 in the errata sheet. But the workaround seems not to works as described, what I discovered is to divide the ADC12OSC by 3 and not set the reference as output, and to use the register of the ADC12 to set the reference (REFMSTR=0). With this configuration temp. sensor, voltage divider and AI seems to works,.
Anyway, another thing is that you can't use REFGENBUSY to check if the reference is stable, this bits indicates that the reference is used bay a module. You have to set an independant wait loop.
You can also use interruption ans set LPM3 to wait for the conversion, ths will reduce ADC noise.
Finally your formula seems not to be correct, have a lock on page 550 of slau208i.pdf. Using the voltage divider, Vref+ (2.0V) and AVss in 12bits mode, the conversion (whitout using TLV) is NADC*4/4095.
Ok, good to know about the REFGENBUSY, I'll revert back to my simple delay. I will have to try to set the ref voltage in ADC register and not in the Shared Reference register.
Your conversion code seems to be the same as mine! Instead of 2 * 2.0 (multiplying first by two because of the Vcc divider and then multiplying by two because of the 2,0V reference) it uses multiplication by 4.
145*4/255 = 2,27V, here using 255 because of the 8-bit resolution.
And question regarding the ADC result; conversion is NOT always the same but it depends on actual Vcc. It just seems to be too small value all the time. I will post more result later.
Oh yeah, my fault concerning the calculation, the 8bit resolution went off my brain while answering:D
You'll not be able to select 2.0V VRef directly with the ADC12 registers, but 1,5 or 2,5. This should be ok for testing the measurement.
Try to lengthen the sampling time too.
I changed my battery and with multimeter I got 3,538 V. This gave me out ADC result of 177. With conversion formula 177*4/255 I got the result of 2,78 V. So when voltage goes up, my result goes up but it is too low...
Edit: Getting out of ideas... I changed to use the ADC reference 2,5V and when expecting 3,538 V, got the result of 141. This turns out as 141*2,5*2/255 = 2,78 V. So not better at all...
Did you have access to the TLV structure?
And could you measure your Vref?
I tried way longer sampling time but with same result. I'll have to measure the Vref once I have time to do that. I'm not sure what TLV is used for. I quickly checked through the datasheet what it means, but didn't know what to see from there.
Thanks for the help so far!
There is some calibration values in the TLV, but your measures are way out of range;)
"Edit: Getting out of ideas... I changed to use the ADC reference 2,5V and when expecting 3,538 V, got the result of 141. This turns out as 141*2,5*2/255 = 2,78 V. So not better at all..."
Is seems it's not a reference problem, as you measure the same voltage the two times. It's perhaps your multimeter which is wrong xD
I've tried with lab power supply with voltage reading too, so unfortunately the answer isn't that easy. :)
ArgailI changed to use the ADC reference 2,5V and when expecting 3,538 V, got the result of 141.
To my knowledge if you can use a reference of 2.5V, you can test a maximum of 2.5V. I am using ADC on 5438 experimenter board and I give a reference of 3.3V, the maximum output of ADC corresponds to 3V.
Please check this and let me know. Hope this helps.
Yeah, it is true that you can measure the Vref at max. But for that reason the ADC channel B (ADC12INCH_11) is Vcc divided by two (with two equal resistors). Therefore I'm actually measuring half of the 3,538 V (which is 1,769 V). The result just needs to be multiplied by two to get the result. It is included in the calculation formula.
I set the ADC reference from ADC registers and disabled the Shared reference. Then I outputted the Vref+ from P2.5. I got mysterious results.
When I set the 2,5 V reference, the measured value was 2,11 V and when I set the 1,5 V reference, the measured value was 1,26 V. Whats going on? The uC pin is unused and unrouted, so it doesn't sink too much current or so. Why the reference levels are so low? These were measured with 2,9+ V power supply. With 3,4 V power supply I get better results, but the 2,5V reference is still bit low 2,4V.
REFCTL0 = 0; ADC12CTL0 = ADC12ON + ADC12REFON; // Turn on ADC12, set sampling time (0000 = 4clk), 1,5 V ref
ADC12CTL2 |= ADC12REFOUT; // Ref out PMAPPWD = 0x02D52; // Get write-access to port mapping regs PMAPCTL |= PMAPRECFG; // Do NOT lock the port settings. P2MAP5 = PM_ANALOG; // Analog data out PMAPPWD = 0; // Lock port mapping registers P2SEL |= BIT5; // Select pin function
Veikko Soininen1When I set the 2,5 V reference, the measured value was 2,11 V and when I set the 1,5 V reference, the measured value was 1,26 V
However, I wouldn't use a multimeter to measure any MCU-related voltage if I have a problem. Use a scope instead. Multimeters do averaging and low-pass high-frequency distortions, while those things may well influence your readings.
Veikko Soininen1 P2MAP5 = PM_ANALOG; // Analog data out
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.