avrapps-1544: getting started with events on the tinyavr 1...
TRANSCRIPT
Getting Started with Eventson the tinyAVR 1-series
Getting Started with Events on the tinyAVRreg 1-series
Prerequisites
bull Hardware Prerequisitesndash ATtiny817 Xplained Pro evaluation kitndash Micro-USB cable (Type-AMicro-B)ndash A breadboardndash A compatible potentiometerndash Three compatible male-to-female wiresndash Internet connection
bull Software Prerequisitesndash Atmel Studio 70ndash Web browser A list of supported browsers can be found here httpstartatmelcomstatic
helpindexhtmlGUID-51435BA6-0D59-4458-A413-08A066F6F7CAbull Estimated Completion Time 120 minutes
Introduction
This hands-on training will demonstrate how to develop AVRreg applications in Atmel Studio and AtmelSTART along with the rich user interface and other great development tools that they provide
Atmel START helps to get started with Microchip microcontroller development It allows to select MCUconfigure software components drivers middleware and example projects to the embedded applicationin a usable and optimized manner Once the configuration is complete the project can be generated inAtmel Studio or another third-party development tool An IDE is used to develop the code required toextend the functionality of the project into the final product as well as compile program and debug thedownloaded code
With Atmel START
bull Get help selecting the MCU based on both software and hardware requirementsbull Find and develop examplesbull Configure drivers middleware and example projectsbull Get help with setting up a valid PINMUX layoutbull Configure system clock settings
The ATtiny817 Xplained Pro evaluation kit is a hardware platform for evaluating the AVR ATtiny817microcontroller A fully integrated embedded debugger is included on the kit which provides seamlessintegration with Atmel Studio Easy access to the features of the ATtiny817 is enabled by the kitfacilitating easy integration of the device in a customer design
This training demonstrates how to configure the application in Atmel START Reconfigure the AtmelSTART project and continue the implementation in Atmel Studio 7
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 1
The peripherals used to create applications are GPIO RTC ADC CPUINT USART and Event System
Figure 1 ATtiny817 Xplained Pro
The following topics are covered
bull Driver configuration in Atmel STARTbull PINMUX driver configurationbull LED toggling triggered by RTC overflow interruptbull USART configuration with string print to USART serial-port terminalbull RTC overflow interrupt triggers an ADC conversion and then ADC result-ready interrupt triggers ADC
data print to USART terminalbull RTC overflow interrupt triggers an ADC conversion and then an ADC result triggers ADC data print to
USART terminal if it is outside a defined windowbull RTC overflow event triggers an ADC conversion then if an ADC result is outside a defined window
waking up CPU with an IRQbull How to use Data Visualizer in Atmel Studio to view the USART print to the embedded terminal and
graph
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 2
Table of Contents
Prerequisites1
Introduction1
1 Icon Key Identifiers 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling 621 Atmel | START Project Creation 622 Atmel | START Project Overview In Atmel Studio 1423 Code Development 1624 Debug the Application 16
3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal2031 USART Configuration in Atmel | START 2032 Expand the USART Functionality2433 USART Output to Data Visualizer Terminal2634 RTC Interrupt Triggers USART Transmission 27
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USARTTerminal 3241 Add ADC Driver In Atmel | START 3242 Configure ADC in Atmel | START3343 Add ADC Functionality to Application Code3644 Connect Potentiometer to ADC3845 Observe ADC Functionality39
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer4151 ADC Re-Configuration in Atmel START 4152 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph43
6 Assignment 5 RTC Interrupt Replaced by Event System4661 Event System Configuration in Atmel START 4662 Event System Driver Code Development49
7 Conclusion51
8 Revision History52
The Microchip Web Site 53
Customer Change Notification Service53
Customer Support 53
Microchip Devices Code Protection Feature 53
Legal Notice54
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 3
Trademarks 54
Quality Management System Certified by DNV55
Worldwide Sales and Service56
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 4
1 Icon Key IdentifiersThe following icons are used in this document to identify different assignment sections and to reducecomplexity
Info Delivers contextual information about a specific topic
Tip Highlights useful tips and techniques
To do Highlights objectives to be completed
Result Highlights the expected result of an assignment step
Warning Indicates important information
Execute Highlights actions to be executed out of the target when necessary
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED TogglingIn this assignment an application that triggers LED toggling from the RTC overflow interrupt will bedeveloped
Atmel | START will be used to configure the RTC clock and PINMUX settings Based on this an AtmelStudio 7 project will be generated
Code will be developed in Atmel Studio 7 using PINMUX and RTC driver functions generated by Atmel |START
Info On the ATtiny817 Xplained Pro board LED0 is connected to pin PB4
Peripherals used
bull RTCbull GPIO (PB4)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock
21 Atmel | START Project CreationConfigure PINMUX driver RTC driver and CLOCK in Atmel | START and create the project
To do Create a new Atmel | START Project
1 Open Atmel Studio2 Select File rarr New rarr Atmel Start Project3 The CREATE NEW PROJECT window appears within Atmel Studio 7 In the Filter on device
text box enter 817X then select ATtiny817 Xplained Pro from the list and verify thatATtiny817Xplained Pro is highlighted then click CREATE NEW PROJECT as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 6
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
The peripherals used to create applications are GPIO RTC ADC CPUINT USART and Event System
Figure 1 ATtiny817 Xplained Pro
The following topics are covered
bull Driver configuration in Atmel STARTbull PINMUX driver configurationbull LED toggling triggered by RTC overflow interruptbull USART configuration with string print to USART serial-port terminalbull RTC overflow interrupt triggers an ADC conversion and then ADC result-ready interrupt triggers ADC
data print to USART terminalbull RTC overflow interrupt triggers an ADC conversion and then an ADC result triggers ADC data print to
USART terminal if it is outside a defined windowbull RTC overflow event triggers an ADC conversion then if an ADC result is outside a defined window
waking up CPU with an IRQbull How to use Data Visualizer in Atmel Studio to view the USART print to the embedded terminal and
graph
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 2
Table of Contents
Prerequisites1
Introduction1
1 Icon Key Identifiers 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling 621 Atmel | START Project Creation 622 Atmel | START Project Overview In Atmel Studio 1423 Code Development 1624 Debug the Application 16
3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal2031 USART Configuration in Atmel | START 2032 Expand the USART Functionality2433 USART Output to Data Visualizer Terminal2634 RTC Interrupt Triggers USART Transmission 27
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USARTTerminal 3241 Add ADC Driver In Atmel | START 3242 Configure ADC in Atmel | START3343 Add ADC Functionality to Application Code3644 Connect Potentiometer to ADC3845 Observe ADC Functionality39
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer4151 ADC Re-Configuration in Atmel START 4152 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph43
6 Assignment 5 RTC Interrupt Replaced by Event System4661 Event System Configuration in Atmel START 4662 Event System Driver Code Development49
7 Conclusion51
8 Revision History52
The Microchip Web Site 53
Customer Change Notification Service53
Customer Support 53
Microchip Devices Code Protection Feature 53
Legal Notice54
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 3
Trademarks 54
Quality Management System Certified by DNV55
Worldwide Sales and Service56
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 4
1 Icon Key IdentifiersThe following icons are used in this document to identify different assignment sections and to reducecomplexity
Info Delivers contextual information about a specific topic
Tip Highlights useful tips and techniques
To do Highlights objectives to be completed
Result Highlights the expected result of an assignment step
Warning Indicates important information
Execute Highlights actions to be executed out of the target when necessary
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED TogglingIn this assignment an application that triggers LED toggling from the RTC overflow interrupt will bedeveloped
Atmel | START will be used to configure the RTC clock and PINMUX settings Based on this an AtmelStudio 7 project will be generated
Code will be developed in Atmel Studio 7 using PINMUX and RTC driver functions generated by Atmel |START
Info On the ATtiny817 Xplained Pro board LED0 is connected to pin PB4
Peripherals used
bull RTCbull GPIO (PB4)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock
21 Atmel | START Project CreationConfigure PINMUX driver RTC driver and CLOCK in Atmel | START and create the project
To do Create a new Atmel | START Project
1 Open Atmel Studio2 Select File rarr New rarr Atmel Start Project3 The CREATE NEW PROJECT window appears within Atmel Studio 7 In the Filter on device
text box enter 817X then select ATtiny817 Xplained Pro from the list and verify thatATtiny817Xplained Pro is highlighted then click CREATE NEW PROJECT as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 6
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Table of Contents
Prerequisites1
Introduction1
1 Icon Key Identifiers 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling 621 Atmel | START Project Creation 622 Atmel | START Project Overview In Atmel Studio 1423 Code Development 1624 Debug the Application 16
3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal2031 USART Configuration in Atmel | START 2032 Expand the USART Functionality2433 USART Output to Data Visualizer Terminal2634 RTC Interrupt Triggers USART Transmission 27
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USARTTerminal 3241 Add ADC Driver In Atmel | START 3242 Configure ADC in Atmel | START3343 Add ADC Functionality to Application Code3644 Connect Potentiometer to ADC3845 Observe ADC Functionality39
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer4151 ADC Re-Configuration in Atmel START 4152 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph43
6 Assignment 5 RTC Interrupt Replaced by Event System4661 Event System Configuration in Atmel START 4662 Event System Driver Code Development49
7 Conclusion51
8 Revision History52
The Microchip Web Site 53
Customer Change Notification Service53
Customer Support 53
Microchip Devices Code Protection Feature 53
Legal Notice54
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 3
Trademarks 54
Quality Management System Certified by DNV55
Worldwide Sales and Service56
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 4
1 Icon Key IdentifiersThe following icons are used in this document to identify different assignment sections and to reducecomplexity
Info Delivers contextual information about a specific topic
Tip Highlights useful tips and techniques
To do Highlights objectives to be completed
Result Highlights the expected result of an assignment step
Warning Indicates important information
Execute Highlights actions to be executed out of the target when necessary
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED TogglingIn this assignment an application that triggers LED toggling from the RTC overflow interrupt will bedeveloped
Atmel | START will be used to configure the RTC clock and PINMUX settings Based on this an AtmelStudio 7 project will be generated
Code will be developed in Atmel Studio 7 using PINMUX and RTC driver functions generated by Atmel |START
Info On the ATtiny817 Xplained Pro board LED0 is connected to pin PB4
Peripherals used
bull RTCbull GPIO (PB4)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock
21 Atmel | START Project CreationConfigure PINMUX driver RTC driver and CLOCK in Atmel | START and create the project
To do Create a new Atmel | START Project
1 Open Atmel Studio2 Select File rarr New rarr Atmel Start Project3 The CREATE NEW PROJECT window appears within Atmel Studio 7 In the Filter on device
text box enter 817X then select ATtiny817 Xplained Pro from the list and verify thatATtiny817Xplained Pro is highlighted then click CREATE NEW PROJECT as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 6
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Trademarks 54
Quality Management System Certified by DNV55
Worldwide Sales and Service56
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 4
1 Icon Key IdentifiersThe following icons are used in this document to identify different assignment sections and to reducecomplexity
Info Delivers contextual information about a specific topic
Tip Highlights useful tips and techniques
To do Highlights objectives to be completed
Result Highlights the expected result of an assignment step
Warning Indicates important information
Execute Highlights actions to be executed out of the target when necessary
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED TogglingIn this assignment an application that triggers LED toggling from the RTC overflow interrupt will bedeveloped
Atmel | START will be used to configure the RTC clock and PINMUX settings Based on this an AtmelStudio 7 project will be generated
Code will be developed in Atmel Studio 7 using PINMUX and RTC driver functions generated by Atmel |START
Info On the ATtiny817 Xplained Pro board LED0 is connected to pin PB4
Peripherals used
bull RTCbull GPIO (PB4)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock
21 Atmel | START Project CreationConfigure PINMUX driver RTC driver and CLOCK in Atmel | START and create the project
To do Create a new Atmel | START Project
1 Open Atmel Studio2 Select File rarr New rarr Atmel Start Project3 The CREATE NEW PROJECT window appears within Atmel Studio 7 In the Filter on device
text box enter 817X then select ATtiny817 Xplained Pro from the list and verify thatATtiny817Xplained Pro is highlighted then click CREATE NEW PROJECT as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 6
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
1 Icon Key IdentifiersThe following icons are used in this document to identify different assignment sections and to reducecomplexity
Info Delivers contextual information about a specific topic
Tip Highlights useful tips and techniques
To do Highlights objectives to be completed
Result Highlights the expected result of an assignment step
Warning Indicates important information
Execute Highlights actions to be executed out of the target when necessary
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 5
2 Assignment 1 RTC Overflow Interrupt Triggers LED TogglingIn this assignment an application that triggers LED toggling from the RTC overflow interrupt will bedeveloped
Atmel | START will be used to configure the RTC clock and PINMUX settings Based on this an AtmelStudio 7 project will be generated
Code will be developed in Atmel Studio 7 using PINMUX and RTC driver functions generated by Atmel |START
Info On the ATtiny817 Xplained Pro board LED0 is connected to pin PB4
Peripherals used
bull RTCbull GPIO (PB4)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock
21 Atmel | START Project CreationConfigure PINMUX driver RTC driver and CLOCK in Atmel | START and create the project
To do Create a new Atmel | START Project
1 Open Atmel Studio2 Select File rarr New rarr Atmel Start Project3 The CREATE NEW PROJECT window appears within Atmel Studio 7 In the Filter on device
text box enter 817X then select ATtiny817 Xplained Pro from the list and verify thatATtiny817Xplained Pro is highlighted then click CREATE NEW PROJECT as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 6
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
2 Assignment 1 RTC Overflow Interrupt Triggers LED TogglingIn this assignment an application that triggers LED toggling from the RTC overflow interrupt will bedeveloped
Atmel | START will be used to configure the RTC clock and PINMUX settings Based on this an AtmelStudio 7 project will be generated
Code will be developed in Atmel Studio 7 using PINMUX and RTC driver functions generated by Atmel |START
Info On the ATtiny817 Xplained Pro board LED0 is connected to pin PB4
Peripherals used
bull RTCbull GPIO (PB4)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock
21 Atmel | START Project CreationConfigure PINMUX driver RTC driver and CLOCK in Atmel | START and create the project
To do Create a new Atmel | START Project
1 Open Atmel Studio2 Select File rarr New rarr Atmel Start Project3 The CREATE NEW PROJECT window appears within Atmel Studio 7 In the Filter on device
text box enter 817X then select ATtiny817 Xplained Pro from the list and verify thatATtiny817Xplained Pro is highlighted then click CREATE NEW PROJECT as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 6
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 2-1 CREATE NEW PROJECT
Info Now the MY SOFTWARE COMPONENTS window appears
4 In the MY SOFTWARE COMPONENTS window rename the project as shown below with 1-2 redmarkings First click MY PROJECT and then select Rename ComponentFigure 2-2 Rename Component
Info Now RENAME COMPONENT window will be displayed
5 In the RENAME COMPONENT window specify the new project name asATtiny817_getting_start_events and click Rename
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 7
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
6 Open PINMUX configuration by clicking on in the navigation tab on the left side of thewindow
Info The PINMUX configurator displays an illustration of the device package selected Itshows which pins are currently used by different peripherals GPIO pins can beconfigured here
Info Here PB4 is configured as LED0 which is available on the ATtiny817 Xplained ProConfiguration is shown in 1-4 red markings below
Figure 2-3 PINMUX Configuration LED0
7 Execute the numbered configuration steps 1-4 from the figure as described belowndash Click PB4 in the PINMUX listndash Enter User label as LED0ndash Select Pin mode Digital outputndash Make sure Initial level is set to Low
Info Technical documents related to the ATtiny817 Xplained Pro can be downloadedfrom the ATtiny817 Xplained Pro rarr Technical Documentation page within Atmel StudioThe ATtiny817 Xplained Pro page is displayed when the ATtiny817 Xplained Pro board isconnected to the PC
8 Add the RTC component
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 8
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Click in the navigation tab on the left side of the window Then click
Info The ADD SOFTWARE COMPONENTS window will appear
Figure 2-4 Add RTC Component
9 RTC ConfigurationExpand Drivers in the ADD SOFTWARE COMPONENTS window as shown above scroll downto locate RTC and click to select it Then click the Add component(s) button The RTC_0module will now be added to the project as shown below
Info In the figure below red markings 1-2 refer to what has been completed aboveSteps 3-7 describes the configuration of the RTC
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 9
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 2-5 RTC Configuration
10 Execute the numbered configuration steps 3 through 7 from the figure above asndash Click RTC_0 to open the RTC driver configuration pagendash Tick the RTCEN checkbox to configure the RTC to be enabled in the RTC initialization
routine that will be generated by Atmel | STARTndash Click the PRESCALER dropdown menu and select 32 to configure the RTC clock
prescaler to 32
Info This will configure the RTC count frequency to 1 kHz as the default RTCclock source is the 32 kHz Internal Ultra Low Power Oscillator
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 10
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ndash Continue by entering decimal number 500 equivalent to the hexadecimal value 0x1f4 in thePER text box to define the RTC period
ndash Tick the OVF checkbox to enable the RTC overflow interrupt
Info The RTC overflow interrupt is configured to trigger approximately twice per secondas the period is set to 500 with a RTC clock frequency of 1 kHz
11 Enable CPUINT Global Interrupt
Info The three steps involved in configuring the CPUINT module are described belowand illustrated in Figure 2-6
ndash Make sure the Show system drivers slider in the top right corner of the DASHBOARD-viewis switched ON
ndash Click CPUINIT to open the CPUINT configuration viewndash Tick the CPU_SREG Global Interrupt Enable checkbox such that the initialization routine
generated by Atmel | START will enable global interrupts
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 11
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 2-6 CPUINT Configuration
Info The RTC and CPUINIT are now configured The RTC will now be able to trigger itsoverflow interrupt
12 Clock configuration Open the clock configuration view by clicking on in the navigation tabon the left side of the window
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 12
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Info The CLOCK CONFIGURATOR view will now be displayed It contains oscillatorsand clock sources of different types Required clock sources can be selected andconfigured The corresponding output frequency is then calculated and presented Thesettings dialog for each element in the clock configuration view can be opened by clickingthe associated cog-wheel
bull The Oscillators section displays the oscillators available for the selected devicebull The Source section is used to configure clock frequency by selecting input signal
and prescaling factor
13 Open the Clock Settings- dialog for Main Clock by clicking its corresponding cog-wheel to viewthe default clock settings as shown below
Info CLOCK SETTINGS window will be displayed
Figure 2-7 MAIN CLOCK CONFIGURATION
Info For this application the default clock settings are kept as is Here the Main Clocksource is the 20 MHz Internal Oscillator with prescaler division set to 6 The resulting CPU
clock frequency is 333 MHz Clicking the question mark next to each configuration willprovide the data sheet description of the individual bit setting The RTC clock wasconfigured to 1 kHz earlier and this is also shown in the figure
14 Click Close to close the CLOCK SETTING window
15 Now click the GENERATE PROJECT button 16 Select the desired path where the project should be stored as shown below and then click OK
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 13
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 2-8 Project Importer Window
Result The Atmel | START project has been created in Atmel Studio
22 Atmel | START Project Overview In Atmel StudioThe Atmel | START project generates peripheral driver functions and files as well as a main() functionthat initializes all drivers
About folders and files generated by Atmel | START
bull Header files and source files for the peripheral drivers generated by START are located in thefolders src and include
bull The atmel_start_pinsh file in the include folder contains useful PINMUX driver functionsbull The utils folder contain files that define some functions that can be commonly used by the drivers
and the application itselfbull The atmel_startc file contains the atmel_start_init() function which initializes the MCU
drivers and middleware defined for the projectbull The driver_isrc file contains generated ISRs if interrupts have been enabled in Atmel | START
To do Get an overview of the Atmel | START project
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 14
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 2-9 Project Overview
1 The Solution Explorer sub-window for the generated ATtiny817_getting_started_events Studioproject should be present as shown in the figure above If not click on the Solution Explorer sub-window as indicated in the figure to unhide it It can also be opened by clicking View followed bySolution Explorer Double-click the mainc file in the Solution Explorer sub-window to open it
2 Right-click on the atmel_start_init() function and then click Goto Implementation Repeat theprocedure for the system_init() function which is called by atmel_start_init() andobserve that system_init() calls the initialization functions for the generated peripheral drivers
Info The mcu_init() function enables the internal pull-up resistor on all pins to reducepower consumption All driver initialization functions are called from the system_init()function in addition to configuring the port pin associated with LED0 to output mode witha defined initial level
3 Go to implementation of CLKCTRL_init() and observe that the default clock settings arecommented out
Info If the non-default clock settings are selected in START it will be reflected inCLKCTRL_init()
4 Open the atmel_start_pinsh file in the Solution Explorer sub-window and then click on the downarrow as shown in the figure below to open the list of functions defined in this file Observe thatmany useful GPIO functions have been generatedFigure 2-10 atmel_start_pinsh Functions
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 15
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Result The Atmel | START project overview is completed
23 Code DevelopmentHere the RTC overflow interrupt will be set up to trigger LED0 toggling on the ATtiny817 Xplained Prodevelopment kit
To do Write code to toggle LED0 in the RTC interrupt handler
1 Open the driver_isrc file in the ATtiny817_getting_started_events project
To do Edit the driver_isrc file
2 Insert the code LED0_toggle_level() in the ISR(RTC_CNT_vect) interrupt handler asshown below This will as the function name reveals toggle the level on the pin connected to LED0each time the RTC overflow interrupt is executedISR(RTC_CNT_vect) Insert your RTC Overflow interrupt handling code LED0_toggle_level() Overflow interrupt flag has to be cleared manually RTCINTFLAGS = RTC_OVF_bm
Info Since the RTC clock runs at 1 kHz and the RTC period is set to 500 the RTCoverflow interrupt will be executed two times per second LED0 will consequently toggletwo times per second
3 The mainc file is kept as is Click Build rarr Build Solution in the top toolbar or press F7 in AtmelStudio to build the solutionNote The build should finish successfully with no errors
24 Debug the Application
To do Debug the application where the RTC overflow interrupt triggers LED0 toggling
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 16
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
1 Power the ATtiny817 Xplained Pro kit by connecting a Micro-USB cable to the computer2 In Studio click Debug rarr Start Debugging and Break to program the kit and start debugging as
shown below This can also be done by pressing Alt+F5Figure 2-11 Start Debugging and Break
Info If the embedded debugger firmware version on is lower than the one in the AtmelStudio installation a firmware upgrade dialog will be opened
Figure 2-12 Firmware Upgrade
Select Upgrade and when the progress bar is complete select Close Now start debugging byclicking Debug rarr Start Debugging and Break or by pressing Alt+F5
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 17
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Result The kit is programmed with the application and a debugging session is initiatedstarting with the code in mainc
3 Click in the margin to the left of the RTCINTFLAGS = RTC_OVF_bm to place a breakpoint in thecode in driver_isrc as shown above This breakpoint is set after the LED0_toggle_level()function call is executed
4 Run the application until the breakpoint is hit by clicking Debug rarr Continue pressing F5 or by
clicking the play button
Tip The play button is located in the top toolbar in Atmel Studio and in the Debugmenu
5 To check the status of all the PORTB pins open the IO View window by selecting Debug rarrWindows rarr IO and click on the IO Ports (PORTB) register group as shown in Figure 2-13
Info In the IO View the status and register values of all peripherals can be inspectedPin status is indicated for PB0 to PB7 from right to left under the Bits column in the OUTregister As shown in the image below the level of pin PB4 (LED0) is HIGH since a filledsquare corresponds to bit status 1 An empty square indicates that the bit status is 0LOW
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 18
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 2-13 IO View
6 Click on to continue the execution and observe that the value of the OUT register in thePORTB register alternates between 0x00 and 0x10 each time the breakpoint is hit This indicatesthat pin PB4 is being set and reset alternatively and LED0 is toggling correspondingly
7 Remove the breakpoint by clicking the shown in Figure 2-11 and run the code again by
pressing F5 or clicking Now LED0 should continuously toggle two times per second8 End the debugging session by clicking Debug rarr Stop Debugging pressing Ctrl+Shift+F5 or by
clicking
Result An application that toggles LED0 on the RTC overflow interrupt has beensuccessfully programmed on the ATtiny817 Xplained Pro evaluation kit
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 19
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
3 Assignment 2 RTC Interrupt Triggers String Sent to USART TerminalIn this assignment it will be demonstrated how to configure the USART module and use it to send astring as well as how to display the string Hello World in the terminal embedded in the Atmel StudioData Visualizer An application will be developed so that the RTC overflow interrupt when set will triggerreading of the string from the USART and output it in the terminal
First Atmel | START will be used from within Studio to reconfigure the project from Assignment 1 InSTART the USART component will be added to the project and then configured The basic USARTdrivers will be automatically generated from START for the project in Studio An extended USARTfunction code is required to be added manually in Studio
Peripherals used
bull USARTbull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz main clockbull 1 kHz RTC clock (from previous assignment)
31 USART Configuration in Atmel | START
To do Add the USART driver and configure the module in Atmel | START by reconfiguring theproject from within Atmel Studio
Info The ATtiny817 Xplained Pro is equipped with the Atmel Embedded Debugger (EDBG)which identifies itself as a composite USB device with a Virtual COM Port interface whenconnected to a computer The Virtual COM Port is connected to the UART on the ATtiny817 viathe EDBG and provides an easy way to communicate with the target application throughterminal software It offers variable baud rate parity and stop bit settings Note that the settingson the ATtiny817 must match the settings given in the terminal software
Tip The USART TX line on the device on ATtiny817 Xplained Pro connected to the EDBGVirtual COM Port is available on pin PB2
1 Open the ATtiny817_getting_started_events project from assignment 12 Right-click on ATtiny817_getting_started_events in the Solution Explorer window the sub window
pops up In the sub-window select Re-Configure Atmel START Project as shown in the figurebelow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 20
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 3-1 Re-Configure Atmel | START Project
Info Atmel | START will be opened in the default web browser in Studio
To do Add in the USART component
3 Open the ADD SOFTWARE COMPONENTS window by clicking 4 Expand the Drivers category and scroll down to locate the USART driver Click it to select it and
then click Add Component(s) as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 21
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 3-2 Add Software Components
Result The USART driver will now be added to the project
To do Configure the USART baud rate to 9600 and enable the transmitter
5 Click the newly added USART_0 box to open the driver configuration viewFigure 3-3 USART Configuration
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 22
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
6 Perform the configuration steps in red markings as illustrated in the figure abovendash Click the TXD dropdown menu under SIGNALSndash Select PB2 as TXD pinndash Tick the TXEN checkbox to let the USART transmitter to be enabled in the USART
initialization routine which will be generated by STARTndash Observe that the default baud rate is 9600 and leave it as is
Result The USART driver configuration is completed
7 Click the GENERATE PROJECT button at the bottom of the window to regenerate the project inAtmel StudioFigure 3-4 Project Code Regenerated
Result The Project Summary window will appear as shown in the figure above
Info The Project Summary gives an overview of the differences between the originaland the reconfigured Studio project Clicking View Diff as shown in figure above willopen the external WinMerge tool which shows the changes to that file This externalWinMerge tool is not installed within Studio by default Here is the info on how to install it
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 23
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ndash Download the tool from httpdownloadssourceforgenetwinmergeWinMerge-2140-Setupexe
ndash Install the tool at the default path (ie CProgram Files (x86)WinMerge) or a user-definedpath
ndash In Atmel Studio go to the Tools Options rarr Atmel Start rarr File Compare menu In ldquoPath of theapplication used for comparing filesrdquo enter CProgram Files (x86)WinMergeWinMergeUexe In ldquoCommand line arguments to be used for file comparisonrdquo enteroriginal mine s u
ndash Click OK and the View Diff as shown in Figure 3-4 should work now8 Since we do not want to overwrite the driverisrc file there is no need to inspect this file Leave the
checkbox unticked and click OK as illustrated in the figure above to regenerate the project for AtmelStudio
Result The project will be regenerated in Studio including reconfiguration updatesperformed in Atmel | START
32 Expand the USART Functionality
To do In Atmel Studio add code to the USART peripheral to send the string Hello Worldand output it to terminal
1 In Studio Solution Explorer window locate the usartc file under the src directory as shown in Figure 3-5 and double-click to open it
2 Expand the function list by clicking the arrow as shown in the red marking number 2 All USARTdriver functions are listed which are automatically generated by Atmel | START Inspect thefunctions and pay attention to the functionality of USART_0_putc(const uint8_t data) andUSART_0_tx_empty() which have been used in this project Selecting a function will jump to thedeclaration of that functionFigure 3-5 USART Driver Function List
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 24
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
3 In the mainc file manually implement the function which will write a string to the USART TX bufferndash Declare a char array hello that holds Hello Worldn and a HELLO_LEN definition that
defines the string lengthconst char hello[]=Hello Worldndefine HELLO_LEN 13
ndash Implement a usart_put_string() function based on the USART_0_putc() andUSART_0_tx_empty() functions which are included in the usartc fileUSART Functionsvoid usart_put_string(const char str[] const uint8_t STR_LEN) for (int i=0 iltSTR_LEN i++) while(USART_0_tx_empty()) USART_0_putc(str[i])
ndash Add a call to usart_put_string() in the main() function before the while(1) loopusart_put_string(hello HELLO_LEN)
ndash The complete code for mainc looks as Figure 3-6 (the code in red markings are supposed tobe added in)Figure 3-6 Add USART Function in mainc
4 Build the solution by pressing F7 or clicking Build rarr Build Solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 25
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Info The solution should build without errors
Result An application that transmits the string Hello World to USART have beenimplemented
33 USART Output to Data Visualizer Terminal
To do Set up the Data Visualizer terminal in Studio to display the string transmitted from theevaluation kit via the EDBG Virtual COM Port
1 In Studio 7 click Tools rarr Data Visualizer to open the Data Visualizer2 In the Data Visualizer window click Configuration located all the way to the left expand the
External Connection group and double-click Serial Port as illustrated by the steps in the figurebelow
3 Expand the drop-down list of COM ports in the Serial Port Control Panel and select the COM portassociated with the Virtual COM Port of the EDGB on the evaluation kit as shown in the figurebelow
Tip The EDBG Virtual COM Port number associated with the ATtiny Xplained Pro kitcan be found in Windows Device Manager by clicking Start rarr Control Panel rarr DeviceManager rarr Ports
4 Leave the serial port settings at default values and click Connect as shown in the figure below toopen the terminalFigure 3-7 Select USART Serial Port
5 Program the device and run the program by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
6 Inspect the terminal in the Data Visualizer tab and verify that Hello World is printed as shown inthe figure below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 26
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 3-8 String Printed to Terminal
Result Transmission of Hello World using USART has been verified with the Data Visualizerterminal
34 RTC Interrupt Triggers USART Transmission
To do Update the application to enable the RTC overflow interrupt to trigger the USARTtransmission of Hello World to the Data Visualizer Terminal
To do Add in the new mainh file
1 Right-click on the project ATtiny817_getting_start_events in Solution Explorer and click Add rarr NewItem as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 27
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 3-9 Add New Item
2 In the pop-up window choose Include File rename the file to mainh and click Add as shownbelow
Result An empty file named mainh will be added to the project and listed just below themainc file in Solution Explorer
Figure 3-10 Add mainh File
3 Locate the mainh file in Solution Explorer and open it
To do Update the newly created mainh file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 28
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
4 Add the line extern volatile uint8_t sendflag in mainh as shown belowFigure 3-11 Updating mainh File
Info The variable sendflag will be used by the application in driver_isrc to initiateUSART transmissions
5 Open the driver_isrc file from Solution Explorer
To do Update the driver_isrc file
6 Make the sendflag variable available in the driver_isrc by including it as shown below7 Raise the flag by writing 1 to the sendflag variable in the RTC ISR as shown below This can
serve as a notification to the CPU that the RTC overflow interrupt has been executedFigure 3-12 Updating driver_isrc File
To do Update the mainc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 29
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
8 In mainc include the mainh file and declare the sendflag variable asinclude mainhvolatile uint8_t sendflag = 0
9 In mainc add the following code in the while(1) loop of the main() functionif (sendflag) usart_put_string(hello HELLO_LEN) sendflag = 0
This piece of code will check if sendflag is set and then call usart_put_string() to print theHello World string to the USART terminal The sendflag is set each time the RTC overflowinterrupt routine defined in driver_isrc is executed After the USART transmission sendflag is resetand ready for a new check
The complete modifications in the mainc file are highlighted in the red markings as shown below
Figure 3-13 Updating mainc File
10 Press F7 to build the solution
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 30
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Info The solution should build without errors
11 Program the kit and start the application by pressing Ctrl+Alt+F5 or by clicking Debug rarr StartWithout Debugging
Info The application should start executing on the kit
12 Open the Data Visualizer terminal and verify that Hello World is printed approximately two timesper second as shown belowFigure 3-14 RTC Interrupt Continuously Triggers String Print to Terminal
Result The RTC overflow interrupt continuously triggers USART transmission of the HelloWorld string to the Data Visualizer terminal two times per second
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 31
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output toUSART TerminalThe ATtiny817 has an ADC module which will be configured The application code will also be updatedA potentiometer will be connected to the ADC input pin to observe the added ADC functionality ADC datawill be sent to USART and observed in the Data Visualizer terminal window
This is based on the project Assignment 2 RTC Triggers Print to USART Terminal Here anapplication will be developed demonstrating the ADC functionality with ADC data output to the USARTterminal First use Atmel | START to add in the ADC drivers and then get the module configured Now twoADC functions must manually be added to Atmel Studio The RTC overflow interrupt will trigger the startof an ADC conversion and the ADC data ready interrupt will trigger sending the ADC data to the USARTterminal
Peripherals used
bull ADCbull USART (from previous assignment)bull RTC (from previous assignment)bull GPIO (PB4 from previous assignment)
Clock details
bull 3333 MHz ADC clockbull 3333 MHz main clock (from previous assignment)bull 1 kHz RTC clock (from previous assignment)
41 Add ADC Driver In Atmel | START
To do Add ADC driver to the project using Atmel | START
1 Open the ATtiny817_getting_started_events project from Assignment 22 Select the project name right-click in the Solution Explorer window and select Re-Configure Atmel
START Project
Info Atmel | START will be opened in the default web browser
3 Click in the Atmel | START window and expand Drivers from the ADDSOFTWARE COMPONENT window
4 Add the ADC to the project by selecting ADC and clicking
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 32
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Result ADC driver is added to ATtiny817_getting_started_events
42 Configure ADC in Atmel | STARTOnce the ADC module has been added to ATtiny817_getting_started_events the ADC driver will beconfigured here
To do Configure the ADC Module
1 Click ADC_0 in the Atmel | START window2 Perform the configuration steps marked with red as depicted in Figure 4-1
ndash Enable the ADC by checking the ENABLE ADC Enable checkboxndash Enable PA6 as an analog input for the ADC by checking the PA6 checkbox Then select ADC
input pin 6 from the MUXPOSAnalog Channel Selection Bits dropdown menu to actuallyselect the enabled PA6 as ADC input pin
ndash Configure the ADC resolution to be 8-bit by selecting 8-bit mode from the RESSELADCResolution dropdown menu
ndash Configure the voltage reference REFSEL to be VDD from the dropdown menundash Enable the Result Ready interrupt by checking the RESRDYResult Ready Interrupt Enable
checkbox
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 33
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 4-1 ADC Configuration in Atmel | START
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 34
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Note Clicking the question mark next to each configuration will provide the data sheet descriptionof the individual bit setting
3 Generate the project by clicking The following project summary windowpops upFigure 4-2 Summary of Project Code Generated by Atmel | START
4 Click View Diff on the driver_isrc file as in red marking in the Figure 4-2 A window pops upshowing the code difference between Assignment 2 version and the Atmel | START regeneratedversion asFigure 4-3 driver_isrc View Difference After Atmel START Modification
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 35
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
As shown the ISR(ADC0_RESRDY_vect) function has been added in while the two linesLED0_toggle_level() and sendflag = 1 are missing in the Atmel | START generated version ofcode The regenerated version needs to be updated including the code that existed in theAssignment 2 versionBy clicking on View Diff on other three files one can see that these files can simply be overwrittenwithout modification required
5 Now choose to regenerate the project in Atmel | START by selecting the three files as circled in redmarking in Figure 4-2 These three selected files do not require modification and will be overwrittenby the Atmel | START generated version of codes when clicking the OK button at the bottom in Figure 4-3 The mainc and driver_isrc files needs to be updated manually as driver_isrc is shownin Figure 4-3
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly added ADC drivers
43 Add ADC Functionality to Application CodeOnce the ADC module has been added and reconfigured using Atmel | START the application codeneeds to be updated using Atmel Studio
To do Update the code in ATtiny817_getting_started_events to make use of the ADC driverjust added through Atmel | START Specifically update the mainc mainh and driver_isrc files
1 Update the code in mainc by performing the steps below The complete code after updating isshown in Figure 4-4
ndash Add a variable declaration for the ADC result adc_resultvolatile uint8_t adc_result = 0
ndash Add the function for starting an ADC conversion ADC_start_conversion() and thefunction for reading out the ADC result ADC_get_result()ADC Functionsvoid ADC_start_conversion() ADC0COMMAND = ADC_STCONV_bm Set start conversion enable mask bitvoid ADC_get_result() adc_result = ADC0RESL
ndash In the while-loop of the main function comment out the code which sent the hello stringfrom assignment 2 and add code for sending adc_result via the USART insteadusart_put_string(hello HELLO_LEN)USART_0_putc(adc_result)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 36
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 4-4 Updates to mainc in Atmel Studio
2 Add a global declaration of the adc_result variable two functions ADC_start_conversion()and ADC_get_result() in mainh as shown in Figure 4-5Figure 4-5 Updates to mainh in Atmel Studio
3 Update the code in driver_isrc by following the steps shown in Figure 4-6ndash Add in include mainh in the headerndash Make the application code trigger an ADC conversion each time the RTC overflows by adding
ADC_start_conversion() to the RTC interrupt handler ISR(RTC_CNT_vect)ADC_start_conversion()
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 37
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ndash Make the application code trigger a read-out of the ADC result for each ADC conversion byadding ADC_get_result() to the ADC interrupt handler ISR(ADC0_RESRDY_vect)ADC_get_result()
ndash Ensure that the new ADC result is sent to the terminal window using the USART by movingsendflag from the RTC interrupt handler to the ADC interrupt handlersendflag = 1
Figure 4-6 Updates to driver_isrc in Atmel Studio
4 Build the project by clicking or F7 Make sure there are no compiler errors or warnings
Result The ADC functionality code is done
44 Connect Potentiometer to ADCA potentiometer also called a potmeter is a three-terminal resistor with a sliding or rotating contact thatprovides an adjustable voltage divider As shown in the upper left corner of the figure below the potmeterhas three pins marked in red as 1 2 and 3 respectively
To do Connect a potentiometer to ATtiny817 Xplained Pro by using a breadboard and threemale-to-female cables
1 Place the potmeter in the breadboard and notice how the pins corresponds with the lettersnumberson the breadboard
2 Connect the pins of the potmeter to ATtiny817 Xplained Pro by using male-to-female cablesndash Pin 1 to VCCndash Pin 2 to PA6
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 38
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ndash Pin 3 to GND
Figure 4-7 Potentiometer Connected to ATtiny817 Xplained Pro
45 Observe ADC FunctionalityNow the ADC driver has been added to the project the application code has been updated to make useof the ADC and the potentiometer has been connected to the ADC input pin It is time to observe theADC functionality using the Data Visualizer in Atmel Studio
Observe ADC functionality using Data Visualizer
1 Program the code by selecting Debug rarr Start Without Debugging or clicking on the top ofmenu bar
2 Open the Data Visualizer by clicking the Data Visualizer tab The output to the USART terminalshould look as shown in Figure 4-8Figure 4-8 Output from USART Terminal Window
Note The output in the USART terminal window is currently in ASCII format which does not givethe best readability when it comes to observing how turning the potmeter knob affects the output
3 Select the output format to be in hexadecimal values by checking the Hexadecimal Values check-box as depicted in red marking in Figure 4-9
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 39
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 4-9 Output in Hex Format from USART Terminal Window
Result By rotating the potentiometer knob the voltage input to ADC input pin PA6 ischanging This can be observed as the ADC result being sent to USART terminal window ischanging as one rotates the knob
Note When rotating the potentiometer knob the ADC result printed in the USART terminal window is inthe range of 0x00-0xFF This is expected as the ADC resolution has been configured to be 8 bits
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 40
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to DataVisualizerIn this assignment an application will be developed that will configure ADC Window Comparison (WCMP)interrupt triggering ADC data print to USART terminal and graph in Data Visualizer
The ADC window comparison is a feature which allows the user to further filter the ADC output in theirpredefined way It is enabled when the window comparator interrupt enable (INTCTRLWCOMP) bit isset There are four window mode options output ADC results only when they are below window abovewindow within window or outside window The mode is configured by writing the CTRLEWINCM fieldWINLT andor WINHT registers also need to be configured to set the window comparator to low andorhigh threshold The ADC interrupt will then be triggered when the ADC output is available and it alsosatisfies the configured mode
First Atmel | START will be used within Atmel Studio to reconfigure the project from Assignment 3 InAtmel | START the ADC driver will be updated using the WCMP interrupt option instead of a result ready(RESRDY) interrupt
51 ADC Re-Configuration in Atmel START1 Open the ATtiny817_getting_started_events project from Assignment 32 Right-click on the project name ATtiny817_getting_started_events in Solution Explorer and then
right-click Re-Configure Atmel Start Project3 In the Atmel | START window click the ADC component4 Scroll down and reconfigure ADC as shown in Figure 5-1 Reconfiguration is shown with red
markingsFigure 5-1 ADC Reconfiguration in START
5 Take a look at the configuration steps described belowndash Unselect the checkbox for the RESRDY Result Ready Interrupt Enable fieldndash Select the checkbox for the WCMP Window Comparator Interrupt Enable field as it now
replaces the just unselected RESRDY interruptndash Select Outside Window from the WINCM Window Comparator Mode dropdown menundash Enter 200 (0xc8 hexadecimal value) in the WINHT Window Comparator High Threshold field
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 41
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ndash Enter 100 (0x64 hexadecimal value) in the WINLT Window Comparator Low Threshold field6 Click the GENERATE PROJECT button at the bottom of the window in order to regenerate the
project in Atmel Studio The project summary window pops up as shown in Figure 5-2Figure 5-2 Project Code Regenerated
7 For the driver_isrc file click on View Diff in red marking to see the difference before and after theAtmel | START regeneration as shown belowFigure 5-3 Driver_isrc View Diff
8 mainc and driver_isrc are not checked as in Figure 5-2 and need to be manually modifiedafterward
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 42
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Click OK to regenerate the project
Result The Atmel | START project has been regenerated in Atmel Studio including thenewly updated ADC drivers
52 Update Application in Atmel Studio and Output ADC Data to Data VisualizerGraph
To do Update the code in the driver_isrc file
1 In Atmel Studio open the driver_isrc file and replace the ISR(ADC0_RESRDY_vect) function withthe ISR(ADC0_WCOMP_vect) function as shown below in red markingFigure 5-4 Driver_isrc Updates
2 Click the Data Visualizer tab and expand the Configuration tab on the left side of the window ClickVisualization and double-click Graph as shown below
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 43
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 5-5 Data Visualizer Graph Selection
3 As shown in Figure 5-6 (red marking number 1) drag the terminal input from Serial Port ControlPanel to the New plot in the Graph window to connect the terminal input to the graph Then selectinput as Points (red marking number 2)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 44
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 5-6 Data Visualizer Graph Data Output
4 Program the code by selecting Debug rarr Start Without Debugging5 Rotate the potmeter and observe the plotted ADC data in the Graph6 Observe that the plotted points for the ADC value matches the ADC value printed in the Terminal
(red marking number 3 in Figure 5-6) When the ADC value is within the 100-200 range points arenot plotted in the Graph Observe that the plotted values in the graph in the Figure 5-6 matches theADC values printed in the terminal outlined by red marking number 3
Result The Data Visualizer Graph shows the plotted ADC data
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 45
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
6 Assignment 5 RTC Interrupt Replaced by Event SystemIn this assignment the RTC overflow event signal instead of the RTC overflow interrupt will be used totrigger an ADC conversion
The Event System (EVSYS) enables direct peripheral-to-peripheral signaling It allows a change in oneperipheral (the Event Generator) to trigger actions in the other peripherals (the Event Users) throughEvent channels without using the CPU A channel path can either be asynchronous or synchronous to themain clock
Here the RTC overflow event signal will be used to trigger an ADC conversion
61 Event System Configuration in Atmel START
To do Configure Event system in Atmel | START
1 Open project ATtiny817_getting_started_events assignment 42 Right-click on ATtiny817_getting_started_events in the Solution Explore window and select Re-
Configure Atmel Start Project3 In the Atmel | START window click the ADD SOFTWARE COMPONENT box and then expand
Drivers from the ADD SOFTWARE COMPONENT window4 Search for the Events driver select it and then click the Add Component(s) (Refer to Figure 2-4 for
adding component of RTC as an example)Note The Events driver will be added to the project Now the EVENT_SYSTEM peripheralconfiguration needs to be done
5 Configure Asynchronous Event Channel 0 as shown below (see the red markings numbered 1 to3)
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 46
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 6-1 Event Source Selection
Execute the configuration steps described below
ndash Select the EVENTS icon on the left side of the window (red marking number 1)ndash Select Asynchronous Event Channel 0 (red marking number 2) and the EVENT SYSYEM
SETTINGS window pops upndash In the popped up EVENT SYSTEM SETTINGS window scroll down and select the Real Time
Counter overflow option and close the window6 Now configure the Event user as shown in Figure 6-2 below (see the red markings numbered 1 to
3)ndash Click the settings dialog under USERS rarr ADC0 (red marking number 1)ndash In the popped up EVENT SYSTEM SETTINGS window select the checkbox of Start Event
Input Enable (red marking number 2)ndash Select Asynchronous Event Channel 0 (red marking number 3) as ASYNCUSER1 and close
the window
Figure 6-2 Event Channel Selection
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 47
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Info The Event system configuration is now completed with the event generator eventchannel and event user defined as shown below
Figure 6-3 Event User Selection
7 RTC will be reconfigured in Atmel | STARTClick DASHBOARD on the left side of the window and click on the existing RTC_0 module toreopen the RTC configuration window Unselect the checkbox for OVF Overflow Interrupt enable inthe red marking as shown below
Figure 6-4 RTC Reconfiguration
8 Click the GENERATE PROJECT button The project summary window pops up as shown in thefigure blow
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 48
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
Figure 6-5 Project Summary After Regenerated
9 Click View Diff for the srcadc_windowc file (see the red marking) to inspect the difference asshown belowFigure 6-6 driver_isrc View Diff
10 Tick the checkbox in order to overwrite the srcadc_windowc file11 Click OK to regenerate the project with overwriting adc_window
62 Event System Driver Code Development
To do Add code in driver_isrc to send ADC data to the terminal when the result is outside ofthe configured window range
1 Update the driver_isrc file
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 49
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ndash Add include ldquomainhrdquo as the difference is shown in Figure 6-6ndash Add in the two lines of ADC_get_result() and sendflag=1 in the
ISR(ADC0_WCOMP_vect) function as shown in the comparison figure abovendash The ISR(RTC_CNT_vect)() function should now have been removed as it has been
replaced by event system2 The complete code of the driver_isrc looks like
include ltdriver_inithgtinclude ltcompilerhgtinclude mainh
ISR(ADC0_WCOMP_vect) Insert your ADC window comparator interrupt handling code here ADC_get_result() sendflag = 1 The interrupt flag has to be cleared manually ADC0INTFLAGS = ADC_WCMP_bm
3 Press F7 to build the solution
Info The solution should build without errors
4 Run the project by clicking Starting Without Debugging or use the hot-key CTRL+ALT+F5
Info The application should start executing on the kit
5 Click the Data Visualizer tab Now the potentiometer can be adjusted The ADC data printed in theterminal and the plotted ADC data shown in the graph should have the same behavior as shown in Figure 5-6
Result The Event system functions as expected and has successfully replaced the RTCoverflow interrupt
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 50
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
7 ConclusionThis training demonstrated configuring RTC triggering ADC conversation using interrupt or event systemWith the feature of Atmel Studio 7 Data Visualizer it is easy to check the data output on the USARTterminal or even in the graph view
With Atmel | START it is easy to configurereconfigure a project by addingremoving peripheral driversand use automatically generated driver functions in the code
With Atmel Studio it is easy to run real-time debugging of an application and use IO view whichprovides register view capability and allows modifying the microcontroller registers in real-time It ispossible to debug the application using various debugging methods such as
bull Breakpointsbull IO view
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 51
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
8 Revision HistoryDoc Rev Date Comments
A 082017 Initial document release
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 52
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
The Microchip Web Site
Microchip provides online support via our web site at httpwwwmicrochipcom 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
bull Product Support ndash Data sheets and errata application notes and sample programs designresources userrsquos guides and hardware support documents latest software releases and archivedsoftware
bull General Technical Support ndash Frequently Asked Questions (FAQ) technical support requestsonline discussion groups Microchip consultant program member listing
bull Business of Microchip ndash Product selector and ordering guides latest Microchip press releaseslisting of seminars and events listings of Microchip sales offices distributors and factoryrepresentatives
Customer Change Notification Service
Microchiprsquos customer notification service helps keep customers current on Microchip productsSubscribers 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 httpwwwmicrochipcom Under ldquoSupportrdquo click onldquoCustomer Change Notificationrdquo and follow the registration instructions
Customer Support
Users of Microchip products can receive assistance through several channels
bull Distributor or Representativebull Local Sales Officebull Field Application Engineer (FAE)bull Technical Support
Customers should contact their distributor representative or Field Application Engineer (FAE) for supportLocal 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 httpwwwmicrochipcomsupport
Microchip Devices Code Protection Feature
Note the following details of the code protection feature on Microchip devices
bull Microchip products meet the specification contained in their particular Microchip Data Sheetbull 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 conditionsbull 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 Microchiprsquos Data Sheets Most likely the person doing so isengaged in theft of intellectual property
bull Microchip is willing to work with the customer who is concerned about the integrity of their code
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 53
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
bull 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 ldquounbreakablerdquo
Code protection is constantly evolving We at Microchip are committed to continuously improving thecode protection features of our products Attempts to break Microchiprsquos 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 NoticeInformation 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 PURPOSEMicrochip disclaims all liability arising from this information and its use Use of Microchip devices in lifesupport andor safety applications is entirely at the buyerrsquos risk and the buyer agrees to defendindemnify 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
TrademarksThe Microchip name and logo the Microchip logo AnyRate AVR AVR logo AVR Freaks BeaconThingsBitCloud CryptoMemory CryptoRF dsPIC FlashFlex flexPWR Heldo JukeBlox KeeLoq KeeLoq logoKleer LANCheck LINK MD maXStylus maXTouch MediaLB megaAVR MOST MOST logo MPLABOptoLyzer PIC picoPower PICSTART PIC32 logo Prochip Designer QTouch RightTouch SAM-BASpyNIC SST SST Logo SuperFlash tinyAVR UNIO and XMEGA are registered trademarks ofMicrochip Technology Incorporated in the USA 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 USA
Adjacent Key Suppression AKS Analog-for-the-Digital Age Any Capacitor AnyIn AnyOut BodyComchipKIT chipKIT logo CodeGuard CryptoAuthentication CryptoCompanion CryptoControllerdsPICDEM dsPICDEMnet Dynamic Average Matching DAM ECAN EtherGREEN In-Circuit SerialProgramming ICSP Inter-Chip Connectivity JitterBlocker KleerNet KleerNet logo Mindi MiWimotorBench MPASM MPF MPLAB Certified logo MPLIB MPLINK MultiTRAK NetDetach OmniscientCode Generation PICDEM PICDEMnet PICkit PICtail PureSilicon QMatrix RightTouch logo REALICE Ripple Blocker SAM-ICE Serial Quad IO SMART-IS SQI SuperSwitcher SuperSwitcher II TotalEndurance TSHARC USBCheck VariSense ViewSpan WiperLock Wireless DNA and ZENA aretrademarks of Microchip Technology Incorporated in the USA and other countries
SQTP is a service mark of Microchip Technology Incorporated in the USA
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 amp Co KG a subsidiary ofMicrochip Technology Inc in other countries
All other trademarks mentioned herein are property of their respective companiescopy 2017 Microchip Technology Incorporated Printed in the USA All Rights Reserved
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 54
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
ISBN 978-1-5224-2066-8
Quality Management System Certified by DNV
ISOTS 16949Microchip received ISOTS-169492009 certification for its worldwide headquarters design and waferfabrication facilities in Chandler and Tempe Arizona Gresham Oregon and design centers in Californiaand India The Companyrsquos quality system processes and procedures are for its PICreg MCUs and dsPICreg
DSCs KEELOQreg code hopping devices Serial EEPROMs microperipherals nonvolatile memory andanalog products In addition Microchiprsquos quality system for the design and manufacture of developmentsystems is ISO 90012000 certified
Getting Started with Events on the tinyAVR 1-series
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 55
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-
AMERICAS ASIAPACIFIC ASIAPACIFIC EUROPECorporate Office2355 West Chandler BlvdChandler AZ 85224-6199Tel 480-792-7200Fax 480-792-7277Technical SupporthttpwwwmicrochipcomsupportWeb AddresswwwmicrochipcomAtlantaDuluth 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
Asia Pacific OfficeSuites 3707-14 37th FloorTower 6 The GatewayHarbour City KowloonHong KongTel 852-2943-5100Fax 852-2401-3431Australia - SydneyTel 61-2-9868-6733Fax 61-2-9868-6755China - BeijingTel 86-10-8569-7000Fax 86-10-8528-2104China - ChengduTel 86-28-8665-5511Fax 86-28-8665-7889China - ChongqingTel 86-23-8980-9588Fax 86-23-8980-9500China - DongguanTel 86-769-8702-9880China - GuangzhouTel 86-20-8755-8029China - HangzhouTel 86-571-8792-8115Fax 86-571-8792-8116China - Hong Kong SARTel 852-2943-5100Fax 852-2401-3431China - NanjingTel 86-25-8473-2460Fax 86-25-8473-2470China - QingdaoTel 86-532-8502-7355Fax 86-532-8502-7205China - ShanghaiTel 86-21-3326-8000Fax 86-21-3326-8021China - ShenyangTel 86-24-2334-2829Fax 86-24-2334-2393China - ShenzhenTel 86-755-8864-2200Fax 86-755-8203-1760China - WuhanTel 86-27-5980-5300Fax 86-27-5980-5118China - XianTel 86-29-8833-7252Fax 86-29-8833-7256
China - XiamenTel 86-592-2388138Fax 86-592-2388130China - ZhuhaiTel 86-756-3210040Fax 86-756-3210049India - BangaloreTel 91-80-3090-4444Fax 91-80-3090-4123India - New DelhiTel 91-11-4160-8631Fax 91-11-4160-8632India - PuneTel 91-20-3019-1500Japan - OsakaTel 81-6-6152-7160Fax 81-6-6152-9310Japan - TokyoTel 81-3-6880- 3770Fax 81-3-6880-3771Korea - DaeguTel 82-53-744-4301Fax 82-53-744-4302Korea - SeoulTel 82-2-554-7200Fax 82-2-558-5932 or82-2-558-5934Malaysia - Kuala LumpurTel 60-3-6201-9857Fax 60-3-6201-9859Malaysia - PenangTel 60-4-227-8870Fax 60-4-227-4068Philippines - ManilaTel 63-2-634-9065Fax 63-2-634-9069SingaporeTel 65-6334-8870Fax 65-6334-8850Taiwan - Hsin ChuTel 886-3-5778-366Fax 886-3-5770-955Taiwan - KaohsiungTel 886-7-213-7830Taiwan - TaipeiTel 886-2-2508-8600Fax 886-2-2508-0102Thailand - BangkokTel 66-2-694-1351Fax 66-2-694-1350
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-79France - Saint CloudTel 33-1-30-60-70-00Germany - 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 - RarsquoananaTel 972-9-744-7705Italy - MilanTel 39-0331-742611Fax 39-0331-466781Italy - PadovaTel 39-049-7625286Netherlands - DrunenTel 31-416-690399Fax 31-416-690340Norway - TrondheimTel 47-7289-7561Poland - 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
copy 2017 Microchip Technology Inc Training Manuals DS00002533A-page 56
- Prerequisites
- Introduction
- Table of Contents
- 1 Icon Key Identifiers
- 2 Assignment 1 RTC Overflow Interrupt Triggers LED Toggling
-
- 21 Atmel | START Project Creation
- 22 Atmel | START Project Overview In Atmel Studio
- 23 Code Development
- 24 Debug the Application
-
- 3 Assignment 2 RTC Interrupt Triggers String Sent to USART Terminal
-
- 31 USART Configuration in Atmel | START
- 32 Expand the USART Functionality
- 33 USART Output to Data Visualizer Terminal
- 34 RTC Interrupt Triggers USART Transmission
-
- 4 Assignment 3 ADC ISRRDY Interrupt Triggers ADC Data Output to USART Terminal
-
- 41 Add ADC Driver In Atmel | START
- 42 Configure ADC in Atmel | START
- 43 Add ADC Functionality to Application Code
- 44 Connect Potentiometer to ADC
- 45 Observe ADC Functionality
-
- 5 Assignment 4 ADC WCMP Interrupt Triggers ADC Data Print to Data Visualizer
-
- 51 ADC Re-Configuration in Atmel START
- 52 Update Application in Atmel Studio and Output ADC Data to Data Visualizer Graph
-
- 6 Assignment 5 RTC Interrupt Replaced by Event System
-
- 61 Event System Configuration in Atmel START
- 62 Event System Driver Code Development
-
- 7 Conclusion
- 8 Revision History
- The Microchip Web Site
- Customer Change Notification Service
- Customer Support
- Microchip Devices Code Protection Feature
- Legal Notice
- Trademarks
- Quality Management System Certified by DNV
- Worldwide Sales and Service
-