Pulse Counter

Discussion in 'General Electronics Chat' started by Dritech, Jan 26, 2014.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Hi all,

    I have an opto sensor connected to a motor shaft which will be used to monitor the position of a linearly moving object. This object is moved 1mm with every 7 rotations from the motor and can move up to 200mm. This means that at 200mm the pulses should count 1400.
    Now my question is, how can I count/store the pulses in an 8-bit microcontroller register?
    Also, if the object moves at a speed up to 30mm per second, that makes up to 210 pulses per second. Is a microcontroller able to count at that frequency while proceeding with some other instructions?

    Thanks in advance.
     
  2. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    hi dr,
    If the PIC/MCU has a 16bit counter that can be externally triggered, ie: Timer1 thats one option,
    The other is to use an On Interrupt input pin, ie: PORTB.0 and count internally to a Word register pair.

    Whats your MCU type.?
    E
     
  3. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    Thanks for the suggestions. I am using a PIC18F4550. Can I use the PWM and the counter simultaneously?
     
  4. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    If Tmr1 is used for PWM, you could consider external clocking Tmr0 [ 8 bit] and using Tmr0 Interrupt to increment a register counter, total 16 bits.
    E
     
  5. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    Doesn't the counter need to be up/down, depending on which direction the actuator is moving? If so, it will take two port pins on the mcu; one for direction, the other for the count pulse. That will require an Interrupt Service Routine which is triggered once per count and it either increments or decrements a 16bit counter variable.
     
  6. ericgibbs

    AAC Fanatic!

    Jan 29, 2010
    2,503
    380
    The way I read the OP, he says:
    So I have assumed that the 'counter' would be Reset to zero for every new stroke.

    If its moves Up/Down as Mike suggests then his solution is an option.

    Please give us more details for the App.
    E
     
  7. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    At 210 pulses/sec, the pic can keep up without breaking a sweat. All you need to do is use a general purpose I/O and either interrupt the processor (use a special pin that interrputs the processor) or else just poll the pin. The increment or decrement a register variable for each pulse.
     
Loading...