hsk_libs-dev  163:b63ae088cc97
High Speed Karlsruhe XC878 library collection
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
hsk_filter.h File Reference

HSK Filter generator. More...

#include <Infineon/XC878.h>
#include <string.h>
Include dependency graph for hsk_filter.h:

Go to the source code of this file.

Macros

#define FILTER_FACTORY(prefix, valueType, sumType, sizeType, size)
 Generates a filter. More...
 
#define FILTER_GROUP_FACTORY(prefix, filters, valueType, sumType, sizeType, size)
 Generates a group of filters. More...
 

Detailed Description

HSK Filter generator.

This file offers preprocessor macros to filter analogue values, by calculating the average of a set of a given length.

The buffer for the filter is stored in xdata memory.

Author
kami

Macro Definition Documentation

#define FILTER_FACTORY (   prefix,
  valueType,
  sumType,
  sizeType,
  size 
)
Value:
\
/** Holds the buffer and its current state. */ \
struct { \
/** The value buffer. */ \
valueType values[size]; \
/** The sum of the buffered values. */ \
sumType sum; \
/** The index of the oldest buffered value. */ \
sizeType current; \
} xdata prefix; \
\
/** Initializes the buffer with 0. */ \
void prefix##_init(void) { \
memset(&prefix, 0, sizeof(prefix)); \
} \
\
/** Updates the filter and returns the current sliding average of
buffered values.
@param value
The value to add to the buffer
@return
The average of the buffed values */ \
valueType prefix##_update(const valueType value) { \
prefix.sum -= prefix.values[prefix.current]; \
prefix.values[prefix.current++] = value; \
prefix.sum += value; \
prefix.current %= size; \
return prefix.sum / size; \
} \

Generates a filter.

The filter can be accessed with:

  • void <prefix>_init(void)
    • Initializes the filter with 0
  • <valueType> <prefix>_update(const <valueType> value)
    • Update the filter and return the current average
Parameters
prefixA prefix for the generated internals and functions
valueTypeThe data type of the stored values
sumTypeA data type that can contain the sum of all buffered values
sizeTypeA data type that can hold the length of the buffer
sizeThe length of the buffer
#define FILTER_GROUP_FACTORY (   prefix,
  filters,
  valueType,
  sumType,
  sizeType,
  size 
)

Generates a group of filters.

The filters can be accessed with:

  • void <prefix>_init(void)
    • Initializes all filters with 0
  • <valueType> <prefix>_update(const ubyte filter, const <valueType> value)
    • Update the given filter and return the current average
Parameters
prefixA prefix for the generated internals and functions
filtersThe number of filters
valueTypeThe data type of the stored values
sumTypeA data type that can contain the sum of all buffered values
sizeTypeA data type that can hold the length of the buffer
sizeThe length of the buffer