Skip to content

Commit

Permalink
projects: eval-ade7978: example project
Browse files Browse the repository at this point in the history
Example project for  ADE7978 in chipset configuration
with ADE7933/ADE7932, and ADE7923.

Tested using the EVAL-ADE7978EBZ.
The example includes measurments of the rms values.
The example is tested with the AD-APARD32690-SL.

Signed-off-by: Radu Etz <radu.etz@analog.com>
  • Loading branch information
raezt committed Dec 17, 2024
1 parent 6eecbb1 commit 08f443c
Show file tree
Hide file tree
Showing 10 changed files with 1,019 additions and 0 deletions.
5 changes: 5 additions & 0 deletions projects/eval-ade7978/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../tools/scripts/generic_variables.mk

include src.mk

include ../../tools/scripts/generic.mk
7 changes: 7 additions & 0 deletions projects/eval-ade7978/builds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"maxim": {
"ade7978_example": {
"flags" : "TARGET=max32690"
}
}
}
69 changes: 69 additions & 0 deletions projects/eval-ade7978/src.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

SRCS += $(PROJECT)/src/main.c

INCS += $(INCLUDE)/no_os_alloc.h \
$(INCLUDE)/no_os_delay.h \
$(INCLUDE)/no_os_error.h \
$(INCLUDE)/no_os_gpio.h \
$(INCLUDE)/no_os_print_log.h \
$(INCLUDE)/no_os_spi.h \
$(INCLUDE)/no_os_timer.h \
$(INCLUDE)/no_os_mutex.h \
$(INCLUDE)/no_os_util.h \
$(INCLUDE)/no_os_lf256fifo.h \
$(INCLUDE)/no_os_list.h \
$(INCLUDE)/no_os_irq.h \
$(INCLUDE)/no_os_units.h \
$(INCLUDE)/no_os_init.h \
$(INCLUDE)/no_os_alloc.h \
$(INCLUDE)/no_os_crc8.h \
$(INCLUDE)/no_os_crc16.h \
$(INCLUDE)/no_os_uart.h \
$(INCLUDE)/no_os_pwm.h \
$(INCLUDE)/no_os_dma.h \
$(PLATFORM_DRIVERS)/maxim_irq.h \
$(PLATFORM_DRIVERS)/maxim_uart.h \
$(PLATFORM_DRIVERS)/maxim_uart_stdio.h \
$(PLATFORM_DRIVERS)/maxim_gpio.h \
$(PLATFORM_DRIVERS)/maxim_spi.h \
$(PLATFORM_DRIVERS)/maxim_gpio_irq.h \
$(PLATFORM_DRIVERS)/../common/maxim_dma.h \
$(PLATFORM_DRIVERS)/maxim_pwm.h

SRCS += $(NO-OS)/util/no_os_alloc.c \
$(DRIVERS)/api/no_os_gpio.c \
$(NO-OS)/util/no_os_mutex.c \
$(NO-OS)/util/no_os_lf256fifo.c \
$(NO-OS)/util/no_os_list.c \
$(NO-OS)/util/no_os_util.c \
$(NO-OS)/util/no_os_crc8.c \
$(NO-OS)/util/no_os_crc16.c \
$(DRIVERS)/api/no_os_irq.c \
$(DRIVERS)/api/no_os_uart.c \
$(DRIVERS)/api/no_os_pwm.c \
$(DRIVERS)/api/no_os_spi.c \
$(DRIVERS)/api/no_os_timer.c \
$(DRIVERS)/api/no_os_dma.c \
$(PLATFORM_DRIVERS)/maxim_irq.c \
$(PLATFORM_DRIVERS)/maxim_gpio_irq.c \
$(PLATFORM_DRIVERS)/maxim_delay.c \
$(PLATFORM_DRIVERS)/maxim_init.c \
$(PLATFORM_DRIVERS)/maxim_uart_stdio.c \
$(PLATFORM_DRIVERS)/maxim_gpio.c \
$(PLATFORM_DRIVERS)/maxim_spi.c \
$(PLATFORM_DRIVERS)/maxim_uart.c \
$(PLATFORM_DRIVERS)/../common/maxim_dma.c \
$(PLATFORM_DRIVERS)/maxim_pwm.c

# Application entry point
SRCS += $(PROJECT)/src/main.c
INCS += $(PROJECT)/src/platform/platform.h
SRCS += $(PROJECT)/src/platform/platform.c
INCS += $(PROJECT)/src/common/common_data.h
SRCS += $(PROJECT)/src/common/common_data.c
INCS += $(PROJECT)/src/interrupt/interrupt.h
SRCS += $(PROJECT)/src/interrupt/interrupt.c

