简体   繁体   English

STM32 ADC DMA。 当 MCU 被告知 ADC 结束时?

[英]STM32 ADC DMA. When MCU is informed about end of ADC?

I use ADC with DMA (STM32F4, ide STM32CubeIDE) and I think that I understand how it works but still have one dilema.我将 ADC 与 DMA(STM32F4,ide STM32CubeIDE)一起使用,我认为我了解它是如何工作的,但仍然有一个难题。 From my understanding MCU is called only when DMA transfer is completed, basically MCU go into this function when DMA ADC is finished根据我的理解 MCU 只在 DMA 传输完成时调用,基本上 MCU 在 DMA ADC 完成时进入这个函数

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Is that right?那正确吗?

So if this is true, I have next dilema: for example adc_clock is 10MHz, sample time is 480 adc_cycles, 12 bit adc resolution.所以如果这是真的,我有下一个困境:例如 adc_clock 是 10MHz,采样时间是 480 adc_cycles,12 位 adc 分辨率。 adc_sample_period = 1/10Mhz * (480 + 12 + 3) = 49.5uS. adc_sample_period = 1/10Mhz * (480 + 12 + 3) = 49.5uS。 That mean MCU will go into HAL_ADC_ConvCpltCallback() every 49.5uS ???这意味着 MCU 将每 49.5uS 进入 HAL_ADC_ConvCpltCallback() ??? For my perspective that is hard intensive, especially in bigger projects.在我看来,这是很难密集的,尤其是在更大的项目中。 Did anyone have idea how to solve this "problem"?有没有人知道如何解决这个“问题”? I want to read ADC results for example every 1mS but also want to implement DMA into ADC.我想例如每 1mS 读取一次 ADC 结果,但也想将 DMA 实现到 ADC 中。 Any idea is welcome欢迎任何想法

Read the uC documentation - do not start from the " magic " HAL functions.阅读 uC 文档 - 不要从“魔法”HAL 函数开始。

1ms period between the the ADC conversions is absolutely nothing. ADC 转换之间的 1ms 周期绝对算不上什么。 I have many projects where I use double or triple ADC modes with resulting sampling rate of 18MSPS.我有许多项目使用双重或三重 ADC 模式,结果采样率为 18MSPS。

Generally speaking if you want poor, slow, inefficient and working "by accident" code - use HAL.一般来说,如果你想要糟糕、缓慢、低效和“偶然”工作的代码 - 使用 HAL。 Otherwise learn your hardware and use registers instead.否则,请学习您的硬件并改用寄存器。

This is how I solve this problem: I change DMA configuration.我是这样解决这个问题的:我改变了 DMA 配置。 DMA was configurated to work in circular mode, that mean when ADC finish one conversion DMA store data and MCU is notified via DMA 被配置为工作在循环模式,这意味着当 ADC 完成一次转换时,DMA 存储数据并通过以下方式通知 MCU

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Basically MCU was notified every 49.5uS and for my purpose that was too intensive (I need ADC result every 1mS).基本上每 49.5uS 通知 MCU 并且我的目的太密集(我每 1mS 需要一次 ADC 结果)。 I create timer which is used to indicate ADC when need to start sample and with DMA in normal mode (ADC will do only 1 measurement) that solve my problem.我创建了一个计时器,用于在需要开始采样时指示 ADC,并且在正常模式下使用 DMA(ADC 将只进行 1 次测量)来解决我的问题。 Every 1mS got result from ADC.每 1mS 从 ADC 得到结果。 So trick was in DMA modes (circular/normal mode).所以技巧是在 DMA 模式(循环/正常模式)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM