View previous topic :: View next topic |
Author |
Message |
LEVENT
Joined: 04 May 2006 Posts: 16
|
pulse count? |
Posted: Mon Jun 05, 2006 2:03 am |
|
|
hi everbody.I want to count external pulses to fix my motor distance.My pulse formula is ( 382 pulses=1meter )...
Is my program right ?
Code: |
int16 a;
...
while(a<382)
{
while(input(pin_a4)); //pin_a4 is my external pulse input...
delay_us(3);
a++;
while(!input(pin_a4));
delay_us(1);
}
...
|
or is there any method to count external pulses at background?because I want to do another procedures when pic16f877 count external pulses and until counter value reach my fix value... |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 05, 2006 2:41 am |
|
|
This is what the CCP modules do.
Have a look at AN594, frm MicroChip, and then come back. If you run 'timer1' from your external source, and run CCP1, in 'compare' mode, you can program it to interrupt, or just set the interrupt flag (which you can poll), when a certain number of pulses have arrived.
Best Wishes |
|
|
LEVENT
Joined: 04 May 2006 Posts: 16
|
|
Posted: Mon Jun 05, 2006 4:45 am |
|
|
but I'm using ccp1 as pwm? |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 05, 2006 4:47 am |
|
|
Use CCP2 then.
That is why there are two modules, and the PWM, uses a different timer source to the counter.
Best Wishes |
|
|
|