Generating Trigger Signals Using Arduino

[Credits: Manoj V Mathew. Experiments were conducted at the Central Imaging and Flow Cytometry Facility (CIFF), National Center for Biological Sciences (NCBS), Bangalore, India.]
For conducting the external trigger experiments on the sCMOS camera, we used the Tektronix AFG 3252 which costs about USD 12,000. I realized that the maximum frequency I required to trigger the sCMOS camera was not more than 25KHz. I could do this with a much cheaper trigger source. That is when I stumbled upon the Arduino.
So what is Arduino? 
Let me quote from the Arduino Web Page. "Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing."
The excellent thing about the Arduino is that for what it offers it is really inexpensive. We got an Arduino UNO R3 which cost us only about USD 20 !
Arduino hardware is open source. Complete documentation, electronic connection diagrams, PCB layouts etc. are available.
The board offers 14 Digital Input Output (DIO) pins. Of the 14, 6 can be used to generate Pulse Width Modulation (PWM) signals to mimic an analog output. It has 6 analog input pins with individual 10bit Analog to Digital Converters (ADC). It is a tiny powerful package. Arduino can be programmed by connecting it to a computer through a USB interface. Quoting Arduino Webpage . "The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and based on Processing and other open-source software. A sketch is a name that Arduino uses for a program. It's the unit of code that is uploaded to and run on an Arduino board."
Once a program is loaded (burned) into the Arduino ROM, you do not need not keep it connected to the computer. It can run on a 5v power supply. When you turn the power ON the code executes. You can restart the code by pushing the reset button on the Arduino Board.
I used Arduino UNO R3 to create a clock to trigger the Hamamatsu Flash 4 sCMOS camera. The Arduino setup is shown in Figure B10.

Figure B10: Arduino Uno setup for generating trigger signals

Two single strand wires with pin connectors on both ends were used to connect one of their ends to the Arduino board and the other end to a coaxial cable.  The coaxial cable had crocodile clips on one end and SMA on the other. The SMA connector was connected to the Ex. Trig input of the sCMOS camera.
The program used to generate the trigger signals is shown in Figure B11.

Figure B11: Arduino sketch used to generate PWM signals. (Original Sketch)

The code works by configuring a Digital Input Output (DIO) pin to operate in the output mode. The output DIO pin is then switched between logic high and logic low for set time periods defined by Off-Time and On-Time of a PWM wave. The On time and Off time are calculated in the code from the required frequency and duty cycle. The example program in Figure B11 generates a PWM signal with frequency 1KHz and duty cycle 20%.
A screen shot of a trigger signal generated is shown in Figure B12 below. The code was programmed to generate 500Hz. The oscilloscope was set to 50 Ohms impedance and infinite persistane to observe jitter.

Figure B12: Oscilloscope screen shot of trigger signal at 500Hz

There are few things we can observe here:
  1. The peak to peak amplitude produced by the digital pin is about 3.3 volts
  2. At small frequencies like 500Hz used here the time jitter is almost negligible.
  3. There is an amplitude jitter of about 350V
  4. The generated frequency is slightly lower than 500 Hz (488.9 Hz). This because this code computer the ON and OFF delays solely based on output frequency and does not consider the internal delays. 
A slightly modified version of the sketch that includes a correction factor for the internal delay can be downloaded from my GitHub Page.
This code works well for frequencies from 0 Hz to about 8Khz. For frequencies greater than 8 kHz the time jitter is too large as can be seen in Figure B13. It shows an Oscilloscope screen shot of the Arduino output when the code is made to generate 10 kHz. This sketch worked really well for trigerring the Hamamatsu Flash 4 V2 camera during our several tests with this camera.  

Figure B13: Oscilloscope screenshot shows the large time jitter for frequencies greater than 8KHz

A better way to generate high frequency is to divide the onboard clock using the built in timer of Arduino Uno. The ATmega processor on Arduino Uno uses a 16MHz clock. 
I have modified a sketch available on the Arduino Forum to generate high frequencies. 
The sketch can be downloaded from my GitHub page. The minimum frequency we can generate by this method is 31.5 kHz and a maximum frequency of 8 MHz. You can run the sketch by editing the Frequency variable in the sketch. The signal is output on pin 11. Figure B14 shows an oscilloscope screenshot of 1 MHz signal generated using the sketch. The oscilloscope is operated at infinite persistence. 

Figure B14: Oscilloscope screen shot of a 1MHz signal generated using Arduino Uno by dividing the onboard clock.

As you can see the timing jitter is negligible at this high frequency. 

Figure B15: Oscilloscope screenshot of 8MHz signal

Figure B15 shows an oscilloscope screenshot of 8 MHz signal generated using the sketch. The oscilloscope is operated at infinite persistence. 8 MHz is the maximum frequency that can be generated using this sketch. At 8MHz the output is no longer a square wave due to the on negligible capacitance effects in the circuits at high frequency. However, as can be seen from the figure the time jitter even in this case is negligible and hence this signal can be used for timing and triggering applications. 
There are few points you need to note when you use this sketch to generate high frequencies:
  1. The sketch can generate a minimum frequency of 31.5 kHz and maximum frequency of 8MHz.
  2. The frequency can only be varied in discrete steps by dividing the onboard clock by integer steps ranging from 2 to 510
  3. The signal is output on pin 11 of the DIO pins since we used Timer 2.
Posted in Microscope Automation and Control.

Leave a Reply

Your email address will not be published. Required fields are marked *