-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Dev/ade7978 #2400
Merged
+2,192
−0
Merged
Dev/ade7978 #2400
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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": { | ||
"ade7978_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,43 @@ | ||
|
||
NO_OS_INC_DIRS += \ | ||
$(INCLUDE) \ | ||
$(PLATFORM_DRIVERS) \ | ||
$(PLATFORM_DRIVERS)/../common/ \ | ||
$(PROJECT)/src/ \ | ||
$(DRIVERS)/meter/ade7978 | ||
|
||
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 \ | ||
$(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 | ||
|
||
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)/maxim_pwm.c | ||
|
||
# Application entry point | ||
SRCS += $(PROJECT)/src/main.c \ | ||
$(PROJECT)/src/platform/platform.c \ | ||
$(PROJECT)/src/common/common_data.c \ | ||
$(PROJECT)/src/interrupt/interrupt.c \ | ||
|
||
# ADE7978 driver files | ||
SRCS += $(DRIVERS)/meter/ade7978/ade7978.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,95 @@ | ||
/***************************************************************************//** | ||
* @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 "common_data.h" | ||
#include "platform.h" | ||
|
||
/** | ||
* @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 = 8.72101 * 0.00001 * dev->temperature - 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; | ||
} |
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,91 @@ | ||
/***************************************************************************//** | ||
* @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 "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" | ||
|
||
/* 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; | ||
}; | ||
|
||
/* 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__ */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is a good idea to have float values in the driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the example project.