Chapter 4
General-Purpose Counter/Timer
©
National Instruments Corporation
4-23
DAQ-STC Technical Reference Manual
4.6.1.7 Relative Position Sensing
Relative Position Sensing is an application in which a general-purpose counter counts the
edges of its source signal, and the counting direction is controlled by a hardware input or by
software.
The only possible error condition is rollover. Rollover occurs when the counter attempts to
count below 0 (underflow) or above 0xFFFFFF hex (overflow). When rollover occurs, the
counter continues counting with the wrap-around counter value, which is defined to be
0xFFFFFF hex for underflow and 0 for overflow. The rollover condition can be checked, but
you can not tell whether the rollover was caused by underflow or overflow.
Use this function to program a counter for relative position sensing. Program the Gi_Source
to select the signal on which you want to count events. For relative position sensing controlled
by a hardware input, input the hardware up/down control signal on the G_UP_DOWNi pin.
For relative position sensing controlled by software, set Gi_Up_Down = 0 for initial down
counting or Gi_Up_Down = 1 for initial up counting. After the counter is armed, the count
direction can be changed in software by writing to Gi_Up_Down.
Function
Relative_Position_Sensing
{
Gi_Load_Source_Select = 0;
Gi_Load_A = initial counter value;
∑
Gi_Load = 1;
∑
Gi_Source_Select = 0 (G_IN_TIMEBASE1) or 1 through 10 (PFI<0..9>) or
11 through 17 (RTSI_TRIGGER<0..6>) or
18 (IN_TIMEBASE2) or 19 (other G_TC);
Gi_Source_Polarity = 0 (count rising edges) or 1 (count falling edges);
Gi_Gate_Select = 0;
Gi_OR_Gate = 0;
Gi_Output_Polarity = 0 (active low) or 1 (active high);
Gi_Gate_Select_Load_Source = 0;
Gi_Gate_Polarity = 0 (disable inversion) or 1 (enable inversion);
Gi_Output_Mode = 1 (one clock cycle output) or 2 (toggle on TC) or
3 (toggle on TC or gate);
Gi_Reload_Source_Switching = 1;
Gi_Loading_On_Gate = 0;
Gi_Loading_On_TC = 0;
Gi_Gating_Mode = 2;
Gi_Gate_On_Both_Edges = 0;
Gi_Trigger_Mode_For_Edge_Gate = 3;
Gi_Stop_Mode = 0;
Gi_Counting_Once = 0;
If (hardware controlled relative position sensing) then