Daqarta
Data AcQuisition And Real-Time Analysis
Scope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
The following is from the Daqarta Help system:

Features:

Oscilloscope

Spectrum Analyzer

8-Channel
Signal Generator

(Absolutely FREE!)

Spectrogram

Pitch Tracker

Pitch-to-MIDI

DaqMusiq Generator
(Free Music... Forever!)

Engine Simulator

LCR Meter

Remote Operation

DC Measurements

True RMS Voltmeter

Sound Level Meter

Frequency Counter
    Period
    Event
    Spectral Event

    Temperature
    Pressure
    MHz Frequencies

Data Logger

Waveform Averager

Histogram

Post-Stimulus Time
Histogram (PSTH)

THD Meter

IMD Meter

Precision Phase Meter

Pulse Meter

Macro System

Multi-Trace Arrays

Trigger Controls

Auto-Calibration

Spectral Peak Track

Spectrum Limit Testing

Direct-to-Disk Recording

Accessibility

Applications:

Frequency response

Distortion measurement

Speech and music

Microphone calibration

Loudspeaker test

Auditory phenomena

Musical instrument tuning

Animal sound

Evoked potentials

Rotating machinery

Automotive

Product test

Contact us about
your application!

Event Triggering


Introduction:

Event triggering allows an external event to launch a Daqarta macro that performs some desired operation. Typically this would be something that you want to happen repeatedly, but not necessarily at a preset or predictable rate. For example, you may want the Generator to play a short tone or recording every time you press a key, or every time a sound or an external pulse or switch change is detected.


Trigger Target Macro:

Trigger macros are included with Daqarta to allow all of the above things. When the triger macro detects the specified event, it calls a separate macro called Trig_Target. This is a one-line macro that simply calls another macro that you specify, which by default is Triggered_Burst:

Trig_Target Macro Listing:

    ;<Help=H492A

    @Triggered_Burst    ;Replace with desired macro

The idea is that you can replace the target in one place and any of the trigger macros can use it. You can easily customize a certain trigger macro to invoke a particular target, just by locating the @Trig_Target line and replacing it with the name of your chosen target macro (preceded by an @ character).

By default, Triggered_Burst will automatically load the Burst_5ms_X2.GEN setup each time it is run, which creates two 5 ms bursts. You can replace this with a setup of your choice, or you can eliminate the automatic load and load your own setup separately.

Triggered_Burst modifies the burst parameters of the loaded setup (but not the .GEN file itself) to eliminate automatic repetition by setting a very long Train Cycle in the Burst Dialog.

A non-burst setup, such as a continuous tone, will not be converted to a burst by Triggered_Burst.

As written, all of the event trigger macros will re-arm after the triggered event and allow subsequent triggers.


Trigger on Key Press:

The Trig_On_Key macro waits for a specified key, then calls the target macro.

Trig_On_Key Macro Listing:

;<Help=H492A

QK=" "            ;Trigger key (spacebar); any other exits
UK=0
WHILE.UK=0              ;Repeat until exit key
    Msg="Waiting for key."
    WHILE.UK=0
        UK=Key?!            ;Get any key pressed
    WEND.
    IF.UK=QK                ;Is it the trigger key?
        @Trig_Target
    ELSE.                   ;If not,
        Msg=                    ;Clear message
        LoopBreak=-1            ;Exit the macro
    ENDIF.
    UK=0                    ;Clear key for next pass
WEND.                   ;Continue until exit key

Trigger on Sound Card Input:

The Trig_On_Input macro waits for an input signal that exceeds the specified trigger level, then calls the target macro.

This macro assumes that Trig_Target is Triggered_Burst, By default, Triggered_Burst will automatically load the Burst_5ms_X2.GEN setup each time it is run, which creates two 5 ms bursts. You can replace this with a setup of your choice, or you can eliminate the automatic load and load your own setup separately.

As it is written, the trigger will re-arm itself after the burst event and allow subsequent Input events to repeat the burst. If you only want a single event detection and burst, remove the leading semicolon from the UR=0 line to break the outer WHILE cycle.

One application for this would be for a Halloween setup where childrens' voices on the front porch trigger a burst of spooky laughter.

Similarly, a burst of barking dogs could be triggered by sounds that might signal a break-in.

In either of these cases, you'd first create a recording of the desired burst sound (laughter or barking) and load it as a Play Wave file. Set Play From and Play To to isolate the part of the recording you want. Then set the burst parameters to play that portion, perhaps using a slow Rise to make it seem the laughter or dogs are coming closer. Set Train Cycle to maximum by attempting to enter "5G".

