📄 filter.h
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (c) 2007 by Qu chun lei watt@vip.163.com
*
* File Name: FILTER.H
* Module: 0602C
* Language: ANSI C
* $Revision: 7 $
*
* DEFINITION
* This is a software module design for a digital filter.
*
* CONSTRAINTS
* This module does not handle data which is considered out of range by the
* application(i.e. fixed constants which represent error condition)
*
* Maximum weight value must be limited to 128 to prevent an overflow
* condition during the calculation.
*
* The internal data type must be large enough to handle the calculations.
* The maximum possible internal value
* = Max Input Value * (weight - 1) + Max Input Value
* If a maximum weight of 128 is used, the internal data type should be 2
* times the size of the input data type.
*
* ACCESS FUNCTIONS
* FilterData Get the filtered data
* FilterDataSet Force the filtered data
* FilterDataUpdate Calculate new filtered data
* FilterWeightSet Set the weight of a filter
* FilterWeight Get the weight of a filter
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef FILTER_H
#define FILTER_H
#include "dac.h"
/*------------------*
| Constants
*------------------*/
/* Definitions of Data Type for filtered and unfiltered data values */
#define FILTER_INT8 1
#define FILTER_UINT8 2
#define FILTER_INT16 3
#define FILTER_UINT16 4
#define FILTER_INT32 5
#define FILTER_UINT32 6
/*------------------*
| Module options
*------------------*/
#define FILTER_COUNT 1 /* Number of independent filters */
#define TFilterDataOption FILTER_UINT8 /* Data Type for filtered and unfiltered
data values */
#define FILTER_WEIGHT_DYNAMIC FALSE /* Set to true to allow the weight to be changed at
run-time, otherwise weight is defined at
compile-time */
#define FILTER_WEIGHT_FIXED FALSE
#define FILTER_WEIGHT_SHIFT 2
#if !FILTER_WEIGHT_DYNAMIC
#define FILTER_WEIGHT_DATA {4} /* Filter weighting factor for each
instance, may not be set to zero. */
#endif
/*--------------------*
| Types
*--------------------*/
#if TFilterDataOption == FILTER_INT8
#define TFilterData INT8
#define TFilterDataInternal INT16
#elif TFilterDataOption == FILTER_UINT8
#define TFilterData UINT8
#define TFilterDataInternal UINT16
#elif TFilterDataOption == FILTER_INT16
#define TFilterData INT16
#define TFilterDataInternal INT32
#elif TFilterDataOption == FILTER_UINT16
#define TFilterData UINT16
#define TFilterDataInternal UINT32
#elif TFilterDataOption == FILTER_INT32
#define TFilterData INT32
#define TFilterDataInternal INT32
#elif TFilterDataOption == FILTER_UINT32
#define TFilterData UINT32
#define TFilterDataInternal UINT32
#endif
/*--------------------*
| Public functions
*--------------------*/
/*---------------------------------------------------------------------------*
| FilterData
|
| This function always reports the filtered data stored internally.
|
| Entry: Instance (if FILTER_COUNT > 1)
| Desired action: report value only.
|
| Exit: Filtered data
*---------------------------------------------------------------------------*/
#if FILTER_COUNT > 1
TFilterData FilterData(UINT8 instance);
#else
TFilterData FilterData(void);
#endif
/*---------------------------------------------------------------------------*
| FilterDataSet
|
| This function always force the filtered data to a given value.
| Typically used for initialization.
|
| Entry: Instance (if FILTER_COUNT > 1)
| Forced New Data value.
|
| Exit: None
*---------------------------------------------------------------------------*/
#if FILTER_COUNT > 1
void FilterDataSet(UINT8 instance, TFilterData newValue);
#else
void FilterDataSet(TFilterData newValue);
#endif
/*---------------------------------------------------------------------------*
| FilterDataUpdate
|
| This function applys new unfiltered input data and calculate the new
| filtered data.
|
| Entry: Instance (if FILTER_COUNT > 1)
| Desired action: filter new input data to get filtered data
|
| Exit: None
*---------------------------------------------------------------------------*/
#if FILTER_COUNT > 1
void FilterDataUpdate(UINT8 instance, TFilterData rawData);
#else
void FilterDataUpdate(TFilterData rawData);
#endif
#if FILTER_WEIGHT_DYNAMIC
/*---------------------------------------------------------------------------*
| FilterWeightSet
|
| Set the weight of the digital filter
|
| Entry: Instance (if FILTER_COUNT > 1)
| Weighting factor
|
| Exit: None
*---------------------------------------------------------------------------*/
#if FILTER_COUNT > 1
void FilterWeightSet(UINT8 instance, UINT8 weight);
#else
void FilterWeightSet(UINT8 weight);
#endif
/*---------------------------------------------------------------------------*
| FilterWeight
|
| Report the weight of the digital filter
|
| Entry: Instance (if FILTER_COUNT > 1)
|
| Exit: Weight
*---------------------------------------------------------------------------*/
#if FILTER_COUNT > 1
UINT8 FilterWeight(UINT8 instance);
#else
UINT8 FilterWeight(void);
#endif
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -