Incremental Encoder Module

This module provides a Service that will read and process the data coming from your Incremental Encoder Feedback Sensor.

This service can run independently but is meant to be used by the Position Feedback Module that is why it uses the same communication interface.

The Service should always run over an IFM tile so it can access the ports to your SOMANET IFM device.

../../../../../_images/core-diagram-qe-interface.png

How to use

Important

We assume that you are using SOMANET Base and your app includes the required board support files for your SOMANET device.

See also

You might find useful the QEI Encoder Interface Test example app, which illustrates the use of this module.

  1. First, add all the SOMANET Motor Control modules to your app Makefile.

    USED_MODULES = configuration_parameters module_biss_encoder lib_bldc_torque_control module_board-support module_hall_sensor module_shared_memory module_utils module_position_feedback module_incremental_encoder module_encoder_rem_14 module_encoder_rem_16mt module_serial_encoder module_spi_master
    

    Note

    Not all modules will be required, but when using a library it is recommended to include always all the contained modules. This will help solving internal dependency issues.

  2. Include the Encoder Service header qei_service.h in your app.

  3. Instantiate the ports where the Service will be reading the Encoder Sensor feedback signals.

    The QEI service uses qei_hall_port 1 or 2 depending on the configuration. The ports structures are defined in position_feedback_service.h. On some boards the p_hall_enc_select is also used to select the input port configuration between RS422 (differential) and TTL.

  4. Inside your main function, instantiate the interfaces array for the Service-Clients communication.

  5. Optionally, instantiate the shared memory interface.

  6. At your IFM tile, instantiate the Service. For that, first you will have to fill up your Service configuration.

    The QEI sensor has some specific parameters. index_type to select if the encoder has a index pulse. signal_type to select the input port configuration between RS422 (differential) and TTL. port_number to select the input port number. You still need to fill up all the generic sensor parameters especially ifm_usec, resolution, velocity_compute_period and sensor_function.

  7. At whichever other core, now you can perform calls to the Encoder Service through the interfaces connected to it.

    #include <CORE_C22-rev-a.bsp>   //Board Support file for SOMANET Core C22 device
    #include <IFM_DC100-rev-b.bsp>  //Board Support file for SOMANET IFM DC100 device
                                    //(select your board support files according to your device)
    
    // 2. Include the Hall Service header
    #include <qei_service.h>
    
    // 3. Instantiate the ports needed for the sensor.
    QEIHallPort qei_hall_port_1 = SOMANET_IFM_HALL_PORTS;
    QEIHallPort qei_hall_port_2 = SOMANET_IFM_QEI_PORTS;
    HallEncSelectPort hall_enc_select_port = SOMANET_IFM_QEI_PORT_INPUT_MODE_SELECTION;
    
    
    int main(void)
    {
        // 4. Instantiate the interfaces array for the Service-Clients communication.
        interface PositionFeedbackInterface i_position_feedback_1[3];
    
        // 5. Instantiate the shared memory interface.
        interface shared_memory_interface i_shared_memory[3];
    
        par
        {
    
            on tile[IFM_TILE]: par {
                // 5. Start the shared memory service
                shared_memory_service(i_shared_memory, 3);
    
                // 6. Fill up your Service configuration and instantiate the Service.
                /* Position feedback service */
                {
                    //set default parameters
                    PositionFeedbackConfig position_feedback_config;
                    position_feedback_config.sensor_type = QEI_SENSOR;
                    position_feedback_config.polarity    = NORMAL_POLARITY;
                    position_feedback_config.resolution  = QEI_SENSOR_RESOLUTION;
                    position_feedback_config.ifm_usec    = IFM_TILE_USEC;
                    position_feedback_config.max_ticks   = SENSOR_MAX_TICKS;
                    position_feedback_config.velocity_compute_period = QEI_SENSOR_VELOCITY_COMPUTE_PERIOD;
                    position_feedback_config.sensor_function = SENSOR_FUNCTION_COMMUTATION_AND_MOTION_CONTROL;
    
                    position_feedback_config.qei_config.index_type  = QEI_SENSOR_INDEX_TYPE;
                    position_feedback_config.qei_config.signal_type = QEI_SENSOR_SIGNAL_TYPE;
                    position_feedback_config.qei_config.port_number = QEI_SENSOR_PORT_NUMBER;
    
                    position_feedback_service(qei_hall_port_1, qei_hall_port_2, null, null, null, null, null, null,
                            position_feedback_config, i_shared_memory[0], i_position_feedback_1,
                            null, null, null);
                }
            }
    
            on tile[APP_TILE]:
            {
                int count_1, position_1, angle_1, velocity_1;
                int count_2, position_2, status_2, angle_2, velocity_2;
    
                // 7. Call to the Position Feddback Service through the interfaces connected to it.
                /* get position from Sensor 1 */
                { count_1, position_1, void } = i_position_feedback_1[0].get_position();
                angle_1 = i_position_feedback_1[0].get_angle();
                velocity_1 = i_position_feedback_1[0].get_velocity();
    
                // 7. You can also read the position using the shared memory.
                UpstreamControlData upstream_control_data = i_shared_memory[2].read();
                angle_1 = upstream_control_data.angle;
                count_1 = upstream_control_data.position;
                velocity_1 = upstream_control_data.velocity;
            }
        }
    
        return 0;
    }
    

API

Types

QEI_SignalType

Type for the kind of Encoder output signals.

Enum Values:

QEI_RS422_SIGNAL

Encoder signal output over RS422 (differential).

QEI_TTL_SIGNAL

Encoder signal output over standard TTL signal.

QEI_IndexType

Type for the sort of Encoder index.

2 is for two signals A and B 3 is for three signals A, B and I for index

Enum Values:

QEI_WITH_NO_INDEX

Encoder with no index signal.

QEI_WITH_INDEX

Encoder with index signal.

QEIConfig

Structure type to define the Encoder configuration.

Structure Members:

QEI_IndexType number_of_channels

Encoder index type.

QEI_SignalType signal_type

Encoder output signal type.

EncoderPortNumber port_number

Configure which input port is used.

PositionFeedbackConfig

Configuration structure of the position feedback service.

Structure Members:

SensorType sensor_type

Select the sensor type.

SensorFunction sensor_function

Select which data to write to shared memory.

SensorPolarity polarity

Encoder polarity.

UsecType ifm_usec

Number of clock ticks in a microsecond >

int pole_pairs

Number of pole pairs.

int resolution

Number of ticks per turn.

int offset

Offset (in ticks) added to the absolute multiturn position (count).

Does not affect the electrical angle

int max_ticks

The multiturn position is reset to 0 when reached.

int velocity_compute_period

Velocity compute period in microsecond.

Is also the polling period to write to the shared memory

BISSConfig biss_config

BiSS sensor configuration.

REM_16MTConfig rem_16mt_config

REM 16MT sensor configuration.

REM_14Config rem_14_config

REM 14 configuration.

QEIConfig qei_config

QEI sensor configuration.

HallConfig hall_config

Hall sensor configuration.

GPIOType gpio_config

GPIO configuration.

QEIHallPort

Structure for Hall/QEI input ports (can also be used for BiSS)

Structure Members:

in port p_qei_hall

4-bit Port for Encoder, BiSS or Hall signals input.

HallEncSelectPort

Structure for the hall_enc_select port used to select the mode (differential or not) of Hall/qei ports.

Also used for the BiSS clock output

Structure Members:

out port p_hall_enc_select

[Nullable] Port to control the signal input circuitry (if applicable in your SOMANET device).

Also used for the BiSS clock output

Service

void qei_service(QEIHallPort &qei_hall_port, port *(& ?gpio_ports)[4], PositionFeedbackConfig &position_feedback_config, client interface shared_memory_interface ?i_shared_memory, server interface PositionFeedbackInterface i_position_feedback[3], int gpio_on)

Service to read and process data from an Feedback Incremental Encoder Sensor.

Parameters:
  • qei_hall_port – Port to read the Encoder signals.
  • gpio_ports – GPIO ports array
  • position_feedback_config – Configuration for the service.
  • i_shared_memory – Client class to write the position data to the shared memory.
  • i_position_feedback – Server class used by clients for configuration and direct position read.
  • gpio_on – Set to 1 to enable GPIO read/write.