[cross-post] Light Source control with ARDUINO - Timing Issues

Sorry for the cross-post, hope that’s ok. Here’s the link to the original thread: Light Source control with ARDUINO - Timing Issues - Usage & Issues - Image.sc Forum


Hi,
I have been working on setting up a system where we will have multiple light source imaging the same sample, with the plan of quickly switching between them.

To do so, I have set-up an ARDUINO UNO board to send TTL triggers to (for example) ThorLabs LED cubes and then have set up channels in the MDA panel to switch between them. To further control the accuracy of my setup, I have connected the triggers to an oscilloscope to see what happens.

For example, a typical imaging cycle could be:

  1. Light Source 1 ON, Light Source 2 OFF - expose for 25ms
  2. Light Source 1 OFF, Light Source 2 ON - expose for 25ms
    repeat

My expectation for this is that on the oscilloscope I would see a very clear and stable square wave for the duration of the image acquisition. However, that is not the case and the period during which the two light sources are on vary, with them often being on for longer then needed/expected - this concerns me in particular due to the fact that I would be using the data to track moving particles i.e. I need to be able to rely on frames being equally spaced etc.

I should also note that the camera I’m planning on using does have any TTL outputs - which I’m afraid might complicate things for me.

Thanks in advance for all the help!

Can you define “longer”? 1% longer? 5% longer? 50% longer?

I’m not an Arduino expert, but I’m not sure they are designed for the precise timing that you might be expecting. I understand, for example, that time between the executions of the loop() function can vary. So if your code is something like the classic blink example:

void loop() {
  digitalWrite(led, HIGH);   // turn the led on
  delay(1000);               // wait for 1 second
  digitalWrite(led, LOW);    // turn the led off
  delay(1000);               // wait for a second
}

Then the time between LOW and HIGH might not be as precise as you hope. The digitalWrite() function may also have a non-zero execution time.

https://forum.arduino.cc/t/accurate-100-hz-square-wave-generator/218567

-Hazen