22
TB3211 Getting Started with AC Introduction Author: Cristian Pop, Microchip Technology Inc. Microchip tinyAVR ® 0- and 1-series, and megaAVR ® 0-series devices features an Analog Comparator (AC) with flexible input selection, selectable hysteresis and configurable output (interrupts on rising/ falling or both edges, event generation, and output inversion). This technical brief explains the AC concepts and its implementation in tinyAVR ® 0- and 1-series, and megaAVR ® 0-series devices with the following use cases: Level Crossing Detector This example shows how to use the AC to detect when a critical value of an analog signal is reached (for example, the battery level) Preventing False Spike Detection Exemplify how to use the hysteresis feature to minimize the number of false transitions in a noisy environment Analog Signal Pulse Duration/Frequency Measurement The example describes how to use the AC together with a timer to measure the pulse duration and/or the period of analog signals with minimal intervention of AVR core Note:  The code examples were developed using ATmega4809 XPlained Pro (ATMEGA4809-XPRO). © 2018 Microchip Technology Inc. DS90003211A-page 1

Getting Started with AC - Microchip Technologyww1.microchip.com/downloads/en/AppNotes/TB3211-Getting-Starte… · Figure 3-4. VREF.CTRLA - AC Voltage Reference Selection b A value

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

  • TB3211 Getting Started with AC

    Introduction

    Author: Cristian Pop, Microchip Technology Inc.

    Microchip tinyAVR® 0- and 1-series, and megaAVR® 0-series devices features an Analog Comparator(AC) with flexible input selection, selectable hysteresis and configurable output (interrupts on rising/falling or both edges, event generation, and output inversion).

    This technical brief explains the AC concepts and its implementation in tinyAVR® 0- and 1-series, andmegaAVR® 0-series devices with the following use cases:

    • Level Crossing DetectorThis example shows how to use the AC to detect when a critical value of an analog signal is reached(for example, the battery level)

    • Preventing False Spike DetectionExemplify how to use the hysteresis feature to minimize the number of false transitions in a noisyenvironment

    • Analog Signal Pulse Duration/Frequency MeasurementThe example describes how to use the AC together with a timer to measure the pulse duration and/orthe period of analog signals with minimal intervention of AVR core

    Note:  The code examples were developed using ATmega4809 XPlained Pro (ATMEGA4809-XPRO).

    © 2018 Microchip Technology Inc. DS90003211A-page 1

  • Table of Contents

    Introduction......................................................................................................................1

    1. Relevant Devices.......................................................................................................31.1. tinyAVR® 0-series......................................................................................................................... 31.2. tinyAVR® 1-series......................................................................................................................... 31.3. megaAVR® 0-series......................................................................................................................4

    2. Overview....................................................................................................................5

    3. Level Crossing Detector............................................................................................ 6

    4. Preventing False Spike Detection............................................................................11

    5. Analog Signal Pulse Duration/Frequency Measurements....................................... 12

    6. References.............................................................................................................. 14

    7. Appendix..................................................................................................................15

    The Microchip Web Site................................................................................................ 19

    Customer Change Notification Service..........................................................................19

    Customer Support......................................................................................................... 19

    Microchip Devices Code Protection Feature................................................................. 19

    Legal Notice...................................................................................................................20

    Trademarks................................................................................................................... 20

    Quality Management System Certified by DNV.............................................................21

    Worldwide Sales and Service........................................................................................22

    TB3211

    © 2018 Microchip Technology Inc. DS90003211A-page 2

  • 1. Relevant DevicesThis chapter lists the relevant devices for this document.

    1.1 tinyAVR® 0-seriesThe figure below shows the tinyAVR 0-series, laying out pin count variants and memory sizes:

    • Vertical migration is possible without code modification, as these devices are fully pin- and featurecompatible.

    • Horizontal migration to the left reduces the pin count and, therefore, the available features.

    Figure 1-1. tinyAVR® 0-series Overview

    8 14 20 24Pins

    Flash

    ATtiny1607

    ATtiny807

    ATtiny1606

    ATtiny806

    ATtiny1604

    ATtiny804

    ATtiny402

    ATtiny202

    ATtiny404

    ATtiny204

    ATtiny406

    32 KB

    16 KB

    8 KB

    4 KB

    2 KB

    devices ATtiny~~ATtiny~~Legend:

    common data sheet

    Devices with different Flash memory size typically also have different SRAM and EEPROM.

    1.2 tinyAVR® 1-seriesThe figure below shows the tinyAVR® 1-series devices, laying out pin count variants and memory sizes:

    • Vertical migration upwards is possible without code modification, as these devices are pin compatibleand provide the same or more features. Downward migration may require code modification due tofewer available instances of some peripherals.

    • Horizontal migration to the left reduces the pin count and therefore, the available features.

    TB3211Relevant Devices

    © 2018 Microchip Technology Inc. DS90003211A-page 3

  • Figure 1-2. tinyAVR® 1-series Overview

    48 KB

    32 KB

    16 KB

    8 KB

    4 KB

    2 KB

    8 14 20 24Pins

    Flash

    ATtiny816 ATtiny817ATtiny814

    ATtiny417

    ATtiny1616 ATtiny1617

    ATtiny414 ATtiny416ATtiny412

    ATtiny214ATtiny212

    ATtiny1614

    ATtiny3216 ATtiny3217

    devicesATtiny~~

    ATtiny~~Legend:

    common data sheet

    Devices with different Flash memory size typically also have different SRAM and EEPROM.

    1.3 megaAVR® 0-seriesThe figure below shows the megaAVR 0-series devices, laying out pin count variants and memory sizes:

    • Vertical migration is possible without code modification, as these devices are fully pin and featurecompatible.

    • Horizontal migration to the left reduces the pin count and, therefore, the available features.

    Figure 1-3. megaAVR® 0-series Overview

    48 KB

    32 KB

    16 KB

    8 KB

    28/32 48Pins

    Flash

    ATmega3208

    ATmega4808

    ATmega3209

    ATmega4809

    ATmega808

    ATmega1608 ATmega1609

    ATmega809

    Devices with different Flash memory size typically also have different SRAM and EEPROM.

    TB3211Relevant Devices

    © 2018 Microchip Technology Inc. DS90003211A-page 4

  • 2. OverviewThe AC is a module that compares two analog input voltages and outputs a signal level indicating whenone of the inputs is higher than the other. An AC is basically an amplifier without feedback and thus hasvery high gain.Figure 2-1. Analog Comparator Block Diagram

    +

    AC-

    Hys

    tere

    sis

    AINN0

    AINNn

    Inve

    rt

    Enab

    le

    AINP0

    Controllerlogic

    OUT

    Voltagedivider

    AINPn

    ...

    ...

    Event out

    CTRLAMUXCTRL

    CMP(Int. Req)

    DACREF

    VREF

    Figure 2-1 shows the block diagram of the analog comparator in tinyAVR® 0- and 1-series, andmegaAVR® 0-series devices. It compares the voltage levels on two inputs and gives a digital outputbased on this comparison.

    The dynamic behavior of the AC can be adjusted by a hysteresis feature. The hysteresis can becustomized to optimize the operation for each application. The input selection includes analog port pinsand internally generated inputs.

    The comparator has one positive input and one negative input. The positive input may be chosen from aselection of analog input pins. The negative input may be chosen from a selection of analog input pins orinternal inputs, such as a band gap reference voltage (DACREF). The digital output from the comparatoris ‘1’ when the difference between the positive and the negative voltage is positive, and ‘0’ otherwise.The AC can be configured to generate interrupt requests and/or events upon several differentcombinations of input change. The AC output state can also be the output on a pin for use by externaldevices.

    TB3211Overview

    © 2018 Microchip Technology Inc. DS90003211A-page 5

  • 3. Level Crossing DetectorThis example shows a basic initialization and set up for the AC module. The comparator can be used tomonitor battery voltage (or any other DC level), and to notify the application/user via interrupt and outputpin.Figure 3-1. Analog Comparator as Voltage Monitor

    DACREFVREF

    VBAT

    V1

    AINP0[PD2]

    +

    -

    OUT[PA7]

    To interrupt system

    0.8V

    To monitor an external voltage, the AC input should be connected to this voltage using an I/O pin. Thispin needs to have the digital input buffer and the pull-up resistor disabled, in order to have the highestpossible input impedance. For the ATmega4809, PORTD pin 2 (PD2/AINP0) is used as AC positive input:Figure 3-2. AC Positive Input

    QFN48/TQFP48

    Pin name (1,2) Special ADC0 AC0

    20 PD0 AIN0

    21 PD1 AIN1 P3

    22 PD2 AIN2 P0

    23 PD3 AIN3 N0

    This translates to the following code:PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc;

    In the selected application, the AC uses the analog pin as positive input and an internal reference for itsnegative input. The Voltage Reference module (VREF) should be configured prior to using the internalvoltage reference on negative input.

    TB3211Level Crossing Detector

    © 2018 Microchip Technology Inc. DS90003211A-page 6

  • Figure 3-3. VREF Block Diagram

    Reference se lect

    Bandgap ReferenceGenerator

    InternalReferenceBUF

    1.1V1.5V2.5V4.3V

    0.55V

    Reference enable

    Reference request

    Bandgapenable

    The VREF provides control registers for selecting between multiple internal reference levels. The internalreferences are generated from an internal band gap.Figure 3-4. VREF.CTRLA - AC Voltage Reference Selection

    b

    A value of 1.5 volts is selected as reference voltage:VREF.CTRLA = VREF_AC0REFSEL_1V5_gc;

    To enable VREF voltage generation, the output buffer must be enabled after selection of reference voltage.This can be done by setting the AC0REFEN bit from the VREF Control B register:

    TB3211Level Crossing Detector

    © 2018 Microchip Technology Inc. DS90003211A-page 7

  • Figure 3-5. VREF.CTRLB - Enable AC0REFEN bit

    b

    This translates to the following code:VREF.CTRLB = VREF_ADC0REFEN_bm;

    After configuring the peripherals and the modules required by the AC, the selection of inputs is doneusing MUXCTRLA register as follows:Figure 3-6. AC Input Selection

    b

    b

    The positive input pin 0 (AINP0) and internal DAC reference are used as AC inputs:AC0.MUXCTRLA = AC_MUXPOS_PIN0_gc | AC_MUXNEG_DACREF_gc;

    TB3211Level Crossing Detector

    © 2018 Microchip Technology Inc. DS90003211A-page 8

  • The analog value used by AC (VDACREF) is derived from internal reference using DACREF register andthe output voltage is defined by:������� = ������256 × ����The DACREF value can be calculated using the following macro:#define DACREF_VALUE (VDACREF * 256 / VREF)

    , where VDACREF represents the desired value on the analog comparator input and VREF represents thevalue selected as internal reference (1.5 Volts).

    Important:  To implement this application, the DACREF register is configured to select 0.8V onthe negative input. The user must select a proper combination of R1 and R2 resistors (see Figure 3-1) in such way that when battery voltage low threshold is reached, voltage V1 shouldbe 0.8V:�1 = 0.8� = ���� × �2�1 + �2Assuming VBAT = 3V and R2=10 kΩ, the value of R1 should be 27.5 kΩ

    The output of the comparator is present on the external pin and the interrupts are enabled on thenegative edge to notify the application when the critical level is reached. That is done using CTRLAregister:Figure 3-7. AC0.CTRLA - Set AC, Enable Interrupts and Output

    b

    b

    b

    These settings are translated into following code:AC0.CTRLA = AC_ENABLE_bm | AC_INTMODE_NEGEDGE_gc | AC_OUTEN_bm;

    To complete the setup and make selected interrupt available to the application, the AC peripheralinterrupt must be enabled. This is done by using the CMP bit from INTCTRL register:

    TB3211Level Crossing Detector

    © 2018 Microchip Technology Inc. DS90003211A-page 9

  • Figure 3-8. AC0.INTCTRL - Enable AC Interrupt

    b

    Tip:  The full code example is available in the Appendix section.

    TB3211Level Crossing Detector

    © 2018 Microchip Technology Inc. DS90003211A-page 10

    https://github.com/MicrochipTech/TB3211_Getting_Started_with_AnalogComparator

  • 4. Preventing False Spike DetectionThis example demonstrates the hysteresis features of the AC module that helps in avoiding frequenttoggling of the AC when the positive input oscillates very close to the negative input level. This applicationis almost similar to the voltage level detector application. Additionally, it has the Hysteresis mode enabled.Figure 4-1. Analog Comparator Response With and Without Hysteresis Enabled

    AINNn

    AOUT without Hysteresis

    AOUT with Hysteresis

    AINNn + 25 mV

    AINNn - 25 mVTime

    AINPn

    The hysteresis is configured by writing to the Hysteresis Mode Select bit field (HYSMODE[1:0]) in theControl A register:Figure 4-2. AC0.CTRLA - Configure Hysteresis Mode

    b

    A medium hysteresis is used (25 mV) and that is translated in the following sequence of code:AC0.CTRLA |= AC_HYSMODE_25mV_gc;

    Tip:  The full code example is also available in the Appendix section.

    TB3211Preventing False Spike Detection

    © 2018 Microchip Technology Inc. DS90003211A-page 11

    https://github.com/MicrochipTech/TB3211_Getting_Started_with_AnalogComparator

  • 5. Analog Signal Pulse Duration/Frequency MeasurementsThe tinyAVR® 0- and 1-series, and megaAVR® 0-series devices feature Event System (EVSYS), a simplebut powerful system that allows autonomous control of peripherals without any use of interrupts, CPU, orDMA resources. It allows a change in one peripheral (the Event Generator) to trigger actions in otherperipherals (the Event Users) through Event Channels. It provides short and predictable response timesbetween peripherals, and can reduce the complexity, size, and execution time of the software, to savepower.Figure 5-1. Analog Signal Duration/Frequency Measurement Block Diagram

    DACREFVREF

    V1

    AINP0[PD2]

    +

    -

    OUT[PA7]

    0.8V

    Analog signal

    Event channel 0CNT

    CCMP

    TCB

    The next application example shows an implementation of duration/frequency measurement for ananalog input signal, with minimal usage of microcontroller power. It uses the Event System (EVSYS) toroute the signals from the AC output through an Event Channel to Timer Counter B (TCB) Event Input. Todo this, the Event System must be configured properly.

    The first step in the Event System configuration is to set the AC output as Event Generator for channel 0:Figure 5-2. EVSYS.CHANNEL - Set AC output as event generator for channel 0

    b

    For EVSYS channel 0, the channel generator selection register must be loaded with 0x20 to enableanalog comparator as Event Generator:EVSYS.CHANNEL0 = EVSYS_GENERATOR_AC0_OUT_gc;

    To trigger events on TCB input, the TCB Event User must be connected to channel 0:EVSYS.USERTCB0 = EVSYS_CHANNEL_CHANNEL0_gc;

    TB3211Analog Signal Pulse Duration/Frequency Measurement...

    © 2018 Microchip Technology Inc. DS90003211A-page 12

  • To enable pulse and period measurements, the TCB is configured in Pulse-Width Measurement mode,having as input the Event System (EVSYS), which is used to route AC output through Event channel 0 toTCB event input.

    In Pulse-Width Measurement mode, the TCB will start counting when a positive edge is detected on theevent input signal. On the next falling edge, the count value is captured. The counter stops when thesecond rising edge of the event input signal is detected, and this will set the Interrupt flag. Reading thecapture will clear the Interrupt flag. When the Capture register is read, or the Interrupt flag is cleared, andthe TCB is ready for a new capture sequence. Therefore, it is recommended to read the Counter registerbefore the Capture register since it is reset to zero at the next positive edge:Figure 5-3. TCB - Input Capture Frequency and Pulse-width Measurement

    CNT

    MAX

    BOTTOM

    "Interrupt"

    Startcounter

    Copy CNT toCCMP

    Stop counter andinterrupt

    CPU reads the

    Ignore tillCapture is read

    Trigger nextcapture sequence

    Event Input

    Edge detector

    CCMP register

    The following code provides a basic initialization for TCB in Pulse-Width Measurement mode with EventSystem as input:int8_t TIMER0_init(){

    TCB0.CTRLB = TCB_CNTMODE_FRQPW_gc; TCB0.EVCTRL = TCB_CAPTEI_bm;

    TCB0.INTCTRL = TCB_CAPT_bm; TCB0.CTRLA = TCB_CLKSEL_CLKDIV2_gc | TCB_ENABLE_bm | TCB_RUNSTDBY_bm;

    }

    Tip:  The full code example is also available in the Appendix section.

    TB3211Analog Signal Pulse Duration/Frequency Measurement...

    © 2018 Microchip Technology Inc. DS90003211A-page 13

    https://github.com/MicrochipTech/TB3211_Getting_Started_with_AnalogComparator

  • 6. References1. ATmega4809 web page: https://www.microchip.com/wwwproducts/en/ATMEGA48092. DS40002015A - MegaAVR® 0-series User Manual: http://ww1.microchip.com/downloads/en/

    DeviceDoc/40002015A.pdf3. ATmega4809 Device Manual: http://ww1.microchip.com/downloads/en/DeviceDoc/40002016A.pdf4. AN2451 - Getting Started with Core Independent Peripherals on AVR® Microcontrollers

    (DS00002451)

    TB3211References

    © 2018 Microchip Technology Inc. DS90003211A-page 14

    https://www.microchip.com/wwwproducts/en/ATMEGA4809http://ww1.microchip.com/downloads/en/DeviceDoc/40002015A.pdfhttp://ww1.microchip.com/downloads/en/DeviceDoc/40002015A.pdfhttp://ww1.microchip.com/downloads/en/DeviceDoc/40002016A.pdfhttp://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en598462http://www.microchip.com/wwwAppNotes/AppNotes.aspx?appnote=en598462

  • 7. AppendixExample 7-1. Level Crossing detector source code

    #include #include

    /* set DACREF to 0.8 Volts for Vref = 1.5Volts */#define DACREF_VALUE (0.8 * 256 / 1.5)

    void PORT0_init (void);void AC0_init(void);

    ISR(AC0_AC_vect){ /* Insert AC interrupt handling code here */ /* The interrupt flag has to be cleared manually */ AC0.STATUS = AC_CMP_bm;}

    void PORT0_init (void){ /* Positive Input - Disable digital input buffer */ PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; /*Enable output buffer on PA7*/ PORTA |= PIN7_bm;}

    void AC0_init(void){

    /* Negative input uses internal reference - voltage reference should be enabled */ VREF.CTRLA = VREF_AC0REFSEL_1V5_gc; /* Voltage reference at 1.5V */ VREF.CTRLB = VREF_AC0REFEN_bm; /* AC0 DACREF reference enable: enabled */ AC0.DACREF = DACREF_VALUE; /* Set DAC voltage reference */

    /*Select proper inputs for comparator*/ AC0.MUXCTRLA = AC_MUXPOS_PIN0_gc /* Positive Input - Analog Positive Pin 0 */ | AC_MUXNEG_DACREF_gc; /* Negative Input - DAC Voltage Reference */ AC0.CTRLA = AC_ENABLE_bm /* Enable analog comparator */ | AC_OUTEN_bm; /* Output Buffer Enable: enabled */ AC0.INTCTRL = AC_CMP_bm; /* Analog Comparator 0 Interrupt enabled */ }

    int main(void){ PORT0_init(); AC0_init(); sei(); /* Global interrupts enabled */ while (1) { ; }}

    TB3211Appendix

    © 2018 Microchip Technology Inc. DS90003211A-page 15

  • Example 7-2. Preventing false spike detection source code

    #include #include

    /* set DACREF to 0.8 Volts for Vref = 1.5Volts */#define DACREF_VALUE (0.8 * 256 / 1.5)

    void PORT0_init (void);void AC0_init (void);

    ISR(AC0_AC_vect){ /* Insert AC interrupt handling code here */ /* The interrupt flag has to be cleared manually */ AC0.STATUS = AC_CMP_bm;}

    void PORT0_init (void){ /* Positive Input - Disable digital input buffer */ PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; /*Enable output buffer on PA7*/ PORTA |= PIN7_bm;}

    void AC0_init (void){

    /* Negative input uses internal reference - voltage reference should be enabled */ VREF.CTRLA = VREF_AC0REFSEL_1V5_gc; /* Voltage reference at 1.5V */ VREF.CTRLB = VREF_AC0REFEN_bm; /* AC0 DACREF reference enable: enabled */ AC0.DACREF = DACREF_VALUE; /* Set DAC voltage reference */ /*Select proper inputs for comparator*/ AC0.MUXCTRLA = AC_MUXPOS_PIN0_gc /* Positive Input - Analog Positive Pin 0 */ | AC_MUXNEG_DACREF_gc; /* Negative Input - DAC Voltage Reference */ AC0.CTRLA = AC_ENABLE_bm /* Enable analog comparator */ | AC_HYSMODE_25mV_gc /* Enable hysteresis @25mV */ | AC_OUTEN_bm; /* Output Buffer Enable: enabled */ AC0.INTCTRL = AC_CMP_bm; /* Analog Comparator 0 Interrupt enabled */

    }

    int main(void){ PORT0_init(); AC0_init(); sei(); /*Global interrupts enabled */ while (1) { ; }}

    Example 7-3. Analog signal pulse duration/frequency measurement source code

    #include

    /* set DACREF to 0.8 Volts for Vref = 1.5Volts */

    TB3211Appendix

    © 2018 Microchip Technology Inc. DS90003211A-page 16

  • #define DACREF_VALUE (0.8 * 256 / 1.5)

    void PORT0_init (void);void EVENT_SYSTEM_init (void);void AC0_init (void);void TIMER0_init (void);

    void PORT0_init (void){ /* Positive Input - Disable digital input buffer */ PORTD.PIN2CTRL = PORT_ISC_INPUT_DISABLE_gc; /*Enable output buffer on PA7*/ PORTA |= PIN7_bm;}

    void AC0_init (void){

    /* Negative input uses internal reference - voltage reference should be enabled */ VREF.CTRLA = VREF_AC0REFSEL_1V5_gc; /* Voltage reference at 1.5V */ VREF.CTRLB = VREF_AC0REFEN_bm; /* AC0 DACREF reference enable: enabled */ AC0.DACREF = DACREF_VALUE; /* Set DAC voltage reference */ /*Select proper inputs for comparator*/ AC0.MUXCTRLA = AC_MUXPOS_PIN0_gc /* Positive Input - Pin 0 */ | AC_MUXNEG_DACREF_gc; /* Negative Input - DAC Voltage Reference */ AC0.CTRLA = AC_ENABLE_bm /* Enable analog comparator */ | AC_OUTEN_bm; /* Output Buffer Enable: enabled */ AC0.INTCTRL = 0; /* Analog Comparator 0 Interrupt disabled */

    }

    /*Init TCB in pulse width-frequency measurement mode, input from Analog Comparator through Event System */void TIMER0_init (void){

    TCB0.CTRLB = TCB_CNTMODE_FRQPW_gc; /* Input Capture Frequency and Pulse-Width measurement */ TCB0.EVCTRL = TCB_CAPTEI_bm; /* Event Input Enable: enabled */ TCB0.INTCTRL = TCB_CAPT_bm; /* Capture or Timeout: enabled */ TCB0.CTRLA = TCB_CLKSEL_CLKDIV2_gc /* CLK_PER/2 (From Prescaler) */ | TCB_ENABLE_bm /* Enable: enabled */ | TCB_RUNSTDBY_bm; /* Run Standby: enabled */

    }

    /* Enable event generation from Analog comparator to TCB */void EVENT_SYSTEM_init (void){ EVSYS.CHANNEL0 = EVSYS_GENERATOR_AC0_OUT_gc; /* Analog Comparator 0 out linked to Event Channel 0 */ EVSYS.USERTCB0 = EVSYS_CHANNEL_CHANNEL0_gc; /* TCB uses Event Channel 0 */}

    int main(void){ uint16_t signal_pulse = 0, signal_period = 0; PORT0_init(); AC0_init(); EVENT_SYSTEM_init(); TIMER0_init(); while(1)

    TB3211Appendix

    © 2018 Microchip Technology Inc. DS90003211A-page 17

  • { if (TCB0.INTFLAGS) { /** * First read the CNT register * The interrupt flag is cleared by writing 1 to it, or when the Capture register * is read in Capture mode */ signal_period = TCB0.CNT; signal_pulse = TCB0.CCMP; } }}

    TB3211Appendix

    © 2018 Microchip Technology Inc. DS90003211A-page 18

  • The Microchip Web Site

    Microchip provides online support via our web site at http://www.microchip.com/. This web site is used asa means to make files and information easily available to customers. Accessible by using your favoriteInternet browser, the web site contains the following information:

    • Product Support – Data sheets and errata, application notes and sample programs, designresources, user’s guides and hardware support documents, latest software releases and archivedsoftware

    • General Technical Support – Frequently Asked Questions (FAQ), technical support requests, onlinediscussion groups, Microchip consultant program member listing

    • Business of Microchip – Product selector and ordering guides, latest Microchip press releases,listing of seminars and events, listings of Microchip sales offices, distributors and factoryrepresentatives

    Customer Change Notification Service

    Microchip’s customer notification service helps keep customers current on Microchip products.Subscribers will receive e-mail notification whenever there are changes, updates, revisions or erratarelated to a specified product family or development tool of interest.

    To register, access the Microchip web site at http://www.microchip.com/. Under “Support”, click on“Customer Change Notification” and follow the registration instructions.

    Customer Support

    Users of Microchip products can receive assistance through several channels:

    • Distributor or Representative• Local Sales Office• Field Application Engineer (FAE)• Technical Support

    Customers should contact their distributor, representative or Field Application Engineer (FAE) for support.Local sales offices are also available to help customers. A listing of sales offices and locations is includedin the back of this document.

    Technical support is available through the web site at: http://www.microchip.com/support

    Microchip Devices Code Protection Feature

    Note the following details of the code protection feature on Microchip devices:

    • Microchip products meet the specification contained in their particular Microchip Data Sheet.• Microchip believes that its family of products is one of the most secure families of its kind on the

    market today, when used in the intended manner and under normal conditions.• There are dishonest and possibly illegal methods used to breach the code protection feature. All of

    these methods, to our knowledge, require using the Microchip products in a manner outside theoperating specifications contained in Microchip’s Data Sheets. Most likely, the person doing so isengaged in theft of intellectual property.

    • Microchip is willing to work with the customer who is concerned about the integrity of their code.

    TB3211

    © 2018 Microchip Technology Inc. DS90003211A-page 19

    http://www.microchip.com/http://www.microchip.com/http://www.microchip.com/support

  • • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of theircode. Code protection does not mean that we are guaranteeing the product as “unbreakable.”

    Code protection is constantly evolving. We at Microchip are committed to continuously improving thecode protection features of our products. Attempts to break Microchip’s code protection feature may be aviolation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your softwareor other copyrighted work, you may have a right to sue for relief under that Act.

    Legal Notice

    Information contained in this publication regarding device applications and the like is provided only foryour convenience and may be superseded by updates. It is your responsibility to ensure that yourapplication meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS ORWARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORYOR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITSCONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE.Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in lifesupport and/or safety applications is entirely at the buyer’s risk, and the buyer agrees to defend,indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resultingfrom such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectualproperty rights unless otherwise stated.

    Trademarks

    The Microchip name and logo, the Microchip logo, AnyRate, AVR, AVR logo, AVR Freaks, BitCloud,chipKIT, chipKIT logo, CryptoMemory, CryptoRF, dsPIC, FlashFlex, flexPWR, Heldo, JukeBlox, KeeLoq,Kleer, LANCheck, LINK MD, maXStylus, maXTouch, MediaLB, megaAVR, MOST, MOST logo, MPLAB,OptoLyzer, PIC, picoPower, PICSTART, PIC32 logo, Prochip Designer, QTouch, SAM-BA, SpyNIC, SST,SST Logo, SuperFlash, tinyAVR, UNI/O, and XMEGA are registered trademarks of Microchip TechnologyIncorporated in the U.S.A. and other countries.

    ClockWorks, The Embedded Control Solutions Company, EtherSynch, Hyper Speed Control, HyperLightLoad, IntelliMOS, mTouch, Precision Edge, and Quiet-Wire are registered trademarks of MicrochipTechnology Incorporated in the U.S.A.

    Adjacent Key Suppression, AKS, Analog-for-the-Digital Age, Any Capacitor, AnyIn, AnyOut, BodyCom,CodeGuard, CryptoAuthentication, CryptoAutomotive, CryptoCompanion, CryptoController, dsPICDEM,dsPICDEM.net, Dynamic Average Matching, DAM, ECAN, EtherGREEN, In-Circuit Serial Programming,ICSP, INICnet, Inter-Chip Connectivity, JitterBlocker, KleerNet, KleerNet logo, memBrain, Mindi, MiWi,motorBench, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, OmniscientCode Generation, PICDEM, PICDEM.net, PICkit, PICtail, PowerSmart, PureSilicon, QMatrix, REAL ICE,Ripple Blocker, SAM-ICE, Serial Quad I/O, SMART-I.S., SQI, SuperSwitcher, SuperSwitcher II, TotalEndurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA aretrademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

    SQTP is a service mark of Microchip Technology Incorporated in the U.S.A.

    Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries.

    GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary ofMicrochip Technology Inc., in other countries.

    All other trademarks mentioned herein are property of their respective companies.

    TB3211

    © 2018 Microchip Technology Inc. DS90003211A-page 20

  • © 2018, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved.

    ISBN: 978-1-5224-4005-5

    Quality Management System Certified by DNV

    ISO/TS 16949Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and waferfabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in Californiaand India. The Company’s quality system processes and procedures are for its PIC® MCUs and dsPIC®

    DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory andanalog products. In addition, Microchip’s quality system for the design and manufacture of developmentsystems is ISO 9001:2000 certified.

    TB3211

    © 2018 Microchip Technology Inc. DS90003211A-page 21

  • AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPECorporate Office2355 West Chandler Blvd.Chandler, AZ 85224-6199Tel: 480-792-7200Fax: 480-792-7277Technical Support:http://www.microchip.com/supportWeb Address:www.microchip.comAtlantaDuluth, GATel: 678-957-9614Fax: 678-957-1455Austin, TXTel: 512-257-3370BostonWestborough, MATel: 774-760-0087Fax: 774-760-0088ChicagoItasca, ILTel: 630-285-0071Fax: 630-285-0075DallasAddison, TXTel: 972-818-7423Fax: 972-818-2924DetroitNovi, MITel: 248-848-4000Houston, TXTel: 281-894-5983IndianapolisNoblesville, INTel: 317-773-8323Fax: 317-773-5453Tel: 317-536-2380Los AngelesMission Viejo, CATel: 949-462-9523Fax: 949-462-9608Tel: 951-273-7800Raleigh, NCTel: 919-844-7510New York, NYTel: 631-435-6000San Jose, CATel: 408-735-9110Tel: 408-436-4270Canada - TorontoTel: 905-695-1980Fax: 905-695-2078

    Australia - SydneyTel: 61-2-9868-6733China - BeijingTel: 86-10-8569-7000China - ChengduTel: 86-28-8665-5511China - ChongqingTel: 86-23-8980-9588China - DongguanTel: 86-769-8702-9880China - GuangzhouTel: 86-20-8755-8029China - HangzhouTel: 86-571-8792-8115China - Hong Kong SARTel: 852-2943-5100China - NanjingTel: 86-25-8473-2460China - QingdaoTel: 86-532-8502-7355China - ShanghaiTel: 86-21-3326-8000China - ShenyangTel: 86-24-2334-2829China - ShenzhenTel: 86-755-8864-2200China - SuzhouTel: 86-186-6233-1526China - WuhanTel: 86-27-5980-5300China - XianTel: 86-29-8833-7252China - XiamenTel: 86-592-2388138China - ZhuhaiTel: 86-756-3210040

    India - BangaloreTel: 91-80-3090-4444India - New DelhiTel: 91-11-4160-8631India - PuneTel: 91-20-4121-0141Japan - OsakaTel: 81-6-6152-7160Japan - TokyoTel: 81-3-6880- 3770Korea - DaeguTel: 82-53-744-4301Korea - SeoulTel: 82-2-554-7200Malaysia - Kuala LumpurTel: 60-3-7651-7906Malaysia - PenangTel: 60-4-227-8870Philippines - ManilaTel: 63-2-634-9065SingaporeTel: 65-6334-8870Taiwan - Hsin ChuTel: 886-3-577-8366Taiwan - KaohsiungTel: 886-7-213-7830Taiwan - TaipeiTel: 886-2-2508-8600Thailand - BangkokTel: 66-2-694-1351Vietnam - Ho Chi MinhTel: 84-28-5448-2100

    Austria - WelsTel: 43-7242-2244-39Fax: 43-7242-2244-393Denmark - CopenhagenTel: 45-4450-2828Fax: 45-4485-2829Finland - EspooTel: 358-9-4520-820France - ParisTel: 33-1-69-53-63-20Fax: 33-1-69-30-90-79Germany - GarchingTel: 49-8931-9700Germany - HaanTel: 49-2129-3766400Germany - HeilbronnTel: 49-7131-67-3636Germany - KarlsruheTel: 49-721-625370Germany - MunichTel: 49-89-627-144-0Fax: 49-89-627-144-44Germany - RosenheimTel: 49-8031-354-560Israel - Ra’ananaTel: 972-9-744-7705Italy - MilanTel: 39-0331-742611Fax: 39-0331-466781Italy - PadovaTel: 39-049-7625286Netherlands - DrunenTel: 31-416-690399Fax: 31-416-690340Norway - TrondheimTel: 47-72884388Poland - WarsawTel: 48-22-3325737Romania - BucharestTel: 40-21-407-87-50Spain - MadridTel: 34-91-708-08-90Fax: 34-91-708-08-91Sweden - GothenbergTel: 46-31-704-60-40Sweden - StockholmTel: 46-8-5090-4654UK - WokinghamTel: 44-118-921-5800Fax: 44-118-921-5820

    Worldwide Sales and Service

    © 2018 Microchip Technology Inc. DS90003211A-page 22

    IntroductionTable of Contents1. Relevant Devices1.1. tinyAVR® 0-series1.2. tinyAVR® 1-series1.3. megaAVR® 0-series

    2. Overview3. Level Crossing Detector4. Preventing False Spike Detection5. Analog Signal Pulse Duration/Frequency Measurements6. References7. AppendixThe Microchip Web SiteCustomer Change Notification ServiceCustomer SupportMicrochip Devices Code Protection FeatureLegal NoticeTrademarksQuality Management System Certified by DNVWorldwide Sales and Service