Skip to content

Conversation

@Robibobo1
Copy link
Contributor

@Robibobo1 Robibobo1 commented Jun 29, 2024

When using the oversampling factor on the SAMD21 family, the value that you get from the conversion is 16 bits instead of 12.

Using a factor of 8 adds 3 bits, a factor of 6 adds 2 bits, etc. I corrected this by dividing the factor by 2 and adding it to the resolution variable.

I didn't find other MCU families that use hardware oversampling. If there are others, we need to check if this is correct for that type of ADC.

Fixes: #74607
Signed-off-by: Robin Carrupt [email protected]

@zephyrbot zephyrbot added the area: ADC Analog-to-Digital Converter (ADC) label Jun 29, 2024
@zephyrbot zephyrbot requested review from anangl and decsny June 29, 2024 08:34
@github-actions
Copy link

Hello @Robibobo1, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

decsny
decsny previously requested changes Jul 4, 2024
Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

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

Address it in the driver for the device, this is not how other ADCs in tree work

@zephyrbot zephyrbot added the platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) label Jul 10, 2024
@Robibobo1
Copy link
Contributor Author

Sorry for my wrong commit, this is my first time contributing

@pdgendt
Copy link
Contributor

pdgendt commented Jul 10, 2024

Check the contribution guidelines, I think you should squash all the commits, and avoid merge commits.

@nandojve nandojve self-assigned this Jul 10, 2024
@Robibobo1 Robibobo1 requested a review from decsny July 11, 2024 07:17
@Robibobo1 Robibobo1 force-pushed the Oversampling branch 2 times, most recently from 1f2eb7f to 2fdc829 Compare July 11, 2024 07:38
@decsny decsny dismissed their stale review July 11, 2024 13:52

outdated

@MaureenHelm
Copy link
Member

@anangl @nandojve please take a look

@Robibobo1 please address the failed compliance check

@Robibobo1 Robibobo1 force-pushed the Oversampling branch 2 times, most recently from 86cc5ff to ec978ea Compare August 22, 2024 16:29
Copy link
Member

@decsny decsny Aug 22, 2024

Choose a reason for hiding this comment

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

please make the commit title clear that this is specific to sam, ie it should start with drivers: adc_sam0:

@nandojve nandojve changed the title adc: Adjust the adc resolution with the oversampling factor drivers: adc: sam0: Adjust resolution with the oversampling factor Aug 22, 2024
@nandojve
Copy link
Member

Hi @attie-argentum ,

Could you check this change?

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Oct 22, 2024
@nandojve nandojve removed the Stale label Oct 22, 2024
@decsny decsny removed their assignment Nov 12, 2024
Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

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

commit title needs to be adjusted

The old SAM0 adc drivers forces you to put 12 bits when using oversampling.
The adc_raw_to_millivolts_dt function is not working properly because if
we uses an oversampling of 8, we get 16 bits of resolution.
The function uses directly the resolution in the DT,
 so the voltage will not be correct.
To counter this, i forced the user to put the right resolution for his
oversampling factor.
Fixes: zephyrproject-rtos#74607
Signed-off-by: Robin Carrupt <[email protected]>
LOG_ERR("Oversampling requires minimum 13 bit resolution");
return -EINVAL;
}
ADC_RESSEL(adc) = ADC_RESSEL_12BIT;
Copy link
Member

Choose a reason for hiding this comment

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

The ADC resolution is 12bit max.
image

However, if you want to Accumulate, Average or Oversampling, see
image

Check below sections:
45.6.2.9 Accumulation
45.6.2.10 Averaging
45.6.2.11 Oversampling and Decimation

This change must work for all sam0 series.

This possible it related to #76963

@decsny decsny removed their request for review January 6, 2025 17:19
@gmarull gmarull dismissed their stale review February 3, 2025 12:42

being handled by others

@github-actions
Copy link

github-actions bot commented Apr 5, 2025

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions
Copy link

github-actions bot commented Jun 7, 2025

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Jun 7, 2025
@github-actions github-actions bot closed this Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ADC Analog-to-Digital Converter (ADC) platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SAM adc driver not taking oversampling from the devicetree in the resolution calculation

9 participants