Saturday, July 10, 2010

Square Wave Generation Using 8051

Some programs to generate a square wave using 8051is given below. This is based on 8051 architecture and all compatible micro controllers can be used for this. To be specific, this is to be tested on AT89S51/AT89S52 with a 12MHz crystal for clock.

Below given is the program to generate a square wave of 1kHz.

                  ORG 0000H
START:    SETB P1.0
          MOV R0,#249
ONE   :   DJNZ R0,ONE
          CLRB P1.0
          MOV R1,#248
TWO   :   DJNZ R1,TWO
          SJMP START
          END     

Next by manipulating the values in R0,R1 we can generate a square wave of 10kHz.

           ORG 0000H
START:     SETB P1.0
           MOV R0,#24
ONE   :    DJNZ R0,ONE
           CLRB P1.0
           MOV R1,#23
TWO   :    DJNZ R1,TWO
           SJMP START
           END     

Square wave output is available at P1.0


13 comments:

sandy said...

THANK U

Anonymous said...

for this method how can i generate a 640khz square wave
and also tell me the formula how to choose the valve in the resister
THANK U..

Anil C S said...

Here the program works based on the delays produced when executing instruction. While using 12Mhz crystal one machine cycle is 1 microsecond. So in the above program all the instructions except branching instructions take one machine cycle to complete and branch instructions will take 2 machine cycles. Using this concept the program for generating 640 khz is impossible since for 640 khz time period is 1.5625. Atleast three instrunctions are to be executed which would take minimum 3 us. Maximum frequency that you could attain using 12Mhz is 1 us 166.6666khz. That program is given below

ORG 0000H
START:
SETB P1.0
MOV R0,#20;
MOV R0,#30;
CLRB P1.0
SJMP START
END

MOV instructions are used just to give sufficient delay so as to make 50% duty cycle.

For higher frequencies you may try higher frequency crystals. I cannot make any comments on that since I have not experimented with higher frequency crystals.

Anil C S said...

I cannot specify any fixed formula for finding the values in the register. I selected those values based on the principle mentioned above so as to get equal high and low time periods.

Anonymous said...

How to check the output of square wave generation after writing this code..?

Anonymous said...

how to check the output of square wave after writing the code?

Anonymous said...

Will anyone please give me programme to generate sine wave,half sine wave,full sine wave and distorted sine wave having third harmonic with different frequencies using 8051 or 8052.All above wave must be combined.
Please mail me the programme in txt format on: ashish27193@gmail.com
I am gonig to make my microcontroller project.
Thanks.

abhijit hande said...

how to check the output of square wave after writing the code?
Ans: select pin present in microcontroller,connect CRO,by making connection you get proper o/p on CRO.

Anonymous said...

hi

Anonymous said...

boringg subject

Anonymous said...

Can you help me with the code to produce 38Khz, 42Khz, 48Khz, 53Khz,57Khz, and 61Khz. I am new to 8051 controller so need your help...

Anonymous said...

hi i'm gurumurthy raghuraman from aneka australian embassy asking about aneka mapreduce in every program/algorithm in the world

Anonymous said...

hello sir I need a programme to generate pulses with frequency of 3KHz and with starting delay of zero that means it conducts only for half interval (0 - 180 degree) remaining ( 180 - 360) zero pulses. Also I need to generate same pulses with 0- 180 degree delay (zero pulse) and 180 to 360 it must generate pulses...

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | coupon codes