4. Interfacing to the world 59
Example Code 4.4 | Encoder position read
uint position = device.Encoder.CurrentPosition; // Read counter current value
device.Encoder.Reset(); // Reset value to 0
position = device.Encoder.CurrentPosition; // Now position is 0
Note
When the encoder position is reset, the targets of all trigger modules are au-
tomatically reset too and restart counting from 0 (see Chapter 6).
The code above congures rising edge on port 2 as encoder reset source:
Example Code 4.5 | Encoder reset with external source
if (device.Encoder.ResetAvailable)
{
EncoderResetSource[] resetSources = device.Encoder.GetAvailableResetSources();
if (Array.Exists(resetSources, t => t == EncoderResetSource.External))
{
// Configure Input port 2 as Reset Input on the rising edge.
device.Encoder.ResetExternalInput = 2;
// Configure Reset as edge-sensitive.
device.Encoder.DetectResetExternalInputEdge = true;
// Reset will be performed on rising edge of input.
device.Encoder.InvertResetExternalInput = false;
// Enable external encoder reset.
device.Encoder.ResetSource = EncoderResetSource.External;
}
}
4.4.2 Frequency Multiplier (Phase Locked Loop (PLL))
When youwant to capture eventsfaster or slower than the related trigger signal frequency or longer/shorter
than the encoder step interval, you can use the NECTA camera internal frequency multiplier: signals
coming from both I/O connector and encoder module can be processed to change the acquisition fre-
quency. The multiplier detects the rising edges of the signal selected as a source and generates an
output pulse train at the resulting frequency. The output frequency f
o
is generated from the input fre-
quency f
i
according to the following formula:
f
o
= f
i
·
M
D
(4.2)
where M and D are the Multiplier and Divisor factor, respectively. The allowed frequency range for the
input signal goes from 400 Hz to 4 MHz.