ade9000.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===============
  3. ADE9000 driver
  4. ===============
  5. This driver supports Analog Device's ADE9000 energy measurement IC on SPI bus.
  6. 1. Supported devices
  7. ====================
  8. * `ADE9000 <https://www.analog.com/media/en/technical-documentation/data-sheets/ADE9000.pdf>`_
  9. The ADE9000 is a highly accurate, fully integrated, multiphase energy and power
  10. quality monitoring device. Superior analog performance and a digital signal
  11. processing (DSP) core enable accurate energy monitoring over a wide dynamic
  12. range. An integrated high end reference ensures low drift over temperature
  13. with a combined drift of less than ±25 ppm/°C maximum for the entire channel
  14. including a programmable gain amplifier (PGA) and an analog-to-digital
  15. converter (ADC).
  16. 2. Device attributes
  17. ====================
  18. Power and energy measurements are provided for voltage, current, active power,
  19. reactive power, apparent power, and power factor across three phases.
  20. Each IIO device has a device folder under ``/sys/bus/iio/devices/iio:deviceX``,
  21. where X is the IIO index of the device. Under these folders reside a set of
  22. device files, depending on the characteristics and features of the hardware
  23. device in question. These files are consistently generalized and documented in
  24. the IIO ABI documentation.
  25. The following tables show the ADE9000 related device files, found in the
  26. specific device folder path ``/sys/bus/iio/devices/iio:deviceX``.
  27. +---------------------------------------------------+----------------------------------------------------------+
  28. | Current measurement related device files | Description |
  29. +---------------------------------------------------+----------------------------------------------------------+
  30. | in_current[0-2]_raw | Raw current measurement for phases A, B, C. |
  31. +---------------------------------------------------+----------------------------------------------------------+
  32. | in_current[0-2]_scale | Scale for current channels. |
  33. +---------------------------------------------------+----------------------------------------------------------+
  34. | in_current[0-2]_calibscale | Calibration gain for current channels (AIGAIN reg). |
  35. +---------------------------------------------------+----------------------------------------------------------+
  36. | in_altcurrent[0-2]_rms_raw | RMS current measurement for phases A, B, C. |
  37. +---------------------------------------------------+----------------------------------------------------------+
  38. | in_altcurrent[0-2]_rms_scale | Scale for RMS current channels. |
  39. +---------------------------------------------------+----------------------------------------------------------+
  40. | in_altcurrent[0-2]_rms_calibbias | RMS offset correction for current channels (IRMSOS reg). |
  41. +---------------------------------------------------+----------------------------------------------------------+
  42. +---------------------------------------------------+----------------------------------------------------------+
  43. | Voltage measurement related device files | Description |
  44. +---------------------------------------------------+----------------------------------------------------------+
  45. | in_voltage[0-2]_raw | Raw voltage measurement for phases A, B, C. |
  46. +---------------------------------------------------+----------------------------------------------------------+
  47. | in_voltage[0-2]_scale | Scale for voltage channels. |
  48. +---------------------------------------------------+----------------------------------------------------------+
  49. | in_voltage[0-2]_calibscale | Calibration gain for voltage channels (AVGAIN reg). |
  50. +---------------------------------------------------+----------------------------------------------------------+
  51. | in_voltage[0-2]_frequency | Measured line frequency from instantaneous voltage. |
  52. +---------------------------------------------------+----------------------------------------------------------+
  53. | in_altvoltage[0-2]_rms_raw | RMS voltage measurement for phases A, B, C. |
  54. +---------------------------------------------------+----------------------------------------------------------+
  55. | in_altvoltage[0-2]_rms_scale | Scale for RMS voltage channels. |
  56. +---------------------------------------------------+----------------------------------------------------------+
  57. | in_altvoltage[0-2]_rms_calibbias | RMS offset correction for voltage channels (VRMSOS reg). |
  58. +---------------------------------------------------+----------------------------------------------------------+
  59. +---------------------------------------------------+----------------------------------------------------------+
  60. | Power measurement related device files | Description |
  61. +---------------------------------------------------+----------------------------------------------------------+
  62. | in_power[0-2]_active_raw | Active power measurement for phases A, B, C. |
  63. +---------------------------------------------------+----------------------------------------------------------+
  64. | in_power[0-2]_active_scale | Scale for active power channels. |
  65. +---------------------------------------------------+----------------------------------------------------------+
  66. | in_power[0-2]_active_calibbias | Calibration offset for active power (xWATTOS regs). |
  67. +---------------------------------------------------+----------------------------------------------------------+
  68. | in_power[0-2]_active_calibscale | Calibration gain for active power (APGAIN reg). |
  69. +---------------------------------------------------+----------------------------------------------------------+
  70. | in_power[0-2]_reactive_raw | Reactive power measurement for phases A, B, C. |
  71. +---------------------------------------------------+----------------------------------------------------------+
  72. | in_power[0-2]_reactive_scale | Scale for reactive power channels. |
  73. +---------------------------------------------------+----------------------------------------------------------+
  74. | in_power[0-2]_reactive_calibbias | Calibration offset for reactive power (xVAROS regs). |
  75. +---------------------------------------------------+----------------------------------------------------------+
  76. | in_power[0-2]_apparent_raw | Apparent power measurement for phases A, B, C. |
  77. +---------------------------------------------------+----------------------------------------------------------+
  78. | in_power[0-2]_apparent_scale | Scale for apparent power channels. |
  79. +---------------------------------------------------+----------------------------------------------------------+
  80. | in_power[0-2]_powerfactor | Power factor for phases A, B, C. |
  81. +---------------------------------------------------+----------------------------------------------------------+
  82. +---------------------------------------------------+----------------------------------------------------------+
  83. | Energy measurement related device files | Description |
  84. +---------------------------------------------------+----------------------------------------------------------+
  85. | in_energy[0-2]_active_raw | Active energy measurement for phases A, B, C. |
  86. +---------------------------------------------------+----------------------------------------------------------+
  87. | in_energy[0-2]_reactive_raw | Reactive energy measurement for phases A, B, C. |
  88. +---------------------------------------------------+----------------------------------------------------------+
  89. | in_energy[0-2]_apparent_raw | Apparent energy measurement for phases A, B, C. |
  90. +---------------------------------------------------+----------------------------------------------------------+
  91. +------------------------------+------------------------------------------------------------------+
  92. | Shared device attributes | Description |
  93. +------------------------------+------------------------------------------------------------------+
  94. | name | Name of the IIO device. |
  95. +------------------------------+------------------------------------------------------------------+
  96. | filter_type | Waveform buffer filter type (sinc4, sinc4+lp). |
  97. +------------------------------+------------------------------------------------------------------+
  98. | filter_type_available | Available filter types for waveform buffer. |
  99. +------------------------------+------------------------------------------------------------------+
  100. 3. Calibration and scaling
  101. ===========================
  102. The ADE9000 provides multiple levels of gain and offset correction:
  103. **Calibration Gain (per-channel)**
  104. Fine-tuning calibration gains applied in the digital domain for each channel type.
  105. Controlled via ``calibscale`` attributes (AIGAIN, AVGAIN, APGAIN registers).
  106. **Calibration Bias (per-channel)**
  107. Hardware calibration offsets applied by the device internally:
  108. - Power measurements: Controlled via ``calibbias`` attributes for power channels (xWATTOS, xVAROS registers).
  109. - RMS measurements: Controlled via ``calibbias`` attributes for RMS channels (IRMSOS, VRMSOS registers).
  110. These are internal chip calibrations, not userspace-applied offsets.
  111. 4. Event attributes
  112. ===================
  113. The ADE9000 provides various interrupts that are mapped to IIO events.
  114. Event functionality is only available if the corresponding interrupts are
  115. connected in the device tree.
  116. +---------------------------------------------------+----------------------------------------------------------+
  117. | IIO Event Attribute | ADE9000 Datasheet Equivalent |
  118. +---------------------------------------------------+----------------------------------------------------------+
  119. | in_voltage[0-2]_thresh_either_en | Zero crossing detection interrupt (ZXVx) |
  120. +---------------------------------------------------+----------------------------------------------------------+
  121. | in_altvoltage[0-2]_rms_thresh_rising_en | RMS swell detection interrupt (SWELLx) |
  122. +---------------------------------------------------+----------------------------------------------------------+
  123. | in_altvoltage[0-2]_rms_thresh_rising_value | RMS swell threshold (SWELL_LVL register) |
  124. +---------------------------------------------------+----------------------------------------------------------+
  125. | in_altvoltage[0-2]_rms_thresh_falling_en | RMS sag/dip detection interrupt (DIPx) |
  126. +---------------------------------------------------+----------------------------------------------------------+
  127. | in_altvoltage[0-2]_rms_thresh_falling_value | RMS sag/dip threshold (DIP_LVL register) |
  128. +---------------------------------------------------+----------------------------------------------------------+
  129. | in_current[0-2]_thresh_either_en | Current zero crossing detection interrupt (ZXIx) |
  130. +---------------------------------------------------+----------------------------------------------------------+
  131. Event directions:
  132. - ``rising``: Upper threshold crossing (swell detection)
  133. - ``falling``: Lower threshold crossing (sag/dip detection)
  134. - ``either``: Any threshold crossing (zero crossing detection)
  135. - ``none``: Timeout or non-directional events
  136. **Note**: Event attributes are only available if the corresponding interrupts
  137. (irq0, irq1, dready) are specified in the device tree. The driver works without
  138. interrupts but with reduced functionality.
  139. 5. Device buffers
  140. =================
  141. This driver supports IIO buffers for waveform capture. Buffer functionality
  142. requires the dready interrupt to be connected.
  143. The device supports capturing voltage and current waveforms for power quality
  144. analysis. The waveform buffer can be configured to capture data from different
  145. channel combinations.
  146. Supported channel combinations for buffered capture:
  147. - Phase A: voltage and current (IA + VA)
  148. - Phase B: voltage and current (IB + VB)
  149. - Phase C: voltage and current (IC + VC)
  150. - All phases: all voltage and current channels
  151. - Individual channels: IA, VA, IB, VB, IC, VC
  152. Usage examples
  153. --------------
  154. Enable waveform capture for Phase A:
  155. .. code-block:: bash
  156. root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_current0_en
  157. root:/sys/bus/iio/devices/iio:device0> echo 1 > scan_elements/in_voltage0_en
  158. Set buffer length and enable:
  159. .. code-block:: bash
  160. root:/sys/bus/iio/devices/iio:device0> echo 100 > buffer/length
  161. root:/sys/bus/iio/devices/iio:device0> echo 1 > buffer/enable
  162. 6. Clock output
  163. ===============
  164. The ADE9000 can provide a clock output via the CLKOUT pin when using an external
  165. crystal/clock source. This feature is enabled by specifying ``#clock-cells = <0>``
  166. in the device tree. The output clock will be registered as "clkout" and can be
  167. referenced by other devices.
  168. 7. Usage examples
  169. =================
  170. Show device name:
  171. .. code-block:: bash
  172. root:/sys/bus/iio/devices/iio:device0> cat name
  173. ade9000
  174. Read voltage measurements:
  175. .. code-block:: bash
  176. root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_raw
  177. 12345
  178. root:/sys/bus/iio/devices/iio:device0> cat in_voltage0_scale
  179. 0.000030517
  180. - Phase A voltage = in_voltage0_raw * in_voltage0_scale = 0.3769 V
  181. Read power measurements:
  182. .. code-block:: bash
  183. root:/sys/bus/iio/devices/iio:device0> cat in_power0_active_raw
  184. 5678
  185. root:/sys/bus/iio/devices/iio:device0> cat in_power0_scale
  186. 0.000244140
  187. - Phase A active power = in_power0_active_raw * in_power0_scale = 1.386 W
  188. Configure calibration gains:
  189. .. code-block:: bash
  190. # Set current channel 0 calibration gain
  191. root:/sys/bus/iio/devices/iio:device0> echo 0x800000 > in_current0_calibscale
  192. # Set voltage channel 0 calibration gain
  193. root:/sys/bus/iio/devices/iio:device0> echo 0x7FFFFF > in_voltage0_calibscale
  194. Configure RMS voltage event thresholds (requires interrupts):
  195. .. code-block:: bash
  196. # Set RMS sag detection threshold
  197. root:/sys/bus/iio/devices/iio:device0> echo 180000 > events/in_altvoltage0_rms_thresh_falling_value
  198. # Enable RMS sag detection
  199. root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_altvoltage0_rms_thresh_falling_en
  200. # Set RMS swell detection threshold
  201. root:/sys/bus/iio/devices/iio:device0> echo 260000 > events/in_altvoltage0_rms_thresh_rising_value
  202. # Enable RMS swell detection
  203. root:/sys/bus/iio/devices/iio:device0> echo 1 > events/in_altvoltage0_rms_thresh_rising_en
  204. 8. IIO Interfacing Tools
  205. ========================
  206. See Documentation/iio/iio_tools.rst for the description of the available IIO
  207. interfacing tools.