Skip to main content

Triggers

The following functions are available for the two Trigger lines. The "X" in a function name must be replaced by the trigger number (1 or 2):

triggerMode

void triggerMode(uint8_t pin, uint8_t mode);

This function configures the input or output characteristics of a trigger pin. By default, all triggers are inputs. The function takes the following arguments:

  • pin Pin should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2
  • mode sets the input or output mode. Valid options are:
    • OUTPUT: Standard output pin (3.3V CMOS push-pull)
    • OUTPUT_OPENDRAIN: Open drain output
    • INPUT: Standard input (floating)
    • INPUT_PULLUP: Input with 22k pull up resistor
    • INPUT_PULLDOWN: Input with 100k pull down resistor

Example

triggerMode(1,INPUT);
triggerMode(2,OUTPUT);

triggerWrite

void triggerWrite(uint8_t pin, uint8_t value);

This function sets a trigger output HIGH or LOW. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.
  • value set the pin to a 0 or 1. Valid options are:
    • LOW
    • HIGH

Example

triggerWrite(1,LOW);
triggerWrite(2,HIGH);

triggerRead

uint8_t triggerRead(uint8_t pin);

The function returns a 0 if the trigger input is low and returns 1 if the trigger is high. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.

Example

if triggerRead(1) {
//trigger1 is high
...
} else {
//trigger 1 is low
...
}

enableInterruptTrigger

void enableInterruptTrigger(uint8_t pin, trigger_edge_t edge, void (*cb_function)(void) );
void enableInterruptTrigger(uint8_t pin, trigger_edge_t edge, void (*cb_function)(void), uint priority );

This function configures the trigger to call a function on the rising, or falling, or either edge of the trigger line. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.
  • edge Sets the edge sensitivtity of the trigger line. Valid options are:
    • FAILLING_EDGE
    • RISING_EDGE
    • BOTH_EDGES
  • cb_function Callback function to run on the rising (or falling) edge of the trigger
  • priority Optional argument to set interrupt priority. Default is 4 for trigger 1 and 5 for trigger 2. Under most circumstance, this arguments should be skipped.

Example

void setup() {  
enableInterruptTrigger(1,RISING_DGE, gotTrigger);
}

void gotTrigger(void) {}
...
}

disableInterruptTrigger

void disableInterruptTriggerX(uint8_t pin);

This function disables the trigger's interrupt function. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.

Example

void watchTrigger(bool on) {
if (on == true) {
enableInterruptTrigger(1,RISING_EDGE, gotTrigger);
//call gotTrigger when Trigger 1 goes high
} else {
disableInterruptTrigger(1); //turn off calling gotTrigger
}
}

void gotTrigger(void) {
...
}

setTriggerClockFreq

float setTriggerClockFreq(float freq);

This function configures the frequency for the trigger clock. Unless the useTriggerClockOutput function is used to enable the Clock Trigger Output, this function has no effect. The frequency can be set between 16 Hz and 66 MHz. The available frequencies are given by the formula:

Frequency=132MHzNFrequency = \frac{132 MHz}{N}

where N is an integer between 2 and 8,388,607 (the second number is 22312^{23}-1). The function takes the following arguments:

  • freq Desired Frequency

Example

void setup() {
float target_frequency = 2.65e6;
float actual_frequency = setTriggerClockFreq(target_frequency);
//actual_frequency will be 2.64e6 or 2.64 MHz
}

readTriggerClockFreq

float readTriggerClockFreq(void);

This function reads the trigger clock frequency.

Example

float freq = readTriggerClockFreq();

useTriggerClockOutput

void useTriggerClockOutput(uint8_t pin, bool enable);

This function turns on or off the Clock Output on a trigger signal. Enabling the trigger Clock Output overrides the triggerMode() setting, so even if the trigger pin is configured as an input, enabling the useTriggerClockOutput will output a clock on the trigger pin. When the Clock Output is disabled, the trigger pin will revert to its original configuration (INPUT, or OUTPUT, etc). The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.
  • enable Set to true to turn on the Clock Output and false to disable Clock Output

Example

setTriggerClockFreq(1e6); //Configure Clock at 1 MHz
triggerMode(1,INPUT); //Set trigger 1 as input
useTriggerClockOutput(1,true); //Output 1 MHz clock on Trigger 1
triggerWrite(1,HIGH); //no effect
useTriggerClockOutput(1,false); //Trigger 1 reverts back to being an input
triggerMode(1,OUTPUT); //Set trigger 1 as output, will out HIGH