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

Meter initialisation. More...

#include "meter.h"

Go to the source code of this file.

Functions

int main (void)

Detailed Description

Meter initialisation.

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_main.c.

Function Documentation

int main ( void  )

set the power reduction register to minimize current consumption

set CPU clock to 32MHz and enables the DFLL32MHz

initialize the LCD module

display all the segments in LCD

initialize the GPIO pins

initializes the UART

load the calibration data from flash

get the ADC offset value

initialize the ADC

load the calibration value from eeprom

initilize RTC to external clock and 1 sec interrupt

initilize the timer

rtc_flag is set

perform the calculation of metering paramters

if power on detected

change the clock frequency to 32MHz

switch off the battery

initialize gpio pins

change the sleep mode to ideal sleep

enable ADC & Timer

initialize lcd module

update power status flag

update the LCD display

check for calibration flag and proceed and call the appropriate calibration funtion

checking the calibration flag for calibrating the date & time

checking the calibration flag for calibrating the voltage

checking the calibration flag for calculating the offset value

checking the calibration flag for calculating the phase angle variation

checking the calibration flag for calculating watt varition

checking the calibration flag for calibrating the current

checking the power_status, if power off is detected

switch on the battery

change the sleep mode to power save mode

switch off the LCD

change reset the gpio pin

disable the ADC

disable the timer

clear all the varilable used in for energy calculation

reduce the cpu clock frequency to minimize power consumption

update power status flag

goes to sleep

Definition at line 51 of file meter_main.c.