mc-Module > mc-Module
AnalogInput units
Nick_W:
I'm reading an analogInput pin, and I would like to convert the reading from mV to voltage independent units (ie 0-1023), as the battery voltage may vary.
I'm currently assuming that reading the Battery Voltage will give me the maximum value (1023 units) and using the following to convert:
--- Code: ---((1023 * reading) / batvolt).ToInteger()
--- End code ---
However it occurs to me that this cannot in fact be correct (or the battery voltage would always read maximum), so there must be an internal voltage reference.
The documentation does say this "When a pin is in “AnalogInput” mode, the system reads the value based on the internal band-gap reference value."
Reading the data sheet, the internal reference is 0.6V, so assuming a gain of 1/6 this would give a range of 0-3.6V (which seems to be the case).
This would then make my conversion:
--- Code: ---((1023 * reading) / 3600).ToInteger()
--- End code ---
Is this correct? am I making the correct assumptions here?
Thanks.
mc-John:
We have the resolution at 14-bit. The system returns the result (NRF_SAADC->RESULT.PRT). Because we return the value in millivolt we multiply that by 3600 and divide that by 2^14.
--- Code: ---return (result*3600)>>14;
--- End code ---
To get the value back you just have to undo this like the code below:
--- Code: ---result = (millivolt<<14)/3600;
--- End code ---
Nick_W:
OK, so your reference is 3600 though, not BatVolt as I suspected.
I'll stick with what I have, no-one needs 14 bits from an on-board ADC, I need 10, same as most applications out there.
BTW, don't you have to oversample to get 14 bits? the built in is only 12 bits. That would slow down the response quite a bit, and seems somewhat pointless. Why not stick with 12 bits? it's more than most applications could possibly need, no-one expects nanoVolt precision from these devices.
mariahernandez:
Hello mcThings' team,
I'm working on a energy sensor using the mc-module120, at the first time when I did't know the resolution of the mc-Module I decided to power the analog input to get the resolution of it and I found that if I power the module with 2,8V(using the VCC pin of the mc-Module) I got a value range close to 2600, and if I power it with 3.3V (external power supply) I got a lower result value close to 1700. That's no make too much sense for me, because if I power the module with a highger voltage the result should be highger and not less, or not? e.i. If I power an Analog input of a NodeMCU with 3.3V I get that the resolution is 1024 (10 bits resolution)
After reading this post I found the that the resolution of the mc-module is 16384 (14 bits resolution), but if I use the following formula (using the correct resolution) I'm not able to get the correct value from the sensor.
--- Code: ---value = (sensorReading*3.3)/16384;
--- End code ---
At the moment I have the energy sensor working with a Particle Electron working perfectly. The resolution of this device is 12 bits (4096) and with the following formula is how I get the value from the sensor:
--- Code: ---float value = (analogRead(A0)*3.3)/4096.0;
--- End code ---
Btw, I'm using a i-Snail-VC-50 -> http://www.phidgets.com/products.php?product_id=3502 if you know something about it I would appreciate any help!
I hope you can solve my doubts with the resolution of the module as soon is possible to start working with it, I'm so excited to see it working!
Best Regards,
Maria C
Nick_W:
Maria,
I think you are mixing float and integer types, plus the voltage reference is 3600 not 3.3.
What I think you are looking for is:
--- Code: ---value = (sensorReading\3600)*16384
--- End code ---
or for 0-1024
--- Code: ---value = (1023 * reading) \ 3600
--- End code ---
where "value" is an integer type. Due to some odd math in McThings, division (/) always returns a float, so unless "value" was a float, you would get strange results. To do integer division, you use \ as shown above.
This will give you a reading from 0 to 16384 (0 to 3.6V), or 0-1024 if you use the second version. 3.6V is the maximum you can read. Note: this is not 3.3V or battery voltage, but is based on the internal 0.6V reference - so you can't change it, or use another number!
You also need to keep your units and data types consistent, sensorReading is in mV, and is a Short, 3.3 is in Volts and is a float. This combination is probably causing all the headaches.
Good luck with the project!
Navigation
[0] Message Index
[#] Next page
Go to full version