It's been years since I posted here -- glad to see the forum is still running well and a helpful resource.

I have a project where I need to detect a light pulse train.

The pulses will be near-infrared (visible), very fast, and unmodulated, and the ambient light will run the gamut from indoors to outside in full sunlight. The source will be quite close to the detector, however (a few cm at most).

Messages are sent by pulse position -- the minimum time between pulses is around 50 microseconds. so, e.g.

flash... 50us pause ... flash... means something, and
flash... 100us pause ... flash... means something else.

The flash itself will be around 50 microseconds long -- including a "light up" and "extinguish" time -- I imagine the intensity will look a bit like a bell curve.

I don't have to decode the messages sent, but I will be sending the result over the hardware serial port, with as low latency as possible.

(yes, this is a rubbish method of signalling, I know -- I have no control over this).

My plan is to hang a photo-diode onto the ADC input of a PIC (with a 20MHz crystal), and periodically take a sample of the ambient voltage from the photodiode. If the voltage drops significantly for a few cycles, then returns back to a similar ambient level, then we have a flash, and a "flash" signal will be sent over HSEROUT immediately. The ambient level will be calculated as an average level (excluding pulses) over a much longer time (microseconds).

I'm going to need to do this, say, every 10 microseconds or so -- is this feasible with a 20MHz crystal, allowing for settling time for the ADC?

I'll obviously need to do a bit of experimentation, but I wanted to check with you experts that this is going to be feasible -- at 10us I'll only have 200 clock cycles to do each program loop, including reading from the ADC (I assume I'll need to read it several times, and take the average), calculating if it was a pulse, and doing relevant ambient level calculations.

I'll also have interrupts set on HSERIN and will have to deal with that, as well as look for various button presses, and do some PWM on some LEDs.

Power source will be batteries, but I would like to consider the possibility of a regulated external power supply in the future -- I imagine this would affect the settling time?

Oh -- if it is relevant, I intend to run the PIC below spec, directly off a pair of AAA batteries. Experience tells me that they usually run just fine like that, but will this affect the ADC sample time?

Any thoughts would be much appreciated.

Thanks in advance,