Electronic Control Unit MARS 2 - USER GUIDE

Electronic Control Unit MARS 2 - USER GUIDE

Pavel Pa ( pisa@cmp.felk.cvut.cz )


1  Multiaxes Control System Description
2  PC Control Via RS232 Port
    2.1  Form of Commands and Requests Sent Via RS232
    2.2  Commands Description
        2.2.1  Movement to Destination Position And Movement to Reference Mark Commands
        2.2.2  Controller Parameters Setting
        2.2.3  Controller Response Tuning Support
        2.2.4  Clearing, Stopping and Controllers Release
        2.2.5  Acknowledgement of Commands Receiving and Completing
        2.2.6  Joystick and Keyboard
        2.2.7  System Status
        2.2.8  Direct Velocity Control
        2.2.9  Direct Control of Inputs and Outputs
        2.2.10  System Commands
    2.3  Configuration
    2.4  Event Triggers
3  Control Via IIC Interface
4  Manual Control
5  Connectors and Wiring

1  Multiaxes Control System Description

Electronic control unit MARS is designed for position control of DC motors (up to the amount of three)  with incremental sensors of position increment and one index mark per one motor revolve. Working area of the controlled equipment can be marked off by electromechanical terminal switches connected to power parts of the motors or by limit position sensors with logic outputs. To precise the initial position, it is possible to use terminal switches and sensors in a selectable combination with an index output.

Commands for the control unit can be inserted with the help of a selectable local keyboard or via I2C interface of the connected keyboard. From a superior computer, the commands can be transmitted via I2C interface, RS-232 or via RS-485. The control unit can be equipped with an input for a three-axes analog joystick.

In addition to the motor control, 5 digital outputs, 4 power outputs and 2 outputs galvanicaly separated from the unit electronics can be used. Index marks of motors and up to nine digital inputs can be used as digital inputs. Five of them are also usable as analog inputs 0...2.5 V with resolution of 10 bits. When using joystick, three of the inputs are used for joystick.

When a change of the input state is defined and after selection of one of four digital inputs, each of two setable event triggers can send information about the position of the controlled axes and about the state of digital inputs.  During the trigger activation it is possible to stop motion of the selected axes and set a state of digital outputs.

Unit MARS - Technical Data :

Supply voltage18 - 36VDC
Max. safe current for one motor5A
 - current protectionelectronic for each axes
Position sensor input   (IRC)2 signals out of phase +  TTL level index or RS-422
Max. frequency of IRC signals3MHz
Inputs of joystick sensors0 - 5 V
 - supposed central position2.5V
 - sensitivity of joystick sensorsrange can be adjusted for a particular joystick with the help of resistors
Fine tuning of sensitivity and zero position of joystickby software
Desired position generator trapezoidal course with settable acceleration and maximal velocity
Motors position controlsliding PID controller with nonlinear damping
Setting of P, I, and D constantsby software
Correction of power exciter non-sensitivityby software
Range of motor position 8000.000 step 0.001
 - range in periods of the IRC signal (4 phases)4000000
Absolute position calibrationautomatic search of a selectable combination of the index and terminal switches

For small and middle size position applications with high precision demands it is suitable to combine the MARS unit with MAXON RE 70 W / 42 VDC motors with HP HEDS 5540 incremental sensors with TTL outputs or HP HEDL 5540 with RS-422. These IRC sensors send 500 periods of out of phase signals per one motor revolve and are complemented by an index mark. The unit MARS can execute measurements with the accuracy of 1/2000 of one revolve, and realize position control and movement to the destination position with the accuracy of 1/2000 of one revolve.

To mark off a working area it is possible to connect terminal (limit) switches with diodes to the power outputs for motors. It ensures return from the positions behind the limit switches and quick stop when getting out of the working area.

As a power supply a feeder with a double-insulated transformer or a pulse power supply can be used. The unit MARS , all peripheries and motors are not dangerous to touch when supplied.


The electronic control unit MARS requires NO MAINTENANCE.

2  PC Control Via RS232 Port

