PSO Fixed Distance Pulse Output

Demonstrates generating a sequence of pulses each time the axis moves a fixed distance.

// PSO Fixed Distance Pulse Output Example:
// Demonstrates generating a sequence of pulses each time the axis moves a fixed distance.
// 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 4000 msec.

program

	var $axis as axis = X

	// Set incremental mode.
	SetupTaskTargetMode(TargetMode.Incremental)

	// 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 10 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, 10) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)))

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

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

	// Configure waveform module in pulse mode: 3 periods per event, 20 ms total time, 10 ms on time (50% duty cycle).
	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 35 units, expecting 3 events.
	MoveLinear($axis, 35)

	// Disable the axis.
	Disable($axis)

	// Stop Data Collection.
	AppDataCollectionStop()

end