I am sampling data on channels ADC0_SE4A and ADC0_SE0 and I am able to sample on the channels independently everything works great, but when I sample one channel and then another the second channel always returns incorrect values, usually 65XXX or something like 4. I thought that I had read somewhere that this is caused by an issue with switching between channels, so the fix was to sample only the same channel type. I want to make sure this is the case before I do a board respin. The microcontroller I am using is: MKL17Z64VDA4
Thanks in advance for your help!
已解决! 转到解答。
Hello, umlengineer
I´m glad that you found out about the issue. It's a pleasure to help. Now I suggest you to marc the question as assumed if you don't have further issues.
Best regards Diego.
Hello, Evan
After taking a look at your code, even though I don´t know the order of your procedures, I could not find something wrong with your configuration parameters. Thanks for showing me your code and the MUXSEL selection bit also I´ve noticed that you even used the function ADC16_SetChannelMuxMode().
I did a test by my side and I was able to sample successfully with both channels ADC_SE0 and ADC_SE4B.
I´ll contact you by email to provide you my main application code for your personal test in order to help you further.
Have a great day,
Diego
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hello, Evan
Thank you, after that please let us know your results!
Have a great day,
Diego
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hey,
I think I found the issues. My guess is multiplexing was part of the issue, but the main thing I found, was that I had incorrectly scoped the ADC_config variable. I made an init function that I called at the top, but the ADC_config was scoped to the function. In someways its interesting it worked at all. Once I correctly scoped the variable, put in the muxing code and explicitly set some channel settings to be sure, it looked like everything was working. I will have to stress it a bit but it looks good.
Thanks to you and Mark for your time, it was super helpful.
Hello, umlengineer
I´m glad that you found out about the issue. It's a pleasure to help. Now I suggest you to marc the question as assumed if you don't have further issues.
Best regards Diego.
Hello, Evan
I'm working on your question, as soon as I have useful information I'll let you know.
Have a great day,
Diego
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hello Evan,
The muxing of ADC channels have to be done by the user, so maybe you are facing a problem with your channel muxing technique, without taking a look at it to me is difficult to tell where the error is.
Your statement on channels of set A and B is correct, there is a bit called MUXSEL from ADCx_CFG2 register. that allows selecting between alternate sets of ADC channels.
About the unlabeled channels, I´ll refer to Marek Neuzil's answer in the thread
kl25z ADC muxing problem. You must select unlabeled channels with one set (set A or set B).
For example, select:
- ADC0_SE0
- ADC0_SE4a
- ADC0_SE7a
- ADC0_SE6a
or
- ADC0_SE0
- ADC0_SE4b
- ADC0_SE7b
- ADC0_SE6b
Have a great day,
Diego
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hi,
So I think I have the muxing set, and I am still seeing the issue. I am sure I am missing something, I am jsut not sure what.
Thanks for all the help, and please see below.
The documentation says that setting it to 0 selects A:
And when I look at the MuxSel register value I see that it is 0.
My ADC init code is as follows:
uint8_t InitializeADC(spi_transfer_t *xfer)
{
adc16_config_t adc16ConfigStruct;
ADC16_GetDefaultConfig(&adc16ConfigStruct);
#ifdef BOARD_ADC_USE_ALT_VREF
adc16ConfigStruct.referenceVoltageSource = kADC16_ReferenceVoltageSourceValt;
#endif
ADC16_Init(ADC16_BASE, &adc16ConfigStruct);
ADC16_EnableHardwareTrigger(ADC16_BASE, false); // Make sure the software trigger is used.
#if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION
if (kStatus_Success != ADC16_DoAutoCalibration(ADC16_BASE))
{
return ADC_AUTO_CAL_FAILURE;
}
#endif /* FSL_FEATURE_ADC16_HAS_CALIBRATION */
ADC16_SetChannelMuxMode(ADC16_BASE, kADC16_ChannelMuxA);
return 0;
}
And my ADC read code is:
Helpful Defines:
#define ADC16_BASE ADC0
#define ADC16_CHANNEL_GROUP 0U
#define ADC16_CHANNEL_TOP 4U
#define ADC16_CHANNEL_BOTTOM 0U
Channel 4a:
adc16ChannelConfigStruct.channelNumber = ADC16_CHANNEL_TOP;
ADC16_SetChannelConfig(ADC16_BASE, ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct);
while (0U == (kADC16_ChannelConversionDoneFlag & ADC16_GetChannelStatusFlags(ADC16_BASE, ADC16_CHANNEL_GROUP)))
{}
counts = ADC16_GetChannelConversionValue(ADC16_BASE, ADC16_CHANNEL_GROUP);
Channel 0:
adc16ChannelConfigStruct.channelNumber = ADC16_CHANNEL_BOTTOM;
ADC16_SetChannelConfig(ADC16_BASE, ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct);
while (0U == (kADC16_ChannelConversionDoneFlag & ADC16_GetChannelStatusFlags(ADC16_BASE, ADC16_CHANNEL_GROUP)))
{}
counts = ADC16_GetChannelConversionValue(ADC16_BASE, ADC16_CHANNEL_GROUP);
Hi Evan
See appendix D of the following for a discussion of ADC muxing details that sometimes catch people out>
https://www.utasker.com/docs/uTasker/uTaskerADC.pdf
Regards
Mark
[uTasker project developer for Kinetis and i.MX RT]