Hello all,
I am currently working on a project trying to get fast readings from a linear photodiode array (Hamamatsu S4111-16) and its driver circuit (Hamamatsu C9004) using an Arduino. The ultimate goal is to get peaks from 16 channels then get the slope of those peaks, but right now I'm stuck on just getting the 16 channels of data in the first place. The timing chart is attached here:
Basically, I need to read 16 evenly spaced signals that occur once every 20 us and last for 10 us, then there is a break between sets of signals. Each set of readings from the sensor takes 360 us. (As a side note I tested out all of the timing with an Oscilloscope and they are all very stable and consistent to the timing chart above)
The current plan is to use digitalReadFast() (from the digitalWriteFast library) on the falling edge of the TRIG with an interrupt and storing it in a 16 wide array of double variables. Then in the time between the 16 channels being read out I would 'unpack' the array to be able to print it out (for now and later to put it on an SD card and/or take a linear regression and store the slope).
This seems reasonable to me, but then trying to keep those 16 variables together and resetting them with the START or END signals have proved challenging to wrap my head around. From what I understand you can't put a timer inside of an interrupt, so using the START signal as my interrupt beginning, then waiting an appropriate amount of time with micros() doesn't work.
Then on the other hand if I use TRIG as my trigger for the interrupt, how do I put the signal into the right position in the array without overwriting data?
Can I somehow use both inside of each other? Or is there a better way to use the internal timers on the Arduino (I know there's three and that I would have to use registers but got a bit overwhelmed when I couldn't find an example that had an inconsistent timer like I need. This definitely seems like a more elegant solution than layered interrupts but I need some more help to get there).
I do not have much of a background in 'actual' programming, so everything I've found online about clock and/or external interrupts has been slightly confusing and I may be misinterpreting it. Part of the problem is System.print is really slow so I haven't been able to print out my data iteratively to have an understanding of what's happening under the hood, so some suggestions about how to get readable intermediate data from this would also help.
Also, if the current frequency is simply too fast for the Arduino to handle I can slow down the driver circuit on the hardware side until I get a faster microcontroller, but I need this to run as quickly as possible in the meantime. Thanks in advance for any help!