Skip to content

drivers: sensor: Add support to ADE9153A #90003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions boards/shields/adi_eval_ade9153ashieldz/Kconfig.shield
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2025 Plentify (Pty) Ltd
# SPDX-License-Identifier: Apache-2.0

config SHIELD_ADI_EVAL_ADE9153ASHIELDZ
def_bool $(shields_list_contains,adi_eval_ade9153ashieldz)
select ADE9153A
select SENSOR
select GPIO
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2025 Plentify (Pty) Ltd
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {

};

&arduino_spi {
status = "okay";

cs-gpios = <&arduino_header 14 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; /* D8 */

ade9153a@0 {
compatible = "adi,ade9153a";
status = "okay";
reg = <0>;
spi-max-frequency = <1000000>; /* conservatively set to 1MHz */
cf-gpios = <&arduino_header 8 (GPIO_ACTIVE_HIGH)>;
irq-gpios = <&arduino_header 9 (GPIO_ACTIVE_LOW)>;
reset-gpios = <&arduino_header 10 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
};
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions boards/shields/adi_eval_ade9153ashieldz/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.. _adafruit_data_logger_shield:

Adafruit Data Logger Shield
###########################

Overview
********

The `Adafruit Data Logger Shield`_ rev. B features an `NXP PCF8523 Real-Time Clock/Calendar with
Battery Backup`_, an SD card interface, two user LEDs, and a prototyping area.

.. figure:: adafruit_data_logger.jpg
:align: center
:alt: Adafruit Data Logger Shield

Adafruit Data Logger Shield (Credit: Adafruit)

.. note::
The older revision A of the Adafruit Data Logger Shield is not supported.

Pin Assignments
===============

+-----------------------+---------------------------------------------+
| Shield Connector Pin | Function |
+=======================+=============================================+
| D3 | User LED1 (green) [1]_ |
+-----------------------+---------------------------------------------+
| D4 | User LED2 (red) [1]_ |
+-----------------------+---------------------------------------------+
| D7 | PCF8523 RTC INT1 [2]_ |
+-----------------------+---------------------------------------------+
| D10 | SD card SPI CS |
+-----------------------+---------------------------------------------+
| D11 | SD card SPI MOSI |
+-----------------------+---------------------------------------------+
| D12 | SD card SPI MISO |
+-----------------------+---------------------------------------------+
| D13 | SD card SPI SCK |
+-----------------------+---------------------------------------------+
| SDA | PCF8523 RTC I2C SDA |
+-----------------------+---------------------------------------------+
| SCL | PCF8523 RTC I2C SCL |
+-----------------------+---------------------------------------------+

.. [1] The user LEDs are not connected to ``D3`` and ``D4`` by default. Jumper or jumper wire
connections must be established between the ``L1`` and ``Digital I/O 3`` pins for ``LED1``
and ``L2`` and ``Digital I/O 4`` pins for ``LED2`` if they are to be used.

.. [2] The PCF8523 RTC ``INT1`` interrupt output pin is not connected to ``D7`` by default. A jumper
wire connection must be established between the ``SQ`` pin and the ``Digital I/O 7`` pin in
order to use the RTC interrupt functionality (i.e. alarm callback, 1 pulse per second
callback). The ``INT1`` interrupt output is open-drain, but the shield definition enables an
internal GPIO pull-up and thus no external pull-up resistor is needed.

Requirements
************

This shield can only be used with a board which provides a configuration for Arduino connectors and
defines node aliases for SPI and GPIO interfaces (see :ref:`shields` for more details).

Programming
***********

Set ``-DSHIELD=adafruit_data_logger`` when you invoke ``west build``. For example:

.. zephyr-app-commands::
:zephyr-app: tests/drivers/rtc/rtc_api
:board: frdm_k64f
:shield: adafruit_data_logger
:goals: build

.. _Adafruit Data Logger Shield:
https://learn.adafruit.com/adafruit-data-logger-shield/

.. _NXP PCF8523 Real-Time Clock/Calendar with Battery Backup:
https://www.nxp.com/docs/en/data-sheet/PCF8523.pdf
1 change: 1 addition & 0 deletions drivers/sensor/adi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

# zephyr-keep-sorted-start
add_subdirectory_ifdef(CONFIG_ADE9153A ade9153a)
add_subdirectory_ifdef(CONFIG_ADLTC2990 adltc2990)
add_subdirectory_ifdef(CONFIG_ADT7310 adt7310)
add_subdirectory_ifdef(CONFIG_ADT7420 adt7420)
Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/adi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

# zephyr-keep-sorted-start
source "drivers/sensor/adi/ade9153a/Kconfig"
source "drivers/sensor/adi/adltc2990/Kconfig"
source "drivers/sensor/adi/adt7310/Kconfig"
source "drivers/sensor/adi/adt7420/Kconfig"
Expand Down
6 changes: 6 additions & 0 deletions drivers/sensor/adi/ade9153a/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2025 Plentify (Pty) Ltd
# SPDX-License-Identifier: Apache-2.0

zephyr_library()
zephyr_library_sources(ade9153a.c)
zephyr_library_sources_ifdef(CONFIG_ADE9153A_TRIGGER ade9153a_trigger.c)
221 changes: 221 additions & 0 deletions drivers/sensor/adi/ade9153a/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
#
# ADE9153a Energy metering IC configuration options
#
# Copyright (c) 2025 Plentify (Pty) Ltd.
# SPDX-License-Identifier: Apache-2.0

menuconfig ADE9153A
bool "ADE9153A Energy metering IC with autocalibration"
default y
depends on DT_HAS_ADI_ADE9153A_ENABLED
select SPI
help
Enable driver for ADE9153A Energy metering IC.

if ADE9153A

config ADE9153A_RESET_ACTIVE_TIME
int "The amount of time (ms) spent between toggling the reset pin on startup"
default 100
help
The time the reset pin will be holding down during reset.

config ADE9153A_POST_RESET_DELAY
int "The amount of time (ms) spent after reset on startup"
default 1000
help
The delay to wait after resetting the ADE9153A

config ADE9153A_AUTO_CALIBRATE
bool "Auto calibrate"
default y
help
After initialized, the sensor driver will start the autocalibration procedure.

config ADE9153A_AI_PGAGAIN
hex "Current channel A PGAGAIN value"
default "0x000A"
help
Signal on IAN, current channel gain

config ADE9153A_BI_CURRENT_CHANNEL
bool "Use B current channel"

config ADE9153A_BI_PGAGAIN
hex "Current channel B PGAGAIN value"
default "0x0000"
depends on ADE9153A_BI_CURRENT_CHANNEL
help
Signal on BI, current channel gain

config ADE9153A_CONFIG0
hex "CONFIG0 settings"
default "0x00000000"

config ADE9153A_CONFIG1
hex "CONFIG1 settings"
default "0x0300"

config ADE9153A_CONFIG2
hex "CONFIG2 settings"
default "0x0C00"

config ADE9153A_CONFIG3
hex "CONFIG3 settings"
default "0x0000"

config ADE9153A_ACCMODE
hex "Energy accumulation modes, Bit 4, 0 for 50Hz, 1 for 60Hz"
default "0x0010"

config ADE9153A_VLEVEL
hex "Assuming Vnom=1/2 of fullscale"
default "0x002C11E8"

config ADE9153A_ZX_CFG
hex "ZX low-pass filter select"
default "0x0000"

config ADE9153A_MASK
hex "Interrupt mask"
default "0x00000100"

config ADE9153A_ACT_NL_LVL
hex "No load threshold for Active power"
default "0x000033C8"

config ADE9153A_REACT_NL_LVL
hex "No load threshold for Reactive power"
default "0x000033C8"

config ADE9153A_APP_NL_LVL
hex "No load threshold for Apparent power"
default "0x000033C8"

config ADE9153A_RUN_ON
hex "DSP on"
default "0x0001"


config ADE9153A_COMPMODE
hex "Computation mode register"
default "0x0005"

config ADE9153A_VDIV_RSMALL
hex "Small resistor on board is 1kOhm=0x3E8"
default "0x03E8"

config ADE9153A_EP_CFG
hex "Energy accumulation configuration"
default "0x0009"

config ADE9153A_EGY_TIME
hex "Accumulate energy for 4000 samples"
default "0x0F9F"

config ADE9153A_TEMP_CFG
hex "Temperature sensor configuration"
default "0x000C"


config ADE9153A_SETUP_ON_STARTUP
bool "Run the setup during startup"
default y

config ADE9153A_ACAL_ON_STARTUP
bool "Run autocalibration on startup"
default y

# FIXME: [rodrigopex] Take a look at the comment values.
# Ideal Calibration Values for EV-ADE9153ASHIELDZ Shield Based on Sensor Values
# shield value 0.838190 = Q31(value=7031246, shift=0)
config ADE9153A_CAL_IRMS_CC
int "RMS current Calibration Constant (CC) Q31 value"
default 1799999318
help
The original default value is 0.838190. The Kconfig value is: (0.838190 * 0x7FFFFF)/(1U << shift))
. In the driver the value
will be recovered as follows: (1799999318 /(double) 0x7FFFFFFF)) * (1U << shift) =
0.8381899999.

