AVR182: Zero Cross Detector. Introduction. AVR ATmega163. AVR 8-bit Microcontrollers APPLICATION NOTE V CC. Serial Input Resistor. Mains.

Similar documents
8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AT88CK490 Evaluation Kit

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

CryptoAuth Xplained Pro

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

APPLICATION NOTE. Authentication Counting. Atmel CryptoAuthentication. Features. Introduction

AT11805: Capacitive Touch Long Slider Design with PTC. Introduction. Features. Touch Solutions APPLICATION NOTE

AVR127: Understanding ADC Parameters. Introduction. Features. Atmel 8-bit and 32-bit Microcontrollers APPLICATION NOTE

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

QT1 Xplained Pro. Preface. Atmel QTouch USER GUIDE

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

USER GUIDE EDBG. Description

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

APPLICATION NOTE. AT12405: Low Power Sensor Design with PTC. Atmel MCU Integrated Touch. Introduction

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. RF System Architecture Considerations ATAN0014. Description

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AN2680 Application note

USER GUIDE. ZigBit USB Stick User Guide. Introduction

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

AN1991. Audio decibel level detector with meter driver

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AN3265 Application note

Quad 2-input NAND Schmitt trigger

Dell Spotlight on Active Directory Server Health Wizard Configuration Guide

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

General Porting Considerations. Memory EEPROM XRAM

Capacitive Touch Technology Opens the Door to a New Generation of Automotive User Interfaces

Measuring Resistance Using Digital I/O

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

Using the RS232 serial evaluation boards on a USB port

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

AT91SAM ARM-based Flash MCU. Application Note

Evaluation Board for the AAT1275 Boost Converter with USB Power Switch

Output Filter Design for EMI Rejection of the AAT5101 Class D Audio Amplifier

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

Spotlight Management Pack for SCOM

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

1-of-4 decoder/demultiplexer

More Secure, Less Costly IoT Edge Node Security Provisioning

SAMA5D2. Scope. Reference Documents. Atmel SMART ARM-based MPU ERRATA

Planar PIN diode in a SOD323 very small plastic SMD package.

Dell One Identity Cloud Access Manager How to Configure vworkspace Integration

HEF4011B. 1. General description. 2. Features and benefits. 3. Ordering information. 4. Functional diagram. Quad 2-input NAND gate

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

APPLICATION NOTE. Atmel AVR600: STK600 Expansion, Routing and Socket Boards. Atmel Microcontrollers. Introduction

Security Analytics Engine 1.0. Help Desk User Guide

HEF4021B. 1. General description. 2. Features and benefits. 3. Ordering information. 8-bit static shift register

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

formerly Help Desk Authority Quest Free Network Tools User Manual

USER GUIDE. ATWINC1500B Hardware Design Guidelines - IEEE b/g/n IoT Module. Atmel SmartConnect. Introduction

10 ma LED driver in SOT457

APPLICATION NOTE. AVR042: AVR Hardware Design Considerations. AVR 8-bit Microcontrollers. Features. Description

AN2389 Application note

Low-power configurable multiple function gate

APPLICATION NOTE. AT05558: Wireless Manufacturing Test Kit. Atmel ATmega256RFR2. Description. Features

AN BGU8009 Matching Options for 850 MHz / 2400 MHz Jammer Immunity. Document information. Keywords

Digital-Output Magnetic Sensor (Hall IC)

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

Atmel AT32UC3A3256 microcontroller 64MBit SDRAM Analog input (to ADC) Temperature sensor RC filter

AN TDA8026ET - 5 slots smart card interface. Document information

AN3353 Application note

Dell Statistica Document Management System (SDMS) Installation Instructions

74HC377; 74HCT General description. 2. Features and benefits. 3. Ordering information

Transcription:

AVR 8-bit Microcontrollers AVR182: Zero Cross Detector APPLICATION NOTE Introduction One of the many issues with developing modern applications is to keep the spikes and EMI at a minimum, especially when switching AC mains in and out. Most of today s new applications are controlled by one or more microcontrollers and this gives the possibility to prevent this noise in a simple and cost efficient way. Noise produced during switching is dependent on the amplitude of the AC sinus at the actual switching point. To get this noise as low as possible the ideal switching would be when the amplitude is 0 volt. The amplitude is crossing 0 volt at the sinus zero crossing. Switching mains in and out at the zero crossing requires a way of detecting when the next crossing will be and launching a switching action at the crossing. This raises the need for a cost efficient way to detect the zero crossing. This application note explains how to do that. Zero cross detection can also be used for other purposes, such as frequency calculation and relative phase measuring. Figure -1. Zero Cross Detector Using AVR V CC VCC Mains Serial Input Resistor 1M PD2/EXT INT0 AVR ATmega163 1M GND Mains GND GND

Features Interrupt Driven Modular C Source Code Size Efficient Code Accurate and Fast Detection A Minimum of External Components 2

