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.cpp
Go to the documentation of this file.
1
/* This file has been prepared for Doxygen automatic documentation generation.*/
22
#include "
filter.h
"
23
34
int16_t
calculateEMA
(uint16_t currentSample, uint16_t previousEMA, uint8_t alphaExponent)
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
}
calculateEMA
int16_t calculateEMA(uint16_t currentSample, uint16_t previousEMA, uint8_t alphaExponent)
Exponential Moving Average (EMA) calculation algorithm.
Definition
filter.cpp:34
filter.h
Filter header file.
MAX_INT
#define MAX_INT
Maximum value of integers.
Definition
filter.h:29
filter.cpp
Generated by
1.10.0