【ST NUCLEO-U5A5ZJ-Q开发板】第4帖 可配置的14Bit的ADC
<div class='showpostmsg'><p> </p><p ><span style="font-family:Times;"><span style="font-size:16px;">之前接触的STM32的芯片大部分都是常规的12bit的ADC</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">这个STM32U5是14bit的ADC</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">而且是可以配置的</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">可以选择配置14Bit还是12bit</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">不同bit位的采样率是不一样的</span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">看下手册里的参数</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">工程建立就不多说了</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">配置下ADC</span></span></p>
<pre>
<code class="language-cpp">
static void MX_ADC1_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
//hadc1.Init.Resolution = ADC_RESOLUTION_14B;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.GainCompensation = 0;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_9;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_391CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}</code></pre>
<p > </p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">换成配置14Bit ADC</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">hadc1.Init.Resolution = ADC_RESOLUTION_14B;</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">修改一下</span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">通过仿真查看下,我们定点采样的结果</span></span></p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">14bit</span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p > </p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">12bit ADC</span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;"> </span></span></p>
<p > </p>
<p ><span style="font-family:Times;"><span style="font-size:16px;">常规的采样结果肯定是差不多的</span></span></p>
<p > </p>
<p > </p>
<p > </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>大佬示例一下DMA采样呀,这DMA有点小麻烦。</p>
lugl4313820 发表于 2024-2-8 13:19
大佬示例一下DMA采样呀,这DMA有点小麻烦。
<p>这个芯片 DMA和stm32其他的不一样? 我都没研究过 还是大佬你眼力尖啊</p>
页:
[1]