Last active
December 3, 2020 09:42
-
-
Save enginsubasi/36c067717ab4d75332919c05914b3c3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const double rshunt = 0.050; // Ohm | |
const double ri = 1100; // Ohm | |
const double rf = 22000; // Ohm | |
const uint32_t adcVoltageRef = 5; | |
const uint32_t adcUpValue = 1023; | |
// Calculate gain in the beginning. | |
setup() | |
{ | |
gain = 1 + ( rf / ri ); | |
} | |
double adcToCurrentMilliamp ( uint32_t adcValue ) | |
{ | |
// This calculation was not simplified for easy understanding. | |
double current = 0; | |
current = adcValue; /* to cast operation in double domain */ | |
current = ( ( current * adcVoltageRef ) / adcUpValue ); | |
current /= gain; | |
current /= rshunt; | |
return ( current ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment