-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
mimxrt: adc: rt117x: initialize LPADC2 and support channel groups #17874
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: master
Are you sure you want to change the base?
Conversation
Code size report:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17874 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 171
Lines 22283 22295 +12
=======================================
+ Hits 21924 21936 +12
Misses 359 359 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Pins may be on the LPADC2 peripheral. Change-Id: I967b2aae07c9cc7e9ce5bc114851c2f03ae22dbb Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
CI |
Hi @robert-hh, |
Thank you for the PR: From what I understand, it selects the input B of an ADC if it exists. Doing that, if actually fixes a bug, which caused A1, A3 and A4 not to return ADC values at the MIMXRT1170_EVK board. Thanks.
If you want to go on another step ahead, you could make the channel_mode configurable, allowing the differential mode. Since that requires to pins to be specified, either these pins have to be named directly, of one would assume sequential pin numbers. Like for the MIMXRT1170_EVK board "A0" in differential mode would specify "A0" and "A1" as paired input. For that board, the A0/1, A2/3 and A4/5 make up a differential pair. |
Helllo @robert-hh , Thank you for reviewing.
I tried to add this, but then I need to I think best to calculate the mode at the already platform specific We specify the group not the mode. As you write next, we may have several modes, single-ended, diff-AB, diff-BA, we hold the group and calculate the mode based on the requested mode and group at the
I am confused...
None of the This information was helpful for me when debugging this issue, I added the Should I remove all? Please notice this is not the mode, which is hardcoded to single-ended in all cases and unrelated to this.
I do not understand where you want to document this can you please provide a reference?
I do not like to mix oracle values of one type with another type just because the oracle is the same. And as you write later, in future we will have different modes for the same group and we need to differentiate the group, mode and the result. I left it as-is, please let me know if you want to merge oracles, but when adding diff-AB, diff-BA we will need to avoid using oracles again.
You are correct in the fact that there is no actual choice of pins, there is no reason to allow to select the "other" pin, the leading pin (A) will be provided and the pair (B) will be selected automatically. BTW: I think you got this wrong, the pairs are This patch may be applied in future on top by adding a constructor Based on the above response, I have not made any change in the patchset... please let me know if you agree to the analysis. I can try and work on a differential patch on top later. Regards, |
About channel_group: Forget my comment. That's a term from the MIMXRT_10xx family's library. So just keep it. You use the data element channel_group from the machine_adc_obj_t to select the input. In the MIMXRT10xx this was to select between ADC1 and ADC2, where ADC2 was never used. About mp_machine_adc_print(): At the moment it prints the instance and the channel, which is already inconsistent because the channel cannot be chosen by the user. For consistency then the channel should be removed. The aim for MicroPython is, that the printout of an object matches the argument list for instantiation. But there are ATM more cases of deviation than match.
There is no good place for adding such hint. Maybe a short note in the quickref.rst, that besides the pins labelled as ADC other pins from the GPIO_AD_XX block can be used for ADC. But that was already true before.
I understand your concern, and the MIXMRT11xx boards are not low at flash. SO just keep it.
With respect to Pin names, we seem to talk about different things. You talk about A/B channels of a ADC input, I talked about the Pin labels was written on the silkscreen of a given board. These names are used in the user documentation. It is True that at ADC hardware level the (B) input follows the (A) input, but the related board pins are not necessary adjacent pins. In any case such pin pairs at a board have to be documented. But at least it seems that a certain ADC#/CH#/INPUT# triple is always assigned to a single GPIO. Looking through the mimxrt1176_af.csv I noticed, that at some GPIO pins channels from both ADC1 and ADC2 are assigned. I should remember since I created that file, but it's a while since then. |
Hello @robert-hh , Reading your verbose response, do I understand correctly that you want to remove all the content of:
As all not provided? not only channel but also the ADC instance? or leave only instance?
Any other change you would like to see? Thanks, |
Hi, I tried and failed to create a patch to add differential mode. Adding enum:
And keyword argument Not sure how to add this:
As it conflicts with the Let's merge this work first then I will try to figure out how to do this. Thanks, |
I'm not sure about what to recommend. Looking at the real output, nothing of that matches the constructor inputs. So we could keep it for now. Only for MIMXRT11x I would change the text from "channel_group" to "channel input" Another thing I forgot to mention: In your PR you use the NXP library version 2.16 from @Hatach 's repository. The version used by MicroPython is actuall V2.11, with the git hash |
Better put the differential mode into a separate PR and keep this PR as a bug fix. Then chances are good that it will get merged fast. Since differential mode is not a common feature, it may stick in PR the queue for a very long time. |
You have to define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS in line 42 of machine_adc.c e.g. as:
But as said, keep that for later. |
Done, I hope this what you meant.
Thank you for capturing this, it was a huge mistake that was added into this patchset. |
Looks better now. Looks like I made a typo for print. Of course it should be channel_input in one word. |
Only kLPADC_SampleChannelSingleEndSideA is used during capture, while pin may be in side B. Detect the side based on the pin configuration. Change-Id: I207f4fa0503864519e5a7f88599e24b5f667d591 Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Fixed. Thank you! |
Differential mode would also have to cater for the different type of the ADC result, which is 13 bits signed instead of 12 bits unsigned. Since read_u16() returns an unsigned quantity, the read() method may have to be used to return the signed value. ADC.read() is port-specific and returns the raw ADC value. |
Summary
LPADC1 is initialized while ADC pins may be at LPADC2 as well.
Only
kLPADC_SampleChannelSingleEndSideA
is used during capture, while pin may be in side B.Testing
Applied in my target, in which pin is in LPADC2 and on side B.
Successfully measure the pin voltage.
Trade-offs and Alternatives
Not sure the
channel_group
member/term is designed for this, although it is not currently used and is related.We could add a constructor parameters for explicitly specify the A, B but I think we can conclude this from pins.