View previous topic :: View next topic |
Author |
Message |
ninjanick
Joined: 25 May 2004 Posts: 25
|
Fastest way to look at input pin? |
Posted: Tue Jul 20, 2004 5:07 pm |
|
|
Was wondering if anyone knew the best way to look at switching logic on the B0 input pin. Right now I have the interrupt counting on every falling edge. I've also tried simply incrementing/decrementing a counter if the input is high or low. Both seem to be just as fast ... does anyone know of another solution? Switching frequency can be from DC to 100Khz. |
|
|
valemike Guest
|
|
Posted: Tue Jul 20, 2004 5:50 pm |
|
|
Can't you just do an input(PIN_B0)? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jul 21, 2004 1:51 am |
|
|
The fastest way to look at an input pin is to poll it using the input() function in combination with setting the #use fast_io directive.
Code: | #use fast_io(A)
set_tris_A(0b00000001) // Make pin A1 an input
while input(PIN_A1)
{
// Do something
}
|
Without more detailed information it is difficult to give you a specific answer. Do you only want to count pulses or do you need to meassure variations in period time as well? If you just want to count a frequency then why are you not using one of the hardware counters? |
|
|
Ttelmah Guest
|
Re: Fastest way to look at input pin? |
Posted: Wed Jul 21, 2004 2:43 am |
|
|
ninjanick wrote: | Was wondering if anyone knew the best way to look at switching logic on the B0 input pin. Right now I have the interrupt counting on every falling edge. I've also tried simply incrementing/decrementing a counter if the input is high or low. Both seem to be just as fast ... does anyone know of another solution? Switching frequency can be from DC to 100Khz. |
The _fastest_ way, of counting an input, would be to use the CTC feature in the chip (assuming you are using a chip with this ability). It'll go up to perhaps 40* the fastest speed that can be handled using a interrupt, and involve th chip in doing less work.
The 'downside' of the interrupt approach, starts to show when you want other jobs to be done at the same time...
Best Wishes |
|
|
ninjanick
Joined: 25 May 2004 Posts: 25
|
|
Posted: Wed Jul 21, 2004 9:56 am |
|
|
Thanks all for the replies. Right now I'm using the fast_io directive and input(pin_b0) in a while loop to monitor the pin. It's a PIC16F87 so I'm not sure what a CTC is ... is that similar to the CCP? |
|
|
Ttelmah Guest
|
|
Posted: Wed Jul 21, 2004 10:27 am |
|
|
ninjanick wrote: | Thanks all for the replies. Right now I'm using the fast_io directive and input(pin_b0) in a while loop to monitor the pin. It's a PIC16F87 so I'm not sure what a CTC is ... is that similar to the CCP? |
Yes.
It is part of the operating 'modes' of this section of the chip. The 'CCP', stands for 'capture/compare/PWM'. You can use this section to give a PWM output, a 'compare' mode (counter which sets/resets something when it reaches a value), or 'Capture', where the counter counts on every pulse (or every 'n' pulses). You can also potentially use the PWM itself as a 'timer' (though using one timer module as well). The first two modes differ from the last, in being 'counter' modes, on an external signal, and chips doing just these modes, with a timer, are sold as 'CTC' chips (counter/timer/compare).
Since you don't need the PWM, you only need the 'CTC' feature of the chip.
This really is the easiest way to deal with counting at high rates, since the unit itself forms a 16bit counter, that can be read at any time, and will operate up to about 10MHz (the exact upper frequency depends on the chip, the 'F' will go to 16MHz, while the 'LF' is only guaranteed to 10MHz).
Best Wishes |
|
|
|