Ad Code

Generate square pulses of 150milli-sec and 30 milli-sec

Generate square pulses of 150milli-sec and 30 milli-sec

banner for generating square wave post


Hi... in this article we will talk about how to generate a continuous square-wave of 150 milli-sec and 30 milli-sec of the pulse width. We will generate two pulses of 150 milliseconds and six pulses of 30 milliseconds. 

The simulation software we gonna use is proteus software and the microcontroller we gonna us is AT89C51.

To write a toggling program we gonna use Keil microvision5 software.

To generate a square wave we need to toggle a dc signal generating from the particular pin of the microcontroller with some particular delay, in this case, we are using pin P3.0 

For toggling at 150milliseconds we gonna do count calculation at Timer 0 mode 2 and for 30 milliseconds at Timer 1 mode 1.

Count calculation

1. for T0M2

delay = 1.085 x 10^-6 x 256 x count

150 x 10^-3 = 1.085 x 256 x count

count = 540.034 or simply 540

2. for T1M1

delay = 1.085 x 10^-6 x 65536 x count

30 x 10^-3 = 1.085 x 10^-6 x 65536 x count

count = 0.42193

now the count value is below 1, hence we need to calculate using another method.

delay = 1.085 x 10^-6 x count

30 x 10^-3 = 1.085 x 10^-6 x count

count = 27649

now, 65536 - 27649 = 37886

convert 37886 into hexadecimal we will get 93FF.

we need this count value in the program to generate an accurate delay.


Now open the proteus simulation and connect all required components.

making circuit on proteus

Write the program and generate the hex file using Keil Microvision5 software 

code

#include <reg51.h>

sbit output_pin=P3^0;

int i,j,k;

void delay1() // delay function for 150msec
{
TMOD=0x02;
  for(i=0;i<540;i++)
{
    TH0=0;
  TR0=1;
  while(TF0==0);
  TF0=0;
}
}


void delay2()  //delay function for 30msec
{
TMOD=0x10;
  TH1=0x93;
TL1=0xFF;
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}

void main()
{
  
for(j=0;j<2;j++)
{
  output_pin=~output_pin;
delay1();
}
for(k=0;k<6;k++)
{
  output_pin=~output_pin;
delay2();
}
}


uploading hex file on proteus


Now simulate the project.


To see the waveform generated by the microcontroller go to debug option at the top of the simulator and select oscilloscope.

after opening the oscilloscope 

select dc
disable the auto 
and select cursor to take the length of the waveform



Video demonstration