Motor Evaluation Kit NEVC-MCTRL-100-t01-1.0.0
Firmware for NEVB-MCTRL-100-01 for trapezoidal control of BLDC motors using Hall-effect sensors
Loading...
Searching...
No Matches
filter.h File Reference

Filter header file. More...

#include "stdint.h"
Include dependency graph for filter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_INT   32767
 Maximum value of integers.
 

Functions

int16_t calculateEMA (uint16_t currentSample, uint16_t previousEMA, uint8_t alphaExponent)
 Exponential Moving Average (EMA) calculation algorithm.
 

Detailed Description

Filter header file.

This file contains defines, typedefs and prototypes for the filter implementation.

Author
Nexperia: http://www.nexperia.com
Support Page
For additional support, visit: https://www.nexperia.com/support
Author
Aanas Sayed
Date
2024/03/08


Definition in file filter.h.

Macro Definition Documentation

◆ MAX_INT

#define MAX_INT   32767

Maximum value of integers.

Definition at line 29 of file filter.h.

Function Documentation

◆ calculateEMA()

int16_t calculateEMA ( uint16_t currentSample,
uint16_t previousEMA,
uint8_t alphaExponent )

Exponential Moving Average (EMA) calculation algorithm.

Calculates EMA from current sample, previous EMA and alpha.

Parameters
currentSampleCurrent measured sampled.
previousEMAPreviously calculated EMA.
alphaExponentUsed to drive alpha where alpha = 1 / (2 ^ alphaExponent).
Returns
Returns the calculated Exponential Moving Average (EMA) as a 16-bit signed integer.

Definition at line 34 of file filter.cpp.

35{
36 if (currentSample > MAX_INT)
37 {
38 currentSample = MAX_INT;
39 }
40 if (previousEMA > MAX_INT)
41 {
42 previousEMA = MAX_INT;
43 }
44
45 int16_t newEMA = (int16_t)previousEMA;
46 newEMA += ((int16_t)currentSample - (int16_t)previousEMA) >> alphaExponent;
47
48 if (newEMA < 0)
49 {
50 newEMA = 0;
51 }
52
53 return newEMA;
54}
#define MAX_INT
Maximum value of integers.
Definition filter.h:29
Here is the caller graph for this function: