how can i create square wave signal in C?

Status
Not open for further replies.

ash

Full Member level 3
Joined
Dec 25, 2002
Messages
151
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Location
Europe
Activity points
1,051
How can i create square wave signal in C for pic micros?

Regards.
 

Hi,

it's so easy
for example to creat 1khz square wave using ccs c compiler.

We calcualte time duration T=1/1000Hz = 1 ms
Then divide it by 2 ---> 1ms/2 = 500 us

while (1) {
output_high(PIN_A1);
delay_us(500);
output_low(PIN_A1);
delay_us(500);

}

Bye
 

Also, many controllers have timers with PWM output. Then you have to program timer to generate PWM with 50% duty cycle and frequency 1kHz....
 

You can use PWM or timer to create square wave ,it may just frequency your need.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…