SlideShare ist ein Scribd-Unternehmen logo
1 von 6
EMBEDDED SYSTEMS TUTORIAL7- TIMERs IN AVR PART-1

Hiii…..friends as we discussed in previous articles that AVR MCU provides us facility of using
some inbuilt advance features, TIMER is one of then and in this tutorial we are going to discuss
about the TIMERs in AVR. Timer is a very useful and most widely used feature of AVR MCU it
will be used in various applications and projects so one must have knowledge of TIMERs. Have
a look…..
INTRODUCTION
The TIMERs in AVR will be discussed in OVERFLOW MODE (TIMER0) and OUTPUT
COMPARE MODE (TIMER1) in this tutorial we will discuss OVERFLOW MODE (TIMER0)
only.
TIMER…??
A TIMER is nothing but a register . its size may bee 8 bit or 16 bit, which is called resolution of
the timer. A 8 bit register can store numbers 0-255 , similarly a 16 bit register can store numbers
0-65535. The value of these registers can be increased or decreased without the CPU
intervention, at a rate defined by the user. this rate can be can be equal to or less than the clock
frequency of the CPU. The frequency at which timer register increases or decreases is known as
Timer frequency.
We can use the TIMER registers to calculate the TIMER efficiently because the increment of
register value by 1 means one clock has completed. So when the timer OVERFLOWS means the
register value reaches to its maximum , we can inform CPU sending an interrupt. After reaching
maximum value register again resets to 0. In overflow condition we must have to write a
INTRUPPT SERVICE ROUTINE(ISR) to handle the event.

USING TIMER IN OVERFLOW MODE(TIMER0)
In ATMEGA 16 and 32 , there are three timers are available , of which simplest is TIMER0, with 8 bit
resolution.
THE PRESCALER
The Prescaler is a mechanism for generating clock for timer by the CPU clock. As you know that
CPU has a clock source such as a external crystal of internal oscillator. Normally these have the
frequency like 1 MHz,8 MHz, 12 MHz or 16MHz(MAX). The Prescaler is used to divide this
clock frequency and produce a clock for TIMER. The Prescaler can be used to get the following
clock for timer. No Clock (Timer Stop). No Prescaling (Clock = FCPU) FCPU/8 FCPU/64
FCPU/256 FCPU/1024

TIMER0 REGISTERS.
Here is the description of some register of TIMER0 , which we are going to useTCCR0 – TIMER COUNTER CONTROL REGISTER
This register is used configure the timer.

As you can see there are 8 Bits in this register each used for certain purpose. For this tutorial I
will only focus on the last three bits CS02 CS01 CS00 They are the CLOCK SELECT bits. They
are used to set up the Prescaler for timer.

TCNT0 – TIMER COUNTER 0
This register is the main counter in the TIMER0. The timer clock counts only this register as 1. It
means tomer clock will increase the value of this 8 bit register by 1 every timer clock pulse.
TIMSK- TIMER INTRUPPT MASK REGISTER

This register is used to activate/deactivate interrupts related with timers. This register controls
the interrupts of all the three timers. The last bit BIT0 Controls the interrupts of TIMER0.
TOIE0 : This bit when set to “1” enables the OVERFLOW interrupt.

PROGRAMMING
PRESCALER- 1024
CLOCK FREQUENCY- 16 MHz
Clock input of TIMER0 = 16MHz/1024 = 15625 Hz Frequency of Overflow = 15625 /256 =
61.0352 Hz if we increment a variable “count” every Overflow when “count reach 61” approx
one second has elapse. If count reaches 61 we will toggle PB0 which is connected to LED and
reset “count= 0”.
SETTING UP THE TIMER0
// Prescaler = FCPU/1024
TCCR0|=(1<<CS02)|(1<<CS00);
//Enable Overflow Interrupt Enable
TIMSK|=(1<<TOIE0);
//Initialize Counter
TCNT0=0;
OR
// Prescaler = FCPU/1024
TCCR0|=TCCR0|00000101;
//Enable Overflow Interrupt Enable
TIMSK|=TIMSK|00000001;
//Initialize Counter
TCNT0=0;
Now the timer is set and firing Overflow interrupts at 61.0352 Hz
The ISR
ISR(TIMER0_OVF_vect)
{
//This is the interrupt service routine for TIMER0 OVERFLOW Interrupt.
//CPU automatically call this when TIMER0 overflows.
//Increment our variable
count++;
if(count==61)
{
PORTC=~PORTC; //Invert the Value of PORTC
count=0;
}
}

COPMLETE SOURCE CODE
/* PROGRAM TO BLINK LE AT 0.5Hz CONNECTED AT PB0 */
#include <avr/io.h>
#include <avr/interrupt.h>
volatile uint8_t count;
void main()
{
// Prescaler = FCPU/1024
TCCR0|=(1<<CS02)|(1<<CS00);
//Enable Overflow Interrupt Enable
TIMSK|=(1<<TOIE0);
//Initialize Counter
TCNT0=0;
//Initialize our varriable
count=0;
//PB0 as out put
DDRB|=0x01;
//Enable Global Interrupts
sei();
//Infinite loop
while(1);
}
ISR(TIMER0_OVF_vect)
{
//This is the interrupt service routine for TIMER0 OVERFLOW Interrupt.
//CPU automatically call this when TIMER0 overflows.
//Increment our variable
count++;
if(count==61)
{
PORTB=~PORTB; //Invert the Value of PORTB
count=0;
}
}

Now just compile the source code and burn the hex file generated in the ATMEGA 16, then
implement the circuit as shown below on a breadboard or on your development board whatever
you want to use, and you will find your LED blinking at a rate of 0.5 Hz.
So we have studied the basic of TIMERs in AVR in next tutorial we will discuss about TIMER
IN OUTPUT COMPARE MODE(TIMER1)

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (7)

In patient care
In patient careIn patient care
In patient care
 
อุทยานเขาหลวง
อุทยานเขาหลวงอุทยานเขาหลวง
อุทยานเขาหลวง
 
pengawetan ikan
pengawetan ikanpengawetan ikan
pengawetan ikan
 
Arduino Full Tutorial
Arduino Full TutorialArduino Full Tutorial
Arduino Full Tutorial
 
Kerajaan buleleng
Kerajaan bulelengKerajaan buleleng
Kerajaan buleleng
 
Akulturasi hindu budha
Akulturasi hindu budhaAkulturasi hindu budha
Akulturasi hindu budha
 
E commerce
E commerceE commerce
E commerce
 

Mehr von Akshay Sharma

The next generation classroom smart, interactive and connected learning envir...
The next generation classroom smart, interactive and connected learning envir...The next generation classroom smart, interactive and connected learning envir...
The next generation classroom smart, interactive and connected learning envir...Akshay Sharma
 
Over voltage protector circuit
Over voltage protector circuitOver voltage protector circuit
Over voltage protector circuitAkshay Sharma
 
Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...
Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...
Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...Akshay Sharma
 
Ldr based line follower robot
Ldr based line follower robotLdr based line follower robot
Ldr based line follower robotAkshay Sharma
 

Mehr von Akshay Sharma (10)

The next generation classroom smart, interactive and connected learning envir...
The next generation classroom smart, interactive and connected learning envir...The next generation classroom smart, interactive and connected learning envir...
The next generation classroom smart, interactive and connected learning envir...
 
Over voltage protector circuit
Over voltage protector circuitOver voltage protector circuit
Over voltage protector circuit
 
Haptic technology
Haptic technologyHaptic technology
Haptic technology
 
Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...
Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...
Double Side Band – Suppressed Carrier (DSB-SC) Modulation Demodulation using ...
 
8085 instructions
8085 instructions8085 instructions
8085 instructions
 
Ldr based line follower robot
Ldr based line follower robotLdr based line follower robot
Ldr based line follower robot
 
Est 11
Est 11Est 11
Est 11
 
Est 8 2 nd
Est 8 2 ndEst 8 2 nd
Est 8 2 nd
 
Est 6
Est 6Est 6
Est 6
 
Est 1
Est 1Est 1
Est 1
 

Kürzlich hochgeladen

Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 

Kürzlich hochgeladen (20)

Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

