Skip to content

Conversation

Phil-Engljaehringer
Copy link

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

@Phil-Engljaehringer
Copy link
Author

Added driver for ADS7953 board

* @max 3.0
* @decimal 2
*/
PARAM_DEFINE_FLOAT(ADC_ADS7953_REFV, 2.5f);
Copy link
Contributor

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

int ret = SPI::init();

if (ret != PX4_OK) {
DEVICE_DEBUG("SPI::init failed (%i)", ret);
Copy link
Contributor

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
Copy link
Contributor

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?

Choose a reason for hiding this comment

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

yes

}

float ref_volt = 2.5f;
param_get(param_find("ADC_ADS7953_REFV"), &ref_volt);
Copy link
Contributor

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()

CONFIG_BOARD_SERIAL_TEL3="/dev/ttyS1"
CONFIG_BOARD_SERIAL_EXT2="/dev/ttyS3"
CONFIG_BOARD_SERIAL_RC="/dev/ttyS5"
CONFIG_DRIVERS_ADC_ADS7953=y
Copy link
Member

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

}


void ADS7953::parameters_update()
Copy link
Member

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.


static const hrt_abstime SAMPLE_INTERVAL{50_ms};

void parameters_update();
Copy link
Member

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

}

ret = rw_msg(&recv_data[0], 0, false);
ret = rw_msg(&recv_data[0], 0, true);
Copy link
Member

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>

int ADS7953::get_measurements()
{
uint8_t recv_data[2];
uint8_t ch_id = 0;
Copy link
Member

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.

reboot_required: true
default: 0


Copy link
Member

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.

return 0;
}


Copy link
Member

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.

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;
Copy link
Member

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?

{
get_measurements();
_adc_report.timestamp = hrt_absolute_time();
_to_adc_report.publish(_adc_report);
Copy link
Member

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.

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