spirilis 1,265 Posted September 12, 2013 Share Posted September 12, 2013 Yeah, you won't find that on an ultra-low-power MCU I'd bet. Fwiw, I think Atmel has some ATTiny chips that can boast <1.0V operation because they include a charge pump onboard... but I've never known atmel's chips to be optimized for "ULP" per se. Quote Link to post Share on other sites
ilpaso 0 Posted September 12, 2013 Author Share Posted September 12, 2013 Hi all, @semicolo: Thanks a lot for the code. but if the the voltage is < 3V i think it can't read the value because it needs a 1.5V reference. The code in the first post is quite ok. I think I need only to reset an ADC register in order to restart in a clean state. But I don't know what I've to reset. Quote Link to post Share on other sites
Register 3 Posted September 13, 2013 Share Posted September 13, 2013 Voltage regulators can only lower voltages... For analogRead the value isn't really the Energia pin# but rather the ADC channel (INCH_xx constant), 11 just happens to be an internal "(Vcc-Vss)/2" generated channel used for measuring the MSP430's Vcc voltage. Sent from my Galaxy Note II with Tapatalk 4 Hi, thanx for the explanation. If one wants to use the #11 pin for power measurement one should not use it for other purpose or it will mess with measurement, I suppose. Quote Link to post Share on other sites
semicolo 39 Posted September 13, 2013 Share Posted September 13, 2013 I was just making a quick test. Something like this should do the same as your code and be easier to read than working with the MSP430 registers: #define ANALOG_HALFVCC_INPUT 11 void setup() { Serial.begin(9600); // msp430g2231 must use 4800 } // returns VCC in millivolts int getVCC() { // start with the 1.5V internal reference analogReference(INTERNAL1V5); int data = analogRead(ANALOG_HALFVCC_INPUT); // if overflow, VCC is > 3V, switch to the 2.5V reference if (data==0x3ff) { analogReference(INTERNAL2V5); data = (int)map(analogRead(ANALOG_HALFVCC_INPUT), 0, 1023, 0, 5000); } else { data = (int)map(data, 0, 1023, 0, 3000); } return data; } void loop() { Serial.print("VCC value:"); int data = getVCC(); Serial.println (data); delay(1000); } Would be nice to have a standard constant for reading VCC ilpaso 1 Quote Link to post Share on other sites
spirilis 1,265 Posted September 14, 2013 Share Posted September 14, 2013 Hi, thanx for the explanation. If one wants to use the #11 pin for power measurement one should not use it for other purpose or it will mess with measurement, I suppose. It's actually not like that ... analog "pin" 11 doesn't correspond to pin#11 on the MCU's leads, it corresponds to an internal virtual channel. So digitalWrite/digitalRead type of operations on pin 11 can still happen while you're reading "analog pin" 11. Analog "pins" and digital "pins" are actually separate concepts in Energia, but it just so happens that the analog pins correspond to the digital pins for the first 8 (A0-A7). Example from Energia's pins_energia.h for the launchpad: static const uint8_t A0 = 0; static const uint8_t A1 = 1; static const uint8_t A2 = 2; static const uint8_t A3 = 3; static const uint8_t A4 = 4; static const uint8_t A5 = 5; static const uint8_t A6 = 6; static const uint8_t A7 = 7; static const uint8_t A10 = 10; // special. This is the internal temp sensor "analog pin" 10, in fact, is the temperature sensor inside the chip and has nothing to do with "digital" pin #10. It's just 0-7 that correspond. 11 isn't listed there but it happens to be the "(Vcc-Vss)/2" channel. What actually happens is the digital pins get resolved by some lookup tables in pins_energia.h into a PxOUT / BITx combination for manipulating the digital states, but analog input channels resolve into INCH_xx values which are written to the ADC10CTL1 register before an ADC conversion (analog read) is performed. abecedarian and Register 2 Quote Link to post Share on other sites
ilpaso 0 Posted September 14, 2013 Author Share Posted September 14, 2013 thanks Semicolo it works well and it is easier to read! Quote Link to post Share on other sites
Register 3 Posted September 16, 2013 Share Posted September 16, 2013 What actually happens is the digital pins get resolved by some lookup tables in pins_energia.h into a PxOUT / BITx combination for manipulating the digital states, but analog input channels resolve into INCH_xx values which are written to the ADC10CTL1 register before an ADC conversion (analog read) is performed. Not the first time I get confused and mess logical and physical pin assignments. My bad Quote Link to post Share on other sites
semicolo 39 Posted September 16, 2013 Share Posted September 16, 2013 Don't know if i should be worried about it Quote Link to post Share on other sites
semicolo 39 Posted September 23, 2013 Share Posted September 23, 2013 Just tried this with the launchpad connected to a li-ion battery, the accuracy drops a lot when the 1.5V reference is used, I'll try to find why. VCC value:3.103 VCC value:3.103 VCC value:3.98 VCC value:3.103 VCC value:3.93 VCC value:3.98 VCC value:3.93 VCC value:3.98 VCC value:3.93 Instead of finding about 3V, it jumps to 4V, maybe there's a bug in the code. Quote Link to post Share on other sites
semicolo 39 Posted September 24, 2013 Share Posted September 24, 2013 Found it! This line is bogus Serial.println (data%1000); It'll display 98 instead of 098. I'll just change the code to display millivolts. Quote Link to post Share on other sites
professorpacs 0 Posted May 27, 2014 Share Posted May 27, 2014 Another variety of the test routine, this time on the F5529 Launchpad. appears to be off by a factor of 2. (5000 is not the right value for the 'map' function?) #include "Energia.h" #define ANALOG_HALFVCC_INPUT 11 void setup() { // start with the 2.5V internal reference analogReference(INTERNAL2V5); Serial.begin(115200); // msp430f5529 Launchpad } // returns VCC in millivolts int getVCC() { int rawdata = analogRead(ANALOG_HALFVCC_INPUT); int data = (int)map(rawdata, 0, 4096, 0, 5000); // Modified for ADC12_A Serial.print("ADC12_A Value: 0x"); Serial.print(rawdata, HEX); Serial.print("\t VCC: "); Serial.println (data, DEC); Serial.print("ADC12REF2_5V: 0x"); Serial.println(ADC12REF2_5V, HEX); Serial.print("ADC12CTL0: 0x"); Serial.println(ADC12CTL0, HEX); Serial.println("---end of ADC CH11 read---"); return 0; } void loop() { int data = getVCC(); delay(1000); } /* --sample output -- ADC12_A Value: 0x7FF VCC: 2498 ADC12REF2_5V: 0x40 ADC12CTL0: 0x412 ---end of ADC CH11 read--- ADC12_A Value: 0x7FF VCC: 2498 ADC12REF2_5V: 0x40 ADC12CTL0: 0x412 ---end of ADC CH11 read--- ADC12_A Value: 0x7FF VCC: 2498 ADC12REF2_5V: 0x40 ADC12CTL0: 0x412 ---end of ADC CH11 read--- */ Quote Link to post Share on other sites
semicolo 39 Posted May 27, 2014 Share Posted May 27, 2014 I don't have a F5529,it looks like it's reading the 2.5V reference instead of half_VCC, I'll try to get the datasheet and have a look if you don't figure it out first. Quote Link to post Share on other sites
semicolo 39 Posted May 27, 2014 Share Posted May 27, 2014 If I'm not mistaken the F5529 has an ADC_12_A but it doesn't seem to be handled in the energia sources, there's ADC10, ADC10_B, ADC12_PLUS and ADC12_B. What do you think @@energia? Quote Link to post Share on other sites
LindsayK 0 Posted November 13, 2015 Share Posted November 13, 2015 I got the above sketch to work on the F5529 by changing the second line to: #define ANALOG_HALFVCC_INPUT A11 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.