The electronic control unit communicates with computers via serial asynchronous interface. The following configuration of the communication port is demanded: 9600 baud, 8 bits, no parity, and 2 stop-bits. Data flow control is executed with the help of hardware by signals CST and RTS. The communication speed is settable within the range from 2400 baud up to 19200 baud with the help of a local keyboard. The chosen value is loaded into the EEPROM memory along with other parameters.

2.1  Form of Commands and Requests Sent Via RS232

Each command consists of a name, operation symbol, and parameters. Individual parts of a command can be separated by spaces.

[Name]is created by an arbitrary combination of letters and numerals and always starts with a letter. Names of commands related to individual motors are supplemented with a symbol (A, B and C ) specifying the motor 'm'.
[Operation symbol]defines a command ( symbol ':' ) or a request ( symbol '?' ). The symbol '' can be used to specify acknowledgements.
[Parameter] The meaning of the parameter is determined by the command. In the next, 'xxx.xxx' represents a decimal number, 'xxx' an integer number, and 'x' is a numeral. Negative numbers begin with the symbol '-'.

Names of Individual Commands.

2.2  Commands Description

The detailed description of the individual commands is given in this section. The commands indicated by '*opt' are available only for several system configurations.

2.2.1   Movement to Destination Position And Movement to Reference Mark Commands

Gm:xxx.xxxMovement to absolute position

Moves the specified motor 'm' to the absolute position 'xxx.xxx'.

GRm:xxx.xxxMovement to relative position

Relative distance 'xxx.xxx' of the motor 'm' movement.

APm? Actual position

Returns the actual position of the specified motor 'm' ( format 'xxx.xxx' ).

HH: Reference position

Finds the reference mark and resets the position data for all motors.

HHm: Reference position of 'm'

Finds the reference mark and resets the position data for the motor 'm'.

2.2.2   Controller Parameters Setting

REGPm: ?xxxProportional gain for 'm'
REGIm: ?xxxIntegral constant for 'm'
REGDm: ?xxxDerivative constant for 'm'
REGS1m: ?xxx1. auxiliary constant for 'm'
REGS2m: ?xxx2. auxiliary constant for 'm'

These commands enable to set and read controller constants for the motor 'm'. The precise meaning of the parameters and their range depend on the type of the chosen controller for the given motor. For PID controllers , the parameters S1 and S2 serve to suppress the output exciter non-sensitivity.

REGMSm: ?xxxMaximal velocity for 'm'

This command enables to set the maximal velocity of the motor 'm' ( format 'xxx' ). The velocity parameter is used in the command of Destination Position Movement and also as a velocity limit when control is executed by joystick. The value is given directly in the IRC increment multiplied by 256 in one sampling period.

REGACCm?xxxAcceleration for motor 'm'

This command enables to set the acceleration of the motor 'm' ( format 'xxx' ). The acceleration parameter is used in the command Destination Position Movement with a trapezoidal course of velocity. In the configuration with a trapezoidal course of velocity, the parameter is used to slow down the velocity when the STOP command is applied or when the movement is interrupted by next Gm, GRm. The acceleration command can be also used to control velocity with the help of commands SPDm and SPDTm. The value determines the velocity increment per one sampling period.

REGMEm: ?xxxMaximal PWM for 'm'

The value of this parameter specifies the PWM level for motor 'm'. Reduction of the maximal PWM level reduces the maximum motor voltage represented in the percentage related to the supply voltage. In practice, this parameter is used to protect motors with the nominal voltage less than the supply voltage. The value of 32000 corresponds to the maximal voltage.

REGCFGm: ?xxxConfiguration word for 'm'

For the motor 'm', the configuration word defines a velocity course when moving from one position to another one, a way of finding of the zero position, and conversions of logical and physical coordinates. The received decadic number is interpreted as a bit field xxxxxNxTxLCRDSSS. A complete description is given in Section 2.3.

REGTYPEm:xController change for 'm'

This command changes the type of the controller for the motor 'm'. The following table shows the possible types of controllers that are implemented in the contemporary software version. According to the software modification the default type is linear PID or PID with a nonlinearity.

0Default type
1PID with nonlinearity
2Linear PID
3Discrete filter
4Relay characteristic
5Output without IRC coupling

Important warning: The contemporary software version does not enable to store the controller type into the setting in the EEPROM memory. If it is necessary to use another type of the controller for the motor than is the default controller, it is always necessary to execute a new setting after the unit switching on. According to the user demands the manufacturer is able to prepare a modified version with various default parameters and types of controllers for individual axes.

REGSFRQ: ?xSampling frequency of controllers

This command sets a sampling frequency of the control loop of all motors. The meaning of the individual values is as follows: 0 .. default, 1 .. 600 Hz, 2 .. 800 Hz 3 .. 1000 Hz, 4 .. 1200 Hz. This value is stored along with other parameters into the EEPROM memory.

2.2.3   Controller Response Tuning Support

REGDBGm:xDebugging of 'm' enabled

This command enables storage of the history of the motor 'm' motion and declares the motors which all other REGDBGxxx commands will relate to. For the motors with a set flag the actual values of velocity and values sent to the PWM generators are always stored after starting the motion.

REGDBGHIS:xxxxMotion history reading

This command reads the motion history. The parameter indicates a number of the sent numbers. Each number is sent in a separated line.

REGDBGPRE:xxxxData preprocessing for response debugging

This command stores data for motor response debugging commands into the memory. The parameter indicates the number of the stored values. The values are sent in the separated lines.

REGDBGGNS: Motor response

It controls PWM outputs of the motors with REGDBGm set to 1 according to the values stored with the help of the command REGDBGPRE. After executing the command, the command REGDBGHIS enables to read the actual course of the motor motion.

REGDBGGNR: Response of the motor control

This command sets the required change of position for motor controllers with REGDBGm set to one according to the values stored with the help of command REGDBGPRE. After executing the command, the command REGDBGHIS enables to read the actual course of the motor motion.

2.2.4   Clearing, Stopping and Controllers Release

CLEARm: Control switching off and clearing of 'm'
CLEAR: Control switching off and clearing of all motors

Switching off of the motor 'm' control and clearing the position reading.

STOPm: Stopping of the motor 'm' motion
STOP: Stopping of all motors motion

Stops the motor 'm' motion, but control goes on. When a trapezoidal course of velocity is enabled, the motion fluently slows down before it stops.

PURGE: Stops control with an error

This command stops motor control with errors and resets the errors. Other motors continue their activities.

RELEASEm: Releases control and stops 'm'
RELEASE: Releases control and stops all motors

This command releases controllers and enables a manual control or stopping motors.

2.2.5   Acknowledgement of Commands Receiving and Completing

READY:xOperation completed response

This command turns ON/OFF a message about finishing all operations. After finishing activities of all motors it sends the line 'R!' or 'FAIL!' ( in case of error flag for at least one motor ).

R: Only one operation completed response

This command sends only one 'R!' or 'FAIL!' after finishing just running operations or immediately when none of the motors is busy.

Rm: Response for a specific motor

This command sends 'Rm!' or 'FAILm!' after finishing activities of the motor 'm'.

REPLY:xCommand acknowledgement

This command turns ON/OFF confirmation of the lines by their copy. The copy starts with a backslash ''.

2.2.6   Joystick and Keyboard

KEYLOCK:xKeyboard locking

This command enables and disables control via the unit keyboard.

JOYSTICKm: Joystick control of the 'm' axis
JOYSTICK: Joystick control of all axes

Turns ON joystick control of the motor position.

JOYRESm: ?xxxJoystick axis resolution
JOYOFFSm: ?xxxCentral position offset of joystick axis
JOYHYSm: ?xxxHysteresis angle of joystick axis

For the individual joystick axes corresponding to the individual motors these commands set resolution, central position offset and hysteresis around the central position.

JOYCAL: Central position calibration

Calibration of the joystick central position (JOYOFFS) for all axes.

2.2.7   System Status

STm? Motor 'm' status

This command returns motor 'm' status. Decadic numbers need to be interpreted as bit fields.

0IRC reading enabled
1Controller enabled
2Generator enabled
4Last command execution
5Control course storage ON

ST? Status of all motors

This command returns logical addition of states of all motors.

2.2.8   Direct Velocity Control

SPDm:xxxMovement with given velocity

With this command the given velocity of the 'm' motor can be demanded. A velocity change can be executed by the acceleration command REGACCm.

SPDTm:xxx,yyyMovement with the velocity of 'xxx' continuing within the max. interval 'yyy'

With this command the given velocity of the 'm' motor can be demanded. A velocity change can be executed by the acceleration command REGACCm. The movement continues within 'yyy' sampling periods. If a next command for the given motor has not come until this time, the movement is smoothly stopped.

2.2.9   Direct Control of Inputs and Outputs

PWMm:xxxDirect PWM setting

Direct PWM output setting of the 'm' motor to the 'xxx' value.

DIGO:xxxxxDigital outputs setting

This command sets the digital outputs 0 .. 15 according to the individual bits of the parameter binary form.

DIGI? Digital input state reading

Reads the digital inputs 0 .. 15 and sends the read state as a decadic value.

ADCa? Analog input reading

Returns a value of the analog input 'a'.

TRIGt:s,m,doTrigger setting

Event triggers - for more information see Section 2.4.

2.2.10   System Commands

VER? Returns software version

This command returns the unit firmware version.

IHEXLD: Loads new software

This command loads a program in the Intel-HEX format into the RAM memory of the MARS unit.

TEST: ? Connection test

Connection checking and input or output command sheet test.

REBOOT: Unit software reboot

Resets the unit software. All parameter values are loaded from EEPROM memory again.

CFGNVSAVE: Saves parameters into EEPROM

Saves parameters settings for individual motors and sampling periods into the EEPROM memory. It guarantees that the saved parameters values will be loaded after the next switch ON of the unit.

CFGDEFAULT: Default parameters setting

Loads standard parameters setting for all motors compiled in the software by the manufacturer.

2.3   Configuration

Configuration setting for individual axes executed by the command REGCFGm determinates a course of velocity when moving from one position to another one and a way of zero position finding. The inserted decadic number is interpreted as a bit field.


The meaning of the individual flags is given in the following table.

SSSStop search speed during HH is REGMSm / 2^SSS
DInitial direction for stop search for HH
RTo find HH the revolve mark from HP HEDS is used
CMark middle search
LLimit switch usage
TTrapezoidal velocity profile usage
NCoordinates from RS232 are not converted
LCR=111Mark search only
CR=11Mark middle search only

To simplify the configuration computation, all combinations of LCR bits are given bellow. To the number it is necessary to add only 16 (D) to change the initial direction,(SSS) to reduce the stop search speed and 256 (T) for fluent starts.

0Motor limit switch search only
16Search the first revolve mark (first from the hardware terminal switch)
32Search the middle of the first revolve mark (first from the hardware terminal switch)
48Search the middle of the mark
64Search the limit switch only
80Search the first revolve mark (first from the limit switch)
96Search the middle of the first revolve mark (first from the limit switch)
112Mark search only

2.4   Event Triggers

Event trigger setting is executed by the following command:

t Trigger number (0 or 1)
s Trigger source 0 .. 3 ( -1 trigger disconnection )
s.0 s.1 Source number
s.4 Rising edge
s.5 Trailing edge
s.6 Sent input state
s.7 Set digital outputs
m Mask of the motors that should be stopped and transmission of their position
m.0 Stop A
m.1 Stop B
m.2 Stop C
m.4 Send A
m.5 Send B
m.6 Send C
do Value of digital outputs set at trigger event

Triggers transmit:

t Trigger number (0 or 1)
di Digital inputs at trigger event or "N", if transition disabled
ma,mb,mc According to the choice of m in the setting it sends the IRC position

3  Control Via IIC Interface

