PSO Window Output

Demonstrates configuring fixed window ranges and driving the PSO output with the output of the window module.

// PSO Window Output Example:
// Demonstrates configuring fixed window ranges and driving the PSO output with the output of the window module.
// 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 window module to track primary feedback.
	PsoWindowConfigureInput($axis, $windowNumber, PsoWindowInput.XC4PrimaryFeedback, false)

	// Configure the window range: 5 to 10 absolute units.
	// To account for differences between position feedback and emulated quadrature resolution caused by the EmulatedQuadratureDivider parameter, divide the window range values by the value of this parameter.
	PsoWindowConfigureFixedRange($axis, $windowNumber, Round(UnitsToCounts($axis, 5) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)), Round(UnitsToCounts($axis, 10) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)))

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

	// Select the window output as the PSO output source.
	PsoOutputConfigureSource($axis, PsoOutputSource.WindowOutput)

	// Trigger Data Collection.
	AppDataCollectionSnapshot()

	// Move the axis 20 units, expecting the output to be on between 5 and 10 absolute units.
	MoveLinear($axis, 20)

	// Change the window range to be from 10 to 15 absolute units.
	PsoWindowConfigureFixedRange($axis, $windowNumber, Round(UnitsToCounts($axis, 10) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)), Round(UnitsToCounts($axis, 15) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)))

	// Move the axis -20 units, expecting the output to be on between 10 and 15 absolute units.
	MoveLinear($axis, 0)

	// Disable the axis.
	Disable($axis)

	// Stop Data Collection.
	AppDataCollectionStop()

end