![]() |
AVR1631 - Energy Meter Reference Design with ATxmega32A4
Rev 1.0
|
Metering Algorithm implementation. More...
#include "meter.h"Go to the source code of this file.
Functions | |
| ISR (TCC1_OVF_vect) | |
| Timer/Counter 1 interrupt occur in every 250 uSec, (4KHz). The ISR routine enables ADC Conversion start on channel 0. This function also perform the pulsing of the led for meter constant of 3200 impulse/kwh. | |
| ISR (ADCA_CH0_vect) | |
| ADC ISR channel 0 interrupt reads the phase value from shunt for Irms and energy calculation. | |
| ISR (ADCA_CH1_vect) | |
| ADC ISR channel 1 interrupt reads the voltage value for Vrms and energy calculation The ADC ISR also check for the sign change in voltage signal for frequency calucaulation. | |
| ISR (ADCA_CH2_vect) | |
| ADC ISR channel 2 interrupt reads the neutral value from CT and accumulate it for neutal current calculation. | |
| int16_t | lp_filter (int16_t *inp_array) |
| void | calculate (void) |
| void | calculate_freq (void) |
| void | get_frequency (void) |
| void | meter_flush () |
Variables | |
| uint8_t | gain_stage = 0 |
| variables used in metering calculations | |
| uint32_t | freq_sum = 0 |
| uint16_t | frequency = 0 |
| uint16_t | max_demand = 0 |
| uint16_t | Vrms [5] = {0} |
| uint16_t | Irms [5] = {0} |
| uint16_t | Nrms = 0 |
| int16_t | p_mean = 0 |
| int16_t | Vmean = 0 |
| int16_t | n_mean = 0 |
| int32_t | phase_mean = 0 |
| int32_t | neutral_mean = 0 |
| int32_t | volt_mean = 0 |
| uint64_t | phase_sum = 0 |
| uint64_t | volt_sum = 0 |
| uint64_t | neutral_sum = 0 |
| int64_t | watts_sum = 0 |
| int64_t | watts_sum_neutral = 0 |
| int64_t | watts_sum_calib = 0 |
| uint16_t | adc_samples = 0 |
| int32_t | active_energy_signed = 0 |
| int32_t | neutral_power = 0 |
| uint16_t | active_power [5] = {0} |
| uint16_t | apparent_power = 0 |
| int16_t | power_factor |
| int16_t | offset [7] = {0} |
| int32_t | volt_temp |
| int32_t | ct_temp |
| int32_t | shunt_temp |
| volatile int16_t | adc_read_ch0 |
| volatile int16_t | adc_read_ch1 |
| int16_t | lp_phase [LP_ORDER] = {0} |
| int16_t | lp_power [LP_ORDER] = {0} |
| int16_t | lp_volt [LP_ORDER] = {0} |
| uint8_t | freq_cnt |
| uint8_t | offset_cnt = 0 |
| const int16_t | lp_coeff [LP_ORDER] = {5252, 5568, 5728, 5728, 5568, 5252} |
| float | pulse_energy_2_5ms = 0 |
| uint8_t | pulse_count = 0 |
| uint8_t | On_Time_counter = 0 |
| float | pulse_energy_acc = 0 |
Metering Algorithm implementation.
$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:
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.c.
| void calculate | ( | void | ) |
brief This function is called on every 1sec and perform the calculation of metering paramters
| Irms | contains the root mean square value of current on phase line |
| Vrms | contains the root mean square value of voltage |
| Nrms | contains the root mean square value of current on neutral line |
| apparent_power | holds the apparent energy (VA) |
| active_power | holds the active energy (Watts) |
| power_factor | hols 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
| frequency | hold the line frequency. |
| freq_avg | hold 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.
| sign_flag | updated when there is a sign change sign_flag = 0, during the negative half cycle sign_flag = 1, during the positive half cycle |
| freq_val | hold the timer value of one sine wave |
| freq_sum | hold the accumulated timer counter for frequency calculation |
| freq_cnt | hold the number of sine waves taken for frequency measument |
Definition at line 420 of file meter_calculations.c.
| ISR | ( | TCC1_OVF_vect | ) |
Timer/Counter 1 interrupt occur in every 250 uSec, (4KHz). The ISR routine enables ADC Conversion start on channel 0. This function also perform the pulsing of the led for meter constant of 3200 impulse/kwh.
| pulse_energy_2_5ms | hold the active energy for 2.5msec |
| pulse_energy_acc | hold the accumulated energy on every 2.5msec |
| On_Time_counter | hold the duration for which the pulse led to be ON |
Definition at line 85 of file meter_calculations.c.
| ISR | ( | ADCA_CH0_vect | ) |
ADC ISR channel 0 interrupt reads the phase value from shunt for Irms and energy calculation.
| adc_read_ch0 | hold the ADC channel result result register |
Definition at line 120 of file meter_calculations.c.
| ISR | ( | ADCA_CH1_vect | ) |
ADC ISR channel 1 interrupt reads the voltage value for Vrms and energy calculation The ADC ISR also check for the sign change in voltage signal for frequency calucaulation.
| adc_read_ch1 | hold the ADC channel result register |
Definition at line 133 of file meter_calculations.c.
| ISR | ( | ADCA_CH2_vect | ) |
ADC ISR channel 2 interrupt reads the neutral value from CT and accumulate it for neutal current calculation.
| p_mean | subtract the DC offset value form the ADC_result register. |
| phase_sum | contains the accumulated phase value |
| v_mean | substract the DC offset value form the ADC_result register. |
| volt_sum | contains the accumulated volt value |
| n_mean | substract the DC offset value form the ADC_result register. |
| neutral_sum | contains the accumulated neutral value |
| watts_sum | contain the accumulated power value of active power calculation |
| lp_phase | array contain the phase signal for low pass filtering |
| lp_volt | array contain the volt signal for low pass filtering |
| lp_power | array contain the instantaneous power signal for low pass filtering |
Definition at line 155 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
| lp_coeff | contains the coefficients for the low pass filtering |
| lp_output | return 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.