-
Notifications
You must be signed in to change notification settings - Fork 14.6k
sensors: add ads7953 adc #25721
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
base: main
Are you sure you want to change the base?
sensors: add ads7953 adc #25721
Conversation
Added driver for ADS7953 board |
* @max 3.0 | ||
* @decimal 2 | ||
*/ | ||
PARAM_DEFINE_FLOAT(ADC_ADS7953_REFV, 2.5f); |
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.
use module.yaml which is the contemporary way to define parameters
https://docs.px4.io/main/en/advanced/parameters_and_configurations.html#creating-defining-parameters
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
int ret = SPI::init(); | ||
|
||
if (ret != PX4_OK) { | ||
DEVICE_DEBUG("SPI::init failed (%i)", ret); |
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.
prefer PX4_DEBUG
int16[12] channel_id # ADC channel IDs, negative for non-existent, TODO: should be kept same as array index | ||
int32[12] raw_data # ADC channel raw value, accept negative value, valid if channel ID is positive | ||
int16[16] channel_id # ADC channel IDs, negative for non-existent, TODO: should be kept same as array index | ||
int32[16] raw_data # ADC channel raw value, accept negative value, valid if channel ID is positive |
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 may have implications for other drivers, did you check?
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.
yes
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
} | ||
|
||
float ref_volt = 2.5f; | ||
param_get(param_find("ADC_ADS7953_REFV"), &ref_volt); |
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.
have this class inherit ModuleParams and use _param_name.get()
Co-authored-by: Jacob Dahl <37091262+dakejahl@users.noreply.github.com>
boards/px4/fmu-v6x/default.px4board
Outdated
CONFIG_BOARD_SERIAL_TEL3="/dev/ttyS1" | ||
CONFIG_BOARD_SERIAL_EXT2="/dev/ttyS3" | ||
CONFIG_BOARD_SERIAL_RC="/dev/ttyS5" | ||
CONFIG_DRIVERS_ADC_ADS7953=y |
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.
We added this for testing reasons, we should remove it from v6x
again, as we do not have enough FLASH
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
} | ||
|
||
|
||
void ADS7953::parameters_update() |
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 not called anywhere, I also do not see it required to listen for param updates as they are marked as reboot_required
anyway.
src/drivers/adc/ads7953/ADS7953.h
Outdated
|
||
static const hrt_abstime SAMPLE_INTERVAL{50_ms}; | ||
|
||
void parameters_update(); |
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.
See other comment regarding parameters_udpate
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
} | ||
|
||
ret = rw_msg(&recv_data[0], 0, false); | ||
ret = rw_msg(&recv_data[0], 0, true); |
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.
You overwrite the previous ret
, so you will mask out errors.
You can use a pattern like this:
int status = PX4_OK;
status = status || <func1>
status = status || <func2>
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
int ADS7953::get_measurements() | ||
{ | ||
uint8_t recv_data[2]; | ||
uint8_t ch_id = 0; |
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.
use the narrowest scope, otherwise one expects that you need ch_id
in different parts of the method, but you actually only need it inside the first if
clause of the while
loop, so its clearer if you move it there.
src/drivers/adc/ads7953/module.yaml
Outdated
reboot_required: true | ||
default: 0 | ||
|
||
|
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.
nit: To better fit the style of other module.yaml
, only have one empty line between params.
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
return 0; | ||
} | ||
|
||
|
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.
nit: You sometimes use two empty spaces between methods and sometimes one. Decide for one to keep it more consistent with others I would use one. Also check others.
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
mask |= (1U << ch_id); | ||
count++; | ||
_adc_report.channel_id[ch_id] = ch_id; | ||
_adc_report.raw_data[ch_id] = ((((uint16_t) recv_data[0]) & 0x0F) << 8) | recv_data[1]; //data_value; |
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.
what should the comment //data_value tell?
src/drivers/adc/ads7953/ADS7953.cpp
Outdated
{ | ||
get_measurements(); | ||
_adc_report.timestamp = hrt_absolute_time(); | ||
_to_adc_report.publish(_adc_report); |
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 outdated and does not match _adc_report_pub
anymore, which causes it to not compile.
Solved Problem
-Needed 16 channel ADC
Fixes #{Github issue ID}
Solution
-Write driver for ADS7953 board
Changelog Entry
-Added driver for ADS7953 board
Test coverage
-Tested performance and stability of measurements manually