Spread the love

timer___________________________________________________________________________________________________

 



  • What is Timer ?-  Timer is used to calculating the amounts of time between events.

timer

  • What is Counter ?-  Counter is used to count external events.

31fbm4j8tqL

 

  • About Timer & Counter-  Timer is fully depend upon the oscillator that attached externally to the microcontroller because it uses the frequency of oscillator to operate. When we trigger timer it start from initial value and run up to decided value stored by user in special function registers. When it reach its maximum value, it overflows and a certain bit is decided to show over flow in SFR(special function register) also called flag bit. Some timers also used prescalar technique to enhance its limits. ATmega32 contain three timer/counter T0, T1 and T2 which is of different size 8 bit and 16 bit. Maximum value that can be achieved by timer is depending upon its size. Suppose a timer is of 16 bit so it can achieved up to = 65536
  • Applications- Generating rectangular pulses (signal modulation), Watchdog timers, Counting objects, Measuring intervals, generating delay, etc.

 

Click Here : understanding of timer/counter as program point of view

1.CREATING A SQUARE WAVE OF 100 MS USING TIMER 0  OF ATMEGA16

CREATING A SQURE WAVE OF 100MS USING TIMER 0 OF ATMEGA16

 1. CREATING A DELAY OF 1 SEC USING timer of ATMEGA 16

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- CREATING DELAY OF 1 SEC USING TIMER OF ATMEGA16
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

void delay(); // crating delay of 1 sec

void main()
  {
      DDRD=0xFF;
      TCCR0=0x01;
      while(1)
        {
           PORTD=~PORTD;
           delay();
         }
   }

void delay()  // creating 1 sec delay
   {
        int i;
        for(i=0;i<5000;i++)
          {
              TCNT0=0x38;
              while((TIFR&0x01)==0);
                  TIFR=0x01;
          }
    }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

____________________________________________________________________________________________________

2. CREATING A SQUARE WAVE OF 100 MS USING TIMER 0 OF ATMEGA16

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- CREATING A SQUARE WAVE OF 100 MS USING TIMER 0 OF ATMEGA16
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

void delay(); // crating delay of 50 mili sec sec

void main()
   {
      DDRD=0xFF;
      TCCR0=0x01;
      while(1)
        {
           PORTD|=(1<<0);
           delay();
		   PORTD&= ~(1<<0);
           delay();
         }
   }

void delay()  // creating 50 mili sec delay
   {
        int i;
        for(i=0;i<5;i++)
          {
              TCNT0=0x38;
              while((TIFR&0x01)==0);
                  TIFR=0x01;
          }
    }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

____________________________________________________________________________________________________

Content for the tab VIDEO