![]() |
AVR1631 - Energy Meter Reference Design with ATxmega32A4
Rev 1.0
|
Meter Calibration routine. More...
Go to the source code of this file.
Functions | |
| void | init_ADC (void) |
| void | clock_init (void) |
| This function intialises the CPU clock to 32MHz and enable the DFLL for runtime calibration of 32MHz internal Rc oscillator. | |
| void | delay_ms (uint16_t) |
Perform a delay of milliseconds. | |
| void | facilitatePowersaving (void) |
| void | get_offset (void) |
| void | init_eeprom (void) |
| This function loads the eeprom vaules during the startup. | |
| void | init_UART (void) |
| This function initializes the UARTC1 to 8 Data bits, No Parity, 1 Stop bit, 38400bps. | |
| void | init_ioport (void) |
| This function initializes the IOPORTS. | |
| void | init_lcd (void) |
| void | init_power_reduction (void) |
| This function disables the clock to unused peripherals and there by reduces the current consumption. | |
| void | init_timer (void) |
| This function disables the clock to unused peripherals and there by reduces the current consumption. | |
Meter Calibration routine.
$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_initialisation.h.
| void clock_init | ( | void | ) |
This function intialises the CPU clock to 32MHz and enable the DFLL for runtime calibration of 32MHz internal Rc oscillator.
The 32.768KHz external crystal is used as reference clock for DFLL
Enable the 32MHz internal RC oscillator
Enable the DFLL for runtime calibration of 32MHz internal RC oscillator
Definition at line 98 of file meter_initialisation.c.
| void delay_ms | ( | uint16_t | ms | ) |
Perform a delay of milliseconds.
| ms | contains the required delay in milli seconds |
Definition at line 59 of file meter_initialisation.c.
| void facilitatePowersaving | ( | void | ) |
brief This function enable pullup on all port pins and set the pins to input mode
Definition at line 455 of file meter_initialisation.c.
| void get_offset | ( | void | ) |
brief This function calculate the ADC offset values for different gain stage.
| offset[ | ] This array hold the offset values at different gain stages. |
Definition at line 377 of file meter_initialisation.c.
| void init_ADC | ( | void | ) |
brief This function initializes the ADC
Set up ADC A to have signed conversion mode and 12 bit resolution.
Set ADC clock frequency to FCPU/128
Set referance voltage on ADC A to be INT 1V.
*************** ADC Channel 0 ********************************
connected to the shunt resistor for current measumemnt in Phase line
Setup channel 0 to have diff gain input.
Set input to the channels in ADC A to be PIN 0 and PIN 4.
Enable medium level interrupts on ADCA channel 0, on conversion complete. */
**********************************************************************/
*************** ADC Channel 1 ********************************
connected to the voltage divider resistor for voltage measumemnt
Setup channel 1 to have diff gain input.
Set input to the channels in ADC A to be PIN 0 and PIN 4.
Enable medium level interrupts on ADCA channel 0, on conversion complete.
*********************************************************************/
*************** ADC Channel 2 ********************************
connected to the CT for current measumemnt in neutral line
Setup channel 1 to have diff gain input.
Set input to the channels in ADC A to be PIN 0 and PIN 4.
Enable medium level interrupts on ADCA channel 0, on conversion complete.
*******************************************************************/
unused
Enable PMIC interrupt level high.
Enable global interrupts.
Enable ADC A with free running mode, VCC reference and signed conversion.
Wait until common mode voltage is stable. Default clock is 32MHz and therefore below the maximum frequency to use this function.
clear all the varilable used in for energy calculation
Definition at line 271 of file meter_initialisation.c.
| void init_eeprom | ( | void | ) |
This function loads the eeprom vaules during the startup.
| refer | the struct eeprom in meter.h |
Definition at line 218 of file meter_initialisation.c.
| void init_ioport | ( | void | ) |
This function initializes the IOPORTS.
PORTB GPIO pin confuguration
PIN0_bm –> TAMPER_CURRENT_REVERSAL indication
PIN1_bm –> TAMPER_EARTH_FAULT indication
PIN2_bm –> LCD switch
PIN3_bm –> TAMPER_NEUTRAL_CUT indication
PORTC GPIO pin confuguration
PIN0_bm –> TWI connector
PIN1_bm –> TWI connector
PIN2_bm –> Cover open switch
PIN3_bm –> Calibration switch
PIN4_bm –> Magnetic Tamper detect
PIN5_bm –> unused switch
PIN6_bm –> UART Rx
PIN7_bm –> UART Tx
PORTD GPIO pin confuguration
PIN0_bm –> LED Pulse
PIN1_bm –> LCD Backlight control
PIN2_bm –> sleep detect
PIN3_bm –> LED debugging and status update
PIN4_bm –> Battery On/Off control
PIN5_bm –> USB D-
PIN6_bm –> USB D+
PIN7_bm –> LCD pin(optional)
Definition at line 120 of file meter_initialisation.c.
| void init_power_reduction | ( | void | ) |
This function disables the clock to unused peripherals and there by reduces the current consumption.
Definition at line 237 of file meter_initialisation.c.
| void init_timer | ( | void | ) |
This function disables the clock to unused peripherals and there by reduces the current consumption.
Definition at line 253 of file meter_initialisation.c.
| void init_UART | ( | void | ) |
This function initializes the UARTC1 to 8 Data bits, No Parity, 1 Stop bit, 38400bps.
Set UART TXD Pin(Pin3) as Output and RXD(Pin 2) Pin as Input Port
Configure USART Control Register, Character Size,Parity,Stop Bit to For example 8 Data bits, No Parity, 1 Stop bit
Configure USART Baud Rate value, 38400bps
Enable Both USART Receiver and Transmitter
Definition at line 192 of file meter_initialisation.c.