AVR1631 - Energy Meter Reference Design with ATxmega32A4  Rev 1.0
 All Data Structures Files Functions Variables Typedefs Macros
meter_calculations.h File Reference

Meter Calibration routine. More...

#include <math.h>

Go to the source code of this file.

Macros

#define VOLT_GAIN   1
#define FREQUENCY_MAX   5000
#define FREQUENCY_MIN   25000
#define LP_ORDER   6
#define ONE_PULSE_ENERGY_THRESHOLD   (float)0.0003125
#define PULSE_ON_TIME   13

Functions

void calculate (void)
void calculate_freq (void)
void get_frequency (void)
int16_t lp_filter (int16_t *)
void meter_flush (void)

Variables

uint16_t Vrms [5]
uint16_t Irms [5]
uint16_t Nrms
int16_t offset [7]
uint16_t adc_samples
int32_t active_energy_signed
int32_t neutral_power
uint16_t active_power [5]
uint16_t apparent_power
int16_t power_factor
int32_t volt_temp
int32_t ct_temp
int32_t shunt_temp
uint8_t calibration_flag
uint8_t calibration_count
uint8_t gain_stage
 variables used in metering calculations
uint16_t frequency
int64_t watts_sum
int64_t watts_sum_calib
uint8_t freq_cnt
uint8_t offset_cnt
uint16_t max_demand
float pulse_energy_2_5ms

Detailed Description

Meter Calibration routine.

Application note:
AVR1631: Energy Meter Reference Design with ATxmega32A4
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author
Atmel Corporation: http://www.atmel.com
Support email: avr@a.nosp@m.tmel.nosp@m..com

$Revision: 1.0
$Date: 2012-07-01 10:10:10 +0530

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  1. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  1. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file meter_calculations.h.

Function Documentation

void calculate ( void  )

brief This function is called on every 1sec and perform the calculation of metering paramters

Parameters
Irmscontains the root mean square value of current on phase line
Vrmscontains the root mean square value of voltage
Nrmscontains the root mean square value of current on neutral line
apparent_powerholds the apparent energy (VA)
active_powerholds the active energy (Watts)
power_factorhols the power factor(PF)

Definition at line 233 of file meter_calculations.c.

void calculate_freq ( void  )

brief This function calculate line frequency from the value

Parameters
frequencyhold the line frequency.
freq_avghold the average timer value.

Definition at line 396 of file meter_calculations.c.

void get_frequency ( void  )

function check for the sign change in voltage signal for frequency calucaulation.

Parameters
sign_flagupdated when there is a sign change
sign_flag = 0, during the negative half cycle
sign_flag = 1, during the positive half cycle
freq_valhold the timer value of one sine wave
freq_sumhold the accumulated timer counter for frequency calculation
freq_cnthold the number of sine waves taken for frequency measument

Definition at line 420 of file meter_calculations.c.

int16_t lp_filter ( int16_t *  inp_array)

brief This function performs the low pass filtering of the input array

Parameters
lp_coeffcontains the coefficients for the low pass filtering
lp_outputreturn the filtered value

Definition at line 208 of file meter_calculations.c.

void meter_flush ( void  )

brief This function clear all the varilable used in for energy calculation

Definition at line 447 of file meter_calculations.c.