Pulse Counter

Thread Starter

Dritech

Joined Sep 21, 2011
907
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.
 

ericgibbs

Joined Jan 29, 2010
21,439
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
 

ericgibbs

Joined Jan 29, 2010
21,439
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
 

MikeML

Joined Oct 2, 2009
5,444
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.
 

ericgibbs

Joined Jan 29, 2010
21,439
The way I read the OP, he says:
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.
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
 

Brownout

Joined Jan 10, 2012
2,390
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.
 
Top