打印

HAL库源文件stm32h7xx_hal_dfsdm.c学习笔记,硬件数字滤波器(2018-09-20 V1.0)

[复制链接]
482|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
你说说说说|  楼主 | 2018-8-10 12:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
说明:
具有8个输入通道,支持4组滤波器。



==============================================================================
                                                                  ##### 驱动如何使用  #####
==============================================================================  
1、通道初始化
初始化滤波器前,要优先初始化通道
(1)函数HAL_DFSDM_ChannelMspInit做预先的准备工作
        a、函数__HAL_RCC_DFSDMz_CLK_ENABLE用于使能时钟
        b、函数__HAL_RCC_GPIOx_CLK_ENABLE用于使能DFSDM GPIO的时钟
        c、函数HAL_GPIO_Init配置DFSDM GPIO的复用模式
        d、如果使用了中断,需要调用函数HAL_NVIC_SetPriority和HAL_NVIC_EnableIRQ
(2)使用函数HAL_DFSDM_ChannelInit配置时钟,输入,串行接口,模拟看门狗,偏移和数据bit右移。


2、通道时钟缺失检测器
(1)函数HAL_DFSDM_ChannelCkabStart() 或者 HAL_DFSDM_ChannelCkabStart_IT()用于启动时钟缺失检测器
(2)查询模式,使用函数HAL_DFSDM_ChannelPollForCkab检测缺失时钟
(3)中断模式,如果使能了中断,且检测到中断缺失,会调用回调函数HAL_DFSDM_ChannelCkabCallback
(4)停止时钟缺失检测,可调用函数HAL_DFSDM_ChannelCkabStop() 或者 HAL_DFSDM_ChannelCkabStop_IT()
(5)对于查询和中断模式,一个通道使用任意模式,所有其他通道都得是相同模式,因为所有通道用的一个中断。
(6)对于中断模式,如果一个通道的时钟缺少检测器停止,所有通道的都会停止。

3、通道短路检测器
(1)函数HAL_DFSDM_ChannelScdStart()和HAL_DFSDM_ChannelScdStart_IT()用于启动通道短路检测器
(2)查询模式,使用函数HAL_DFSDM_ChannelPollForScd检测通道短路
(3)中断模式,如果使能了中断,且检测通道短路,会调用回调函数HAL_DFSDM_ChannelScdCallback
(4)停止时钟缺失检测,可调用函数HAL_DFSDM_ChannelScdStop() 或者 HAL_DFSDM_ChannelScdStop_IT()
(5)对于查询和中断模式,一个通道使用任意模式,所有其他通道都得是相同模式,因为所有通道用的一个中断。
(6)对于中断模式,如果一个通道的短路检测器停止,所有通道的都会停止。

4、通道模拟看门狗值
     使用函数HAL_DFSDM_ChannelGetAwdValue获取数值

5、通道的偏移值修改
     使用函数HAL_DFSDM_ChannelModifyOffset修改通道偏移值

6、滤波器初始化
(1)通道初始化完毕后,就是滤波器的初始化
(2)函数HAL_DFSDM_FilterMspInit做预先的准备工作
(3)如果使用中断模式,使用函数HAL_NVIC_SetPriority和HAL_NVIC_EnableIRQ使能和配置DFSDMz_FLTx全局中断
(4)注意,如果是用于通道中断,DFSDMz_FLT0全局中断可能已经使能。
(5)如果使用DMA模式,需要调用函数HAL_DMA_Init配置,并使用函数__HAL_LINKDMA链接句柄。
(6)使用函数配置规则通道,注入通道和滤波器参数

7、滤波器规则通道转换
(1)使用函数HAL_DFSDM_FilterConfigRegChannel选择规格通道并使能或禁止连续转换模式
(2)用于启动规则转换的函数
        HAL_DFSDM_FilterRegularStart(),
        HAL_DFSDM_FilterRegularStart_IT(),
        HAL_DFSDM_FilterRegularStart_DMA()
        HAL_DFSDM_FilterRegularMsbStart_DMA().
(3)查询模式,调用函数HAL_DFSDM_FilterPollForRegConversion检测转换结束
(4)中断模式,如果转换结束会调用回调函数HAL_DFSDM_FilterRegConvCpltCallback
(5)函数HAL_DFSDM_FilterGetRegularValue用于获取规则通道的转换值
(6)在DMA模式,传输完成回调函数HAL_DFSDM_FilterRegConvCpltCallback和半传输中断函数HAL_DFSDM_FilterRegConvHalfCpltCallback会被调用。另外注意,只有在DMA循环模式,半传输回调函数HAL_DFSDM_FilterRegConvHalfCpltCallback才会被调用。
(7)停止转换函数可以选择下面三个HAL_DFSDM_FilterRegularStop(), HAL_DFSDM_FilterRegularStop_IT() 和 HAL_DFSDM_FilterRegularStop_DMA()

8、滤波器注入通道转换
(1)使用函数HAL_DFSDM_FilterConfigInjChannel选择并配置注入通道
(2)启动注入动态可以采用如下函数:
        HAL_DFSDM_FilterInjectedStart_IT(), HAL_DFSDM_FilterInjectedStart_DMA() 或 HAL_DFSDM_FilterInjectedMsbStart_DMA().
