Lab 08 MIP
Lab 08 MIP
LAB 08
ATmega32 Timer-1 and Counter programming and
implementation of timers / counters on ATmega32 Kit
_______________________________________________________________________
1|P a g e
Microprocessor Interfacing & Programming LAB: 08
ATmega32 Timer-1 and Counter programming and
LAB: 08
implementation of timers / counters on Atmega32 Kit
Learning Objectives:
Demonstration of:
Timer-1 Programming
Timer Programming as Counter
Software Required:
Super Pro Device Programmer
Proteus 8.5
Atmel Studio 6
Hardware Required:
AVR Atmega32 MCU
Bread board
5V DC Power Supply
Resistors
Jumper Wires
Push button
PC
LEDs
Programmer
Introduction:
Timer 1:
Timer 1 is 16 bit timer. Timer 1 is a 16-bit Timer and has many different capabilities. It has 16bit
count registers split into two 8-bit registers. These are referred to as TCNT1L and TCNT1H.
• It has two 8-bit control registers TCCR1A and TCCR1B. The TOV1 flag bit goes HIGH
when overflow occurs.
• Timer 1 also has the pre-scalar options of 1:1, 1:8, 1:64, 1:256, and 1:1024.
• There are two 16-bit OCR registers OCR1A and OCR1B. There are two separate flags for
each of the OCR registers which work independently.
• Whenever TCNT1 equals OCR1A, the OCF1A flag will be set on the next timer clock
• When TCNT1 equals OCR1B, the OCF1B flag will be set on the next clock
The two 8-bit control registers TCCR1A and TCCR1B allow Timer to be programmed in 16
different modes.
2|P a g e
Microprocessor Interfacing & Programming LAB: 08
Modes are selected by programming bits WGM10, WGM11, WGM12, WGM13 found in TCCR1A
and TCCR1B registers.
3|P a g e
Microprocessor Interfacing & Programming LAB: 08
Counters Programming:
We used the timers of the AVR to generate time delays. The AVR timer can also be used to
count, detect, and measure the time of events happening outside the AVR. External Clock is
used for this purpose.
In counter mode, registers such as TCCRn, OCRn, and TCNTn are the same as for the timer.
For timer 0 as counter you have to program CS02 to CS00 bits as 6 or 7. These bits are part
of TCCR0 (Control) register.
4|P a g e
Microprocessor Interfacing & Programming LAB: 08
Lab 8 Performance:
Task 8.1:
Write a test program for the AVR chip to form 4-way Taffic signal by using Timer 1(CTC
mode). Assume a crystal frequency of 8 MHz. Show your code working on Atmel Studio
and Proteus. Then implement on hardware using ATMEGA32.
Task 8.2:
Generate a delay of 0.5 seconds using Timer1 (normal mode). PORTA upper four bits are
being toggled continuously with a delay generated by Timer1. Assume a crystal frequency
of 8 MHz. Show your code working on Atmel Studio and Proteus simulation.
5|P a g e
Microprocessor Interfacing & Programming LAB: 08
Task 8.3:
You have to count number of people entering into the room by using Timer1 as a counter
using external event trigger mode. For sensing the person entering into the room you can use
IR sensors. The current count is displayed in real-time on output ports (e.g., PORTC and
PORTD) by showing the lower and higher bytes of the count.
6|P a g e
Microprocessor Interfacing & Programming LAB: 08
Timer 1 Registers:
7|P a g e
Microprocessor Interfacing & Programming LAB: 08
8|P a g e