C2000Ware Digital Power SDK  5.03.00.00
EMAVG

Introduction

Data Structures

struct  EMAVG
 Defines the Exponential Moving Average (EMAVG) structure. More...
 

Functions

static void EMAVG_reset (EMAVG *v)
 resets internal storage data More...
 
static void EMAVG_config (EMAVG *v, float32_t multiplier)
 configures EMAVG module More...
 
static void EMAVG_run (EMAVG *v, float in)
 Run EMAVG module. More...
 

Typedefs

typedef float float32_t
 
typedef long double float64_t
 

Macros

#define C2000_IEEE754_TYPES
 

Exponential Moving Average (EMAVG) Module

Introduction

The exponential moving average (EMAVG) API provides a set of functions that performs exponential moving average over data.

Exponential Moving Average Model

The math operation performed can be represented in time domain as follows:

\[ EMAVG.Out[n] = (in - EMAVG.Out[n-1])*multiplier+ EMAVG[n-1] \]

Where in is the input data that is passed as an argument to the EMAVG function at sample instance 'n',
$\bullet$ EMAVG.Out [n] is the exponential moving average output at time instance 'n',
$\bullet$ EMAVG.Out [n-1] is the exponential moving average output at time instance 'n-1',
$\bullet$ multiplier is the weighting factor used in exponential moving average
In z-domain the equation can be interpreted as

\[ \frac{EMAVG.Out}{in} = \frac{multiplier}{1-(1-multiplier){z}^{-1}} \]

This can be seen as a special case for a Low Pass Filter, where pass band gain is equal to multiplier and filter time constant is (1-multiplier).

Note multiplier is always ≤ 1, hence (1-multiplier) is always a positive value. Also the lower the value of multiplier, the larger the time constant and more sluggish the response of the filter.

The following diagram illustrates the math function operated on in this block:

Exponential Moving Average Detailed Model

The block is used in the PFC software to get the average value of AC Line. The multiplier value for this can be estimated through two methods as follows:

Time Domain: The PFC stage runs at 100Khz and the input AC signal is 60Hz. As the average of the rectified sine signal is desired the effective frequency of the signal being averaged is 120Hz. This implies that (100Khz/120) = 833 samples in one half sine. For the average to be true representation the average needs to be taken over multiple sine halves (note: taking average over integral number of sine halves is not necessary). The multiplier value distributes the error equally over the number of samples for which average is taken. For AC line average a value of 4000 samples is chosen, as it averages roughly over 4 sine halves. Therefore:

\[ multiplier = 1/4000 = 0.00025 \]

Frequency Domain: Alternatively the multiplier value can be estimated from the z-domain representation as well. The signal is sampled at 100Khz and the frequency content is at 60Hz. Only the DC value is desired, therefore assuming a cut-off frequency of 5Hz the value can be estimated as follows:

For a first order approximation,

\[ z={e^{sT}} =1+s{T_{s}}\]

where T is the sampling period and solving the equation:

\[ \frac{Out(s)}{Input(s)}=\frac{1+s{T_{s}}}{1+s{\frac{T_{s}}{Mul}}} \]

Comparing with the analog domain low pass filter, the following equation can be written:

\[ multiplier=((2*{\pi}*f_{cut\_off})/f_{sampling})=(5*2*3.14/100K)=(0.000314) \]

API Usage

The following is a sequence of steps that can be followed to use the EMAVG API library functions in an existing C program. For a set of code examples that illustrates the use of this library, see the examples in the Digial Power SDK.

Before you can using the library you must add the libraries directory path as a searchable directory in the project include options. This can be done by right-clicking on the project in the Project Explorer window, selecting "Properties". In the window that opens, navigate to "Build, C2000 Compiler, Include Options". In the include path
window, click on the green add directory path button on the right and enter the path to the Digital Power SDK libraries directory.

This allows CCS to search the entire directory for library files.

Once that is done you should follow these steps incorporate this library into your project:

  1. Specify the include file(s)
    #include "emavg.h"

  2. Declare and add module structure to project source file
    EMAVG emavg1;

  3. Initialize module, pass the multiplier value as the argument. The selection of the multiplier value is explained in the description earlier and is dependent on the ISR Frequency at which the module will be called.
    EMAVG_reset(&emavg1);
    EMAVG_config(&emavg1, float multiplier);

  4. Using the module, pass the input as the argument. After the function call emavg1.out will have the new value
    EMAVG_run(&emavg1, in);

    Note: The functions are typically called in an interrupt source routine (ISR) which is called at the defined ISR frequency rate.

API Integration Information

There is only one module in this package, the APIs can be referenced at EMAVG. The module headers are located at emavg.h.

Macro Definition Documentation

◆ C2000_IEEE754_TYPES

#define C2000_IEEE754_TYPES

Definition at line 51 of file emavg.h.

Typedef Documentation

◆ float32_t

typedef float float32_t

Definition at line 56 of file emavg.h.

◆ float64_t

typedef long double float64_t

Definition at line 57 of file emavg.h.

Function Documentation

◆ EMAVG_reset()

static void EMAVG_reset ( EMAVG v)
inlinestatic

resets internal storage data

Parameters
vThe EMAVG structure

Definition at line 78 of file emavg.h.

◆ EMAVG_config()

static void EMAVG_config ( EMAVG v,
float32_t  multiplier 
)
inlinestatic

configures EMAVG module

Parameters
vThe EMAVG structure
multiplierMultiplier value

Definition at line 87 of file emavg.h.

◆ EMAVG_run()

static void EMAVG_run ( EMAVG v,
float  in 
)
inlinestatic

Run EMAVG module.

Parameters
vThe EMAVG structure
inInput

Definition at line 97 of file emavg.h.

EMAVG_config
static void EMAVG_config(EMAVG *v, float32_t multiplier)
configures EMAVG module
Definition: emavg.h:87
EMAVG_run
static void EMAVG_run(EMAVG *v, float in)
Run EMAVG module.
Definition: emavg.h:97
emavg.h
EMAVG_reset
static void EMAVG_reset(EMAVG *v)
resets internal storage data
Definition: emavg.h:78
EMAVG
Defines the Exponential Moving Average (EMAVG) structure.
Definition: emavg.h:70