PSO Fixed Distance Event Window Mask Pulse Output

Demonstrates generating a sequence of pulses each time the axis moves a fixed distance, but only when within the specified window range.

// PSO Fixed Distance Event Window Mask Pulse Output Example:
// Demonstrates generating a sequence of pulses each time the axis moves a fixed distance, but only when within the specified window range.
// To help you visualize the behavior of the PSO output generated by this configuration, the pulse times used in this program are
// longer than would be typical and this program triggers data collection. You can use the Data Visualizer to collect the
// "OutputActive" bit of the "Pso Status" signal and the Position Feedback signal. To see the complete output from this program,
// you must collect data at a period of 1 msec and a time to collect of at least 5000 msec.

program

	var $axis as axis = X
	var $windowNumber as integer = 0

	// Set absolute mode.
	SetupTaskTargetMode(TargetMode.Absolute)

	// Enable and home the axis.
	Enable($axis)
	Home($axis)

	// Reset all PSO configuration.
	PsoReset($axis)

	// Configure the distance module to track primary feedback.
	PsoDistanceConfigureInputs($axis, [PsoDistanceInput.XC4PrimaryFeedback])

	// Configure the distance module to generate an event every 5 units.
	// To account for differences between position feedback and emulated quadrature resolution caused by the EmulatedQuadratureDivider parameter, divide the distance by the value of this parameter.
	PsoDistanceConfigureFixedDistance($axis, Round(UnitsToCounts($axis, 5) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)))

	// Enable the distance counter.
	PsoDistanceCounterOn($axis)

	// Enable distance events.
	PsoDistanceEventsOn($axis);

	// Configure the window module to track primary feedback.
	PsoWindowConfigureInput($axis, $windowNumber, PsoWindowInput.XC4PrimaryFeedback, false)

	// Configure the window range: 12.5 to 37.5 absolute units.
	// Like the distances, we must also divide the window ranges by the EmulatedQuadratureDivider parameter.
	PsoWindowConfigureFixedRange($axis, $windowNumber, Round(UnitsToCounts($axis, 12.5) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)), Round(UnitsToCounts($axis, 37.5) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)))

	// Enable the window output.
	PsoWindowOutputOn($axis, $windowNumber)

	// Configure the event mask to include the window output.
	PsoEventConfigureMask($axis, PsoEventMask.WindowMask)

	// Configure waveform module in pulse mode: 20 ms total time, 10 ms on time (50% duty cycle), 3 periods per event.
	PsoWaveformConfigureMode($axis, PsoWaveformMode.Pulse)
	PsoWaveformConfigurePulseFixedTotalTime($axis, 20000)
	PsoWaveformConfigurePulseFixedOnTime($axis, 10000)
	PsoWaveformConfigurePulseFixedCount($axis, 3)
	PsoWaveformApplyPulseConfiguration($axis)
	PsoWaveformOn($axis)

	// Select the waveform module output as the PSO output source.
	PsoOutputConfigureSource($axis, PsoOutputSource.Waveform)

	// Trigger Data Collection.
	AppDataCollectionSnapshot()

	// Move the axis 50 units, expecting 5 events to occur within the window range.
	MoveLinear($axis, 50)

	// Disable the axis.
	Disable($axis)

	// Stop Data Collection.
	AppDataCollectionStop()

end