0% found this document useful (0 votes)
16 views8 pages

Lab 08 MIP

for notes making

Uploaded by

i222162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views8 pages

Lab 08 MIP

for notes making

Uploaded by

i222162
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Microprocessor Interfacing & Programming LAB: 08

Microprocessor Interfacing &


Programming
EL-3002
LABORATORY MANUAL
Fall 2024

LAB 08
ATmega32 Timer-1 and Counter programming and
implementation of timers / counters on ATmega32 Kit

Asma khan 22i-2162 A

STUDENT NAME ROLL NO SEC

_______________________________________________________________________

NATIONAL UNIVERSITY OF COMPUTER AND EMERGING


SCIENCES (NUCES), ISLAMABAD

Prepared by: Engr. Warda Shafiq Version: 1.01


Last Edited by: Engr. Iqra Akram Date: 23, Oct, 2019
Verified by: Shehzad Ahmed

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.

Department of Electrical Engineering FAST NU, Islamabad 3|Page

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.

External Clock is connected to T0 pin of Microcontroller.

Steps to follow for Counters Programming:

1. Initialize TO pin as an input for the external clock signal


2. Initialize Port C as output ports
3. Initialize TCNT register
4. Initialize the TCCR register to select mode
5. Copy value in TCNT to Port C
6. Check TOV flag for overflow if overflow then goto 7 else goto 5
7. Clear TOV flag
8. Goto 5

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

You might also like