I am new to STM32F103. I need to connect a shunt current measurement sensor whose output voltage range is 5V to the ADC pin of STM32F103. But the ADC conversion range of STM32 is 3.6V. What is the solution so that I can get proper output from the current sensor?
-
\$\begingroup\$ Change shunt? Choose a 5 V capable A/D? Voltage divider? \$\endgroup\$– winnyNov 16, 2018 at 8:19
-
\$\begingroup\$ Thanks. But its not possible to change shunt. So can you please explain the other two methods. \$\endgroup\$– JackieNov 16, 2018 at 8:21
-
\$\begingroup\$ What bandwidth do you need? \$\endgroup\$– winnyNov 16, 2018 at 8:22
-
1\$\begingroup\$ Could you provide a schematic or drawing of what you are trying to achieve ? \$\endgroup\$– Peter KarlsenNov 16, 2018 at 8:47
-
2\$\begingroup\$ Is the shunt a simple resistor or are you using a sensor such as an LEM module? \$\endgroup\$– Spehro PefhanyNov 16, 2018 at 15:42
2 Answers
Ideally you would use a low-side shunt, and perhaps amplify it. That way you start within the range of the ADC, and potentially map the expected (typically small) voltages seen across the shunt to a meaningful fraction of the ADC range.
If you must stay with a hide side shunt, a better solution might be a differential amplifier which can remove the offset voltage and multiply, yielding an increased voltage variation ranging up from ground. You can do this yourself with op-amps, or you can use a chip specifically made for this purpose, such as the INA139/INA169.
Beware too that the STM32F1xx ADC is considered a bit noisy by some - be careful with analog design, shut down unused parts of the MCU during the measurement, and consider software filtering.
Another solution could be to use the INA219, which handles both the high side to low side offset conversion, and also includes the ADC, so that you merely query it over its I2C interface. Adafruit has a breakout board for this and sample Arduino code you can use to give it a try before integrating it into a design; the board is widely cloned by others (it is an open hardware design) though one should suspect they may come with the lower quality grade of the chip and perhaps a cheaper shunt resistor (but you may end up removing the on-board shunt anyway).
If your system already has a differential amplifier and outputs a 0-5v range, then a divider as Jeff suggests might work, but it depends on the nature of the amplifier output. Some (such as the INA139/169 mentioned above) use a load resistor to program the output voltage range, if you have such a system what you would probably want to do is calculate a parallel external load resistor which would reprogram the range to match your ADC range.
A simple voltage divider will scale the 0-5V output to a 0-3.57V input when using the resistor values given below.
simulate this circuit – Schematic created using CircuitLab
-
\$\begingroup\$ While that is true, this will make for a very limited measurement - the entire expected range of current will probably map to just a handful of ADC counts. \$\endgroup\$ Nov 16, 2018 at 15:19
-
1\$\begingroup\$ @Chris, It looks OK to me. The OP is using a 0 - 5 V output current sensor. This will give 0 - 3.57 V to the ADC. What am I missing? \$\endgroup\$ Nov 16, 2018 at 17:42
-
1\$\begingroup\$ That would depend if they have a system with an amplifier which outputs a 0-5v range signal, or if they have a high side current shunt which would output a signal a few millivolts less than 5v. Note that some amplifier systems have their output range programmed by a resistor, so instead of a divider you should probably just calculate a parallel resistance to change the range. \$\endgroup\$ Nov 16, 2018 at 17:57