A message consists of an information about a type of the message and of data. Types of the I2C messages used in the unit MARS are given in the following table.

SymbolCodeType of message
IC_CMD40HCommands for motor control
IIC_TEC51HControl of IIC keyboard and a display
IIC_TEK52HInformation about pressed keys
IIC_TED53HData display

Messages of IIC_CMD type are used to send commands for position controllers, to set controller parameters, and to read position and state of individual motors. A format of a full message is shown bellow.

Write to IIC addr 10H+W
0Type of the IIC_CMD message
2Motor number
3,4,[5,6]Parameter value for given motor
Read from IIC addr 10H+R
0,1System status
2,3,[4,5]Parameter value of given motor

If the unit MARS receives a message containing only a type of the message no operation will be executed and during the next reading a system status will be sent. If the message contains only a type of the message and an operation the command will be run for all axes and a next reading will return a system status. When a motor number is added, the value of the parameter specified by the operation and the motor number are also read during the reading operation. If the message also contains a value, the value is saved into a specified parameter. The unit MARS enables to receive and read 16-bit and 32-bit parameters. Longer representations are advantageous especially for position data.

Codes for the individual operations are given in the table bellow. In the second column (Parameter) there are given the parameter values that are settable or readable for the given operation.

0Actual positionActual position reading
1Desired positionDesired position setting
2Desired positionAfter inserting the position the motion starts up
3StatusRuns hard home
4REG PSetting and reading of P constant
5REG ISetting and reading of I constant
6REG DSetting and reading of D constant
7REG MEMaximal duty of PWM
8REG MSMaximal speed of motion
9REG ACCMaximal acceleration
AREG SCMMultiplicative constant for coordinates conversion
BREG SCDDividing constant for coordinates conversion
CMin LSNot implemented
DMax LSNot implemented
EREG CFGConfiguration flags
FStatusMotor status

Flags setting for hard home is the same as the setting via RS-232 (see 2.3).

State flags read via I2C are given in the following table.

3FL_ENOVEnergy overflow for a motor start
5ERR_FLGError during control
6CMD_LCKNext command can not be received
7CMD_BSYLast command execution

4  Manual Control

The MARS control unit can be handled directly by the local keyboard or a keyboard connected via the I2C interface.

[A, B, C]Switches the display over to control individual motors: A, B, and C. Writing a number and pressing the ENTER key runs a movement to the given position. Numbers are inserted by the keys 0 .. 9 and a decimal point. Signs can be changed by the key IMPL *.*
[LIST]Displays summary data for all motors. Individual motors are accessible via cursors and .
[RUN]Enables control of all axes by joystick.
[HOLD]Runs hard home (zero position search) for all axes
[END]Disconnects controllers and sets the actual position to zero
[PURGE]Stops control with an error - other operations go on.
[MOTOR STOP]Stops all motions. Control of all motors goes on.

5  Connectors and Wiring


Figure 1: Connections layout on the unit MARS

Connector for connecting joystick

For the MARS unit, an analog joystick with three potentiometers is required. The unit connector has the following wiring:

PinSignalAlt. TTL inputDB9

In case of encasing the electronic control unit, the input of the joystick is wired to the female DB9 Canon connector.

Communication connector RS232

Cable is connected to the unit board via a crimped connector. To the control unit, a transfer connector is supplied to use standard connectors DB9 or DB25. To connect the unit to PC, the connection with DB 25V is given in the table bellow.

Board pin SignalDB9SignalDB25DB9

Connectors for connecting motors and IRC sensors

Power outputs for individual motors are accessible via MOTOR A, MOTOR B and MOTOR C connectors. Incremental sensors of position need to be connected to the unit via IRC A,IRC B and IRC C connectors.

2Phase A
3VCC +5V
4Phase B

Index inputs can be also used and read as digital inputs


Digital inputs and outputs

Connector I1
2I11 (I2)
Connector I2
2I12 (I3)
Connector I/O1
Connector I/O2
1PWR 12 - 24V

Communication I2C