Spread the love

timers of ARM7___________________________________________________________________________________________________



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

DSC04827

  • 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.

 

1.CREATING A SQUARE WAVE OF 100 MS USING TIMERS OF ARM7 ( LPC2148 )

ckt of wave created by timer on lpc2148

 1. CREATING A DELAY OF 1 SEC USING TIMERS OF ARM7 ( LPC2148 )

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- CREATING DELAY OF 1 SEC USING TIMER 0 OF ARM7(LPC2148)
******************************************************/

#include<lpc21xx.h>

# define PRESCALAR 60000    // define prescalar as 60000

void pll();
void timer0_ini();
void delay(unsigned long int ms);

int main()
  {
        PINSEL0=0x00000000;   // select gpio pin
        IO0DIR=0XFFFFFFFF;    // make gpio as output pin
        pll();                // calling pll function
        timer0_ini();         // calling timer function
        while(1)  
         {
                             IO0SET=0XFFFFFFFF;    // led on
                             delay(0x000000fF);    // delay using timer 0
                             IO0CLR=0XFFFFFFFF;    // led off
                             delay(0x000000fF);    // delay using timer 0            
         }
        return 0;
        
  }
        
void pll()
   {
                 //PLL IS CONFIGURED TO GET 60HZ pCLK
                        PLLCFG=0X24;           // SET PSEL=2 AND MSEL=5
                        PLLCON=0X01;           //PLL IS ACTIVE BUT NOT YET CONNECT
                        PLLFEED=0XAA;          //FEED SEQUENCE
                        PLLFEED=0X55;          //FEED SEQUENCE
                        while((PLLSTAT & 0X400)==0);   //WAIT FOR FEED SEQUENCE TO BE INSERTED
                        PLLCON=0X03;          // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
                        VPBDIV=0X00;           // SET PCLK SAME AS FCCLK
                        PLLFEED=0XAA;         //FEED SEQUENCE
                        PLLFEED=0X55;         //FEED SEQUENCE
  }
         
void timer0_ini()
  {
        T0TCR=0X0;    // to stop timer
        T0PR=PRESCALAR-1;  //load the timer value
        T0TCR=0X02;       //reset timer
  }

void delay(unsigned long int ms)
  {
        T0TC=0x00000000;   // t0 reset timer counting
        T0TCR=0X02;    // reset the timer  
        T0TCR=0X01;    // start timer
        while(T0TC<=ms);  // check the condition
        T0TCR=0X00;   // stop timer
  }

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

download (1)

____________________________________________________________________________________________________

2. CREATING A SQUARE WAVE OF 100 MS USING TIMERS OF ARM7 ( LPC2148 )

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

#include<lpc21xx.h>

# define PRESCALAR 60000    // define prescalar as 60000

void pll();
void timer0_ini();
void delay(unsigned long int ms);

int main()
  {
        PINSEL0=0x00000000;   // select gpio pin
        IO0DIR=0XFFFFFFFF;    // make gpio as output pin
        pll();                // calling pll function
        timer0_ini();         // calling timer function
        while(1)  
         {
                                                IO0SET=0X01;    // high level 
                                                delay(0x0000000F);    // delay using timer 0
                                                IO0CLR=0X01;    // low level
                                                delay(0x0000000F);    // delay using timer 0            
         }
                                return 0;
        
  }
        
void pll()
   {
                 //PLL IS CONFIGURED TO GET 60HZ pCLK
                        PLLCFG=0X24;           // SET PSEL=2 AND MSEL=5
                        PLLCON=0X01;           //PLL IS ACTIVE BUT NOT YET CONNECT
                        PLLFEED=0XAA;          //FEED SEQUENCE
                        PLLFEED=0X55;          //FEED SEQUENCE
                        while((PLLSTAT & 0X400)==0);   //WAIT FOR FEED SEQUENCE TO BE INSERTED
                        PLLCON=0X03;          // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
                        VPBDIV=0X00;           // SET PCLK SAME AS FCCLK
                        PLLFEED=0XAA;         //FEED SEQUENCE
                        PLLFEED=0X55;         //FEED SEQUENCE
  }
         
void timer0_ini()
  {
        T0TCR=0X0;    // to stop timer
        T0PR=PRESCALAR-1;  //load the timer value
        T0TCR=0X02;       //reset timer
  }

void delay(unsigned long int ms)
  {
              T0TC=0x00000000;   // t0 reset timer counting
        T0TCR=0X02;    // reset the timer  
        T0TCR=0X01;    // start timer
        while(T0TC<=ms);  // check the condition
        T0TCR=0X00;   // stop timer
  }

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

download (1)

____________________________________________________________________________________________________

Content for the tab VIDEO