SlideShare a Scribd company logo
To generate a time delay is to clear the counter at the start time and wait until
the counter reaches a certain number.
Microcontroller with an oscillator with frequency of 1 MHz
There is a flag for each of the counters
 The second method to generate a time delay is to load the counter register
and wait until the counter overflows and the flag is set.
The AVR has one to six timers depending on the family member as Timers 0,
1, 2, 3, 4, and 5.
They can be used as timers to generate a time delay or as counters to count
events happening outside the microcontroller.
In the AVR some of the timers/counters are 8-bit and some are 16-bit.
In ATmega32, there are three timers: Timer0, Timer1, and Timer2.
 Timer 0 and Timer2 are 8-bit.
 Timer1 is 16-bit.
Every timer needs a clock pulse to tick. The clock source can be internal or external.
If we use the internal clock source, then the frequency of the crystal oscillator is fed
into the timer.
Therefore, it is used for time delay generation and consequently is called a timer. By
choosing the external clock option, we feed pulses through one of the AVR's pins.
This is called a counter. In this section we discuss the AVR timer, and in the next
section we program the timer as a counter.
 ATmega32 have TCNTO, TCNT1, and TCNT2.
 The TCNTn register is a counter, It counts up with each pulse
 You can load a value into the TCNTn register or read its value.
Each timer has a TOVn (Timer Overflow) flag, as well. When a timer overflows, its TOVn
flag will be set.
 Each timer also has the TCCRn (timer/counter control register) register for setting modes of
operation.
C Programming For Timers.
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
Interrupts
Events that temporarily suspend the main program, pass the control to the external sources
and execute their task.
whenever any device needs the microcontroller's service, the device notifies it by sending
an interrupt signal. Upon receiving an interrupt signal, the microcontroller stops whatever it is
doing and serves the device.
The program associated with the interrupt is called the interrupt service routine (ISR) or
interrupt handler. The advantage of interrupts is that the microcontroller can serve many
devices (not all at the same time, of course); each device can get the attention of the
microcontroller based on the priority assigned to it.
More importantly, in the interrupt method the microcontroller can also ignore (mask) a device
request for service. The So interrupts are used to avoid tying down the microcontroller.
Steps in executing an interrupt
Upon activation of an interrupt, the microcontroller goes through the following steps:
1. It finishes the instruction it is currently executing and saves the address of the next instruction (program counter)
on the stack.
2. It jumps to a fixed location in memory called the interrupt vector table. The interrupt vector table directs the
microcontroller to the address of the interrupt service routine (ISR).
3. The microcontroller starts to execute the interrupt service subroutine until it reaches the last instruction of the
subroutine, which is RETI (return from interrupt).
4. Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted. First, it gets
the program counter (PC) address from the stack by popping the top bytes of the stack into the PC. Then it starts to
execute from that address.
Notice from Step 4 the critical role of the stack. For this reason, we must be careful in manipulating the stack contents
in the ISR. Specifically, in the ISR, just as in any CALL subroutine, the number of pushes and pops must be equal.
Unit 3 timer and counter and there application .pptx
Sources of interrupts in the AVR
The following are some of the most widely used sources of interrupts in the AVR:
1. There are at least two interrupts set aside for each of the timers, one for overflow and another for compare match.
2. Three interrupts are set aside for external hardware interrupts. Pins PD2 (PORTD.2), PD3 (PORTD.3), and PB2 (PORTB.2)
are for the external hard ware interrupts INTO, INT1, and INT2, respectively.
3. Serial communication's USART has three interrupts, one for receive and two interrupts for transmit.
4. The SPI interrupts.
5. The ADC (analog-to-digital converter).
RS-232 is a straightforward, universal, and commonly implemented serial interface. Despite its limited 15 m transmission
distance, its low cost and easy wiring features make RS-232 the first choice for many applications. RS-232 establishes two-
way (full-duplex) communications.
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx

More Related Content

PPTX
AVRTIMER.pptx
PDF
Avr timers
PPTX
Interrupts programming in embedded C using 8051
DOCX
Arduino 101
PDF
Lecture7
PPTX
timer counter (1).pptx
PPTX
Mc module5 ppt_msj
PPT
UNCC-IESLecture13 - Timers and Event Counters.ppt
AVRTIMER.pptx
Avr timers
Interrupts programming in embedded C using 8051
Arduino 101
Lecture7
timer counter (1).pptx
Mc module5 ppt_msj
UNCC-IESLecture13 - Timers and Event Counters.ppt

Similar to Unit 3 timer and counter and there application .pptx (20)

PPTX
37471656 interrupts
PPT
ES-CH6.ppt
PPTX
Interrupt in 8051
PPTX
5th unit embedded system and iot design timer and controller
PDF
Microcontroller part 2
PPT
UNIT-5.ppt
PPTX
hardware interrupts in 8051 microcontroller
PPTX
Timer & Interrupt Atmega16
PPT
lecture 12 counter_microcontroller2.ppt
PPTX
Atmel and pic microcontroller
DOCX
DSP_Assign_2 (Autosaved)
PPTX
UNIT 2.pptx
PDF
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
PPTX
3.12_8086 microprocessor Interrupts.pptx
PDF
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
PDF
AVR_Course_Day7 timers counters and interrupt programming
PPT
03- introduction in Interrupts AndTimers.ppt
PPTX
Interrupt programming
37471656 interrupts
ES-CH6.ppt
Interrupt in 8051
5th unit embedded system and iot design timer and controller
Microcontroller part 2
UNIT-5.ppt
hardware interrupts in 8051 microcontroller
Timer & Interrupt Atmega16
lecture 12 counter_microcontroller2.ppt
Atmel and pic microcontroller
DSP_Assign_2 (Autosaved)
UNIT 2.pptx
Introduction to Embedded C for 8051 and Implementation of Timer and Interrupt...
3.12_8086 microprocessor Interrupts.pptx
DEVICE DRIVERS AND INTERRUPTS SERVICE MECHANISM.pdf
AVR_Course_Day7 timers counters and interrupt programming
03- introduction in Interrupts AndTimers.ppt
Interrupt programming
Ad

Recently uploaded (20)

PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Welding lecture in detail for understanding
PPTX
Internet of Things (IOT) - A guide to understanding
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
additive manufacturing of ss316l using mig welding
PDF
composite construction of structures.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
Sustainable Sites - Green Building Construction
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Structs to JSON How Go Powers REST APIs.pdf
Welding lecture in detail for understanding
Internet of Things (IOT) - A guide to understanding
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Foundation to blockchain - A guide to Blockchain Tech
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Operating System & Kernel Study Guide-1 - converted.pdf
Lesson 3_Tessellation.pptx finite Mathematics
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
additive manufacturing of ss316l using mig welding
composite construction of structures.pdf
573137875-Attendance-Management-System-original
Sustainable Sites - Green Building Construction
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Ad

Unit 3 timer and counter and there application .pptx

  • 1. To generate a time delay is to clear the counter at the start time and wait until the counter reaches a certain number. Microcontroller with an oscillator with frequency of 1 MHz There is a flag for each of the counters  The second method to generate a time delay is to load the counter register and wait until the counter overflows and the flag is set. The AVR has one to six timers depending on the family member as Timers 0, 1, 2, 3, 4, and 5. They can be used as timers to generate a time delay or as counters to count events happening outside the microcontroller. In the AVR some of the timers/counters are 8-bit and some are 16-bit. In ATmega32, there are three timers: Timer0, Timer1, and Timer2.  Timer 0 and Timer2 are 8-bit.  Timer1 is 16-bit.
  • 2. Every timer needs a clock pulse to tick. The clock source can be internal or external. If we use the internal clock source, then the frequency of the crystal oscillator is fed into the timer. Therefore, it is used for time delay generation and consequently is called a timer. By choosing the external clock option, we feed pulses through one of the AVR's pins. This is called a counter. In this section we discuss the AVR timer, and in the next section we program the timer as a counter.  ATmega32 have TCNTO, TCNT1, and TCNT2.  The TCNTn register is a counter, It counts up with each pulse  You can load a value into the TCNTn register or read its value. Each timer has a TOVn (Timer Overflow) flag, as well. When a timer overflows, its TOVn flag will be set.  Each timer also has the TCCRn (timer/counter control register) register for setting modes of operation.
  • 6. Interrupts Events that temporarily suspend the main program, pass the control to the external sources and execute their task. whenever any device needs the microcontroller's service, the device notifies it by sending an interrupt signal. Upon receiving an interrupt signal, the microcontroller stops whatever it is doing and serves the device. The program associated with the interrupt is called the interrupt service routine (ISR) or interrupt handler. The advantage of interrupts is that the microcontroller can serve many devices (not all at the same time, of course); each device can get the attention of the microcontroller based on the priority assigned to it. More importantly, in the interrupt method the microcontroller can also ignore (mask) a device request for service. The So interrupts are used to avoid tying down the microcontroller.
  • 7. Steps in executing an interrupt Upon activation of an interrupt, the microcontroller goes through the following steps: 1. It finishes the instruction it is currently executing and saves the address of the next instruction (program counter) on the stack. 2. It jumps to a fixed location in memory called the interrupt vector table. The interrupt vector table directs the microcontroller to the address of the interrupt service routine (ISR). 3. The microcontroller starts to execute the interrupt service subroutine until it reaches the last instruction of the subroutine, which is RETI (return from interrupt). 4. Upon executing the RETI instruction, the microcontroller returns to the place where it was interrupted. First, it gets the program counter (PC) address from the stack by popping the top bytes of the stack into the PC. Then it starts to execute from that address. Notice from Step 4 the critical role of the stack. For this reason, we must be careful in manipulating the stack contents in the ISR. Specifically, in the ISR, just as in any CALL subroutine, the number of pushes and pops must be equal.
  • 9. Sources of interrupts in the AVR The following are some of the most widely used sources of interrupts in the AVR: 1. There are at least two interrupts set aside for each of the timers, one for overflow and another for compare match. 2. Three interrupts are set aside for external hardware interrupts. Pins PD2 (PORTD.2), PD3 (PORTD.3), and PB2 (PORTB.2) are for the external hard ware interrupts INTO, INT1, and INT2, respectively. 3. Serial communication's USART has three interrupts, one for receive and two interrupts for transmit. 4. The SPI interrupts. 5. The ADC (analog-to-digital converter).
  • 10. RS-232 is a straightforward, universal, and commonly implemented serial interface. Despite its limited 15 m transmission distance, its low cost and easy wiring features make RS-232 the first choice for many applications. RS-232 establishes two- way (full-duplex) communications.