PSO Fixed Distance Bit Output

Demonstrates generating a sequence of bit values to be driven onto the PSO output each time the axis moves a fixed distance.

// PSO Fixed Distance Bit Output Example:
// Demonstrates generating a sequence of bit values to be driven onto the PSO output 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.

#define NUM_BIT_WORDS 2

program

	var $axis as axis = X
	var $bitValues[NUM_BIT_WORDS] 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])

	// Configure the distance module to generate an event every 0.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, 0.5) / ParameterGetAxisValue($axis, AxisParameter.PrimaryEmulatedQuadratureDivider)))

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

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

	// Write bit value word to drive array.
	$bitValues[0] = 0xF0F00F0F
	$bitValues[1] = 0xAAAA5555
	DriveArrayWrite($axis, $bitValues, 0, NUM_BIT_WORDS, DriveArrayType.PsoBitmapBits)

	// Configure bit data from drive array.
	PsoBitmapConfigureArray($axis, 0, NUM_BIT_WORDS, false)

	// Select the bit data as the PSO output source.
	PsoOutputConfigureSource($axis, PsoOutputSource.Bitmap)

	// Trigger Data Collection.
	AppDataCollectionSnapshot()

	// Move the axis 40 units, expecting 80 events. The first 64 events will drive each bit to the output.
	MoveLinear($axis, 40)

	// Disable the axis.
	Disable($axis)

	// Stop Data Collection.
	AppDataCollectionStop()

end