(3)查询模式,调用函数HAL_DFSDM_FilterPollForInjConversion查询转换是否结束
(4)中断模式,如果转换结束会调用回调函数HAL_DFSDM_FilterInjConvCpltCallback
(5)函数HAL_DFSDM_FilterGetInjectedValue用于获取注入通道的转换值
(6)在DMA模式,传输完成回调函数HAL_DFSDM_FilterInjConvCpltCallback和半传输中断函数HAL_DFSDM_FilterInjConvHalfCpltCallback会被调用。另外注意,只有在DMA循环模式,半传输回调函数HAL_DFSDM_FilterInjConvHalfCpltCallback才会被调用。
(7)停止转换函数可以选择下面三个函数:
        HAL_DFSDM_FilterInjectedStop(),HAL_DFSDM_FilterInjectedStop_IT() 或 HAL_DFSDM_FilterInjectedStop_DMA()。

9、模拟看门狗
(1)函数HAL_DFSDM_FilterAwdStart_IT用于启动模拟看门狗
(2)如果模拟看门狗设置的数值范围产生,回调函数HAL_DFSDM_FilterAwdCallback会被调用
(3)停止模拟看门狗调用函数HAL_DFSDM_FilterAwdStop_IT

10、滤波器极端探测器(Filter extreme detector)
(1)函数HAL_DFSDM_FilterExdStart用于启动极端探测器
(2)函数HAL_DFSDM_FilterGetExdMaxValue用于获取极端探测器最大值
(3)函数HAL_DFSDM_FilterGetExdMinValue用于获取极端探测器最小值
(4)函数HAL_DFSDM_FilterExdStop用于停止极端探测器

11、转换时间
(1)函数HAL_DFSDM_FilterGetConvTimeValue用于获取转换时间


函数:

初始化和复位初始化
HAL_StatusTypeDef HAL_DFSDM_ChannelInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
HAL_StatusTypeDef HAL_DFSDM_ChannelDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
void HAL_DFSDM_ChannelMspInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
void HAL_DFSDM_ChannelMspDeInit(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);


通道操作函数
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
HAL_StatusTypeDef HAL_DFSDM_ChannelCkabStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);

HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, uint32_t Threshold, uint32_t BreakSignal);
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStart_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, uint32_t Threshold, uint32_t BreakSignal);
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
HAL_StatusTypeDef HAL_DFSDM_ChannelScdStop_IT(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);

int16_t           HAL_DFSDM_ChannelGetAwdValue(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
HAL_StatusTypeDef HAL_DFSDM_ChannelModifyOffset(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, int32_t Offset);

HAL_StatusTypeDef HAL_DFSDM_ChannelPollForCkab(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, uint32_t Timeout);
HAL_StatusTypeDef HAL_DFSDM_ChannelPollForScd(DFSDM_Channel_HandleTypeDef *hdfsdm_channel, uint32_t Timeout);

void HAL_DFSDM_ChannelCkabCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);
void HAL_DFSDM_ChannelScdCallback(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);

通道状态函数
HAL_DFSDM_Channel_StateTypeDef HAL_DFSDM_ChannelGetState(DFSDM_Channel_HandleTypeDef *hdfsdm_channel);

滤波器初始化和复位初始化
HAL_StatusTypeDef HAL_DFSDM_FilterInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
void HAL_DFSDM_FilterMspInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
void HAL_DFSDM_FilterMspDeInit(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);

滤波控制函数
HAL_StatusTypeDef HAL_DFSDM_FilterConfigRegChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                   uint32_t                    Channel,
                                                   uint32_t                    ContinuousMode);
HAL_StatusTypeDef HAL_DFSDM_FilterConfigInjChannel(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                                   uint32_t                    Channel);

滤波器操作函数
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, int32_t *pData, uint32_t Length);
HAL_StatusTypeDef HAL_DFSDM_FilterRegularMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, int16_t *pData, uint32_t Length);
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterRegularStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, int32_t *pData, uint32_t Length);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedMsbStart_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, int16_t *pData, uint32_t Length);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterInjectedStop_DMA(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterAwdStart_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter,
                                              DFSDM_Filter_AwdParamTypeDef* awdParam);
HAL_StatusTypeDef HAL_DFSDM_FilterAwdStop_IT(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
HAL_StatusTypeDef HAL_DFSDM_FilterExdStart(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t Channel);
HAL_StatusTypeDef HAL_DFSDM_FilterExdStop(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);

int32_t  HAL_DFSDM_FilterGetRegularValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t* Channel);
int32_t  HAL_DFSDM_FilterGetInjectedValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t* Channel);
int32_t  HAL_DFSDM_FilterGetExdMaxValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t* Channel);
int32_t  HAL_DFSDM_FilterGetExdMinValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t* Channel);
uint32_t HAL_DFSDM_FilterGetConvTimeValue(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);

void HAL_DFSDM_IRQHandler(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);

HAL_StatusTypeDef HAL_DFSDM_FilterPollForRegConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t Timeout);
HAL_StatusTypeDef HAL_DFSDM_FilterPollForInjConversion(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t Timeout);

void HAL_DFSDM_FilterRegConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
void HAL_DFSDM_FilterRegConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
void HAL_DFSDM_FilterInjConvCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
void HAL_DFSDM_FilterInjConvHalfCpltCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
void HAL_DFSDM_FilterAwdCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter, uint32_t Channel, uint32_t Threshold);
void HAL_DFSDM_FilterErrorCallback(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);

滤波器状态函数
HAL_DFSDM_Filter_StateTypeDef HAL_DFSDM_FilterGetState(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);
uint32_t                      HAL_DFSDM_FilterGetError(DFSDM_Filter_HandleTypeDef *hdfsdm_filter);









2018-09-21_001818.png (182.53 KB, 下载次数: 1)

下载附件



2018-9-21 00:18 上传

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

355

主题

355

帖子

1

粉丝