# ADE7978 driver files
INCS += $(DRIVERS)/meter/ade7978/ade7978.h
SRCS += $(DRIVERS)/meter/ade7978/ade7978.c
103 changes: 103 additions & 0 deletions projects/eval-ade7978/src/common/common_data.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/***************************************************************************//**
* @file common_data.c
* @brief Defines common data to be used by ADE7978 example project
* @author REtz (radu.etz@analog.com)
********************************************************************************
* Copyright (c) 2024 Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "common_data.h"
#include "platform.h"

/******************************************************************************/
/************************ Functions Definitions *******************************/
/******************************************************************************/

/**
* @brief Saves the current and voltage values of device 1 in rms_adc structure
* @param dev - device structure
* @param value - structure holding the measurements values
* @param phase - selects the phase for measurements read
* @return 0 in case of success, negative error code otherwise
*/
int rms_adc_values_read(struct ade7978_dev *dev, struct measurements *value,
enum ade7978_phase phase)
{
int ret;
// variables used to calculate the values of the measurements
float v1_rms, v2_rms, i_rms, temperature;

if (!dev)
return -ENODEV;
if (!value)
return -EINVAL;

// Read the measurements for the selected phase
ret = ade7978_read_data_ph(dev, phase);
if (ret)
return ret;

// Compute v1 value in mV
v1_rms = (float) ADE7978_FS_VOLTAGE_RMS * (float)((int32_t) dev->vrms_val) *
(float) ADE7978_VOLTAGE_TR_FCN / ((float) ADE7978_WAVE_FS_CODES *
(float) 10);

// Compute i value in mA
i_rms = (float) ADE7978_FS_CURRENT_RMS * (float)((int32_t) dev->irms_val) *
(float) ADE7978_SHUNT_RES / (float) ADE7978_WAVE_FS_CODES;

// Save the values in the measurements structure
value->v1_rms = v1_rms;
value->v1_rms_adc = dev->vrms_val;
value->i_rms = i_rms;
value->i_rms_adc = dev->irms_val;

/* The second voltage channel is multiplexed with the temperature sensor.
The channel function is selected by the user through temp_en */
if (dev->temp_en) {
// Compute temperature in °C
temperature = (float) 8.72101 * (float)(0.00001) *
(float) dev->temperature - (float) 306.47;
// Save the temperature values in the measurements structure
value->temperature_c = temperature;
value->temperature = dev->temperature;
} else {
// Compute v2 value
v2_rms = (float) ADE7978_FS_VOLTAGE_RMS * (float)((int32_t) dev->v2rms_val) *
(float) ADE7978_VOLTAGE_TR_FCN / ((float) ADE7978_WAVE_FS_CODES *
(float) 10);
// Save the v2 values in the measurements structure
value->v2_rms = v2_rms;
value->v2_rms_adc = dev->v2rms_val;
}

return 0;
}
102 changes: 102 additions & 0 deletions projects/eval-ade7978/src/common/common_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/***************************************************************************//**
* @file common_data.h
* @brief Defines common data to be used by ADE7978 example project
* @author REtz (radu.etz@analog.com)
********************************************************************************
* Copyright (c) 2024 Analog Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Analog Devices, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef __COMMON_DATA_H__
#define __COMMON_DATA_H__

/******************************************************************************/
/***************************** Include Files **********************************/
/******************************************************************************/
#include "ade7978.h"
#include "no_os_uart.h"
#include "no_os_pwm.h"
#include "no_os_delay.h"
#include "no_os_gpio.h"
#include "no_os_spi.h"
#include "no_os_print_log.h"
#include "no_os_units.h"
#include "no_os_util.h"
#include "no_os_error.h"
#include "maxim_uart.h"
#include "maxim_gpio.h"
#include "maxim_uart_stdio.h"
#include "maxim_pwm.h"
#include "maxim_spi.h"
#include "maxim_irq.h"

/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/

/* Hardware dependent definitions */

/* Current sesing using a shunt */
// Value of shunt in mohms
#define ADE7978_SHUNT_RES 1

/* Assuming a voltage divider with Rlow 1k and Rup 990k */
#define ADE7978_UP_RES 990000
#define ADE7978_DOWN_RES 1000
#define ADE7978_VOLTAGE_TR_FCN ((ADE7978_DOWN_RES + ADE7978_UP_RES) / ADE7978_DOWN_RES)

/**
* @struct measurements
* @brief measurements structure.
*/
struct measurements {
/* I rms value */
float i_rms;
/* V1 rms value */
float v1_rms;
/* V2 rms value */
float v2_rms;
/* Temperature °C value */
float temperature_c;
/* I ADC rms value */
int32_t i_rms_adc;
/* V1 ADC rms value */
int32_t v1_rms_adc;
/* V2 ADC rms value */
int32_t v2_rms_adc;
/* Temperature ADC value */
int32_t temperature;
};

/******************************************************************************/
/************************ Functions Declarations ******************************/
/******************************************************************************/

/* Saves the current and voltage values of device 1 in rms_adc structure */
int rms_adc_values_read(struct ade7978_dev *dev, struct measurements *value,
enum ade7978_phase phase);

#endif /* __COMMON_DATA_H__ */
Loading

0 comments on commit 08f443c

Please sign in to comment.