Table of Contents Introduction...1 Features... 2 1. Application Example... 4 1.1. Hardware...4 1.2. Software... 5 2. Special Considerations...8 2.1. Emulators and Clamp Diodes...8 2.2. RC Filter and Delay Between V CC /2 and the Actual Zero Cross... 8 2.3. Ground Must be Symmetrical...8 2.4. How to Calculate a Slow Switch (Relay)... 8 3. Revision History...10

1. Application Example This application note shows the user how to implement a zero cross detector with a minimum of external components. It should be noted that this solution will not give any galvanic isolation for the microcontroller against the AC mains. The zero cross sense resistor can be a way for electronic noise to get into the system. This will not be described in this application note. See AVR040: EMC Design Considerations for further details on this. The application uses ATmega16, but the code can be recompiled for any AVR device. The example code is written for Atmel START. It can be downloaded from the "BROWSE EXAMPLES" entry of Atmel START for both Atmel Studio 7 and IAR IDE. Double click the downloaded.atzip file and the project will be imported to Atmel Studio 7. To import the project in IAR, refer Atmel START in IAR. Select "Atmel Start Output in External Tools" "IAR". 1.1. Hardware To protect the device from voltages above V CC and below GND, the AVR has internal clamping diodes on the I/O pins (see Figure -1). The diodes are connected from the pins to V CC and GND and keep all input signals within the AVR s operating voltage (see the figure below). Any voltage higher than V CC + 0.5V will be forced down to V CC + 0.5V (0.5V is the voltage drop over the diode) and any voltage below GND - 0.5V will be forced up to GND - 0.5V. By adding a large resistor in series, these diodes can be used to convert a high voltage sinus signal down to a low voltage square wave signal, with amplitude within the AVR s operating voltage ±0.5V. The diodes will thus clamp the high voltage signal down to the AVR s operating voltage. Note: Note that the series resistor and the pin input capacitance form an RC filter that will introduce a small phase difference between the square wave and the AC mains signal. The phase difference is insignificant in the current example, see section RC Filter and Delay Between V CC /2 and the Actual Zero Cross for more details. As the square wave signal is in phase with the AC mains, using the falling edge will tell very accurately where the zero crossing happens. By using this signal the AVR can be programmed to be a very accurate zero cross detector with a very small and interrupt-driven code. The square wave is the mains signal with its tops cut off and will have the same voltage from V CC - 0.5V to V CC + 0.5V as the mains signal (see the figure below). When the square wave triggers the AVR s falling edge interrupt at around V CC /2, the mains amplitude will also be at V CC /2 and just before a zero crossing. If this is done on a falling edge the AVR will get an interrupt just before the zero crossing and will have time to start a zero crossing action at the actual crossing point. The interrupt will be triggered at around V CC /2, as this is the middle of the AVR s logical threshold voltage. The signal is connected to the External Interrupt 0-pin, which makes it possible to place the zero cross detection routine in an interrupt routine and make the detection fully interrupt driven. The second figure below shows an oscilloscope screen-shot of the actual input signal. Note that the Mains signal is scaled and the rising edge of the external int 0-pin is the same edge as for the Mains, because of the scaling, the Mains edge looks like it appears after the external int 0 edge. 4

Figure 1-1. Square Wave Input Signal on External Interrupt 0-pin Mains GND 110-240 V AC Mains V CC + 0.5V V CC + 0.5V V CC + 0.5V Squarewave on External Interrupt 0 AVR GND GND - 0.5V Figure 1-2. Oscilloscope Screen-shot of Square Wave Input on External Interrupt 0-pin The series input resistor is a 1MΩ resistor. It is not recommended that the clamping diodes are conducting more than maximum 1mA, and 1MΩ will then allow a maximum voltage of approximately 1,000V. Any voltage higher than 1,000V would probably be spikes or surges. The clamping diodes are able to handle spikes for a short period of time but not surges. The application note will not go into how to protect against surges, but simply recommend implementing protection against surges in the design. Most resistors have an upper maximum voltage limit. Make sure that the resistors used in the application can handle the highest possible AC mains voltage, including high voltage spikes. For systems with lower mains voltages the resistor value can be changed, but in general it should be able to sense 110-240V AC systems without any problems. The 1MΩ resistor in series to mains GND will ensure a correct ground potential for the application. 1.2. Software The external hardware and internal clamping diodes will make a square wave signal on the AVR s External Interrupt 0-pin. As described in the hardware section the square wave will have the same 5

