ATMEL AVR1501 User Manual

http://www.BDTIC.com/ATMEL
AVR1501: Xplain training – XMEGA
Timer/Counter

Prerequisites

Required knowledge
Completed AVR1500: XMEGA
Software prerequisites
Atmel® AVR® Studio® 4.18 SP2 or later WinAVR/GCC 20100110 or later
Hardware prerequisites
- Xplain evaluation board
- JTAGICE mkII
Estimated completion time:
- 2 hours

1 Introduction

Atmel XMEGA has a set of high-end and very flexible 16-bit Timer/Counters (TC). Their basic capabilities include accurate program execution timing, frequency and waveform generation, event management, and time measurement of digital signals.
Basics training
8-bit Microcontrollers
Application Note
In this hand-on we will learn more about the XMEGA timers, PWM generation, High resolution Extension and Advanced Waveform extension.
Rev. 8309A-AVR-06/10

2 Overview

http://www.BDTIC.com/ATMEL
Atmel XMEGA has a set of high-end and very flexible 16-bit Timer/Counters (TC). Their basic capabilities include accurate program execution timing, frequency and waveform generation, event management, and time measurement of digital signals.
The Timer/Counter consists of a Counter (COUNT) and a set of Compare and Capture (CC) channels. It has direction (DIR) control and period (PER) settings that can be used for timing.
The Hi-Resolution Extension (Hi-Res) and Advanced Waveform Extension (AWeX) can be used together with a Timer/Counter to ease implementation of more advanced and specialized frequency and waveform generation features.
Here is a short overview of the tasks in this training:
Task 1: Starting the Timer/Counter
In the first task you will be guided through initial setup to start the Timer/Counter, including the prescaler and period settings.
Task 2: Compare Match
In this task you will learn how to use the Capture/Compare (CCx) registers for compare checking.
Task 3: Waveform Generation
The CC channels and compare match can be used for waveform generation output on the I/O pins, and in this task you will learn how to configure this.
Task 4: AWeX and Pattern Generation
The Timer/Counter extensions can be used to enable more specialized features. In this task we will look at the Common Waveform and Pattern Generation modes.
Good luck!
2
AVR1501
8309A-AVR-06/10

3 Task 1: Starting the Timer/Counter

http://www.BDTIC.com/ATMEL
The Timer/Counter needs a clock source to run. The available clock sources are the (pre-scaled) Peripheral Clock and the Event System. In this task we will only use the Peripheral Clock, but setting up the TC to use the Event System is equally easy.
The goal for this task is that you know how to:
Start the Timer/Counter using the prescaler (CLKSEL bits) in the CTRLA register
Use the PER register, to set how far the counter should count
TASK:
1. Locate the Atmel XMEGA-TimerCounter folder, find the Task 1 folder and open the
StartingTheTimer.aps project file in Atmel AVR Studio
2. Look through the code and ensure that you understand how things are set up
3. Build the project; ensure that there are no errors
4. Start the debugging session
5. In the I/O-view locate the 16-bit Timer/Counter with PWM C0, and expand it, so you can see the settings change as you start debugging
AVR1501
8309A-AVR-06/10
3
http://www.BDTIC.com/ATMEL
4
6. Single step through the code until you reach the while (1) statement
7. The TCC0 is now running in Normal Mode with no pre-scaling, and you can see the TCC0 setup details by using the IO view
8. Continue to single step and you will see that the Count (CNT) value is changing and that the OVVIF in INTFLAGS is set when the Count (CNT) register reach 0x30 and wraps around. The LED will toggle
9. Run the code (F5). You will notice that both LED0 and LED1 will be on. This is because the code runs too fast for you to see the LEDs toggle
10. Break the execution (Ctrl+F5). Change the Clock Selection so that the TC runs from the Peripheral Clock divided by 64 using the I/O view in Atmel AVR Studio
AVR1501
8309A-AVR-06/10
http://www.BDTIC.com/ATMEL
AVR1501
8309A-AVR-06/10
11. Change the Period (PER) register to a higher value so you can see that the LED toggles when you run the code
12. A higher PER setting gives a longer period for the timer, hence the LED will toggle with a slower frequency
5
Loading...
+ 10 hidden pages