Counter in the PIC18F2550

Thread Starter

KansaiRobot

Joined Jan 15, 2010
324
Quick question.
Is there a counter function implemented in the PIC18F2550. Like for example use it with a motor encoder signal? And if there is, do I need to use certain pins or can i use say A0 and A1 and then configure the counter to it.

Lot of thanks in advance

Kansai
 

eng1ne

Joined Dec 4, 2009
97
I would implement a manual counter; i.e. is signal on [I/O pin high] high? Yes, increment COUNTER.

You might be able to use interrupts; I'm sure one of the pins on the PIC you quote will have an interrupt function. Many possibilities...

That might not suit your application, but without knowing more about your application, it is hard to make a better judgement.

At what frequency are you expecting to count?
 

AlexR

Joined Jan 16, 2008
732
Read the data sheet!

The chip has quite a few timers (4 I think) of which several can be configured for use as counters.
 

CVMichael

Joined Aug 3, 2007
419
Like for example use it with a motor encoder signal?
There are a few types of encoders, what kind are talking about ?

If it's the type with 2 outputs, one for CW rotation, and the other for CCW rotation, then you could use the interrupts on RB0 & RB1 pins.
What pins you use it also depends on what other stuff you have connected to the microcontroller. For example you could also use "interrupt on change" on pins RB4 to RB7...

I don't think timers are good to use in this case, because you need to increment/decrement a counter for every impulse. A timer is good if you want to have an event say... every 100 impulses (when the counter overflows). So only after 100 impulses your counter gets incremented, I don't think you wan that. (the # 100 is just an example)

Chaper 9 in the datasheet talks about interrupts, you should read it.
 
Last edited:
Top