Computer Science, asked by Babuluvictory368, 1 year ago

Write the program using timer that generate the square wave with on 3microsec and off 10microsec

Answers

Answered by jogi23
0
How do I generate a square wave for different duty cycles in 8051 using embedded C?

Answer

13

Follow

Request

More

7 ANSWERS



Vishal Chovatiya, Worked for Delhi Metro's Embedded Systems

Answered Mar 30, 2015

To generate square wave, you have to use timer which will count ON period and OFF period of you square wave, and according to which you have to calculate duty cycle of your wave form

Here is sample code for it
c programming of timers in 8051 microcontroller

Look for firmcodes TAB in this link and its second example
which generate square wave of 100 microsecond

7.3k Views · View Upvoters

Is this answer still relevant and up to date?

YesNo

Upvote · 2

 

Comment...



Mihai Buleandra, Software Engineer

Answered Mar 23, 2015

Continue Reading

Use a timer and adjust it as you want. This is an example from Google.
It's incomplete because you need to create another delay method called T1M2Delay2.

You final while loop must look like this:
mybit=~mybit;
T1M2Delay /*ON period*/ 
mybit=~mybit;
T1M2Delay2  /*OFF period*/ 

PS:read some doc about how to calculate the delay, because it depends on the quartz frequency, timer mode and machine cycle.



10.5k Views · View Upvoters

Is this answer still relevant and up to date?

YesNo

Upvote · 5

 

Comment...

RecommendedAll



Rod Nussbaumer, I speak C as a second language

Answered Dec 5, 2016

Use a timer that generates an interrupt on each terminal count. In the interrupt service routine, toggle an output pin, and reload the timer with a value that reflects whatever the duty cycle for the next half cycle should be. If you were hoping to get a code fragment to do this, it probably isn’t practical since you haven’t stated enough detail. If you’re programming microcontrollers, you need to acquaint yourself with the data sheets and the fine art of reading them, so a generic solution can be turned into an implementation.

Similar questions