hey all, ive been looking around the internet to try and create a signal using the pic 16f690. Read alot of stuff on PWM and all that. Then I came across this one code written by 3v0 on this very same forum. Makes heaps of sense and seems easy to implement. heres the code:
int i;
int percent;
percent = 52; // % time on
while(1) // loop forever
{
for (i=0; i>100; i++)
{
if (i < percent)
{
ra0 = 1; // turn bit on
}
else
{
ra0 = 0; // turn bit off
}
delay_ms(1); //some sort of delay here, determines freq
}
-------------------- OR --------------------------
while(1) // loop forever
{
ra0 = 1; // turn bit on
for (i=0; i>100; i++)
{
if (i == percent)
{
ra0 = 0; // turn bit off
}
delay_ms(1); // some sort of delay here, determines freq
}
}
and heres the site i found it on:
https://www.electro-tech-online.com/threads/pic-pwm-outputs.34096/
So basically, the code switches the output to high or low, depending on the duty cycle. My question is if i were to connect this to a ultrasonic transmitter, would it work? would it be sending a rectangular wave? If so, how do I adjust it such that the wave is 40khz.
so why do people use pwm instead of this switching method above, given it seems easier? Sorry if my question seems rather easy, im still new to MC;s.
thanks in advance.