PSO Array Distance Pulse Output

Demonstrates generating a sequence of pulses each time the axis moves a sequences of distances, specified in the drive array.

// PSO Array Distance Pulse Output Example:
// Demonstrates generating a sequence of pulses each time the axis moves a sequence of distances, specified in the drive array.
// 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.

#define NUM_DISTANCES 3

program

	var $axis as axis = X
	var $distances[NUM_DISTANCES] as real

	// 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])

	// Write the event distances to the drive array.
	// To account for differences between position feedback and emulated quadrature resolution caused by the EmulatedQuadratureDivider parameter, divide the distances by the value of this parameter.
	$distances[0] = UnitsToCounts($axis, 5)  / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)
	$distances[1] = UnitsToCounts($axis, 10) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)
	$distances[2] = UnitsToCounts($axis, 15) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)
	DriveArrayWrite($axis, $distances, 0, NUM_DISTANCES, DriveArrayType.PsoDistanceEventDistances)

	// Configure the distance module to generate an event at the distances specified in the drive array.
	PsoDistanceConfigureArrayDistances($axis, 0, NUM_DISTANCES, false)

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

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

	// 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 35 units, expecting 3 events.
	MoveLinear($axis, 35)

	// Disable the axis.
	Disable($axis)

	// Stop Data Collection.
	AppDataCollectionStop()

end