Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

c language coding for square wave generation

Status
Not open for further replies.

ADRITA

Newbie level 4
Joined
Sep 21, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,316
i want c language coding for square wave generation..can anyone help me out!
 

Your basic requirements are the generation of Pulse Width Modulation (PWM), of which the defacto square wave is PWM with a 50% duty cycle, half the period of the waveform ON and the other half OFF.

There are primarily two ways of generating PWM, through software/bit-banging or using a hardware PWM module on the MCU.

What MCU are you using in your design?

BigDog
 

HI,

check this:

void main()
{
while (1) {
output_high(PIN_B4);
delay_us(500); // change the delay as per the frequency you need
output_low(PIN_B4);
delay_us(500);// change the delay as per the frequency you need
}
}
 

check this:

void main()
{
while (1) {
output_high(PIN_B4);
delay_us(500); // change the delay as per the frequency you need
output_low(PIN_B4);
delay_us(500);// change the delay as per the frequency you need
}
}

The above example would be the software/bit-bang method. The major drawback of such an implementation is the entire MCU is dedicated to generating the square wave and no other task. There are usually better alternatives to PWM generation, these largely depend on your particular MCU/processor and its features.

BigDog
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top