Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Dev/ade7978 #2400

wants to merge 2 commits into from

Conversation

raezt
Copy link
Collaborator

@raezt raezt commented Dec 17, 2024

Pull Request Description

Basic driver for ADE7978 with SPI communication.
The ADE7978 communicates via a digital interface with ADE7933/ADE7932, or ADE7923 forming a
chipset dedicated to measuring 3-phase electrical energy using shunts as current sensors.

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

@raezt raezt force-pushed the dev/ade7978 branch 8 times, most recently from 08f443c to dcc7207 Compare December 17, 2024 10:21
@raezt raezt marked this pull request as ready for review December 17, 2024 13:34
Comment on lines 72 to 73
if ((reg_addr >= ADE7978_REG_MMODE && reg_addr <= ADE7978_REG_LAST_RWDATA8) ||
(reg_addr >= ADE7978_REG_CONFIG2 && reg_addr <= ADE7978_SET_SPI_ADDR)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would define a macro for these conditions, since they do repeat.


/* Hard reset the device */
if (!init_param.reset_desc)
goto error_dev;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret is not initialized at this moment.

Comment on lines 185 to 170
if (!dev)
return -ENODEV;
if (!status)
return -EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove these, since they are checked in the ade7978_read() call below.

Comment on lines 87 to 88
temperature = (float) 8.72101 * (float)(0.00001) *
(float) dev->temperature - (float) 306.47;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cast anything here.

Comment on lines 47 to 49
/******************************************************************************/
/********************** Macros and Constants Definitions **********************/
/******************************************************************************/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to not have these comments in new drivers, since they don't really add any value.

Comment on lines 129 to 134
if (val == NO_OS_GPIO_LOW)
val = NO_OS_GPIO_HIGH;
else
val = NO_OS_GPIO_LOW;

return no_os_gpio_set_value(gpio_led_desc, val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be replaced with

return no_os_gpio_set_value(gpio_led_desc, !val);

return ret;

// /* Enable the DSP */
// return ade7978_write(dev, ADE7978_REG_RUN, ADE7978_RUN_ON);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line.

return ret;
}

// Dumb read of energy registers to erase their contents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment style should be consistent throughout No-OS. Use /**/ instead.

Comment on lines 4 to 23
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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NO_OS_INC_DIRS variable can be used to avoid adding all these explicitly.

The ADE7978, the ADE7933/ADE7932, and ADE7923 form a
chipset dedicated to measuring 3-phase electrical energy using
shunts as current sensors.

The ADE7933/ADE7932 are isolated, sigma-delta
analog-to-digital converters.
The ADE7923 is a nonisolated, 3-channel Σ-Δ ADC.
ADE7933 has 3 channels and ADE7932 2 channels.

The ADE7978 is a high accuracy, 3-phase electrical energy
measurement IC with serial interfaces and three flexible pulse
outputs.

This is a basic driver implementation with communication done on SPI.

Signed-off-by: Radu Etz <[email protected]>
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 <[email protected]>
@raezt
Copy link
Collaborator Author

raezt commented Dec 20, 2024

v2 change log:

  • all comments were addressed.

*/
struct measurements {
/* I rms value */
float i_rms;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants