Skip to content
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

Basic ADC support for SAMx7x #935

Merged
merged 2 commits into from
Dec 26, 2022

Conversation

chris-durand
Copy link
Member

@chris-durand chris-durand commented Dec 3, 2022

Extend basic SAMG55 ADC driver to support SAMx7x devices. The example has been tested in hardware. The peripheral instances follow the naming convention from the datasheet. There the ADC is called AFEC (analog front-end controller), but it will be provided by the modm:platform:adc module for commonality reasons.

Tested in hardware.

@chris-durand chris-durand added this to the 2022q4 milestone Dec 3, 2022
@chris-durand chris-durand force-pushed the feature/samx7x_adc branch 4 times, most recently from a05cd68 to 9cb62bf Compare December 3, 2022 21:39
@chris-durand chris-durand added the ci:hal Triggers the exhaustive HAL compile CI jobs label Dec 3, 2022
%% if target.family == "e7x/s7x/v7x"
// values from vendor hal code and application note
// {{reg}}_MR_TRANSFER(1) is a forbidden value according to the datasheet
{{reg}}_MR_TRANSFER(1) |
Copy link
Member

Choose a reason for hiding this comment

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

But but it's forbidden???2?

Copy link
Member Author

@chris-durand chris-durand Dec 4, 2022

Choose a reason for hiding this comment

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

I have completely stopped trusting the correctness of the ADC section in the datasheet. It states for the TRACKTIM field:

"Inherent tracking time is always 15 AFE clock cycles. Do not modify this field."

If I follow their guidance and leave TRACKTIM on the reset value of 0, the ADC will read values close to half scale about 50% of the time when its input is connected to GND.

The examples in the app note number 44046 ("Using the Analog Front End in the SAM V7/E7/S7
MCUs") use AFEC_MR_TRACKTIM(2) which according to the text means TRACKTIM + 1 = 3 AFE clock cycles which is not at all equal to 15. That example also has the illegal value of AFEC_MR_TRANSFER(1). Those values are also what the ASF3 vendor HAL has as defaults.

Assuming the app note is right about the meaning of the TRACKTIM field it has to be set to 14 to achieve the recommended tracking time of 15 AFE clock cycles.

There are actually 3 different vendor HAL options offered right now, ASF3, ASF4 and MPLAB Harmony.
ASF4 can only be obtained by registering and downloading a Windows IDE, so I skipped it. The others can be found somewhere on github.

The MPLAB HAL has AFEC_MR_TRANSFER(2) and AFEC_MR_TRACKTIM(15U) which would equate to 16 cycles if the app note was right.

This is all a bit too confusing. I'll go with AFEC_MR_TRACKTIM(14) and the datasheet recommended value of AFEC_MR_TRANSFER(2) until proven otherwise. At least the ADC seems to do the right thing.

Copy link
Member

Choose a reason for hiding this comment

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

ERMAHGERD 🙄

src/modm/platform/adc/samg/module.lb Outdated Show resolved Hide resolved
src/modm/platform/adc/samg/module.lb Outdated Show resolved Hide resolved
Copy link
Member

@salkinium salkinium left a comment

Choose a reason for hiding this comment

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

awesome!

@salkinium salkinium added ci:hal Triggers the exhaustive HAL compile CI jobs and removed ci:hal Triggers the exhaustive HAL compile CI jobs labels Dec 14, 2022
@salkinium salkinium merged commit 7330500 into modm-io:develop Dec 26, 2022
@salkinium
Copy link
Member

Whoops, forgot about this, sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:hal Triggers the exhaustive HAL compile CI jobs feature 🚧
Development

Successfully merging this pull request may close these issues.

None yet

2 participants