-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: adc: sam0: Fix adc_reference implementation #45703
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
drivers: adc: sam0: Fix adc_reference implementation #45703
Conversation
|
Hi @attie-argentum , |
|
I've checked over the handling of However, we loose access to the I think for absolute clarity and flexibility, my preferred solution would be to place definitions in the relevant Example for SAML21 #define ADC_REFCTRL_REFSEL_INTERNAL ADC_REFCTRL_REFSEL_INTREF
#define ADC_REFCTRL_REFSEL_VDD_1_2 ADC_REFCTRL_REFSEL_INTVCC1
#define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC2PS: in the SAML21 PR, I pre-define the |
I understood your point about
We have two paths in place today:
I prefer not add a third option. |
I'm not sure if this is what you're meaning, but putting these |
|
I agree with @attie-argentum regarding the Each microcontroller of this series has its own set of selectable references (as you can see below). @nandojve I think it might be hard to make If the only solution is to implement each one in the fixup file, I volunteer to do it (if needed). |
|
@lucasssvaz - watch out for |
Thanks, fixed it |
2cf1966 to
4426063
Compare
|
@attie-argentum , @lucasssvaz , Since there is no good solution, I propose to keep internal voltage reference as is. For all devices the internal reference tracks VDDANA somehow and the default value is 1.0V. If that reference is good or not it is out of scope because code should select appropriated parameter and user should calibrate device on all temperature range. In the case of |
Agreed
I believe this is the documented / expected behaviour ( /** @brief ADC references. */
enum adc_reference {
ADC_REF_VDD_1, /**< VDD. */
ADC_REF_VDD_1_2, /**< VDD/2. */
ADC_REF_VDD_1_3, /**< VDD/3. */
ADC_REF_VDD_1_4, /**< VDD/4. */
ADC_REF_INTERNAL, /**< Internal. */
ADC_REF_EXTERNAL0, /**< External, input 0. */
ADC_REF_EXTERNAL1, /**< External, input 1. */
}; |
Sure, so current version fits well, right? Or do you still see any change for improvement? |
|
@nandojve Looks good. The only improvement I can see is to somehow support those unusual reference values (I think this is unfeasible for now but would be nice to have in a future update). Also, |
Gah, sorry - I missed the update... Yes, LGTM, though I'm not 100% convinced that switching on (
Agreed - " |
The other thing that can be made is: #ifndef ADC_REFCTRL_REFSEL_VDD_1
# if defined(ADC0_BANDGAP)
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC1
# elif defined(ADC_REFCTRL_REFSEL_INTVCC2)
# define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC2
# else
- # define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INT1V
+ # define ADC_REFCTRL_REFSEL_VDD_1 ADC_REFCTRL_REFSEL_INTVCC0
# endif
#endifSo, people that uses 2.96V or 3.2V (1/1.48 or 1/1.6) can have something to work too. |
|
@nandojve Seems like an 'ok' solution, as long as this behavior is documented somewhere easy to find. This way new Zephyr devs using these processors won't have to delve deep into the source code to find out how it actually works. |
Personally, I'd prefer to not define ... but I'm not going to block / be difficult about it. |
|
@attie-argentum Agreed. If I had to choose I would prefer to have a predictable behavior over the use of unusual references (although the ideal solution would be to rework the ADC API to have both) |
The current sam0 adc driver not implement correctly the adc_reference enum values. This try homonize adc input referece by tracking VDDANA at ADC_REF_VDD_1. The ADC_REF_VDD_1_2 were fixed with correct INTVCCx channel selection. Fixes zephyrproject-rtos#45443 Signed-off-by: Gerson Fernando Budke <[email protected]>
4426063 to
aecb5ad
Compare
|
Hi, where are we at with this PR? If you've worked out a solution, can someone please approve? |
|
LGTM, don't think I can approve though. |
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.
🥳 (thanks for the invite @stephanosio)
|
@mbolivar-nordic I also can't approve it but it seems OK to me. Thanks for the help guys! |



The current sam0 adc driver not implement correctly the adc_reference enum values because the current fixuips not reflect all sam0 variants.
This merges ADC_REF_INTERNAL and ADC_REF_VDD_1 implementation because there are devices that only support 1.0V. This assumption is valid for those devices that have a bandgap which allows user to change the internal voltage reference to other values then 1.0V. However, that option is out of scope and it is currently not supported.
The other common adc reference with mistakes is ADC_REF_VDD_1_2. This was fixed selecting the proper INTVCCx reference.
Fixes #45443
Signed-off-by: Gerson Fernando Budke [email protected]