Trigger sequences (FlexiTrig)
All Ikalogic logic analyzers manufactured after 2012 come with an IP (intellectual property) bloc called “FlexiTrig”. This is a trigger engine that is unique of its kind, because it allows almost any logic sequence to be described in order to generate a trigger condition when such a sequence is detected. For example, a non acknowledged I2C address call can be used to trigger a capture.
Although recent devices like SP209 series logic analyzers have very deep sampling depths, making this feature less vital, it still can be very useful to generate such precise trigger to synchronize other lab instruments. Indeed, SP209 series logic analyzers have TRIG-OUT SMA connectors that will generate a trigger pulse when a trigger condition is detected by the FlexiTrig engine.
Under the hood, FlexiTrig’s trigger sequence works with what we call “trigger steps”. Each time the logic signals match with a trigger step, the FlexiTrig engine advances to the next step. This operation continues until the very last step is reached, which generates the actual trigger pulse.
Each trigger step is described with a text string, where each character represents a logic state according to the following table:
Character | Logic state or transition |
---|---|
0 | Logic low level |
1 | Logic high level |
R | Rising edge |
F | Falling edge |
X | Don’t care (ignore channel) |
For example, a rising edge transition on the second channel of a 4 channels logic analyzer, can be described with this text string: "XXRX"
. Note that the rightmost character represents the first channel.
Important note: A step description may never contain more than one transition (like a Falling edge or Rising edge). Adding a step with 2 or more edges will generates errors, since it’s physically impossible to make 2 edges coincide at the same instant in time.
Here are some valid trigger step examples:
Trigger step text string | Description in plain words |
---|---|
"001X" |
Low level on channels 3 and 4, high level on channel 2, and don’t care on channel 1. |
"1XXXXFXX" |
Falling edge on channel 3, while channel 9 is logic high. Other channels are ignored. |
The number of characters in the text string must be equal to the number of channels of a logic analyzer device. Thus, it’s the script’s responsibility to retrieve the number of channels, and build a correct trigger step string accordingly. The number of channels can be retrieved using the function ScanaStudio.get_device_channels_count()
which is described in the General functions chapter.
The time between two steps can be constrained using:
- A minimum time
- A maximum time
- A minimum and maximum time
This effectively tells the logic analyzer device to only accept a trigger step match if it happens within defined time limits. (This is essential for triggering on asynchronous protocol words like UART, CAN , 1-Wire or LIN).
Consecutive edges of the same polarity
It is possible to build a trigger sequence with two consecutive edges of the same polarity on the same channel.
One example application for this, is to trigger when a signal reaches a certain frequency:
In that particular case, we’re interested in measuring a signal period (T2), that is, the time between two consecutive rising or falling edges, but the relation between a rising edge and the next falling edge (T1) is not useful.
It’s important to understand that FlexiTrig IP translates 2 same polarity consecutive edges into 3 steps:
- First edge
- Implicitly added edge of opposite polarity
- Second edge
If the logic level on the channels is different between the first and the last edge, the (Implicitly) added edge will have DONT CARE
values. If the logic value is stable, it will be maintained in the added edge.
The example below describing how the Implicitly added edge deals with the other channels, the ones without edges (the 3 MSB channels in that example).
For instance, if the script is creating the trigger sequence below:
01XR
11XR
It would be translated - inside the FlexiTrig system - into those 3 steps
01XR
X1XF <----- Implicitly added falling edge step
11XR
In practical terms, the following example simply means that the trigger should happen if there are two consecutive rising edges on channel 0. The logic level on channel 2 must be stable at logic level 1, and the logic level on channel 3 must have the values 0 and 1 at the instant of the first and second rising edge respectively. Channel 3’s value may be unstable between the two edges without any consequences on the trigger sequence. Finally, channel 1 is DONT CARE
(X) during the whole sequence, which means that it’s value is ignored.
01XR
11XR
While this may work in many situations, sometimes, this may not be the required behavior. In this case, it’s recommended to fully specify all the steps of a trigger sequence, without skipping any edge.
Entry point function
Like any other feature of ScanaStudio scripts, the trigger script work with entry point functions that are described below:
on_draw_gui_trigger()
is called when ScanaStudio need to draw the trigger configuration GUIon_eval_gui_trigger()
is called when ScanaStudio need to evaluate the trigger configuration GUIon_build_trigger()
is called when ScanaStudio need to build or rebuild the trigger sequence using that specific script.
ScanaStudio.flexitrig_append(“step_description”,t_min,t_max)
Description: This function appends a new trigger step described by "step_description"
and constrained with the previous step by t_min and t_max.
Parameters:
- “step_description”: Text string describing the trigger step
- t_min : Minimum time between this step and the previous step expressed in seconds. For example, if this parameter is set to 0.1, it mean 100ms. This parameter is ignored for the very first appended step. set to -1 to ignore this constrain
- t_max : Maximum time between this step and the previous step expressed in seconds. This parameter is ignored for the very first appended step. set to -1 to ignore this constrain
Context: Trigger
ScanaStudio.flexitrig_print_steps()
Description: This function is simply used for diagnosting and debugging of your trigger steps builder script. Calling this function will simply display a list describing all the trigger steps that have been created by your script, and as they were understood by ScanaStudio.
Steps will be displayed in ScanaStudio’s console.
Context: Trigger
Example trigger sequence generator script
The script below shows how to build a trigger sequence in a way that the logic analyzer triggers when a threshold frequency is reached.
Note: A trigger builder script need also to implement protocol decoding features to be used by ScanaStudio. Those functions are not shown in this example for the sake of clarity, but let’s assume it’s part of a more complete script called “My protocol”. Also, prior to using a script based trigger, the corresponding protocol decoder must be added to the workspace. For example, to use the UART trigger, one must first add (and configure) UART trigger in the ScanaStudio workspace.
//Trigger sequence GUI
function on_draw_gui_trigger()
{
ScanaStudio.gui_add_ch_selector("f_channel","Channel","");
ScanaStudio.gui_add_info_label("Trigger will occure when the frequency is above the threshold");
ScanaStudio.gui_add_engineering_form_input_box("f_th","Threshold frequency",1,20e6,10e3,"Hz");
}
function on_build_trigger()
{
var f_channel = ScanaStudio.gui_get_value("f_channel");
var f_th = ScanaStudio.gui_get_value("f_th");
ScanaStudio.flexitrig_append(build_trigger_step_string(f_channel),-1,-1);
ScanaStudio.flexitrig_append(build_trigger_step_string(f_channel),-1,1/f_th);
ScanaStudio.flexitrig_print_steps();
}
function build_trigger_step_string(channel)
{
var i;
var ret = "";
for (i = 0; i < ScanaStudio.get_device_channels_count(); i++)
{
if (i == channel)
{
ret = "R" + ret;
}
else {
ret = "X" + ret;
}
}
return ret;
}
Now, we can use this script (called “My protocol” in this example) in ScanaStudio and add this trigger sequence to a workspace as in the image below:
When you click on OK button, the function on_build_trigger
is called and the trigger sequence is effectively built. Since the script implements a call to ScanaStudio.flexitrig_print_steps()
, the following printout should be visible in ScanaStudio log (console):
[My Protocol Trigger] ** Trigger steps printout, total 2 steps
[My Protocol Trigger] Step index, Description, Tmin, Tmax
[My Protocol Trigger] Step (1): XXXR N/A N/A
[My Protocol Trigger] Step (2): XXXR 1.00e-04 N/A
This simply shows the two trigger steps created by the script. The two steps define a Rising edge on the first channel (channel 0). The first step has no any time constraints on Tmin or Tmax (which is normal, since it’s the first step), the second trigger step though, defines a 0.1 ms maximum time constraint between this step and the previous step. A maximum time of 0.1 ms means a minimum frequency of 10 KHz.