Hello Team,
I am trying to help my customer to achieve higher speed on the ADC peripheral, Could you please advise how can I get the maximum sampling time into the KV31P100M120SF7.
According to the datasheet, the maximum sampling in 12-bit is 1.2MS/s.
I made few tests to check the performance of the ADC and MCU functionality and got different numbers.
1. ADC get value in polling mode (12 or 10bit) = 3.128µsec
2. Set channel config by using function ADC16_SetChannelConfig = 0.448µsec
Please find below my ADC configuration and I'm using with 120MHz system clock (BOARD_BootClockHSRUN):
adc16ConfigStruct.clockSource = kADC16_ClockSourceAlt0;
adc16ConfigStruct.hardwareAverageMode = kADC16_HardwareAverageDisabled;
adc16ConfigStruct.resolution = kADC16_ResolutionSE12Bit;
adc16ConfigStruct.clockDivider = kADC16_ClockDivider1;
adc16ConfigStruct.longSampleMode = kADC16_LongSampleDisabled;
adc16ConfigStruct.enableHighSpeed = true;
adc16ConfigStruct.enableContinuousConversion = true;
adc16ConfigStruct.enableAsynchronousClock = false;
Please advise how can we improve the ADC sampling time to <1µsec?
Waiting for your kind response, Thanks.
Best Regards,
Shai
Hi Shai,
According to the datasheet, you need to configure:
fADCK(ADC conversion clock frequency)=24MHz
12bit mode
CFG2[ADHSC] must be set and CFG1[ADLPC] must be clear
Then you will get the 1200 Ksps Crate(ADC conversionrate).
Notice: No ADC hardware averaging Continuous conversions enabled, subsequent conversion time
Please check whether the ADC clock source in your configuration can be divided to 24MHz.
According to your codes, I can see you configure the Core clock to 120MHz.
But I don't know the frequency of Bus clock.(I am afraid 120MHz MCGOUTCLK can't divide to 48MHz or 24MHz Bus clock)
It caused you can't achieve 1200 Ksps ADC.
Maybe you can try to select kADC16_ClockDivider2:
use IRC48M as ADC clock
or
configure 96MHz MCGOUTCLK and 48MHz Bus clock, select Bus clock as ADC clock source.
Best Regards,
Robin
-------------------------------------------------------------------------------
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.
-------------------------------------------------------------------------------
Dear @Robin_Shen,
Thanks for the info and support.
I've created a project from scratch and added the relevant drivers.
I changed the ADC configuration according to your suggestion.
Now, ADC sampling time is around 2.5usec and if I change the divider to 1 it was improved to 2usec (but it’s not like the recommendation).
Be noted, If it would assist I can share with you the customer project for review.
In addition, the example project of ADC polling mode contains the following condition for the end of conversion.
while (0U == (kADC16_ChannelConversionDoneFlag &
ADC16_GetChannelStatusFlags(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP)))
{
}
Is it enough to wait only to kADC16_ChannelConversionDoneFlag? If yes, the ADC sampling time will improve to 1u.
One more question, what is the fast way to read and set the GPIO?
The function of GPIO_PinWrite takes around – ~0.4µsec (while working MCGOUTCLK as 120MHz).
Waiting for your feedback, Thanks in advance.
Kind regards,
Shai
I think you can refer frdmkv31f_adc16_continuous_edma example instead of frdmkv31f_adc16_polling.
Would you please let me know the clock source of ADC that you selected? (IRC48M or 120MHz MCGOUTCLK)
If you select MCGOUTCLK as clock source of ADC, MCGOUTCLK should be configured 96MHz in order to get 24MHz fADCK.
GPIO_PinWrite will determine whether to set or clear, maybe you can direct write the PCOR or PSOR register.(But I don't think it will not reduce too much time consumption)
What is the purpose of GPIO operation? If you just want to observe the ADC sampling frequency, you can refer verify ADC conversion rate with oscilloscope.
The customer used the IRC48M as a clock source of ADC, he will try to use the adc16_continuous_edma example demo to see if he can achieve 1 usec.
BTW, Did you managed to achieve 1 usec with frdmkv31f MCU?
Thanks in advance
Shai
I used the Processor Expert tool in KDS to configure a simple test project to quickly verify the ADC sampling frequency. (The ADC clock source is Bus Clock, which is divided down to 24MHz for ADC use)
Thank you so much for your great support, the customer works with MCUexpresso and he tried to use the internal IRC48M as the ADC clock source.
But without a success, I can share the project if needed.
BTW, I do not familiar with KDS, and if it possible that you will provide me your project so the customer would try it on its own (preferred in MCUexpresso format).
secondly and more important could you please elaborate more about the figure of the scope, for example, what did you measure and how did you perform the test in order to get the 920 nsec results output?
Thanks in advance
Kind regards,
Shai
For more detail about the the figure of the scope, you may need to read verify ADC conversion rate with oscilloscope.
The probe of oscilloscope is connect at ADC0_DP0_RC(Pin5 J2) of FRDM-KV31F board.
Dear @Robin_Shen,
Thanks for your great support and info.
There is bad and good news.
The bad news is that I made the same test as below and didn’t get the figures that you achieved.
I was using with 2K resistor and ADC0_SE8 pin.
I would be happy to understand what am I missing.
The good news is that when I bypass the function of the GPIO driver and set\get directly from the registers the TP time is improved.
For example, the GPIO_PinWrite function takes around 500nSec but when I set the IO directly from the registers is takes 160nSec.
520nSec -> GPIO_PinWrite(BOARD_DBG_GPIO, BOARD_DBG_GPIO_PIN, LOGIC_HIGH);
160nSec -> BOARD_DBG_GPIO->PSOR = GPIO_FIT_REG(u32flag << BOARD_DBG_GPIO_PIN);
Waiting for your kind comment on how I can reach a better conversion time as you managed to reach?
Thanks in advance
BR,
Shai
I modify the frdmkv31f_adc16_continuous_edma based on SDK_2.9.0_FRDM-KV31F with MCUXpresso IDE v11.3.1_5262.
You can refer the modification shown below:
notice the setting of oscilloscope: AC 20mV
Customer can direct test the attached project.
Best Regards,
Robin
-------------------------------------------------------------------------------
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.
-------------------------------------------------------------------------------