Saturday, July 19, 2014

Create a frequency using 8051 Microcontroller. Timer 0 Mode 1. Proteus simulation

8051 has two timers. Timers can be used to generate delay. So, we can create pulse of various frequencies using 8051. Let's see as how to create a frequency on particular pin of microcontroller, 8051. We will use proteus simulation to demonstrate the same.

                                                         Circuit diagram


Here is the code, which generates a frequency of 10Hz on pin  P2.7.

Code :
#include "reg52.h"
#define Baud_rate 0xFD  // BAUD RATE 9600                     
void delay(void);
sbit App = P2^7;


void main()
{ 
while(1)
 {
 App=~App; //To generate a pulse(ON/OFF)
 delay();
 }
}

void delay(void)
{
  TMOD=0x01;      //Timer 0 mode 1
  TL0=0xFD; 
  TR0=0x4B;
  TR1=1;         //start timer
  while(TF1==0); //Timer flag
  TR1=0;         //reset timer
  TF1=0;
}


The Microcontroller used here has a crystal frequency of 11.0592MHz. 
In order to generate a Frequency of  10Hz, we need to use timer registers.
The steps to load values into TH and TL registers which generate delay are as follows
1) Divide the desired time delay by 1.085us. Here delay is 1/10=100ms. So, 100ms/2=50ms/1.085us=46083
2) Perform 65536-delay=65536-46083=19453
3)Convert the value obtained in the above step to Hex.  19453 is in decimal, in Hex, the value is 4BFD.
4)Load TH=4B
5)Load TL=FD
when you start the timer, the timer registers will count till FFFF generating the desired delay. Thus generating a pulse of required frequency/delay.

1 comment:

  1. How generate wave with 10 hz frequency but x % dutycycle

    ReplyDelete