Table of Contents
Introduction
ArduinoPulseGenerator is a simple program for generating pulse sequences (with pulse widths on the order of seconds to milliseconds) using an Arduino. There is an associated GUI that runs on the local computer, or you can simply connect to the Arduino with a serial console (9600 baud) and send it commands.
Pulse sequences are defined by simple programs. For example, the following program will generate 15 ms pulses on channel 2 at 10 Hz for 3 seconds:
set channel 2 to repeat 15 ms pulses at 10 Hz
wait 3 s
turn off channel 2
end program
To see the pulse sequence the program will generate you can use the Simulate button. Once you are happy with the pulse sequence you've created, the Run on Device button will run the program on the Arduino, generating the pulses on its digital outputs. Channels 1 through 8 are mapped to Arduino pins 2, 3, 4, 5, 8, 9, 10, and 11 respectively.
Lines starting with a '#' are treated as comments, e.g.
# This is a comment.
Repeat loops can be used to run the same commands multiple times, for example:
# Generate three 20 Hz pulse trains each 500 ms long,
# with 2 seconds between each pulse train.
repeat 3 times:
set channel 1 to repeat 10 ms pulses at 20 Hz
wait 500 ms
turn off channel 1
wait 2 s
end repeat
end program
Controls
Program Tabs
The Program Tabs allow you to choose between using controls or text-based instructions to describe a pulse sequence. The first tab is labeled with the name of the program (initially "<new program>", and provides an edit box for creating your program. The second tab is labeled Traditional Controls, and provides the following controls for creating a pulse sequence:
Channel
The Traditional Controls allow you to generate a pulse sequence on a single channel determined by the Channel> control.
Pulse Width
Specifies the width of each individual pulse in this pulse sequence.
Pulse Train
Allows you to generate multiple pulses when this box is checked, and a single pulse when not checked. All of the controls below this control aren't relevant for a single pulse and thus are disabled when this box is not checked
Pulse Frequency
Specifies the number of pulses to generate per second during a pulse train. Note that the maximum frequency is limited by the pulse width; for example if the pulse width is 100 ms, one can only fit 10 pulses into a second (at which point the channel is simply on all of the time).
Train Duration
Specifies the period of time to generate pulses at the given pulse frequency before pausing. This duration is considered to be one train of pulses
Number of Trains
Specifies the number of pulse trains to generate.
Delay between Trains
Specifies the time to wait between the end of one pulse train and the start of the next. This is only meaningful (and thus only enabled) if more than one pulse train will be generated.
Equivalent Program
Displays the program that has been generated from the controls above.
The program in the first of the Program Tabs will usually not be the same as the program in the Traditional Controls tab. The currently active tab in the Program Tabs specifies the program that is saved, simulated, or run by the Save, Simulate, or Run on Device buttons respectively.
It's often faster to describe simple pulse sequences using the Tradition Controls tab, but the text-based interface allows much more complex pulse sequences to be described. When first learning the text-based programming language, it may be useful to use the Traditional Controls to generate an initial pulse sequence and then copy and paste the equivalent program into the <new program> tab. You can then make modifications and test them using the Simulate button.
Help
The Help button can be used to open this manual in a web browser.
New
The New button will open a new window with a sample pulse generator program.
Open
The Open button allows you to open text files containing pulse generator programs. By default it expects the file names to end in .psq, but you can choose the "All Files" filter if you've saved your program with a different extension.
Save
The Save button allows you to save the current program as a text file that you can open later with the Open button.
Simulate
The Simulate button allows you to draw a graph of the pulse sequence that the current program will generate. This is useful for debugging your programs before you generate real pulses (which might damage your experimental preparation).
Port
The Port combo box allows you to specify which port your Arduino is connected to, or if you have multiple Arduinos attached to the computer, which Arduino will be used by the Run on Device button in this window.
Lock
The Lock checkbox allows you to lock the Run on Device button so that it can not be pressed until the Lock checkbox is clicked again. This is a safety feature requested by one of our users, because if the stimulation being used is dangerous to the experimenter or the experimental preparation, pressing the Run on Device button when you meant to press Simulate could be a disaster.
Run on Device
The Run on Device button will upload the current program to the Arduino which will then run the program, generating the pulse sequence. Note that the correct port for the Arduino must be selected in the Port combo box for this command to work.
While the program is running, the Run on Device button will be replaced by the Interrupt Program button (see below).
Interrupt Program
The Interrupt Program button replaces the Run on Device button while the Arduino is running a pulse sequence program. Pressing this button will reset the Arduino, halting any currently running program and turning off all of the channels.
Language Reference
Values
The following types of values are used by commands:
Number
Numbers are used for things like the number of times to repeat a loop. Numbers should be specified as non-negative decimal integers between 0 and 4294967295 (i.e. 232 - 1), inclusive, for example "5", "23", "0", or "4192".
Channel
A channel is a number between 1 and 8, inclusive, for example "5", "1", or "3".
Float
A float is a non-negative real number, specified in decimal format, for example "2.13", "0", "123456.78", or "0.0023".
Time unit
A time unit can be "s" (seconds), "ms" (milliseconds), or "us" or "μs" (both synonyms for microseconds). Note that the accuracy of timing in this program is about ±200 microseconds on the Arduino Mega 2560 and about ±35 microseconds on the Arduino Due.
Interval
An interval is a duration of time, specified as a float followed by a time unit. A few examples of intervals are "53 s", "102.25 ms", and "9345 us".
Frequency unit
A frequency unit can be "Hz" (Hertz, i.e. per second), "kHz" (kilohertz).
Frequency
An frequency is specified as a float followed by a frequency unit. A few examples off frequencies are "30 Hz", "0.125 Hz", and "2.048 kHz".
Commands
The following commands are supported by ArduinoPulseGenerator:
# Comment
Comments are notes left by the programmer which have no effect on the execution of the program. Comments are indicated with a '#' mark, and continue to the end of the current line. Examples:
# This is a comment.
# This is an indented comment.
turn off channel 1 # Comments can be used on the same line as a command.
set channel [channel] to [Interval] pulses at [frequency]
Sets the given channel to start outputting pulses of the given duration at the given frequency. The channel will continue to output these pulses until the program ends or another command changes the settings for this channel. Examples:
set channel 8 to 10 ms pulses at 20 Hz
set channel 1 to 1 s pulses at 0.01 Hz
set channel [channel] to [Interval] pulses every [Interval]
Sets the given channel to start outputting pulses of the given duration with the given interval between repeats. The channel will continue to output these pulses until the program ends or another command changes the settings for this channel. Examples:
set channel 6 to 1.2 s pulses every 2 s
set channel 2 to 15 ms pulses every 100 ms
turn off channel [channel]
Sets the given channel to low/off, stopping any pulses that it might have been generating. Example:
turn off channel 3
turn on channel [channel]
Sets the given channel to high/on, stopping any pulses that it might have been generating. Example:
turn on channel 2
wait [Interval]
Waits until the given interval of time has passed before executing subsequent commands. During this time the channels will continue to generate pulses with the frequency and duration they were set to. Examples:
wait 12.1 s
wait 250 ms
wait 1200 us
repeat [Number] times:
Repeats all of the commands between this command and the matching end repeat. Repeats can be nested. Example:
repeat 10 times:
end repeat
The "end repeat" command marks the end of a block of statements to repeat. Each repeat statement should have an end repeat that follows it. Example:
end repeat
end program
The "end program" command marks the end of the program. Each program should have exactly one "end program" command as the last line of the program. Example:
end program