我的一个应用,需要使用STM32G474RE输入捕获功能,使用 TIM2 通道 3 作为输入捕获通道。在一段指定时长内采集脉冲间隔。脉冲的最高频率很高,如果直接用 `HAL_TIM_IC_Start_IT` 开启中断捕获,会挤占其他任务的运行时间。
我的思路是改用 DMA,调用 `HAL_TIM_IC_Start_DMA`。只有当数据缓冲区存满时,DMA 中断才会触发。但我的需求是在一段固定时长内记录脉冲,这段时间内有可能没有脉冲事件,或者采集到的数据量填不满整个缓冲区,所以无法满足需求。
我的设想大致如下:
HAL_TIM_Base_Start_IT(tim1); //start timer to measure period
HAL_TIM_IC_Start_DMA(tim2); //start input capture
while(1) //handle other tasks while waiting on input capture
{
//do other things here
}
//input capture period timer has elapsed, so stop capture and store data
base_time_interrupt()
{
//stop IC
HAL_TIM_IC_Stop_DMA();
//DMA input capture data from peripheral
//get number of samples captured
}
请教这个方案是否可行?或者有没有其他更好方案来采集这些数据?
|
|