You can skip the Trig_Target call in this case, by commenting it out with a leading semicolon, and removing the leading semicolons from the three lines following. Those turn on the generator, then wait until the burst is over before re-arming the input trigger (assuming the UR=0 is still commented out.)

Trig_On_Input Macro Listing:

;<Help=H492A

Gen=0                      ;Generator off (assumes Gen target)
Input=1                    ;Monitor Input for signal
UR=1                       ;Repeat flag
WHILE.UR=1                 ;Repeat as needed
    TrigSrc=LI                 ;Left Input
    TrigLevel=20               ;Threshold 20% of full-scale
    TrigSngl=0                 ;Repeating trigger
    TrigMode=Norm              ;Wait for trigger
    Trig=1                     ;Enable trigger
    A=Posn?D                   ;Current sample at screen start
    WHILE.Posn?D=<=A           ;Wait for the next, on sound trigger
    WEND.
    @Trig_Target               ;Run the target macro
;    Gen=1                      ;Alternative for preset Burst
;    Ch=0                       ;Assume burst on Left Stream 0
;    WaitSecs=Ch.TrainCount * Ch.BurstCycle + 200m  ;Wait for Burst end
;    UR=0                       ;Uncomment to run only once
WEND.

Trigger on External Pulse:

You can use an external Arduino or Numato USB device to wait for a trigger pulse or state change. The Trig_On_Arduino and Trig_On_Numato macros monitor a user-selectable digital I/O pin. They first wait for the pin to be low, then launch the Trig_Target macro as soon as the pin goes high.


Monitoring Switch State:

A typical use is to monitor a switch. Since digital inputs only give reliable operation if either high or low, not floating unconnected, the usual approach is to provide a "pullup" resistor from the input to the positive supply (+5 or +3.3 V depending on model). This resistor value is not critical, usually between 10K and 100K. The Arduino can provide this internally (about 35K) when requested, as is done here. The Numato will need an external resistor.

The switch is then connected between the pin and ground, such that opening the switch ungrounds it and allows the resistor to pull the pin high.

If you instead want to detect closing the switch, omit the pullup resistor and connect it from the input pin to ground instead of high. In the Trig_On_Arduino macro you should also change UI=2 to UI=1 to select normal input with no pullup.