config ADE9153A_CAL_IRMS_CC_SHIFT
int "RMS current Calibration Constant (CC) Q31 shift value"
default 0

config ADE9153A_CAL_VRMS_CC # shield value 13.41105 = Q31(value=7031251, shift=4)
int "RMS voltage Calibration Constant (CC) Q31 value"
default 1800000660
help
Same happens as CAL_IRMS_CC.
# FIXME: [rodrigopex] Move the complete documentation to the first Q31 value in the Kconfig to help developers
config ADE9153A_CAL_VRMS_CC_SHIFT
int "RMS voltage Calibration Constant (CC) Q31 shift value"
default 4
help
Number used to scale the number. ADE9153A_CAL_VRMS_CC/(1U << ADE9153A_CAL_VRMS_CC_SHIFT)
to keep the number inside the interval [-1.0, 1.0[. The default original value is
13.41105. To make that normalized we need to use a shift of 7. The value is (13.41105/1U
<< 7) = 0.104773827877256.

include <stdint.h>
include <stdio.h>

int main(int argc, char *argv[]) {
double original_value = 13.41105;
uint8_t shift = 7;
int64_t q_value = (original_value / (1U << shift)) * INT32_MAX; // 0x7FFFFF
double recovered_value = ((double)(q_value) / INT32_MAX) * (1U << shift);
printf("The result is %0.20lf\n", recovered_value);
return 0;
}

config ADE9153A_CAL_POWER_CC # shield value 1508.743 = Q31(value=6179810, shift=11)
int "Power Calibration Constant (CC) Q31 value"
default 1582031699

config ADE9153A_CAL_POWER_CC_SHIFT
int "Power Calibration Constant (CC) Q31 shift value"
default 11

config ADE9153A_CAL_ENERGY_CC # shield value 0.858307 = Q31(value=7200000, shift=0)
int "Energy Calibration Constant (CC) Q31 value"
default 1843200246

config ADE9153A_CAL_ENERGY_CC_SHIFT
int "Energy Calibration Constant (CC) Q31 shift value"
default 0

config ADE9153A_AI_TURBO_CAL_TIME
int "The time spent on the current turbo calibration in milliseconds"
default 2000

config ADE9153A_AV_TURBO_CAL_TIME
int "The time spent on the voltage turbo calibration in milliseconds"
default 4000

config ADE9153A_TRIGGER
bool "Trigger on"

if ADE9153A_TRIGGER

config ADE9153A_THREAD_STACK_SIZE
int "Trigger thread stack size."
default 1024

config ADE9153A_THREAD_PRIORITY
int "Trigger thread priority."
default 4

config ADE9153A_TRIGGER_IRQ
bool "Trigger on IRQ"
default y
depends on GPIO

config ADE9153A_TRIGGER_CF
bool "Trigger on CF"
default y
depends on GPIO

endif # ADE9153A_TRIGGER

endif # ADE9153A
Loading
Loading