|
|
View previous topic :: View next topic |
Author |
Message |
goethe Guest
|
rtcc rising edegs |
Posted: Sat Apr 30, 2005 4:06 pm |
|
|
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
|
|
Posted: Sun May 01, 2005 2:40 am |
|
|
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 |
|
|
|
|
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
|