Skip to content

Instantly share code, notes, and snippets.

@enginsubasi
Last active December 3, 2020 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginsubasi/36c067717ab4d75332919c05914b3c3e to your computer and use it in GitHub Desktop.
Save enginsubasi/36c067717ab4d75332919c05914b3c3e to your computer and use it in GitHub Desktop.
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