Counter in the PIC18F2550

Discussion in 'Embedded Systems and Microcontrollers' started by KansaiRobot, Jun 14, 2010.

  1. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    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
     
  2. eng1ne

    Member

    Dec 4, 2009
    97
    3
    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?
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Read the data sheet!

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

    Senior Member

    Aug 3, 2007
    416
    17
    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: Jun 14, 2010
    KansaiRobot likes this.
Loading...