Commit 4361c96c authored by Jordan Yates's avatar Jordan Yates Committed by Henrik Brix Andersen
Browse files

adc: current_sense_amplifier: resistance in milli-ohms



Change the unit of the sense resistor in the devicetree binding from
micro-ohms to milli-ohms. This is done for three reasons.

Firstly, the maximum value resistor that can currently be represented
is 4.2 kOhms, due to the limitation of devicetree properties to 32 bits.

Secondly, storing the resistance at such a high resolution makes
overflows much more likely when the desired output unit is micro-amps,
not milli-amps.

Finally, micro-ohms, are an unnecessarily precise unit for the purpose
of these calculations, and a resolution that is not realistic to
achieve. The high resistor resolution results in large divisors that
reduce the resolution of outputs. Unlike resistors characterised down to
the micro-ohm, devices wanting to measure micro-amps are actually
realistic.

Signed-off-by: default avatarJordan Yates <jordan@embeint.com>
parent e0a262b3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -65,14 +65,14 @@
	csa_vbus: vbusc {
		compatible = "current-sense-amplifier";
		io-channels = <&adc1 17>;
		sense-resistor-micro-ohms = <3000>;
		sense-resistor-milli-ohms = <3>;
		sense-gain-mult = <100>;
	};

	csa_cc2: vconc {
		compatible = "current-sense-amplifier";
		io-channels = <&adc1 18>;
		sense-resistor-micro-ohms = <10000>;
		sense-resistor-milli-ohms = <10>;
		sense-gain-mult = <25>;
	};

+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@
	csa_i_sense: i_sense {
		compatible = "current-sense-amplifier";
		io-channels = <&adc 5>;
		sense-resistor-micro-ohms = <4000>;
		sense-resistor-milli-ohms = <4>;
		sense-gain-mult = <100>;
	};

+3 −0
Original line number Diff line number Diff line
@@ -240,6 +240,9 @@ Sensors
* The existing driver for the Microchip MCP9808 temperature sensor transformed and renamed
  to support all JEDEC JC 42.4 compatible temperature sensors. It now uses the
  :dtcompatible:`jedec,jc-42.4-temp` compatible string instead to the ``microchip,mcp9808`` string.
* The :dtcompatible:`current-sense-amplifier` sense resistor is now specified in milli-ohms
  (``sense-resistor-milli-ohms``) instead of micro-ohms in order to increase the maximum representable
  resistor from 4.2k to 4.2M.

* The ``nxp,`` prefixed properties in :dtcompatible:`nxp,kinetis-acmp` have been deprecated in favor
  of properties without the prefix. The sensor based driver for the :dtcompatible:`nxp,kinetis-acmp`
+3 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/pm/device.h>
#include <zephyr/sys/__assert.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(current_amp, CONFIG_SENSOR_LOG_LEVEL);
@@ -115,6 +116,8 @@ static int current_init(const struct device *dev)
	struct current_sense_amplifier_data *data = dev->data;
	int ret;

	__ASSERT(config->sense_milli_ohms != 0, "Milli-ohms must not be 0");

	if (!adc_is_ready_dt(&config->port)) {
		LOG_ERR("ADC is not ready");
		return -ENODEV;
+2 −2
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@ properties:
    description: |
      Channels available with this divider configuration.

  sense-resistor-micro-ohms:
  sense-resistor-milli-ohms:
    type: int
    required: true
    description: |
      Resistance of the shunt resistor in micro-ohms
      Resistance of the shunt resistor in milli-ohms.

  sense-gain-mult:
    type: int
Loading