CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

detecting rising edges on pins RA0 and RA1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SlimG



Joined: 03 Dec 2004
Posts: 6

View user's profile Send private message

detecting rising edges on pins RA0 and RA1
PostPosted: Tue Mar 08, 2005 3:45 pm     Reply with quote

Hi folks I trying to detect the rising of 2 square waves each been applied to pin RA0 and Pin RA1.(PIC16F873)

Below are examples of the 2 codes:

N.B. the code are NOT to the letter just to give an idea of what im doing

If (pinA0 =1){ // detecting a 1 state instead of rising edge
bla bla
}


else {
if (pinA1=1){ //detecting a 1 state instead of rising edge

bla bla
}
}
the above doesn't give a consistent answer because it check the state and not the rising edge


SECOND EXAMPLE

sample_1=pinA0;
sample_2=pinA0;
sample_3=pinA1;
sample_4=pinA1;

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

View user's profile Send private message

PostPosted: Tue Mar 08, 2005 4:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Mar 08, 2005 4:15 pm     Reply with quote

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?

Good luck with your final year! Smile
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group