Est 7

  • 1. EMBEDDED SYSTEMS TUTORIAL7- TIMERs IN AVR PART-1 Hiii…..friends as we discussed in previous articles that AVR MCU provides us facility of using some inbuilt advance features, TIMER is one of then and in this tutorial we are going to discuss about the TIMERs in AVR. Timer is a very useful and most widely used feature of AVR MCU it will be used in various applications and projects so one must have knowledge of TIMERs. Have a look….. INTRODUCTION The TIMERs in AVR will be discussed in OVERFLOW MODE (TIMER0) and OUTPUT COMPARE MODE (TIMER1) in this tutorial we will discuss OVERFLOW MODE (TIMER0) only. TIMER…?? A TIMER is nothing but a register . its size may bee 8 bit or 16 bit, which is called resolution of the timer. A 8 bit register can store numbers 0-255 , similarly a 16 bit register can store numbers 0-65535. The value of these registers can be increased or decreased without the CPU intervention, at a rate defined by the user. this rate can be can be equal to or less than the clock frequency of the CPU. The frequency at which timer register increases or decreases is known as Timer frequency. We can use the TIMER registers to calculate the TIMER efficiently because the increment of register value by 1 means one clock has completed. So when the timer OVERFLOWS means the register value reaches to its maximum , we can inform CPU sending an interrupt. After reaching maximum value register again resets to 0. In overflow condition we must have to write a INTRUPPT SERVICE ROUTINE(ISR) to handle the event. USING TIMER IN OVERFLOW MODE(TIMER0) In ATMEGA 16 and 32 , there are three timers are available , of which simplest is TIMER0, with 8 bit resolution. THE PRESCALER
  • 2. The Prescaler is a mechanism for generating clock for timer by the CPU clock. As you know that CPU has a clock source such as a external crystal of internal oscillator. Normally these have the frequency like 1 MHz,8 MHz, 12 MHz or 16MHz(MAX). The Prescaler is used to divide this clock frequency and produce a clock for TIMER. The Prescaler can be used to get the following clock for timer. No Clock (Timer Stop). No Prescaling (Clock = FCPU) FCPU/8 FCPU/64 FCPU/256 FCPU/1024 TIMER0 REGISTERS. Here is the description of some register of TIMER0 , which we are going to useTCCR0 – TIMER COUNTER CONTROL REGISTER This register is used configure the timer. As you can see there are 8 Bits in this register each used for certain purpose. For this tutorial I will only focus on the last three bits CS02 CS01 CS00 They are the CLOCK SELECT bits. They are used to set up the Prescaler for timer. TCNT0 – TIMER COUNTER 0 This register is the main counter in the TIMER0. The timer clock counts only this register as 1. It means tomer clock will increase the value of this 8 bit register by 1 every timer clock pulse.
  • 3. TIMSK- TIMER INTRUPPT MASK REGISTER This register is used to activate/deactivate interrupts related with timers. This register controls the interrupts of all the three timers. The last bit BIT0 Controls the interrupts of TIMER0. TOIE0 : This bit when set to “1” enables the OVERFLOW interrupt. PROGRAMMING PRESCALER- 1024 CLOCK FREQUENCY- 16 MHz Clock input of TIMER0 = 16MHz/1024 = 15625 Hz Frequency of Overflow = 15625 /256 = 61.0352 Hz if we increment a variable “count” every Overflow when “count reach 61” approx one second has elapse. If count reaches 61 we will toggle PB0 which is connected to LED and reset “count= 0”. SETTING UP THE TIMER0 // Prescaler = FCPU/1024 TCCR0|=(1<<CS02)|(1<<CS00); //Enable Overflow Interrupt Enable TIMSK|=(1<<TOIE0); //Initialize Counter TCNT0=0; OR // Prescaler = FCPU/1024 TCCR0|=TCCR0|00000101; //Enable Overflow Interrupt Enable TIMSK|=TIMSK|00000001; //Initialize Counter TCNT0=0;
  • 4. Now the timer is set and firing Overflow interrupts at 61.0352 Hz The ISR ISR(TIMER0_OVF_vect) { //This is the interrupt service routine for TIMER0 OVERFLOW Interrupt. //CPU automatically call this when TIMER0 overflows. //Increment our variable count++; if(count==61) { PORTC=~PORTC; //Invert the Value of PORTC count=0; } } COPMLETE SOURCE CODE /* PROGRAM TO BLINK LE AT 0.5Hz CONNECTED AT PB0 */ #include <avr/io.h> #include <avr/interrupt.h> volatile uint8_t count; void main() { // Prescaler = FCPU/1024 TCCR0|=(1<<CS02)|(1<<CS00); //Enable Overflow Interrupt Enable TIMSK|=(1<<TOIE0); //Initialize Counter TCNT0=0; //Initialize our varriable count=0; //PB0 as out put
  • 5. DDRB|=0x01; //Enable Global Interrupts sei(); //Infinite loop while(1); } ISR(TIMER0_OVF_vect) { //This is the interrupt service routine for TIMER0 OVERFLOW Interrupt. //CPU automatically call this when TIMER0 overflows. //Increment our variable count++; if(count==61) { PORTB=~PORTB; //Invert the Value of PORTB count=0; } } Now just compile the source code and burn the hex file generated in the ATMEGA 16, then implement the circuit as shown below on a breadboard or on your development board whatever you want to use, and you will find your LED blinking at a rate of 0.5 Hz.
  • 6. So we have studied the basic of TIMERs in AVR in next tutorial we will discuss about TIMER IN OUTPUT COMPARE MODE(TIMER1)