Documentation search search close
CONTENTS

    Open this example in MATLAB

v10.0.1.x for R2026a
View other versions

IO3xx Quadrature - Position Control

This example demonstrates the quadrature code module functionalities using a quadrature encoder QAE v3 and a quadrature decoder QAD v5, which are both on the same I/O module connected to a loopback. This example shows in detail how to set up a position controlled QAE setup.

Setup

Prerequisites

You will require the following to run this example:
  • Speedgoat real-time target machine with one I/O module from the IO3xx family installed
  • A Speedgoat configuration file that supports at least 1 x QAD channel and 1 x QAE channel
  • Connector cable from the I/O module to the terminal board
  • Terminal board with jumper wires

Test Setup

In this example, data is sent from the QAE to the QAD. You must therefore connect the pins on the terminal board where these channels are located. The exact pins depend on the configuration file (bitstream) used.
In the pin mapping of your configuration file, locate the functionalities specified in the table below and then locate the corresponding pins on the terminal board. Connect theses pins with jumper wires.
IO3xx_Quadrature_pinWiring.png

Initialize and Open the Simulink model

% Open Simulink model
modelName = 'sgMdl_IO3xx_Quadrature_PositionControl';
open_system(modelName);
Before the Simulink model can be built, the I/O module and configuration file must be specified in the IO3xx Setup block, as this example can be executed on different configurable I/O modules. First, open the mask of the IO3xx Setup block and select your I/O module from the drop-down. Once the mask has extended, select the configuration file that supports the required functionalities.
With the Pin Mapping button you can now check where the functionalities are located.

Model Description

QAE Signal generation

In the model, the QAE generates qadrature signals as depicted in the following image (Example with 8 Slots per turn):

QAD Signal analyzing

The QAD analyzes the data as depicted in the following image (Example with 4 Slots per turn):

Model Behavior

In the example model, both the Quadrature Encoder (QAE) and the Quadrature Decoder (QAD) block are set to 8 slots per turn. The QAD block is configured to use the A and the B signal to detect the position.The index (signal "C/Index" described in the above image) is used to reset the detected position to 0.
In this model, the QAE Block is fed with a constant value on the Speed [RPM] input until 4.1s simulation time. After this time, the Speed [RPM] value is changed from a constant value to a regulated value.
This regulated value is the output of a simple p-controller that compares the current position of the QAE to a target position.
  • The current position is the sum of the outputs Position [Number of Slot] (in whole numbers) and Slot Position (fraction between 0 and 1)
  • The target position is the constant value target position
The difference between target and current position is multiplied by a constant factor which results in a speed that is feed to the QAE. With this regulation circuit, the QAE block will finally end on the targeted position.
Note that this simple p-controller will still have a small position error in the end.

Build, Download, and Run the Example

To run the example, either run the following code section or click the Run on Target button in the REAL-TIME tab in the Simulink model:
% Build the Simulink model
slbuild(modelName); % this will create the real-time application file (.mldatx)
 
% Create and connect to the Speedgoat real-time target machine
tg = slrealtime;
tg.connect;
 
% Download and install the real-time application on the target machine
tg.load(modelName);
tg.setStopTime(10);
% Connect the Simulink model with external mode to the real-time application on the target machine
set_param(modelName,'SimulationMode','external') % put model into External Mode
set_param(modelName,'SimulationCommand','connect') % connect with External Mode
% Start the real-time application
tg.start;
 
% Wait a few seconds and then stop the real-time application on the target machine
pause(10)
tg.stop;

Check the Results

To check if the loopback is working as expected, open the Simulink scope that is connected to the following signals:
  1. QaeSpeed: This is the speed value [RotationsPerMinute] of the QAE.
  2. QaePositionPrecise: This is the sum of the QAE Position (present Slot Number) and the position within the slot.
  3. QadPosition: This is the QAD position
  4. QadSpeed: This is the measured speed of the QAD.
  5. QadSpeedValid: This signal indicates when the QAD speed measurement signal is valid.

Additional References