-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
projects: eval-ade7754: example project
Example project for ADE7754. Not tested. This is a basic example on how to use the ADE7754 driver. The platform used is Maxim and the MCU board is the AD-APARD32690-SL. The example uses SPI communication and prints on the serial port the rms values for all three phases, the temperature and frequency. The other measurements are saved in strucutures. Signed-off-by: Radu Etz <[email protected]>
- Loading branch information
Showing
10 changed files
with
921 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"maxim": { | ||
"ade7754_example": { | ||
"flags" : "TARGET=max32690" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
NO_OS_INC_DIRS += \ | ||
$(INCLUDE) \ | ||
$(PLATFORM_DRIVERS) \ | ||
$(PLATFORM_DRIVERS)/../common/ \ | ||
$(PROJECT)/src/ \ | ||
$(DRIVERS)/meter/ade7754 | ||
|
||
SRCS += $(PROJECT)/src/main.c | ||
|
||
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 \ | ||
$(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 | ||
|
||
SRCS += $(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 \ | ||
$(PROJECT)/src/common/common_data.c \ | ||
$(PROJECT)/src/interrupt/interrupt.c \ | ||
$(PROJECT)/src/platform/maxim/platform.c | ||
|
||
# ADE7754 driver files | ||
SRCS += $(DRIVERS)/meter/ade7754/ade7754.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/***************************************************************************//** | ||
* @file common_data.c | ||
* @brief Defines common data to be used by ADE7754 example project | ||
* @author REtz ([email protected]) | ||
******************************************************************************** | ||
* Copyright (c) 2025 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 "common_data.h" | ||
|
||
/** | ||
* @brief Read rms measurements | ||
* @param dev - The device structure. | ||
* @return 0 in case of success, negative error code otherwise. | ||
*/ | ||
int read_rms_measurements(struct ade7754_dev *dev) | ||
{ | ||
int ret; | ||
struct ade7754_rms_values rms_vals; | ||
int32_t status; | ||
|
||
/* read rms values */ | ||
if (no_os_test_bit(no_os_find_first_set_bit(ADE7754_ZXA_MSK), | ||
dev->irq_status)) { | ||
ret = ade7754_rms_vals_phase_a(dev, &rms_vals); | ||
if (ret) | ||
return ret; | ||
} else if (no_os_test_bit(no_os_find_first_set_bit(ADE7754_ZXB_MSK), | ||
dev->irq_status)) { | ||
ret = ade7754_rms_vals_phase_b(dev, &rms_vals); | ||
if (ret) | ||
return ret; | ||
} else if (no_os_test_bit(no_os_find_first_set_bit(ADE7754_ZXC_MSK), | ||
dev->irq_status)) { | ||
ret = ade7754_rms_vals_phase_c(dev, &rms_vals); | ||
if (ret) | ||
return ret; | ||
} else { | ||
ret = -EINVAL; | ||
return ret; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @brief print measurements | ||
* @param dev - The device structure. | ||
* @return 0 in case of success, negative error code otherwise. | ||
*/ | ||
int print_measurements(struct ade7754_dev *dev) | ||
{ | ||
int ret; | ||
struct ade7754_energy_values energy_vals; | ||
struct ade7754_rms_values rms_vals; | ||
struct ade7754_period_value period_val; | ||
struct ade7754_temp_value temp_val; | ||
float current_rms_val, voltage_rms_val; | ||
float period_value; | ||
float temperature_C; | ||
int32_t status, temperature; | ||
|
||
|
||
/* Phase A */ | ||
current_rms_val = ((float)rms_vals.current_rms_reg_val_phase_a / | ||
CURRENT_RMS_FS_CODE) * ADC_FS_RMS_IN * I_GAIN; | ||
/* value in mV */ | ||
voltage_rms_val = ((float)rms_vals.voltage_rms_reg_val_phase_a / | ||
VOLTAGE_RMS_FS_CODE) * ADC_FS_RMS_IN * V_GAIN; | ||
|
||
pr_info("I rms phase A: %.2f mA \n", current_rms_val); | ||
|
||
pr_info("V rms phase A: %.2f mV \n", voltage_rms_val); | ||
/* Phase B */ | ||
current_rms_val = ((float)rms_vals.current_rms_reg_val_phase_b / | ||
CURRENT_RMS_FS_CODE) * ADC_FS_RMS_IN * I_GAIN; | ||
/* value in mV */ | ||
voltage_rms_val = ((float)rms_vals.voltage_rms_reg_val_phase_b / | ||
VOLTAGE_RMS_FS_CODE) * ADC_FS_RMS_IN * V_GAIN; | ||
|
||
pr_info("I rms phase B: %.2f mA \n", current_rms_val); | ||
|
||
pr_info("V rms phase B: %.2f mV \n", voltage_rms_val); | ||
/* Phase C */ | ||
current_rms_val = ((float)rms_vals.current_rms_reg_val_phase_c / | ||
CURRENT_RMS_FS_CODE) * ADC_FS_RMS_IN * I_GAIN; | ||
/* value in mV */ | ||
voltage_rms_val = ((float)rms_vals.voltage_rms_reg_val_phase_c / | ||
VOLTAGE_RMS_FS_CODE) * ADC_FS_RMS_IN * V_GAIN; | ||
|
||
pr_info("I rms phase C: %.2f mA \n", current_rms_val); | ||
|
||
pr_info("V rms phase C: %.2f mV \n", voltage_rms_val); | ||
|
||
|
||
/* read & print temperature */ | ||
ret = ade7754_temperature_val(dev, &temp_val); | ||
if (ret) | ||
return ret; | ||
|
||
temperature_C = ((float)temp_val.temp_reg_val * (float)TEMP_G) + | ||
ADE7754_AMB_T_CELSIUS; | ||
|
||
pr_info("Temperature %.2f °C \n", temperature_C); | ||
|
||
/* read & print period value */ | ||
ret = ade7754_period_val(dev, &period_val); | ||
if (ret) | ||
return ret; | ||
|
||
period_value = ((float)PERIOD_RES * (float)period_val.per_reg_val) / 1000; | ||
|
||
pr_info("Period %.2f ms \n", period_value); | ||
|
||
pr_info("\n"); | ||
pr_info("\n"); | ||
pr_info("\n"); | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* @brief Toggle Led | ||
* @param gpio_led_desc - led descriptor | ||
* @return 0 in case of success, negative error code otherwise. | ||
*/ | ||
int interface_toggle_led(struct no_os_gpio_desc *gpio_led_desc) | ||
{ | ||
uint8_t val; | ||
int ret; | ||
|
||
ret = no_os_gpio_get_value(gpio_led_desc, &val); | ||
if (ret) | ||
return ret; | ||
|
||
return no_os_gpio_set_value(gpio_led_desc, !val); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/***************************************************************************//** | ||
* @file common_data.h | ||
* @brief Defines common data to be used by ADE7754 example project | ||
* @author REtz ([email protected]) | ||
******************************************************************************** | ||
* Copyright (c) 2025 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 "ade7754.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" | ||
|
||
/* UART init params */ | ||
extern struct no_os_uart_init_param uart_ip; | ||
/* GPIO LED init params */ | ||
extern struct no_os_gpio_init_param gpio_led1_ip; | ||
/* SPI init params */ | ||
extern struct no_os_spi_init_param ade7754_spi_ip; | ||
/* GPIO RESET init params */ | ||
extern struct no_os_gpio_init_param gpio_reset_ip; | ||
/* GPIO IRQ init params */ | ||
extern struct no_os_gpio_init_param ade7754_gpio_irq_ip; | ||
/* GPIO interrupt init params */ | ||
extern struct no_os_irq_init_param ade7754_gpio_int_ip; | ||
|
||
/* Read data interval in irq multiple */ | ||
#define PRINT_INTERVAL 50 | ||
|
||
/* Setup values for ADE7754 */ | ||
/* value for R_small defined by user */ | ||
#define RSMALL 1 | ||
/* value for R high defined by user */ | ||
#define RHIGH 0 | ||
#define V_GAIN ((RSMALL + RHIGH) / RSMALL) | ||
/* Change the gain accordingly to the current sensor | ||
and sense circuit */ | ||
#define I_GAIN 1 | ||
/* RMS full scale code value defined by user */ | ||
#define VOLTAGE_RMS_FS_CODE 1848772 | ||
#define CURRENT_RMS_FS_CODE 1898124 | ||
/* ADC input at full scale rms voltage mV */ | ||
#define ADC_FS_RMS_IN 353.5 | ||
/* Period resolution µs/LSB */ | ||
#define PERIOD_RES 2.4 | ||
/* Temperature resolution 4 °C / LSB */ | ||
#define TEMP_G 4 | ||
/* Temperature °C correspnding to 00h code */ | ||
#define ADE7754_AMB_T_CELSIUS 129 | ||
|
||
/* Read measurements */ | ||
int read_rms_measurements(struct ade7754_dev *dev); | ||
|
||
/* Print measurements */ | ||
int print_measurements(struct ade7754_dev *dev); | ||
|
||
/* Toggle user LED */ | ||
int interface_toggle_led(struct no_os_gpio_desc *gpio_led_desc); | ||
|
||
#endif /* __COMMON_DATA_H__ */ |
Oops, something went wrong.