Batch Processing

Hello everyone, I guess this is my first post. Well, I'm currently using multiple 328s in my project. The job the MCU has to do is - 1. Take one pulse from a sensor 2. Take several pulses from a rotary encoder 3. Fire an output when the encoder hits a specified number of pulses.

For Example: When an object passes under the sensor it triggers an interrupt to start counting encoder pulses. When the encoder pulses have reached a certain number 'x', say it fires an LED.

My problem here is, this can be done with a simple program when it is just one object getting sensed. My requirement is multiple objects go under the sensor and when the encoder reaches 'x' pulses it fires the LED every-time.

So when the object is sensed, the encoder starts from zero, then heads up to 'x' and then the LED fires. Now, what if the first object is sensed, then the second and the third and so on, how can I make the encoder pulses start from zero every-time it senses a new object, before firing the LED for the previous object ? or what I mean is , I'm only able to finish a 'SENSE -> COUNT -> BLINK' for one object, I need to 'SENSE -> COUNT -> BLINK' for the next object, even though the 'SENSE -> COUNT -> BLINK' cycle for the previous object hasn't completed yet.

Sorry, I have no code at the moment, since I don't have a proper algorithm to start with.

Please help !

Thanks

When the 2nd & 3rd object are sensed, do they all count up from the same encoder? If so, create a flag to indicate which counter is active when a sensor is tripped. When the encoder pulse comes in, increment all the counters with an active flag, and when the individual counters reach their upper limit then fire their LEDs and clear their active flag so they stop counting.

Oh, and Welcome to forum! There is an India forum also if you need to converse with someone in a similar timezone, needs tips for local part sources, etc.

Well all the pulses are coming from the same encoder. I thought of the idea you gave, I'll roughly need about 30 counters, obviously within a loop, these counters will 'increment' with each pulse of the encoder. But, since the encoder is feeding an interrupt, will there be enough time for the counter to 'increment' ?. I'll be roughly getting 2000 pulses a second, will it still work ?

Oh yeah. That's about 500uS /pulse, interrupt takes about 4uS, lots of time left, 8,000 clock cycles to check status and update some counters.