The pullup or pulldown is not needed (but won't hurt) if the pin is monitoring another digital signal.


Monitoring Resistance Change:

You can also use this same macro to sense resistance changes instead of switch activation. For example, you can replace the switch with a photoresistor such as a cadmium sulphide (CdS) cell, whose resistance can change from a few hundred ohms in bright light to a few hundred thousand ohms in darkness.

If you wire the cell between the input pin and ground, and use an internal or external pullup resistor of about 35K, this will create a simple voltage divider. When the cell is in darkness (high resistance) the pullup will insure that the pin is well above its "on" threshold, and when sufficient light shines on the cell it will pull the pin well below the "off" threshold. So if the cell is normally in the path of a light beam, this arrangement will detect when an object breaks the beam.

If you reverse the positions of the resistor and photoresistor, the arrangement will detect daylight, car headlights, etc.

Note that CdS cells have slow response times, so they may not be appropriate to detect whirling fan blades on an car's engine. But they'll probably be fine for a slow ceiling fan.

Instead of a CdS cell, you can use any other variable resistance the same way. For example, you can wire a potentiometer wiper to the input pin, and the other ends to power and ground. If the potentiometer is connected to an arm and float, it could trigger on liquid level.

Note that you can do the same resistance or level change detection using the Trigger on DC Level methods below.


Trig_On_Arduino Macro Listing:

;<Help=H492A

Posn#0="Ardu"           ;Scan for Arduino
Posn#1=0                ;First match
@_ComDev_Scan           ;Scan COM devices for match

UP=2                             ;Arduino pin for trigger
UI=2                             ;1=INPUT, 2=INPUT PULLUP
Port#D2=(h40+UI)<<8 + hD0 + UP    ;Set pin to input type

UK=0
WHILE.UK=0
    UE=1
    Msg="Waiting for LOW"
    WHILE.UE=>0                 ;Wait for pin low
        UK=Key?!                    ;Get key, if any
        IF.UK=>0                    ;Any key hit?
            LoopBreak=2                 ;Exit WHILE if so
        ENDIF.
        Port#D1=hB0 + UP        ;Request digital input
        UE=Port?1                    ;Read input pin UP
    WEND.                       ;Keep waiting for pin low or key hit
    IF.UK=0                     ;If no key, must be pin low
        Msg="Waiting for HIGH"
        WHILE.UE=0                  ;Wait for pin high
            UK=Key?!                    ;Get key, if any
            IF.UK=>0                    ;Any key hit?
                LoopBreak=2                 ;Exit WHILE if so
            ENDIF.
            Port#D1=hB0 + UP            ;Request digital input
            UE=Port?1                   ;Read input pin UP
        WEND.
        IF.UK=0
            Msg="HIGH found"
            @Trig_Target
        ENDIF.
    ENDIF.
WEND.
Msg="Key break"
Port#O=0                ;Close COM port

Trig_On_Numato Macro Listing:

Note: This macro assumes you are using the Numato 8 device. Change the Posn#0="Nu08" line as needed to use other Numato devices:

    "Nu08"      ;Numato 8
    "Nu16"      ;Numato 16
    "Nu32"      ;Numato 32
    "Nu64"      ;Numato 64
;<Help=H492A

Posn#0="Nu08"           ;Scan for Numato08
Posn#1=0                ;First match
@_ComDev_Scan           ;Scan COM devices for match

;This uses Numato pin 0 (IO0) for trigger.  To use another
;pin, change "gpio read 0" (two places)
UK=0
WHILE.UK=0
    UE=1
    Msg="Waiting for LOW"
    WHILE.UE=>0                 ;Wait for pin low
        UK=Key?!                    ;Get key, if any
        IF.UK=>0                    ;Any key hit?
            LoopBreak=2                 ;Exit WHILE if so
        ENDIF.
        Port="gpio read 0"          ;Request DIGITAL read, pin IO0
        UE=Port?V                   ;Read returned data (0,1)
    WEND.                       ;Keep waiting for pin low or key hit
    IF.UK=0                     ;If no key, must be pin low
        Msg="Waiting for HIGH"
        WHILE.UE=0                  ;Wait for pin high
            UK=Key?!                    ;Get key, if any
            IF.UK=>0                    ;Any key hit?
                LoopBreak=2                 ;Exit WHILE if so
            ENDIF.
            Port="gpio read 0"          ;Request pin state
            UE=Port?V                   ;Read state (0,1)
        WEND.
        IF.UK=0
            Msg="HIGH found"
            @Trig_Target
        ENDIF.
    ENDIF.
WEND.
Msg="Key break"
Port#O=0                ;Close COM port

Trigger on External DC Level:

The Arduino and Numato USB devices include analog-to-digital converters that can read DC voltages between 0 and 5 volts (or 0 and 3.3 V on some models). You can use these instead of the digital inputs discussed above under Trigger on External Pulse, with the advantage that you can set trigger threshold voltages as desired, with no need for pullup or pulldown resistors.

Similar to the digital versions, the Trig_On_Arduino_DC and Trig_On_Numato_DC macros monitor the voltage on a selected ADC input. The ADC output is a 10-bit value from 0 to 1023, where 1023 corresponds to the maximum voltage (5 or 3.3 V).

The macros first wait for the output to be below a specified lower threshold, then launch the Trig_Target macro as soon as a specified upper threshold is exceeded.

By default, you specify the upper and lower thresholds as a main trigger "center" level UT and a "hysteresis" value UH, which is usually much smaller. The resulting upper threshold UU is then found as UT + UH, and the lower UL as UT - UH. You can think of the hysteresis as a noise margin, with the macro ignoring noise less than this value.

The advantage of this approach is that you can keep the hysteresis constant while you adjust the threshold center, or conversely you can keep the center and widen the hysteresis band about it to compensate for a noisy sensor system.

Note that you may want to add a 0.01 microFarad capacitor between the A/D input pin an ground to reduce noise pickup, especially if the sensor it is reading has long leads and/or a high impedance.

If you prefer, you can set UU and UL directly by inserting lines after the calculation section, indicated here by commented UU=456 and UL=123.

Another feature of using the ADC instead of a digital input is that the current 0-1023 output is displayed continuously so you can monitor what's going on.

Trig_On_Arduino_DC Macro Listing:

;<Help=H492A

Posn#0="Ardu"           ;Scan for Arduino
Posn#1=0                ;First match
@_ComDev_Scan           ;Scan COM devices for match

UP=hA0                  ;Measure Analog pin A0
UT=512                  ;Trigger level (0-1023)
UH=10                   ;Hysteresis on above

UU=UT+UH                ;Upper threshold
IF.UU=>1023
    UU=1023
ENDIF.

UL=UT-UH                ;Lower threshold
IF.UL=<0
    UL=0
ENDIF.

;UU=456                     ;Set direct UU and UL values here
;UL=123                     ; instead of using the above UT and UH

Port#D1=UP              ;Get initial analog input
UA=Port?2               ;analogRead input pin UP, 2 bytes (0-1023)
Mtr0=UA                 ;Display A/D count
UK=0
WHILE.UK=0
    Msg="Waiting for analog LOW"
    WHILE.UA=>UL            ;Wait for analog low
        UK=Key?!                ;Get key, if any
        IF.UK=>0                ;Any key hit?
            LoopBreak=2             ;Exit WHILE if so
        ENDIF.
        Port#D1=UP               ;Request analog input
        UA=Port?2                ;analogRead input pin UP
        Mtr0=UA                  ;Display current A/D value
    WEND.                   ;Keep waiting for analog low or key hit
    IF.UK=0                 ;If no key, must be analog low
        Msg="Waiting for analog HIGH"
        WHILE.UA=<UU            ;Wait for analog high
            UK=Key?!                ;Get key, if any
            IF.UK=>0                ;Any key hit?
                LoopBreak=2             ;Exit WHILE if so
            ENDIF.
            Port#D1=UP              ;Request analog input
            UA=Port?2               ;analogRead pin UP
            Mtr0=UA                 ;Display current A/D value
        WEND.
        IF.UK=0
            Msg="Analog HIGH found"
            @Trig_Target
        ENDIF.
    ENDIF.
WEND.
Msg=                   ;Close message
Mtr0=                  ;Close meter
Port#O=0               ;Close COM port

Trig_On_Numato_DC Macro Listing:

Note: This macro assumes you are using the Numato 8 device. Change the Posn#0="Nu08" line as needed to use other Numato devices:

    "Nu08"      ;Numato 8
    "Nu16"      ;Numato 16
    "Nu32"      ;Numato 32
    "Nu64"      ;Numato 64

Note also that the Numato 32 does not have an ADC 0 channel, so if you use that model you must additionally change the UP="0" line.

;<Help=H492A

Posn#0="Nu08"           ;Scan for Numato 8
Posn#1=0                ;First match
@_ComDev_Scan           ;Scan COM devices for match

UP="0"                 ;Measure ADC 0 (Numato pin IO0)
UT=512                 ;Trigger level (0-1023)
UH=10                  ;Hysteresis on above

UU=UT+UH               ;Upper threshold
IF.UU=>1023
    UU=1023
ENDIF.

UL=UT-UH               ;Lower threshold
IF.UL=<0
    UL=0
ENDIF.

;UU=456                     ;Set direct UU and UL values here
;UL=123                     ; instead of using the above UT and UH

Port="adc read " + UP(A)   ;Request ADC read UP
UA=Port?V                  ;Read returned data
Mtr0=UA                    ;Display ADC count
UK=0                       ;Will hold key value
WHILE.UK=0                 ;Repeat until any key hit
    Msg="Waiting for analog LOW"
    WHILE.UA=>UL               ;Wait for analog low
        UK=Key?!                   ;Get key, if any
        IF.UK=>0                   ;Any key hit?
            LoopBreak=2                ;Exit WHILE if so
        ENDIF.
        Port="adc read " + UP(A)   ;Request ADC read UP
        UA=Port?V                  ;Read returned data
        Mtr0=UA                    ;Display ADC count
    WEND.                      ;Keep waiting for analog low or key hit
    IF.UK=0                    ;If no key, must be analog low
        Msg="Waiting for analog HIGH"
        WHILE.UA=<UU               ;Wait for analog high
            UK=Key?!                   ;Get key, if any
            IF.UK=>0                   ;Any key hit?
                LoopBreak=2                ;Exit WHILE if so
            ENDIF.
            Port="adc read " + UP(A)   ;Request ADC0 read UP
            UA=Port?V                  ;Read returned data
            Mtr0=UA                    ;Display ADC count
        WEND.
        IF.UK=0
            Msg="Analog HIGH found"
            @Trig_Target
        ENDIF.
    ENDIF.
WEND.                      ;Back for next pass
Msg=                       ;Close message
Mtr0=                      ;Close meter
Port#O=0                   ;Close COM port

See also Macro Examples and Mini-Apps

GO:

Questions? Comments? Contact us!

We respond to ALL inquiries, typically within 24 hrs.
INTERSTELLAR RESEARCH:
Over 35 Years of Innovative Instrumentation
© Copyright 2007 - 2022 by Interstellar Research
All rights reserved