Skip to main content

The future of AI in business and its potential to transform industries

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


Popular posts from this blog

What is machine learning and it's types?

 What is machine learning(ML)? Machine learning is a subset of artificial intelligence. Machine learning enables computers or machines to make data-driven decisions rather than being explicitly programmed for a certain task. These programs or algorithms are designed in a way that they learn and improve over time when are exposed to new data. Examples:- 1. Product recommendations   While checking for a product did you noticed when it recommends a product similar to what you are looking for? or did you noticed "the person bought this product also bought this" combination of products? How are they doing this recommendation? This is machine learning. 2. Email spam and malware filtering  There are a number of spam filtering approaches that email clients use.  To ascertain that these spam filters are continuously updated they are powered by machine learning. 3. Online customer support A number of websites nowadays offer the option to chat with customer support representati...

PIC18 Timer programming in C

The PIC18 timer is divided into 4 types Timer 0 Timer 1 Timer 2 Timer 3 PIC18 timers can be used to generate a time delay or as a counter to count external event happening outside the microcontroller. In this article, we will see how to generate a time delay by programming the PIC18 timer. Timer 0 The timer 0 module has the following features Software is scalable as an 8 bit or 16-bit timer/counter. Readable and writable Dedicated 8 bit software programmable Prescaler Clock source selectable to be internal or external Edge select for external clock Register required for Timer 0 Control register Each timer has a control register called TCON to set the various timer operation modes. T0CON is an 8-bit register used for control of timer 0. TOCON TMR0ON (Timer0 on/off control bit)                                       1 = Enable timer 0                ...

Top 7 domains to expertise after learning python

Top 7 domains to expertise after learning python Python is one of the most popular programming languages. It is an object-oriented, dynamic semantics and high-level programming language. It's high-level built-in data structure combined with dynamic binding and dynamic typing makes it attractive for rapid application development. Often programmers fall in love with python because of the increased productivity it provides. Python is one of the most readable languages in the world right now. This language is very popular among developers and is widely used by many programmers to create application and programs. The implementation of this programming language is simple and at the same time, the language has a very clean structure as compared to other languages.  So if you mastered your python concepts and skills, you can dominate these 7 domains. Machine learning / Artificial intelligence Desktop GUI Data analytics and data visualization  Web development Game development Mobile ap...