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 CCS Technical Support

Fastest way to look at input pin?

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



Joined: 25 May 2004
Posts: 25

View user's profile Send private message

Fastest way to look at input pin?
PostPosted: Tue Jul 20, 2004 5:07 pm     Reply with quote

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







PostPosted: Tue Jul 20, 2004 5:50 pm     Reply with quote

Can't you just do an input(PIN_B0)?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jul 21, 2004 1:51 am     Reply with quote

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?
PostPosted: Wed Jul 21, 2004 2:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jul 21, 2004 9:56 am     Reply with quote

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







PostPosted: Wed Jul 21, 2004 10:27 am     Reply with quote

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