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

rtcc rising edegs

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







rtcc rising edegs
PostPosted: Sat Apr 30, 2005 4:06 pm     Reply with quote

hi,
how can I count the rising edegs on rtcc?

setup_counters(rtcc,edge H to L);


I mean
{ char a;
/////what here?////when edge goes high ,count one up
a++;

}

I hope someone can help
thx
Ttelmah
Guest







PostPosted: Sun May 01, 2005 2:40 am     Reply with quote

First of all, setting the 'edge high to low', means the RTC would count when the signal changes from 'high', to 'low', and detect the _falling_ edge. Also to count an external signal, you need to connect the RTCC to the external pin.
So setup the counter with:
setup_counters(RTCC_EXT_L_TO_H);

Then attach your signal to the external timer0 input, and timer0, will count whenever the edge rises.
If you want to 'wait' for this edge, then:

Code:

int8 old;
old=get_timer0();
while(old==get_timer0()) ;


This will simply sit waiting for the count to change. However the more 'normal' use, would be to read the value, and wait for a period (using one of the other timers, or a delay), then read the 'new' value, to find out how many edges have been seen in the time.
So (crudely!):
Code:

int8 last;
int8 counts;
last=get_timer0();
delay_ms(100);
counts=get_timer0()-last;


This counts how many edges take place in 0.1 seconds. There are 'limits' to this. It has a (slight) error, because of the times taken to actually take the readings, which are outside the 'delay'. Using an interrupt driven timer would avoid this. It only supports counts up to 255. However it shows a 'starting point'.

Best Wishes
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