if (sample_1==0 && sample_2==1) //detecting rising edge 0 to 1
{
bla bla;
}
else
{ if (sample_3==0 && sample_4==1) //detecting rising edge 0 to1
{
bla bla
};
the second example doesn't work at all!
Does anybody have suggestions pls????!!!! It is my final year project.
fuzzy
Joined: 26 Feb 2005 Posts: 64
Posted: Tue Mar 08, 2005 4:09 pm
you can try to store the status of one port in the last bit of a byte. every cicle you shift left this byte and store the new status of port. if first and second bit are equal there isn't a change. instead in the first is high and the second low you have a rising edge and viceversa.
you can do it oalso using 2 variables one fore the actual status and the another to store the previous one. and then you can compare them.
bluetooth
Joined: 08 Jan 2005 Posts: 74
Posted: Tue Mar 08, 2005 4:15 pm
SlimG:
What you want to do is best done with hardware.... while you can do what you want, you'll tie up the PIC spinning tightly looking at the two square waves, and if you take time to do anything else, you'll absolutely lose timing accuracy or worse, miss transitions all together.
The PIC you're using has a "change detector" on pins RB4 through RB7.
Why not hook up to those pins and use interrupts to achieve your goal?
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum