REM 16MT Encoder Module

This module provides functions to read data coming from a REM 16MT Encoder.

Those functions are used in Serial Encoder Module itself used by Position Feedback Module to create a service for reading a REM 16MT encoder.

The functions should always run over an IF2 Tile so it can access the ports to your SOMANET Drive module.

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 REM 16MT Sensor Demo, 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_adc module_encoder_rem_16mt lib_bldc_torque_control module_board-support module_hall_sensor module_utils module_position_feedback module_pwm module_incremental_encoder module_biss_encoder module_encoder_rem_14 module_serial_encoder module_shared_memory module_spi_master module_watchdog
    

    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 REM 16MT Service header rem_16mt_service.h in your app.

  3. Instantiate the ports for the REM 16MT.

    REM 16MT needs a SPIPorts structure containing two clock blocks and 4 1-bit ports for SPI.

  4. Fill up the REM 16MT configuration structure.

    The functions use the same configuration structure as the Position Feedback Module. You need to fill up all the generic sensor parameters especially ``tile_usec`. And fill up the REM 16MT specific parameters.

  5. At your IF2 tile, You can use the functions to read REM 16MT data.
    #include <CoreC2X.bsp>                          //Board Support file for SOMANET Core C2X device
    #include <Drive1000-rev-c4.bsp>     //Board Support file for SOMANET Drive module
                                        //(select your board support files according to your device)
    
    // 2. Include the REM 16MT Service header **rem_16mt_service.h** in your app.
    #include <rem_16_service.h>
    
    // 3.Instantiate the ports for the REM 16MT.
    SPIPorts spi_ports = SOMANET_DRIVE_SPI_PORTS;
    
    int main(void)
    {
        par
        {
            on tile[IF2_TILE]:
            {
                // 4. Fill up the REM 16MT configuration structure.
                PositionFeedbackConfig position_feedback_config;
                position_feedback_config.polarity    = NORMAL_POLARITY;
                position_feedback_config.pole_pairs  = POLE_PAIRS;
                position_feedback_config.tile_usec   = IF2_TILE_USEC;
                position_feedback_config.offset      = 0;
    
                position_feedback_config.rem_16mt_config.filter = REM_16MT_FILTER;
    
                // 5. Use the functions to read REM 16MT data.
                // initialize the sensor
                rem_16mt_init(spi_ports, position_feedback_config);
    
                // read REM 16MT data
                int status, count, singleturn_filtered, singleturn_raw, timestamp;
                { status, count, singleturn_filtered, singleturn_raw, timestamp } = rem_16mt_init(spi_ports, position_feedback_config.tile_usec);
    
                //reset REM 16MT position to zero
                rem_16mt_write(spi_ports, REM_16MT_CONF_NULL, 0, 0, position_feedback_config.tile_usec)
    
                //write REM 16MT filter setting
                rem_16mt_write(spi_ports, REM_16MT_CONF_FILTER, 0x02, 8, position_feedback_config.tile_usec)
    
    
            }
        }
    
        return 0;
    }
    

API

Definitions

DEFAULT_SPI_CLOCK_DIV

divisor for SPI clock frequency, (250/DIV)/2 MHz

SPI_MASTER_MODE
SPI_MASTER_SD_CARD_COMPAT

MOSI high during input.

REM_16MT_TIMEOUT

Time to wait after read in micro seconds.

REM_16MT_POLLING_TIME

Time between reads in micro seconds.

REM_16MT_CTRL_RESET

Software reset.

REM_16MT_CONF_DIR

Polarity 0=CW, 1=CCW.

REM_16MT_CONF_NULL

Reset the position to 0.

REM_16MT_CONF_PRESET

Reset both multiturn and single turn position to a new value.

REM_16MT_CONF_STPRESET

Reset singleturn position to a new value.

REM_16MT_CONF_MTPRESET

Reset multiturn position to a new value.

REM_16MT_CONF_FILTER

Filter setting.

0x00 to disable. 0x02 to 0x09 to enable. 0x09 is the strongest.

REM_16MT_CALIB_TBL_SIZE

Start a calibration with the given table size (4,8,16,...,256) This reset the offset and the polarity to 0 It is recommended to use a strong filter (0x09) during calibration.

Wait at least 200 ms before starting the first calibration point.

REM_16MT_CALIB_TBL_POINT

Setup a calibration point, the magnet should be positioned to the corresponding angle before.

The first calibration point is 0 then the angle should be increased in CW direction for each point [0 to (table size - 1)]. For example for a 4 points calibration the first point is 0°, then 90°, 180° and 270°. After sending the last point the table is saved to the flash memory.

REM_16MT_CTRL_SAVE

Save the calibration and configuration data to flash.

It is recommended to send a reset command after saving.

Types

REM_16MTConfig

Structure type to define the REM16 Sensor configuration.

Structure Members:

int filter

filter parameter for REM 16MT sensor.

0x00 to disable. 0x02 to 0x09 to enable. 0x09 is the strongest.

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 tile_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.

SPIPorts

Structure for SPI ports and clock blocks.

Structure Members:

spi_master_class spi_class
port *movable slave_select

Functions

SensorError rem_16mt_init(SPIPorts &spi_ports, PositionFeedbackConfig &config)

Initialize REM 16MT sensor.

Parameters:
  • spi_ports – the SPI ports structure
  • config – position feedback config containing the REM 16 sensor config
Returns:

status

{ SensorError, int, unsigned int, unsigned int, unsigned int } r rem_16mt_read(SPIPorts &spi_ports, UsecType tile_usec)

REM 16MT sensor position data.

Parameters:
  • spi_ports – the SPI ports structure
  • tile_usec – number of ticks in a microseconds
Returns:

status

Returns:

absolute multiturn count

Returns:

singleturn position filtered

Returns:

singleturn position raw

Returns:

timestamp

{ SensorError, int, unsigned int, unsigned int, unsigned int } r rem_16mt_read(SPIPorts &spi_ports, UsecType tile_usec)

REM 16MT sensor position data.

Parameters:
  • spi_ports – the SPI ports structure
  • tile_usec – number of ticks in a microseconds
Returns:

status

Returns:

absolute multiturn count

Returns:

singleturn position filtered

Returns:

singleturn position raw

Returns:

timestamp

void rem_16mt_write(SPIPorts &spi_ports, int opcode, int data, int data_bits, UsecType tile_usec)

Write REM 16MT command.

Parameters:
  • spi_ports – the SPI ports structure
  • opcode – the opcode of the command
  • data – the data to write
  • data_bits – the number of data bits to write
  • tile_usec – number of ticks in a microseconds