frequency as the AC mains. The high period of the signal will be when the AC mains amplitude is above V CC /2. This gives mains zero crossings very close to the edges of the square wave. The rising edge of the square wave is slightly after the crossing, and the falling edge is slightly before the crossing. As the falling edge of the square wave is just before a zero crossing, the falling edge interrupt will occur so close to the actual crossing that it immediately can start the zero crossing action. In this application example the zero crossing action will only be to set PB0 high for a short period of time and then immediately start looking for the next falling edge zero crossing. This makes it very easy to check if the zero crossing detection is correct or not. Simply connect an oscilloscope probe to the mains and another to PB0. If the detection is correct this will show PB0 going high for a short period of time at each negative edge zero crossing (see the first two figures below). Figure 1-3. Screen-shot from Oscilloscope, Mains Input and PB0 Output Figure 1-4. Screen-shot from Oscilloscope, Mains Input and PB0 Output In a real application the disabling of external interrupt 0 before returning from the interrupt routine will make a single detection. To detect a new zero crossing, simply enable the falling edge interrupt again in the main program. To make sure the interrupts are valid and not only products of spikes on the pin, there is a filter implemented in the interrupt routine. The filter samples the level on the interrupt line five times and compares the values to see if the value is stable. If the value is not the same for all the samples, the event is discarded and the routine returns to the main program waiting for a new interrupt (see the figure below). 6

For more details about the software, see the comments in the code. Figure 1-5. Software Flowchart for Main Program and External Interrupt 0 Handling Routine Main Program Start EXT INT0 Handler Routine Enable EXT INT0 (Falling Edge) EXT INT0 Pin Low? Eternal Loop no yes no EXT INT0 Pin Sampled Low 5 Times? yes Set PB0 High Set PB0 Low End EXT INT0 Handler Routine 7

2. Special Considerations Applying high voltages to microcontrollers increases the possibility of malfunction or injury. It is advisable to follow a few special steps as any error can cause severe damage to components, emulators, or electric shock. 2.1. Emulators and Clamp Diodes The AVR family is set up with a complete system of emulators, but because of the nature of the PODs of some of the emulators, they are not equipped with internal clamping diodes. ICE200 and ICE40/50 are the only emulators with clamping diodes. ICE10 and ICE30 do not contain clamping diodes. By adding external clamping diodes these emulators will get the same input as the part. To apply a high AC voltage to an emulator can cause severe damage on the equipment and care should be taken. It is recommended to use isolation transformers on the mains and galvanic separated RS-232 communication to the PC. 2.2. RC Filter and Delay Between V CC /2 and the Actual Zero Cross The series resistor and the input pin capacitance will form an RC filter, which will delay the response compared to the actual zero crossing. The 1MΩ resistor together with the input capacitance on the AVR introduces a delay that brings the detection very close to the actual crossing. For other AC voltages or series resistors it is recommended to do a test with an oscilloscope to see how close the detection is to the actual crossing. This makes it very easy to check if the zero crossing detection is correct or not. Connect an oscilloscope probe to the mains and another to PB0. A correct detection will show PB0 going high for a short period of time at each falling edge zero crossing (see Figure 1-3 and Figure 1-4). If the detection is after the actual crossing, the next crossing should be targeted by adding a delay to the action. The delay should be equal to the time left before the next crossing. The series resistor can also be modified to make the detection closer but note that the maximum current through the AVR s clamping diode should not be higher than 1mA. 2.3. Ground Must be Symmetrical The mains ground must be symmetrical to the phases in the mains net. As the sensor is only using one phase and ground, this is necessary to detect the actual zero crossing according to the three phases in the mains net. If ground is not symmetrical it is not possible to know when the crossing is using only one phase. This can only be a problem in delta shaped mains net. Most countries, except Norway and Albania, use star shaped mains system and will not have this problem. 2.4. How to Calculate a Slow Switch (Relay) The typical use of a zero cross detector can be to control a mains relay. As relays have a response time that will be larger than the delay from the zero cross sensing to the actual crossing one technique can be to add a delay to the handling, i.e., sense the crossing on falling edge and make the relay close on rising edge. To do this, the response time of the relay and the frequency of the mains has to be known. These values can either be known from the manufacturer, or measured in a lab or by the AVR itself. 8

The measurement can be implemented into the AVR software. By using the zero cross detector it can easily sample the frequency of the signal and with some few external components it can also measure the relay response time. This will give a universal system that can adapt to almost any AC mains frequency and relay response time. It will also continue being correct even if the relay response time or frequency will change over time. 9

3. Revision History Doc Rev. Date Comments 2508C 09/2016 New template and some minor changes 2508B 01/2004 2508A Initial document release 10

Atmel Corporation 1600 Technology Drive, San Jose, CA 95110 USA T: (+1)(408) 441.0311 F: (+1)(408) 436.4200 www.atmel.com 2016 Atmel Corporation. / Rev.: Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, AVR, and others are registered trademarks or trademarks of Atmel Corporation in U.S. and other countries. Other terms and product names may be trademarks of others. DISCLAIMER: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. SAFETY-CRITICAL, MILITARY, AND AUTOMOTIVE APPLICATIONS DISCLAIMER: Atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death ( Safety-Critical Applications ) without an Atmel officer's specific written consent. Safety-Critical Applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear facilities and weapons systems. Atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by Atmel as military-grade. Atmel products are not designed nor intended for use in automotive applications unless specifically designated by Atmel as automotive-grade.