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

Fix incorrect bitfield name in ADC_Init #220

Open
wants to merge 1 commit into
base: release/2.6.x_k32w0
Choose a base branch
from

Conversation

tcv-git
Copy link

@tcv-git tcv-git commented Nov 26, 2024

This is a pretty clear bug that causes the ADC sample time to not be set as configured and also causes the PASS bit to be set incorrectly if the configured sample time was odd.

Setting PASS results in wildly incorrect ADC results. Not setting the sample time will also produce incorrect results if the ADC input signal is of high impedance.

I have put the fix in the same place as sampleTimeNumber is otherwise set, but you may which to reformat because I don't know if there is a strict order that registers must be written, and also I don't know all the possible silicon variations this might be used with. I will test this with my K32W041A and post the results through the NXP community forum.

@@ -96,6 +96,13 @@ void ADC_Init(ADC_Type *base, const adc_config_t *config)
tmp32 |= ADC_CTRL_TSAMP(config->sampleTimeNumber);
#if (defined(FSL_FEATURE_ADC_SYNCHRONOUS_USE_GPADC_CTRL) && FSL_FEATURE_ADC_SYNCHRONOUS_USE_GPADC_CTRL)
}
else
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @tcv-git, thanks for your effort. I'd like to know what ADC clock mode in your project? From the K32W0 user manual information, the device doesn't support synchronous mode, and the ADC sample time is determined by GPADC_CTRL0[GPADC_TSAMP], the CTRL[TSAMP] should stay to default during application. So, for your patch, in asynchronous mode, you have no way to set the GPADC_CTRL0[GPADC_TSAMP].
Could you please close this PR? as we need to do internal devices feature header and driver update to fix this bug.

Copy link
Author

Choose a reason for hiding this comment

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

Hi,

The device does support synchronous mode. See UM11323 Fig. 82. Perhaps you are reading the manual for another part?

I have set CLOCK_AttachClk(kNONE_to_ADC_CLK); and .clockMode = kADC_ClockSynchronousMode,. It is reading values correctly using the code fixed code I have supplied.

Have you tried this with hardware?

Copy link
Author

Choose a reason for hiding this comment

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

By the way, I have seen the part that you are referring to in section 17.1.2 of the register manual. The lack of correct punctuation and the fact that it contradicts the sentence immediately before and after it make It looks like a copy+paste error. Perhaps you could arrange for the manual to be updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @tcv-git, yes, I have tried both synchronous mode and asynchronous mode on my local, ADC can convert in both modes. I checked with the internal team, it is strongly recommended you use asynchronous mode, using synchronous mode may result in reduced accuracy in some environments. The UM11323 needs to be updated to hide information about synchronous mode. We currently only describe related information in CTRL[ASYNMODE] and CTRL[CLKDIV] bitfield description field.

Copy link
Author

Choose a reason for hiding this comment

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

Hi Zhaoxiang,

Thankyou for your help. Both the pdf documentation and example projects in the SDK need to be updated because they all use synchronous mode. Can you also please confirm that this will be published in the device errata document? because many customers will have already written applications based on the pre-existing examples.

More importantly for me, if you look for the function update_ctrl0_adc_register in board_utility.c, it modifies the sample time in the GPADC_CTRL0 register. If this is required to be changed to synchronous mode then the sample time will have to be made in the CTRL register and I need to know which values to use to replace 0x1f and 0x14.

Thanks,
Tom

Copy link
Author

Choose a reason for hiding this comment

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

Hi Zhaoxiang,

Yes we can use asynchronous mode with a 4MHz clock. I was only trying to save a small amount of power by using synchronous mode.

After the updated SDK is available I am happy for you to reject this pull request.

Thanks,
Tom

Choose a reason for hiding this comment

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

From the K32W0 user manual information, the device doesn't support synchronous mode

@ZhaoxiangJin I can't find this mentioned in the manual UM11323 rev. 1.2, the most recent version available for download on the NXP website.
For example chapter 27.6.5 states: "Two clocking modes are available, synchronous mode and asynchronous mode"

Copy link
Contributor

Choose a reason for hiding this comment

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

From the K32W0 user manual information, the device doesn't support synchronous mode

@ZhaoxiangJin I can't find this mentioned in the manual UM11323 rev. 1.2, the most recent version available for download on the NXP website. For example chapter 27.6.5 states: "Two clocking modes are available, synchronous mode and asynchronous mode"

Hello @ckielstra, please refer UM11323 Rev. 1.2 Register Manual ADC chapter CTRL register ASYNMODE bitfield description. The synchronous mode related description in User Manual chapter 27 will be removed.

Choose a reason for hiding this comment

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

The synchronous mode related description in User Manual chapter 27 will be removed.

@ZhaoxiangJin Can the example drivers be updated as well? The four examples under SDK_2_6_15_K32W041\boards\k32w061dk6\driver_examples\adc all use synchronous mode

Copy link
Contributor

Choose a reason for hiding this comment

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

The synchronous mode related description in User Manual chapter 27 will be removed.

@ZhaoxiangJin Can the example drivers be updated as well? The four examples under SDK_2_6_15_K32W041\boards\k32w061dk6\driver_examples\adc all use synchronous mode

Hello @ckielstra, yes, both driver and driver examples will be updated in the in the next release.

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