Hello!
I have an application where a lot of counting is involved. I'm measuring the timing of an event similar to that of a chronograph that measures the speed of a bullet.
I have about an 8 microsecond delay between each of these steps in my code.
InitMicros = micros();
Nano2_data.CH1TrigTime_Rising = 0;
while(digitalRead(CH1_TRIG) == HIGH && !Nano2_data.TrigTimeOut);
Nano2_data.CH1TrigTime_Falling = (unsigned int)(micros() - InitMicros);
while(digitalRead(CH2_TRIG) == LOW && !Nano2_data.TrigTimeOut);
Nano2_data.CH2TrigTime_Rising = (unsigned int)(micros() - InitMicros);
while(digitalRead(CH2_TRIG) == HIGH && !Nano2_data.TrigTimeOut);
Nano2_data.CH2TrigTime_Falling = (unsigned int)(micros() - InitMicros);
while(digitalRead(CH3_TRIG) == LOW && !Nano2_data.TrigTimeOut);
Nano2_data.CH3TrigTime_Rising = (unsigned int)(micros() - InitMicros);
while(digitalRead(CH3_TRIG) == HIGH && !Nano2_data.TrigTimeOut);
Nano2_data.CH3TrigTime_Falling = (unsigned int)(micros() - InitMicros);
I realize there is A LOT of extra work I'm putting between things and I can probably minimize that 8 microseconds considerably by doing all the math and unit conversion at the end (just store the long integers and process them later). Still, I'm looking for something on the order of 1us precision in timing. I also don't like how I have to sequence and that if the first "HIGH" on CH1_TRIG doesn't happen, none of it happens.
I'm thinking about using some external counters for this application. I'm finding a few I2C ones that MAXIM makes. They will HAVE to be I2C because I don't think I could support a basic binary counter that has 16+ pins in my project. However none of the ones I've seen have the features I'm looking for.
Ideally I would like to be able to setup 6 of these binary counters, each one looking for a different event (Channel 1 - 3 , HIGH and LOW). There would be a "START" pin and "STOP" pin. The arduino would transmit a "START" signal to each counter simultaneously. Each of my input signals would then be tied to corresponding "STOP" pins. At the end of an "event" the Arduino will download (via I2C) the data from each counter.
Can anyone give me pointers to hardware that might be useful for this? Thank you!