linuxcnc EMC2 Users Manual

Page 1
Integrators Manual V2.4
The EMC Team
December 9, 2011
Page 2
EMC V2.4 Integrator Manual
This manual is a work in progress. If you are able to help with writing, editing, or graphic preparation please contact any member of the writing team or join and send an email to emc­users@lists.sourceforge.net.
Copyright (c) 2000-9 LinuxCNC.org
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU
Free Documentation License, Version 1.1 or any later version published by the Free Software
EMC Handbook is the product of several authors writing for linuxCNC.org. As you find it to be of
value in your work, we invite you to contribute to its revision and growth." A copy of the license is
included in the section entitled "GNU Free Documentation License". If you do not find the license
you may order a copy from Free Software Foundation, Inc. 59 Temple Place, Suite 330 Boston, MA
02111-1307
I
Page 3
Contents
Cover I
1 Important Concepts 1
1.1 Stepper Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Base Period . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 Step Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Servos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.1 Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.2 Proportional term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.3 Integral term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2.4 Derivative term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.5 Loop tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.6 Manual tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 RTAI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
I Configuration 4
2 Hardware 5
2.1 Latency Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Port Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3 Config Files 8
3.1 Files Used for Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 INI File 9
4.1 The INI File Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.1 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.1.2 Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.3 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.1.4 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
II
Page 4
EMC V2.4 Integrator Manual CONTENTS
4.2.1 [EMC] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2.2 [DISPLAY] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2.3 [FILTER] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2.4 [RS274NGC] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2.5 [EMCMOT] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.6 [TASK] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.7 [HAL] section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.2.8 [TRAJ] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2.9 [AXIS_<num>] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2.9.1 Homing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2.9.2 Servo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.2.9.3 Stepper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2.10[EMCIO] Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Homing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3.2 Homing Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3.3 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3.3.1 HOME_SEARCH_VEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3.3.2 HOME_LATCH_VEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.3.3.3 HOME_FINAL_VEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.3.4 HOME_IGNORE_LIMITS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.3.5 HOME_USE_INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.3.6 HOME_OFFSET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.3.7 HOME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.3.8 HOME_IS_SHARED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.3.3.9 HOME_SEQUENCE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
4.4 Lathe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.4.1 Default Plane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.4.2 INI Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
5 EMC2 and HAL 27
5.1 motion (realtime) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.1.1 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.1.2 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.1.3 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.1.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.2 axis.N (realtime) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2.1 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2.2 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3 iocontrol (userspace) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
5.3.1 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
III
Page 5
EMC V2.4 Integrator Manual CONTENTS
II HAL 32
6 Getting Started 33
6.1 Hal Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
6.1.1 loadrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.1.2 addf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.1.3 loadusr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.1.4 net . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.1.5 setp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1.6 unlinkp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1.7 Obsolete Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1.7.1 linksp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1.7.2 linkps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.1.7.3 newsig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.2 Hal Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2.1 Bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2.2 Float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2.3 s32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.2.4 u32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.3 Hal Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.4 HAL Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.5 Logic Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.5.1 and2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.5.2 not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.5.3 or2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.5.4 xor2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.5.5 Logic Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6 Conversion Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6.1 weighted_sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.7 Halshow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.7.1 Starting Halshow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.7.2 Hal Tree Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.7.3 Hal Show Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.7.4 Hal Watch Area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
IV
Page 6
EMC V2.4 Integrator Manual CONTENTS
7 Basic Configuration 48
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.2 Maximum step rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.3 Pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
7.3.1 standard_pinout.hal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7.3.2 Overview of the standard_pinout.hal . . . . . . . . . . . . . . . . . . . . . . . . . . 50
7.3.3 Changing the standard_pinout.hal . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.3.4 Changing the polarity of a signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.3.5 Adding PWM Spindle Speed Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
7.3.6 Adding an enable signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
7.3.7 Adding an external ESTOP button . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
8 HAL Components 53
8.1 Commands and Userspace Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
8.2 Realtime Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.2.1 abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.2.2 and2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.2.3 at_pid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
8.2.4 axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2.5 biquad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2.6 bldc_hall3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2.7 blend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2.8 charge_pump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
8.2.9 clarke2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
8.2.10clarke3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
8.2.11clarkeinv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
8.2.12classicladder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.13comp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.14constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.15conv_bit_s32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.16conv_bit_u32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.17conv_float_s32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.18conv_float_u32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.19conv_s32_bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.20conv_s32_float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.21conv_s32_u32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.22conv_u32_bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
8.2.23conv_u32_float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.24conv_u32_s32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
V
Page 7
EMC V2.4 Integrator Manual CONTENTS
8.2.25counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.26ddt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.27deadzone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.28debounce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.29edge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.30encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.31encoder_ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.32estop_latch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.33feedcomp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
8.2.34flipflop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.35freqgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.36gantrykins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.37gearchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.38genhexkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.39genserkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.40hm2_7i43 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.41hm2_pci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.42hostmot2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.43hypot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.44ilowpass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
8.2.45integ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.46invert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.47joyhandle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.48kins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.49knob2float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.50limit1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.51limit2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.52limit3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.53logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.54lowpass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.55lut5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
8.2.56maj3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.57match8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.58maxkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.59minmax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.60motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.61mult2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.62mux2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
VI
Page 8
EMC V2.4 Integrator Manual CONTENTS
8.2.63mux4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.64mux8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.65near . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.66not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
8.2.67offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.68oneshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.69or2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.70pid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.71pluto_servo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.72pluto_step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.73pwmgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.74rotatekins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.75sample_hold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.76sampler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.77scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2.78scarakins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.79select8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.80serport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.81siggen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.82sim_encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.83sphereprobe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.84stepgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.85steptest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.86streamer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.87sum2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.88supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.2.89thc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.90threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.91threadtest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.92timedelay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.93timedelta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.94toggle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.95toggle2nist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.96tripodkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.97tristate_bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.98tristate_float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.99trivkins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.2.100updown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
VII
Page 9
EMC V2.4 Integrator Manual CONTENTS
8.2.101wcomp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.2.102weighted_sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.2.103xor2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
8.3 Hal Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.4 Stepgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.4.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.4.2 Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.4.3 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
8.4.4 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
8.4.5 Step Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
8.4.6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
8.5 PWMgen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.5.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.5.2 Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.5.3 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
8.5.4 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.5.5 Output Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.5.6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
8.6 Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.6.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.6.2 Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
8.6.3 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
8.6.4 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.6.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
8.7 PID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.7.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.7.2 Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.7.3 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
8.7.4 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.7.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.8 Simulated Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.8.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.8.2 Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.8.3 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.8.4 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.8.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
8.9 Debounce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.9.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
VIII
Page 10
EMC V2.4 Integrator Manual CONTENTS
8.9.2 Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.9.3 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.9.4 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.9.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
8.10Siggen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.10.1Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.10.2Removing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.10.3Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.10.4Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.10.5Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
9 Parallel Port 87
9.1 Parport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.1.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
9.1.2 Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
9.1.3 Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
9.1.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
9.1.5 Common problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
9.1.6 Using DoubleStep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
9.2 probe_parport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
9.2.1 Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
10 Hal User Interface 92
10.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
10.2Halui pin reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
10.2.1Abort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
10.2.2Axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
10.2.3E-Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
10.2.4Feed Override . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10.2.5Flood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10.2.6Homing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10.2.7Jog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
10.2.8Joint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
10.2.9Lube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
10.2.10Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
10.2.11Max Velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
10.2.12MDI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
10.2.13Mist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
10.2.14Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
10.2.15Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
10.2.16Spindle Override . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
10.2.17Spindle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
10.2.18Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
IX
Page 11
EMC V2.4 Integrator Manual CONTENTS
11 HAL Examples 98
11.1Manual Toolchange . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
11.2Compute Velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
11.3Soft Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
12 Virtual Control Panel 103
12.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
12.2Panel Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
12.3Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
12.4AXIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
12.5Stand Alone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
12.6Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
12.6.1Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
12.6.2LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
12.6.2.1Round LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
12.6.2.2Rectangle LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
12.6.3Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
12.6.3.1Text Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
12.6.3.2Checkbutton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
12.6.3.3Radiobutton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
12.6.4Number Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
12.6.4.1Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
12.6.4.2s32 Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
12.6.4.3u32 Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
12.6.4.4Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
12.6.4.5Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
12.6.5Number Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
12.6.5.1Spinbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
12.6.5.2Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
12.6.5.3Dial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
12.6.5.4Jogwheel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.6.6Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
12.6.6.1Image Bit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
12.6.6.2Image u32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
12.6.7Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
12.6.7.1Borders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
12.6.7.2Hbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
12.6.7.3Vbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
12.6.7.4Labelframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
12.6.7.5Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
12.6.7.6Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
X
Page 12
EMC V2.4 Integrator Manual CONTENTS
13 VCP Examples 122
13.1AXIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
13.2Floating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
13.3Jog Buttons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
13.4Port Tester . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
13.5GS2 RPM Meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
III Hardware Drivers 134
14 AX5214H 135
14.1Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
14.2Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
14.3Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
14.4Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
15 GS2 VFD 137
16 Mesa HostMot2 139
16.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
16.2Firmware Binaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
16.3Installing Firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
16.4Loading HostMot2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
16.5Watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
16.6HostMot2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
16.7Pinouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
16.8PIN Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
16.9Firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
16.10HAL Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
16.11Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
16.12GPIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
16.13StepGen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
16.14PWMGen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
16.15Encoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
16.16Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
XI
Page 13
EMC V2.4 Integrator Manual CONTENTS
17 m5i20 150
17.1Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
17.2Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
17.3Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
17.4Connector pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
17.4.1Connector P2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
17.4.2Connector P3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
17.4.3Connector P4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
17.4.4LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
18 Motenc 155
18.1Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
18.2Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
18.3Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
19 OPTO22 PCI 157
19.1The Adapter Card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
19.2The Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
19.3PINS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
19.4PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
19.5FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
19.6Configuring I/O Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
19.7Pin Numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
20 Pico PPMC 160
20.0.1Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
20.0.2Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
20.0.3Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
21 Pluto-P 163
21.1General Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
21.1.1Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
21.1.2Connectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
21.1.3Physical Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
21.1.4LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
21.1.5Power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
21.1.6PC interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
21.1.7Rebuilding the FPGA firmware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
21.1.8For more information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
21.2pluto-servo: Hardware PWM and quadrature counting . . . . . . . . . . . . . . . . . . . . 165
XII
Page 14
EMC V2.4 Integrator Manual CONTENTS
21.2.1Pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
21.2.2Input latching and output updating . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
21.2.3HAL Functions, Pins and Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 167
21.2.4Compatible driver hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
21.3Pluto-step: 300kHz Hardware Step Generator . . . . . . . . . . . . . . . . . . . . . . . . . 167
21.3.1Pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
21.3.2Input latching and output updating . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
21.3.3Step Waveform Timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
21.3.4HAL Functions, Pins and Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 169
22 Servo-To-Go 170
22.0.5Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
22.1Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
22.2Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
22.2.1Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
IV Advanced topics 172
23 Kinematics in EMC2 173
23.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
23.1.1Joints vs. Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
23.2Trivial Kinematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
23.3Non-trivial kinematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
23.3.1Forward transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
23.3.2Inverse transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
23.4Implementation details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
V Tuning 177
24 Stepper Tuning 178
24.1Getting the most out of Software Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
24.1.1Run a Latency Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
24.1.2Figure out what your drives expect . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
24.1.3Choose your BASE_PERIOD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
24.1.4Use steplen, stepspace, dirsetup, and/or dirhold . . . . . . . . . . . . . . . . . . . 181
24.1.5No Guessing! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
25 PID Tuning 183
25.1PID Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
25.1.1Control loop basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
25.1.2Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
25.1.3Loop Tuning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
XIII
Page 15
EMC V2.4 Integrator Manual CONTENTS
VI Ladder Logic 186
26 Ladder programming 187
26.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
26.2Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
27 Classic Ladder 189
27.1Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
27.2Ladder Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
27.3Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
27.4Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
27.4.1Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
27.4.2Realtime Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
27.4.3Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
27.5Loading the Classic Ladder user module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
27.6Classic Ladder GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
27.6.1Sections Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
27.6.2Section Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
27.6.3The Variable Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
27.6.4Symbol Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
27.6.5The Editor window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
27.6.6Config Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
27.7Ladder objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
27.7.1CONTACTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
27.7.2IEC TIMERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
27.7.3TIMERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
27.7.4MONOSTABLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
27.7.5COUNTERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
27.7.6COMPARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
27.7.7VARIABLE ASSIGNMENT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
27.7.8COILS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
27.7.8.1JUMP COIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
27.7.8.2CALL COIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
27.8Classic Ladder Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
27.9GRAFCET Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
27.10Modbus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
27.10.1MODBUS Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
27.10.2MODBUS Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
27.10.3Communication Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
XIV
Page 16
EMC V2.4 Integrator Manual CONTENTS
27.10.4MODBUS Bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
27.11Setting up Classic Ladder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
27.11.1Add the Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
27.11.2Adding Ladder Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
27.12Ladder Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
27.12.1Wrapping Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
27.12.2Reject Extra Pulses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
27.12.3External E-Stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
27.12.4Timer/Operate Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
27.12.5Tool Turret . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
27.12.6Sequential Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
VII Hardware Examples 222
28 Second Parallel Port 223
29 Spindle Control 224
29.10-10v Spindle Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
29.2PWM Spindle Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
29.3Spindle Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
29.4Spindle Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
29.5Spindle Soft Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
30 Spindle Feedback 226
30.1Spindle Synchronized Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
30.2Spindle At Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
31 MPG Pendant 228
32 GS2 Spindle 230
VIII Diagnostics 231
33 Steppers 232
33.1Common Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
33.1.1Stepper Moves One Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
33.1.2No Steppers Move . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
33.1.3Distance Not Correct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
33.2Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
33.2.1Following Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
33.2.2RTAPI Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
33.3Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
33.3.1Step Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
XV
Page 17
EMC V2.4 Integrator Manual CONTENTS
IX FAQ 235
34 Linux FAQ 236
34.1Automatic Login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
34.2Automatic Startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
34.3Man Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
34.4List Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.5Editing a Root File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.5.1The Command Line Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.5.2The GUI Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.5.3Root Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.6Terminal Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.6.1Working Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
34.6.2Changing Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
34.6.3Listing files in a directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
34.6.4Finding a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
34.6.5Searching for Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
34.6.6Bootup Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
34.7Convenience Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
34.7.1Terminal Launcher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
34.8Hardware Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
34.8.1Hardware Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
34.8.2Monitor Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
X Appendices 240
35 Glossary 241
36 Legal Section 245
36.1Copyright Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
36.2GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
XVI
Page 18
Chapter 1

Important Concepts

1.1 Stepper Systems

1.1.1 Base Period

BASE_PERIOD is the "heartbeat" of your EMC computer. Every period, the software step generator decides if it is time for another step pulse. A shorter period will allow you to generate more pulses per second, within limits. But if you go too short, your computer will spend so much time generating step pulses that everything else will slow to a crawl, or maybe even lock up. Latency and stepper drive requirements affect the shortest period you can use.
Worst case latencies might only happen a few times a minute, and the odds of bad latency happening just as the motor is changing direction are low. So you can get very rare errors that ruin a part every once in a while and are impossible to troubleshoot.
The simplest way to avoid this problem is to choose a BASE_PERIOD that is the sum of the longest timing requirement of your drive, and the worst case latency of your computer. This is not always the best choice for example if you are running a drive with a 20uS hold time requirement, and your latency test said you have a maximum latency of 11uS, then if you set the BASE_PERIOD to 20+11 = 31uS and a not-so-nice 16,129 steps per second.
The problem is with the 20uS hold time requirement. That plus the 11uS latency is what forces us to use a slow 31uS period. But the EMC2 software step generator has some parameters that let you increase the various time from one period to several. For example, if steplen is changed from 1 to 2, then it there will be two periods between the beginning and end of the step pulse. Likewise, if dirhold is changed from 1 to 3, there will be at least three periods between the step pulse and a change of the direction pin.
If we can use dirhold to meet the 20uS hold time requirement, then the next longest time is the
4.5uS high time. Add the 11uS latency to the 4.5uS high time, and you get a minimum period of
15.5uS. When you try 15.5uS, you find that the computer is sluggish, so you settle on 16uS. If we leave dirhold at 1 (the default), then the minimum time between step and direction is the 16uS period minus the 11uS latency = 5uS, which is not enough. We need another 15uS. Since the period is 16uS, we need one more period. So we change dirhold from 1 to 2. Now the minimum time from the end of the step pulse to the changing direction pin is 5+16=21uS, and we don’t have to worry about the drive stepping the wrong direction because of latency.
For more information on stepgen see Section (8.4).

1.1.2 Step Timing

Step Timing and Step Space on some drives are different. In this case the Step point becomes important. If the drive steps on the falling edge then the output pin should be inverted.
1
Page 19
EMC V2.4 Integrator Manual Chapter 1. Important Concepts

1.2 Servos

1.2.1 Tuning

Servo systems must be "tuned" as they don’t quite work out of the box like a stepper system might. This is because servos don’t "step" in fixed increments like steppers do. PID is the "Black Magic" that makes your servos move where you want them to move and when you want them to move.
PID stand for Proportional, Integral, and Derivative. The Proportional value determines the reaction to the current error, the Integral value determines the reaction based on the sum of recent errors, and the Derivative value determines the reaction based on the rate at which the error has been changing. They are three common mathematical techniques that are applied to the task of getting a working process to follow a set point. In the case of EMC the process we want to control is actual axis position and the set point is the commanded axis position.
Figure 1.1: PID Loop
By "tuning" the three constants in the PID controller algorithm, the controller can provide control action designed for specific process requirements. The response of the controller can be described in terms of the responsiveness of the controller to an error, the degree to which the controller overshoots the set point and the degree of system oscillation.

1.2.2 Proportional term

The proportional term (sometimes called gain) makes a change to the output that is proportional to the current error value. A high proportional gain results in a large change in the output for a given change in the error. If the proportional gain is too high, the system can become unstable. In contrast, a small gain results in a small output response to a large input error. If the proportional gain is too low, the control action may be too small when responding to system disturbances.
In the absence of disturbances, pure proportional control will not settle at its target value, but will retain a steady state error that is a function of the proportional gain and the process gain. Despite the steady-state offset, both tuning theory and industrial practice indicate that it is the proportional term that should contribute the bulk of the output change.

1.2.3 Integral term

The contribution from the integral term (sometimes called reset) is proportional to both the mag­nitude of the error and the duration of the error. Summing the instantaneous error over time (integrating the error) gives the accumulated offset that should have been corrected previously. The accumulated error is then multiplied by the integral gain and added to the controller output.
The integral term (when added to the proportional term) accelerates the movement of the process towards set point and eliminates the residual steady-state error that occurs with a proportional
2
Page 20
EMC V2.4 Integrator Manual Chapter 1. Important Concepts
only controller. However, since the integral term is responding to accumulated errors from the past, it can cause the present value to overshoot the set point value (cross over the set point and then create a deviation in the other direction).

1.2.4 Derivative term

The rate of change of the process error is calculated by determining the slope of the error over time (i.e. its first derivative with respect to time) and multiplying this rate of change by the derivative gain.
The derivative term slows the rate of change of the controller output and this effect is most noticeable close to the controller set point. Hence, derivative control is used to reduce the magnitude of the overshoot produced by the integral component and improve the combined controller -process stability.

1.2.5 Loop tuning

If the PID controller parameters (the gains of the proportional, integral and derivative terms) are chosen incorrectly, the controlled process input can be unstable, i.e. its output diverges, with or without oscillation, and is limited only by saturation or mechanical breakage. Tuning a control loop is the adjustment of its control parameters (gain/proportional band, integral gain/reset, derivative gain/rate) to the optimum values for the desired control response.

1.2.6 Manual tuning

A simple tuning method is to first set the I and D values to zero. Increase the P until the output of the loop oscillates, then the P should be set to be approximately half of that value for a "quarter amplitude decay" type response. Then increase I until any offset is correct in sufficient time for the process. However, too much I will cause instability. Finally, increase D, if required, until the loop is acceptably quick to reach its reference after a load disturbance. However, too much D will cause excessive response and overshoot. A fast PID loop tuning usually overshoots slightly to reach the set point more quickly; however, some systems cannot accept overshoot, in which case an "over­damped" closed-loop system is required, which will require a P setting significantly less than half that of the P setting causing oscillation.

1.3 RTAI

The Real Time Application Interface (RTAI) is used to provide the best Real Time (RT) performance. The RTAI patched kernel lets you write applications with strict timing constraints. RTAI gives you the ability to have things like software step generation which require precise timing.
ACPI
The Advanced Configuration and Power Interface (ACPI) has a lot of different functions, most of which interfere with RT performance (for example: power management, CPU power down, CPU fre­quency scaling, etc). The EMC2 kernel (and probably all RTAI-patched kernels) has ACPI disabled. ACPI also takes care of powering down the system after a shutdown has been started, and that’s why you need to push the power button to completely turn off your computer.
3
Page 21
Part I
Configuration
4
Page 22
Chapter 2

Hardware

2.1 Latency Test

Latency is how long it takes the PC to stop what it is doing and respond to an external request. For EMC2 the request is BASE_THREAD that makes the periodic "heartbeat" that serves as a timing reference for the step pulses. The lower the latency, the faster you can run the heartbeat, and the faster and smoother the step pulses will be.
Latency is far more important than CPU speed. A lowly Pentium II that responds to interrupts within 10 microseconds each and every time can give better results than the latest and fastest P4 Hyperthreading beast.
The CPU isn’t the only factor in determining latency. Motherboards, video cards, USB ports, and a number of other things can hurt the latency. The best way to find out what you are dealing with is to run the RTAI latency test.
Generating step pulses in software has one very big advantage - it’s free. Just about every PC has a parallel port that is capable of outputting step pulses that are generated by the software. However, software step pulses also have some disadvantages:
limited maximum step rate
jitter in the generated pulses
loads the CPU
The best way to find out what you are dealing with is to run the HAL latency test. To run the test, open a terminal window from Applications/Accessories/Terminal (Ubuntu) and run the following command:
latency-test
You should see something like this:
5
Page 23
EMC V2.4 Integrator Manual Chapter 2. Hardware
While the test is running, you should "abuse" the computer. Move windows around on the screen. Surf the web. Copy some large files around on the disk. Play some music. Run an OpenGL program such as glxgears. The idea is to put the PC through its paces while the latency test checks to see what the worst case numbers are.
NOTE: Do not run EMC2 or Stepconf while the latency test is running.
The important numbers are the "max jitter". In the example above, that is 7555 nanoseconds, or
7.5 microseconds. Record this number, and enter it in Stepconf when it is requested.
In the example above, latency-test only ran for a few seconds. You should run the test for at least several minutes; sometimes the worst case latency doesn’t happen very often, or only happens when you do some particular action. For instance, one Intel motherboard worked pretty well most of the time, but every 64 seconds it had a very bad 300uS latency. Fortunately that was fixable see
http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?FixingSMIIssues
So, what do the results mean? If your Max Jitter number is less than about 15-20 microseconds (15000-20000 nanoseconds), the computer should give very nice results with software stepping. If the max latency is more like 30-50 microseconds, you can still get good results, but your maximum step rate might be a little disappointing, especially if you use microstepping or have very fine pitch leadscrews. If the numbers are 100uS or more (100,000 nanoseconds), then the PC is not a good candidate for software stepping. Numbers over 1 millisecond (1,000,000 nanoseconds) mean the PC is not a good candidate for EMC, regardless of whether you use software stepping or not.
Note that if you get high numbers, there may be ways to improve them. Another PC had very bad latency (several milliseconds) when using the onboard video. But a $5 used video card solved the problem - EMC does not require bleeding edge hardware.
For more information on stepper tuning see the Stepper Tuning chapter (24).

2.2 Port Address

For those who build their own hardware, one safeguard against shorting out an on-board parallel port - or even the whole motherboard - is to use an add-on parallel port card. Even if you don’t need the extra layer of safety, a parport card is a good way to add extra I/O lines with EMC.
One good PCI parport card is made with the Netmos 9815 chipset. It has good +5V signals, and can come in a single or dual ports.
To find the I/O addresses for these cards open a terminal window and use the list pci command:
lspci -v
Look for the entry with "NetMos" in it. Example of a 2-port card:
0000:01:0a.0 Communication controller: Netmos Technology PCI 9815 Multi-I/O Controller (rev 01)
Subsystem: LSI Losgic / Symbios Logic 2POS (2 port parallel adapter) Flags: medium devsel, IRQ 5
I/O ports at b800 [size=8] I/O ports at bc00 [size=8] I/O ports at c000 [size=8] I/O ports at c400 [size=8] I/O ports at c800 [size=8] I/O ports at cc00 [size=16]
From experimentation, I’ve found the first port (the on-card port) uses the third address listed (c000), and the second port (the one that attaches with a ribbon cable) uses the first address listed (b800).
You can then open an editor and put the addresses into the appropriate place in your .hal file.
6
Page 24
EMC V2.4 Integrator Manual Chapter 2. Hardware
loadrt hal_parport cfg="0x378 0xc000"
You must also direct EMC to run the "read" and "write" functions for the second card. For example,
addf parport.1.read base-thread 1 addf parport.1.write base-thread -1
Please note that your values will differ. The Netmos cards are Plug-N-Play, and might change their settings depending on which slot you put them into, so if you like to ’get under the hood’ and re-arrange things, be sure to check these values before you start EMC.
7
Page 25
Chapter 3
Config Files
3.1 Files Used for Configuration
The EMC is configured with human readable text files. All of these files can be read and edited in any of the common text file editors available with most any Linux distribution.1You’ll need to be a bit careful when you edit these files. Some mistakes will cause the start up to fail. These files are read whenever the software starts up. Some of them are read repeatedly while the CNC is running.
Configuration files include
INI The ini file overrides defaults that are compiled into the EMC code. It also provides sections
that are read directly by the Hardware Abstraction Layer.
HAL The HAL files start up process modules and provide linkages between EMC signals and specific
hardware pins.
VAR The var file is a way for the interpreter to save some values from one run to the next. These val-
ues are saved from one run to another but not always saved immediately. See the Parameters section of the G Code Manual for information on what each parameter is.
TBL The tbl file saves tool information. See the User Manual Tool File section for more info.
NML The nml file configures the communication channels used by the EMC. It is normally setup
to run all of the communication within a single computer but can be modified to communicate between several computers.
.emcrc This file saves user specific information and is created to save the name of the directory
when the user first selects an EMC configuration.
Items marked (H AL) are used only by the sample HAL files and are suggested as a good convention. Other items are used by EMC directly, and must always have the section and item names given.
1
Don’t confuse a text editor with a word processor. A text editor like gedit or kwrite produce files that are plain text. They also produce lines of text that are separated from each other. A word processor like Open Office produce files with paragraphs and word wrapping and lots of embedded codes that control font size and such. A text editor does none of this.
2
Usually this file is in the users home directory (e.g. /home/user/ )
2
8
Page 26
Chapter 4

INI File

4.1 The INI File Layout

A typical INI file follows a rather simple layout that includes;
comments.
sections,
variables.
Each of these elements is separated on single lines. Each end of line or newline character creates a new element.
4.1.1 Comments
A comment line is started with a ; or a # mark. When the ini reader sees either of these marks at the start a line, the rest of the line is ignored by the software. Comments can be used to describe what some INI element will do.
; This is my little mill configuration file. ; I set it up on January 12, 2006
Comments can also be used to select between several values of a single variable.
DISPLAY = axis # DISPLAY = touchy
In this list, the DISPLAY variable will be set to axis because the other one is commented out. If someone carelessly edits a list like this and leaves two of the lines uncommented, the first one encountered will be used.
Note that inside a variable, the "#" and ";" characters do not denote comments:
INCORRECT = value # and a comment # Correct Comment CORRECT = value
9
Page 27
EMC V2.4 Integrator Manual Chapter 4. INI File
4.1.2 Sections
Related parts of an ini file are separated into sections. A section line looks like [THIS_SECTION]. The name of the section is enclosed in brackets. The order of sections is unimportant. The following sections are used by EMC:
[EMC] general information (4.2.1)
[DISPLAY] settings related to the graphical user interface (4.2.2)
[FILTER] settings input filter programs ([sub:[FILTER]-Section])
[RS274NGC] settings used by the g-code interpreter (4.2.4)
[EMCMOT] settings used by the real time motion controller (4.2.5)
[HAL] specifies .hal files (4.2.7)
[TASK] settings used by the task controller (4.2.6)
[TRAJ] additional settings used by the real time motion controller (4.2.8)
[AXIS_0] ... [AXIS_n] individual axis variables (4.2.9)
[EMCIO] settings used by the I/O Controller (4.2.10)
[HALUI] MDI commands used by HALUI. See the HALUI chapter for more information (10.2.12)
4.1.3 Variables
A variable line is made up of a variable name, an equals sign(=), and a value. Everything from the first non-white space character after the = up to the end of the line is passed as the value, so you can embed spaces in string symbols if you want to or need to. A variable name is often called a keyword.
The following sections detail each section of the configuration file, using sample values for the configuration lines.
Some of the variables are used by EMC, and must always use the section names and variable names shown. Other variables are used only by HAL, and the section names and variable names shown are those used in the sample configuration files.
4.1.4 Definitions
Machine Unit The unit of measurement for an axis is determined by the settings in the [TRAJ] sec-
tion. A machine unit is equal to one unit as specified by LINEAR_UNITS or ANGULAR_UNITS.

4.2 Sections

4.2.1 [EMC] Section
VERSION = $Revision: 1.3 $ The version number for the INI file. The value shown here looks odd
because it is automatically updated when using the Revision Control System. It’s a good idea to change this number each time you revise your file. If you want to edit this manually just change the number and leave the other tags alone.
10
Page 28
EMC V2.4 Integrator Manual Chapter 4. INI File
MACHINE = My Controller This is the name of the controller, which is printed out at the top of
most graphical interfaces. You can put whatever you want here as long as you make it a single line long.
DEBUG = 0 Debug level 0 means no messages will be printed when EMC is run from a terminal.
Debug flags are usually only useful to developers. See src/emc/nml_int/emcglb.h for other settings.
4.2.2 [DISPLAY] Section
Different user interface programs use different options, and not every option is supported by every user interface. The main two interfaces for EMC are AXIS and Touchy. Axis is an interface for use with normal computer and monitor, Touchy is for use with touch screens. Descriptions of the interfaces are in the Interfaces section of the User Manual.
DISPLAY = axis The name of the user interface to use. Valid options may include:
axis
touchy
keystick
mini
tkemc
xemc
POSITION_OFFSET = RELATIVE The coordinate system (RELATIVE or MACHINE) to show when
the user interface starts. The RELATIVE coordinate system reflects the G92 and G5x coordi­nate offsets currently in effect.
POSITION_FEEDBACK = ACTUAL The coordinate value (COMMANDED or ACTUAL) to show when
the user interface starts. The COMMANDED position is the ideal position requested by EMC. The ACTUAL position is the feedback position of the motors.
MAX_FEED_OVERRIDE = 1.2 The maximum feed override the user may select. 1.2 means 120%
of the programmed feed rate
MIN_SPINDLE_OVERRIDE = 0.5 The minimum spindle override the user may select. 0.5 means
50% of the programmed spindle speed. (This is useful as it’s dangerous to run a program with a too low spindle speed).
MAX_SPINDLE_OVERRIDE = 1.0 The maximum spindle override the user may select. 1.0 means
100% of the programmed spindle speed
PROGRAM_PREFIX = ~/emc2/nc_files The default location for g-code files and the location for
user-defined M-codes
INTRO_GRAPHIC = emc2.gif The image shown on the splash screen
INTRO_TIME = 5 The maximum time to show the splash screen
CYCLE_TIME = 0.0500 Cycle time in seconds that display will sleep between polls.
The following [DISPLAY] items are used only if you select AXIS as your user interface program.
DEFAULT_LINEAR_VELOCITY = .25 The default velocity for linear jogs, in machine units per sec-
ond.
11
Page 29
EMC V2.4 Integrator Manual Chapter 4. INI File
MIN_VELOCITY = .01 The approximate lowest value the jog slider.
MAX_LINEAR_VELOCITY = 1.0 The maximum velocity for linear jogs, in machine units per sec-
ond.
MIN_LINEAR_VELOCITY = .01 The approximate lowest value the jog slider.
DEFAULT_ANGULAR_VELOCITY = .25 The default velocity for angular jogs, in machine units per
second.
MIN_ANGULAR_VELOCITY = .01 The approximate lowest value the jog slider.
MAX_ANGULAR_VELOCITY = 1.0 The maximum velocity for angular jogs, in machine units per
second.
INCREMENTS = 1 mm, .5 in, ... Defines the increments available for incremental jogs. The IN-
CREMENTS can be used to override the default. The values can be decimal numbers (e.g.,
0.1000) or fractional numbers (e.g., 1/16), optionally followed by a unit (cm, mm, um, inch, in or mil). If a unit is not specified the machine unit is assumed. Metric and imperial distances may be mixed: INCREMENTS = 1 inch, 1 mil, 1 cm, 1 mm, 1 um is a valid entry.
OPEN_FILE = /full/path/to/file.ngc The file to show in the preview plot when AXIS starts. Use a
blank string "" and no file will be loaded at start up.
EDITOR = gedit The editor to use when selecting File > Edit or File Edit Tool Table from the AXIS
menu. This must be configured for these menu items to work. Another valid entry is gnome­terminal -e vim.
PYVCP = /filename.xml The pyVCP panel description file. See the pyVCP section for more infor-
mation.
LATHE = 1 This displays in lathe mode with a top view and with Radius and Diameter on the DRO.
GEOMETRY = XYZABCUVW Controls the preview and backplot of rotary motion. This item con-
sists of a sequence of axis letters, optionally preceded by a "-" sign. Only axes defined in [TRAJ]AXES should be used. This sequence specifies the order in which the effect of each axis is applied, with a "-" inverting the sense of the rotation. The proper GEOMETRY string depends on the machine configuration and the kinematics used to control it. The example string GEOMETRY=XYZBCUVW is for a 5-axis machine where kine­matics causes UVW to move in the coordinate system of the tool and XYZ to move in the coordinate system of the material. The order of the letters is important, because it expresses the order in which the different transformations are applied. For example rotating around C then B is different than rotating around B then C. Geometry has no effect without a rotary axis.
ARCDIVISION = 64 Set the quality of preview of arcs. Arcs are previewed by dividing them into
a number of straight lines; a semicircle is divided into ARCDIVISION parts. Larger values give a more accurate preview, but take longer to load and result in a more sluggish display. Smaller values give a less accurate preview, but take less time to load and may result in a faster display. The default value of 64 means a circle of up to 3 inches will be displayed to within 1 mil (.03%).
1
The following [DISPLAY] items are not used if you select AXIS as your user interface program.
HELP_FILE = tkemc.txt Path to help file (not used in AXIS).
1
In emc2.4 and earlier, the default value was 128.
12
Page 30
EMC V2.4 Integrator Manual Chapter 4. INI File
4.2.3 [FILTER] Section
AXIS has the ability to send loaded files through a filter program. This filter can do any desired task: Something as simple as making sure the file ends with M2, or something as complicated as detecting whether the input is a depth image, and generating g-code to mill the shape it defines. The [FILTER] section of the ini file controls how filters work. First, for each type of file, write a PROGRAM_EXTENSION line. Then, specify the program to execute for each type of file. This program is given the name of the input file as its first argument, and must write rs274ngc code to standard output. This output is what will be displayed in the text area, previewed in the display area, and executed by EMC when Run.
PROGRAM_EXTENSION = .extension Description
If your post processor outputs files in all caps you might want to add the following line:
PROGRAM_EXTENSION = .NGC XYZ Post Processor
The following lines add support for the image-to-gcode converter included with EMC2:
PROGRAM_EXTENSION = .png,.gif Greyscale Depth Image png = image-to-gcode gif = image-to-gcode
It is also possible to specify an interpreter:
PROGRAM_EXTENSION = .py Python Script py = python
In this way, any Python script can be opened, and its output is treated as g-code. One such example script is available at nc_files/holecircle.py. This script creates g-code for drilling a series of holes along the circumference of a circle. Many more g-code generators are on the EMC Wiki site
http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl.
If the environment variable AXIS_PROGRESS_BAR is set, then lines written to stderr of the form
FILTER_PROGRESS=%d
Sets the AXIS progress bar to the given percentage. This feature should be used by any filter that runs for a long time.
4.2.4 [RS274NGC] Section
PARAMETER_FILE = file.var The file which contains the parameters used by the interpreter (saved
between runs).
RS274NGC_STARTUP_CODE = G21 G90 A string of NC codes that the interpreter is initialized
with. This is not a substitute for specifying modal g-codes at the top of each ngc file, because the modal codes of machines differ, and may be changed by g-code interpreted earlier in the session.
13
Page 31
EMC V2.4 Integrator Manual Chapter 4. INI File
4.2.5 [EMCMOT] Section
You may find other entries in this section and they should not be changed.
BASE_PERIOD = 50000 (HAL) "Base" task period, in nanoseconds - this is the fastest thread in the
machine. On servo-based systems, there is generally no reason for BASE_PERIOD to be smaller than SERVO_PERIOD. On machines with software step generation, the BASE_PERIOD determines the maximum number of steps per second. In the absence of long step length and step space requirements, the absolute maximum step rate is one step per BASE_PERIOD. Thus, the BASE_PERIOD shown above gives an absolute maximum step rate of 20000 steps per second. 50000ns is a fairly conservative value. The smallest usable value is related to the Latency Test result, the necessary step length, and the processor speed. Choosing a BASE_PERIOD that is too low can lead to the "Unexpected real time delay" message, lockups, or spontaneous reboots.
SERVO_PERIOD = 1000000 (HAL) "Servo" task period is also in nanoseconds. This value will be
rounded to an integer multiple of BASE_PERIOD. This value is used even on systems based on stepper motors. This is the rate at which new motor positions are computed, following error is checked, PID output values are updated, and so on. Most systems will not need to change this value. It is the update rate of the low level motion planner.
TRAJ_PERIOD = 1000000 (HAL) Trajectory Planner task period in nanoseconds This value will be
rounded to an integer multiple of SERVO_PERIOD. Except for machines with unusual kinematics (e.g., hexapods) there is no reason to make this value larger than SERVO_PERIOD.
4.2.6 [TASK] Section
TASK = milltask Specifies the name of the "task" executable. "task" does various things, such
as communicate with the UIs over NML, communicate with the realtime motion planner over non-HAL shared memory, and interpret gcode. Currently there is only one task executable that makes sense for 99.9% of users, milltask In the dim mists of time (before HAL), it was frequently the case that an integrator would have to build a modified version of things like task, io, and motion for a specific machine.
CYCLE_TIME = 0.001 The period, in seconds, at which EMCTASK will run. This parameter affects
the polling interval when waiting for motion to complete, when executing a pause instruction, and when accepting a command from a user interface. There is usually no need to change this number.
4.2.7 [HAL] section
HALFILE = example.hal Execute the file ’example.hal’ at start up. If HALFILE is specified multiple
times, the files are executed in the order they appear in the ini file. Almost all configurations will have at least one HALFILE, and stepper systems typically have two such files, one which specifies the generic stepper configuration (core_stepper.hal) and one which specifies the machine pin out (xxx_pinout.hal)
HALCMD = command Execute ’command’ as a single hal command. If HALCMD is specified mul-
tiple times, the commands are executed in the order they appear in the ini file. HALCMD lines are executed after all HALFILE lines.
14
Page 32
EMC V2.4 Integrator Manual Chapter 4. INI File
SHUTDOWN = shutdown.hal Execute the file ’shutdown.hal’ when EMC is exiting. Depending on
the hardware drivers used, this may make it possible to set outputs to defined values when EMC is exited normally. However, because there is no guarantee this file will be executed (for instance, in the case of a computer crash) it is not a replacement for a proper physical e-stop chain or other protections against software failure.
POSTGUI_HALFILE = example2.hal (Only with the AXIS GUI) Execute ’example2.hal’ after the GUI
has created its HAL pins. See section 12.4 for more information.
4.2.8 [TRAJ] Section
The [TRAJ] section contains general parameters for the trajectory planning module in EMCMOT.
COORDINATES = X Y Z The names of the axes being controlled. X, Y, Z, A, B, C, U, V, and W are
all valid. Only axis named in COORDINATES are accepted in g-code. This has no effect on the mapping from G-code axis names (X- Y- Z-) to joint numbers–for "trivial kinematics", X is always joint 0, A is always joint 4, and U is always joint 7, and so on. It is permitted to write an axis name twice (e.g., X Y Y Z for a gantry machine) but this has no effect.
AXES = 3 One more than the number of the highest joint number in the system. For an XYZ
machine, the joints are numbered 0, 1 and 2; in this case AXES should be 3. For an XYUV machine using "trivial kinematics", the V joint is numbered 7 and therefore AXES should be 8. For a machine with nontrivial kinematics (e.g., scarakins) this will generally be the number of controlled joints.
HOME = 0 0 0 Coordinates of the homed position of each axis. Again for a fourth axis you will need
0 0 0 0. This value is only used for machines with nontrivial kinematics. On machines with trivial kinematics this value is ignored.
LINEAR_UNITS = <units> Specifies the machine units for linear axes. Possible choices are (in,
inch, imperial, metric, mm). This does not affect the linear units in NC code (the G20 and G21 words do this).
ANGULAR_UNITS = <units> Specifies the machine units for rotational axes. Possible choices are
’deg’, ’degree’ (360 per circle), ’rad’, ’radian’ (2pi per circle), ’grad’, or ’gon’ (400 per circle). This does not affect the angular units of NC code. In RS274NGC, A-, B- and C- words are always expressed in degrees.
DEFAULT_VELOCITY = 0.0167 The initial rate for jogs of linear axes, in machine units per second.
The value shown equals one unit per minute.
DEFAULT_ACCELERATION = 2.0 In machines with nontrivial kinematics, the acceleration used
for "teleop" (Cartesian space) jogs, in machine units per second per second.
MAX_VELOCITY = 5.0 The maximum velocity for any axis or coordinated move, in machine units
per second. The value shown equals 300 units per minute.
MAX_ACCELERATION = 20.0 The maximum acceleration for any axis or coordinated axis move,
in machine units per second per second.
POSITION_FILE = position.txt If set to a non-empty value, the joint positions are stored between
runs in this file. This allows the machine to start with the same coordinates it had on shut­down. This assumes there was no movement of the machine while powered off. If unset, joint positions are not stored and will begin at 0 each time EMC is started. This can help on smaller machines without home switches.
NO_FORCE_HOMING = 1 The default behavior is for EMC to force the user to home the machine
before any MDI command or a program is run. Normally jogging only is allowed before homing.
15
Page 33
EMC V2.4 Integrator Manual Chapter 4. INI File
Setting NO_FORCE_HOMING = 1 allows the user to make MDI moves and run programs with­out homing the machine first. Interfaces without homing ability will need to have this option set to 1. Warning: Using this will allow the machine to run past soft limits while in operation and is not generally desirable to allow this.
4.2.9 [AXIS_<num>] Section
The [AXIS_0], [AXIS_1], etc. sections contains general parameters for the individual components in the axis control module. The axis section names begin numbering at 0, and run through the number of axes specified in the [TRAJ] AXES entry minus 1.
AXIS_0 = X
AXIS_1 = Y
AXIS_2 = Z
AXIS_3 = A
AXIS_4 = B
AXIS_5 = C
AXIS_6 = U
AXIS_7 = V
AXIS_8 = W
TYPE = LINEAR The type of axes, either LINEAR or ANGULAR.
WRAPPED_ROTARY = 1 When this is set to 1 for an ANGULAR axis the axis will move 0-359.999
degrees. Plus Numbers will move the axis in a positive direction and minus numbers will move the axis in the opposite direction.
UNITS = inch If specified, this setting overrides the related [TRAJ] UNITS setting.
(e.g., [TRAJ]LINEAR_UNITS if the TYPE of this axis is LINEAR, [TRAJ]ANGULAR_UNITS if the TYPE of this axis is ANGULAR)
MAX_VELOCITY = 1.2 Maximum velocity for this axis in machine units per second.
MAX_ACCELERATION = 20.0 Maximum acceleration for this axis in machine units per second
squared.
BACKLASH = 0.000 Backlash in machine units. Backlash compensation value can be used to
make up for small deficiencies in the hardware used to drive an axis. If backlash is added to an axis and you are using steppers the STEPGEN_MAXACCEL must be increased to 1.5 to 2 times the MAX_ACCELERATION for the axis.
COMP_FILE = file.extension A file holding compensation structure for the axis. The file could
be named xscrew.comp for example for the X axis. File names are case sensitive and can contain letters and or numbers. The values are triplets per line separated by a space. The first value is nominal (where it should be). The second and third values depend on the setting of COMP_FILE_TYPE. Currently the limit inside EMC2 is for 256 triplets per axis. If COMP_FILE is specified, BACKLASH is ignored. Compensation file values are in machine units.
COMP_FILE_TYPE=0 the second and third values specify the forward position (where the axis is while traveling forward) and reverse position (where the axis is while traveling reverse) positions which correspond to the nominal position.
16
Page 34
EMC V2.4 Integrator Manual Chapter 4. INI File
COMP_FILE_TYPE=1 the second and third values specify the forward trim (how far from nom­inal while traveling forward) and the reverse trim (how far from nominal while traveling in reverse).
COMP_FILE_TYPE = 0 For COMP_FILE_TYPE of zero, the values in the compensation file are nom-
inal, forward & reverse. For COMP_FILE_TYPE of non-zero the values in the compensation file are nominal, forward_trim and reverse_trim.
MIN_LIMIT = -1000 The minimum limit (soft limit) for axis motion, in machine units. When this
limit is exceeded, the controller aborts axis motion.
MAX_LIMIT = 1000 The maximum limit (soft limit) for axis motion, in machine units. When this
limit is exceeded, the controller aborts axis motion.
MIN_FERROR = 0.010 This is the value in machine units by which the axis is permitted to deviate
from commanded position at very low speeds. If MIN_FERROR is smaller than FERROR, the two produce a ramp of error trip points. You could think of this as a graph where one dimension is speed and the other is permitted following error. As speed increases the amount of following error also increases toward the FERROR value.
FERROR = 1.0 FERROR is the maximum allowable following error, in machine units. If the differ-
ence between commanded and sensed position exceeds this amount, the controller disables servo calculations, sets all the outputs to 0.0, and disables the amplifiers. If MIN_FERROR is present in the .ini file, velocity-proportional following errors are used. Here, the maximum al­lowable following error is proportional to the speed, with FERROR applying to the rapid rate set by [TRAJ]MAX_VELOCITY, and proportionally smaller following errors for slower speeds. The maximum allowable following error will always be greater than MIN_FERROR. This prevents small following errors for stationary axes from inadvertently aborting motion. Small following errors will always be present due to vibration, etc. The following polarity values determine how inputs are interpreted and how outputs are applied. They can usually be set via trial-and-error since there are only two possibilities. The EMC2 Servo Axis Calibration utility program (in the AXIS interface menu Machine/Calibration and in TkEMC it is under Setting/Calibration) can be used to set these and more interactively and verify their results so that the proper values can be put in the INI file with a minimum of trouble.
4.2.9.1 Homing
These parameters are Homing related, for a better explanation read the Homing Section (4.3).
HOME = 0.0 The position that the joint will go to upon completion of the homing sequence.
HOME_OFFSET = 0.0 The axis position of the home switch or index pulse, in machine units.
HOME_SEARCH_VEL = 0.0 Initial homing velocity in machine units per second. Sign denotes di-
rection of travel. A value of zero means assume that the current location is the home position for the machine. If your machine has no home switches you will want to leave this value alone.
HOME_LATCH_VEL = 0.0 Homing velocity in machine units per second to the home switch latch
position. Sign denotes direction of travel.
HOME_FINAL_VEL = 0.0 Velocity in machine units per second from home latch position to home
position. If left at 0 or not included in the axis rapid velocity is used. Must be a positive number.
HOME_USE_INDEX = NO If the encoder used for this axis has an index pulse, and the motion card
has provision for this signal you may set it to yes. When it is yes, it will affect the kind of home pattern used. Currently, you can’t home to index with steppers unless your using stepgen in velocity mode and pid.
17
Page 35
EMC V2.4 Integrator Manual Chapter 4. INI File
HOME_IGNORE_LIMITS = NO Some machines use a single switch as a home switch and limit
switch. This variable should be set to yes if the machine configured this way.
HOME_IS_SHARED = <n> If the home input is shared by more than one axis set <n> to 1 to prevent
homing from starting if the one of the shared switches is already closed. Set <n> to 0 to permit homing if a switch is closed.
HOME_SEQUENCE = <n> Used to define the "Home All" sequence. <n> starts at 0 and no numbers
may be skipped. If left out or set to -1 the joint will not be homed by the "Home All" function. More than one axis can be homed at the same time.
VOLATILE_HOME = 0 When enabled (set to 1) this joint will be unhomed if the Machine Power is
off or if E-Stop is on. This is useful if your machine has home switches and does not have position feedback such as a step and direction driven machine.
4.2.9.2 Servo
The following items are for servo-based systems and servo-like systems. This description assumes that the units of output from the PID component are volts.
DEADBAND = 0.000015 (HAL) How close is close enough the consider the motor in position.
BIAS = 0.000 (HAL) This is used by hm2-servo and some others. Bias is a constant amount that
is added to the output. In most cases it should be left at zero. However, it can sometimes be useful to compensate for offsets in servo amplifiers, or to balance the weight of an object that moves vertically. bias is turned off when the PID loop is disabled, just like all other components of the output.
P = 50 (HAL) The proportional gain for the axis servo. This value multiplies the error between
commanded and actual position in machine units, resulting in a contribution to the computed voltage for the motor amplifier. The units on the P gain are volts per machine unit, e.g.,
volt
mu
.
I = 0 (HAL) The integral gain for the axis servo. The value multiplies the cumulative error between
commanded and actual position in machine units, resulting in a contribution to the computed voltage for the motor amplifier. The units on the I gain are volts per machine unit second, e.g.,
volt
.
mu s
D = 0 (HAL) The derivative gain for the axis servo. The value multiplies the difference between the
current and previous errors, resulting in a contribution to the computed voltage for the motor amplifier. The units on the D gain are volts per machine unit per second, e.g.,
volt
mu/s
.
FF0 = 0 (HAL) The 0th order feed forward gain. This number is multiplied by the commanded
position, resulting in a contribution to the computed voltage for the motor amplifier. The units on the FF0 gain are volts per machine unit, e.g.,
volt
mu
.
FF1 = 0 (HAL) The 1st order feed forward gain. This number is multiplied by the change in com-
manded position per second, resulting in a contribution to the computed voltage for the motor amplifier. The units on the FF1 gain are volts per machine unit per second, e.g.,
volt
mu s
.
FF2 = 0 (HAL) The 2nd order feed forward gain. This number is multiplied by the change in com-
manded position per second per second, resulting in a contribution to the computed voltage for the motor amplifier. The units on the FF2 gain are volts per machine unit per second per second, e.g.,
volt
mu s
.
2
OUTPUT_SCALE = 1.000
OUTPUT_OFFSET = 0.000 (HAL) These two values are the scale and offset factors for the axis
output to the motor amplifiers. The second value (offset) is subtracted from the computed output (in volts), and divided by the first value (scale factor), before being written to the D/A converters. The units on the scale value are in true volts per DAC output volts. The units on
18
Page 36
EMC V2.4 Integrator Manual Chapter 4. INI File
the offset value are in volts. These can be used to linearize a DAC. Specifically, when writing outputs, the EMC first converts the desired output in quasi-SI units to raw actuator values, e.g., volts for an amplifier DAC. This scaling looks like:
raw =
output off set
scale
The value for scale can be obtained analytically by doing a unit analysis, i.e., units are [output SI units]/[actuator units]. For example, on a machine with a velocity mode amplifier such that 1 volt results in 250 mm/sec velocity,
amplif ier[volts] = (output[
mm
] − off set[
sec
mm
sec
])/250
mm
sec volt
Note that the units of the offset are in machine units, e.g., mm/sec, and they are pre­subtracted from the sensor readings. The value for this offset is obtained by finding the value of your output which yields 0.0 for the actuator output. If the DAC is linearized, this offset is normally 0.0. The scale and offset can be used to linearize the DAC as well, resulting in values that reflect the combined effects of amplifier gain, DAC non-linearity, DAC units, etc. To do this, follow this procedure:
1. Build a calibration table for the output, driving the DAC with a desired voltage and mea­suring the result. See table 4.2.9.2 for an example of voltage measurements.
2. Do a least-squares linear fit to get coefficients a, b such that
meas = a raw + b
3. Note that we want raw output such that our measured result is identical to the com­manded output. This means
(a)
cmd = a raw + b
(b)
raw = (cmd b)/a
4. As a result, the a and b coefficients from the linear fit can be used as the scale and offset for the controller directly.
MAX_OUTPUT = 10 (HAL) The maximum value for the output of the PID compensation that is
written to the motor amplifier, in volts. The computed output value is clamped to this limit. The limit is applied before scaling to raw output units. The value is applied symmetrically to both the plus and the minus side.
Output Voltage Measurements
Raw Measured
-10 -9.93
-9 -8.83 0 -0.03 1 0.96 9 9.87
10 10.87
INPUT_SCALE = 20000 (HAL) Specifies the number of pulses that corresponds to a move of one
machine unit as set in the [TRAJ] section. For a linear axis one machine unit will be equal to the setting of LINEAR_UNITS. For an angular axis one unit is equal to the setting in ANGU­LAR_UNITS.
19
Page 37
EMC V2.4 Integrator Manual Chapter 4. INI File
A second number, if specified, is ignored. For example, on a 2000 counts per rev encoder, and 10 revs/inch gearing, and desired units of inch, we have
input_scale = 2000
= 20000
4.2.9.3 Stepper
The following items are Stepper related items.
SCALE = 4000 (HAL) Specifies the number of pulses that corresponds to a move of one machine
unit as set in the [TRAJ] section. For stepper systems, this is the number of step pulses issued per machine unit. For a linear axis one machine unit will be equal to the setting of LINEAR_UNITS. For an angular axis one unit is equal to the setting in ANGULAR_UNITS. For servo systems, this is the number of feedback pulses per machine unit. A second number, if specified, is ignored. For example, on a 1.8 degree stepper motor with half-stepping, and 10 revs/inch gearing, and desired machine units of inch, we have
input_scale =
2 steps
1.8 degree
= 4000
counts
rev
counts
inch
360
steps
inch
10
degree
rev
rev
inch
10
rev
inch
Older stepper configuration .ini and .hal used INPUT_SCALE for this value.
STEPGEN_MAXACCEL = 21.0 (HAL) Acceleration limit for the step generator. This should be 1%
to 10% larger than the axis MAX_ACCELERATION. This value improves the tuning of stepgen’s "position loop". If you have added backlash compensation to an axis then this should be 1.5 to 2 times greater than MAX_ACCELERATION.
STEPGEN_MAXVEL = 1.4 (HAL) Older configuration files have a velocity limit for the step gener-
ator as well. If specified, it should also be 1% to 10% larger than the axis MAX_VELOCITY. Subsequent testing has shown that use of STEPGEN_MAXVEL does not improve the tuning of stepgen’s position loop.
4.2.10 [EMCIO] Section
CYCLE_TIME = 0.100 The period, in seconds, at which EMCIO will run. Making it 0.0 or a negative
number will tell EMCIO not to sleep at all. There is usually no need to change this number.
TOOL_TABLE = tool.tbl The file which contains tool information, described in the User Manual.
TOOL_CHANGE_POSITION = 0 0 2 Specifies the X Y Z location to move to when performing a tool
change if three digits are used. Specifies the X Y Z A B C location when 6 digits are used. Specifies the X Y Z A B C U V W location when 9 digits are used. Tool Changes can be combined. For example if you combine the quill up with change position you can move the Z first then the X and Y.
TOOL_CHANGE_WITH_SPINDLE_ON = 1 The spindle will be left on during the tool change when
the value is 1. Useful for lathes or machines where the material is in the spindle not the tool.
TOOL_CHANGE_QUILL_UP = 1 The Z axis will be moved to machine zero prior to the tool change
when the value is 1. This is the same as issuing a G0 G53 Z0.
20
Page 38
EMC V2.4 Integrator Manual Chapter 4. INI File
TOOL_CHANGE_AT_G30 = 1 The machine is moved to reference point defined by parameters 5181-
5186 for G30 if the value is 1. For more information on G30 and Parameters see the G Code Manual.
RANDOM_TOOLCHANGER = 1 This is for machines that cannot place the tool back into the pocket
it came from. For example, machines that exchange the tool in the active pocket with the tool in the spindle.
21
Page 39
EMC V2.4 Integrator Manual Chapter 4. INI File

4.3 Homing

4.3.1 Overview
Homing seems simple enough - just move each joint to a known location, and set EMC’s internal variables accordingly. However, different machines have different requirements, and homing is actually quite complicated.
4.3.2 Homing Sequence
There are four possible homing sequences, along with the associated configuration parameters as shown in the following table. For a more detailed description of what each configuration parameter does, see the following section.
SEARCH_VEL LATCH_VEL USE_INDEX Homing Type
nonzero nonzero NO Switch-only nonzero nonzero YES Switch + Index
0 nonzero YES Index-only 0 0 NO None
Other combinations Error
4.3.3 Configuration
There are six pieces of information that determine exactly how the home sequence behaves. They are defined in an [AXIS] section of the inifile.
4.3.3.1 HOME_SEARCH_VEL
The default value is zero. A value of zero causes EMC to assume that there is no home switch; the search stage of homing is skipped.
If HOME_SEARCH_VEL is non-zero, then EMC assumes that there is a home switch. It begins by checking whether the home switch is already tripped. If tripped it backs off the switch at HOME_SEARCH_VEL. The direction of the back-off is opposite the sign of HOME_SEARCH_VEL. Then it searches for the home switch by moving in the direction specified by the sign of HOME_SEARCH_VEL, at a speed determined by its absolute value. When the home switch is detected, the joint will stop as fast as possible, but there will always be some overshoot. The amount of overshoot depends on the speed. If it is too high, the joint might overshoot enough to hit a limit switch or crash into the end of travel. On the other hand, if HOME_SEARCH_VEL is too low, homing can take a long time.
4.3.3.2 HOME_LATCH_VEL
Specifies the speed and direction that EMC uses when it makes its final accurate determination of the home switch (if present) and index pulse location (if present). It will usually be slower than the search velocity to maximise accuracy. If HOME_SEARCH_VEL and HOME_LATCH_VEL have the same sign, then the latch phase is done while moving in the same direction as the search phase. (In that case, EMC first backs off the switch, before moving towards it again at the latch velocity.) If HOME_SEARCH_VEL and HOME_LATCH_VEL have opposite signs, the latch phase is done while moving in the opposite direction from the search phase. That means EMC will latch the first pulse after it moves off the switch. If HOME_SEARCH_VEL is zero (meaning there is no home switch), and this parameter is nonzero, EMC goes ahead to the index pulse search. If HOME_SEARCH_VEL is non-zero and this parameter is zero, it is an error and the homing operation will fail. The default value is zero.
22
Page 40
EMC V2.4 Integrator Manual Chapter 4. INI File
4.3.3.3 HOME_FINAL_VEL
It specifies the speed that EMC uses when it makes its move from HOME_OFFSET to the HOME position. If the HOME_FINAL_VEL is missing from the ini file, then the maximum joint speed is used to make this move. The value must a positive number.
4.3.3.4 HOME_IGNORE_LIMITS
Can hold the values YES / NO. This flag determines whether EMC will ignore the limit switch inputs. Some machine configurations do not use a separate home switch, instead they route one of the limit switch signals to the home switch input as well. In this case, EMC needs to ignore that limit during homing. The default value for this parameter is NO.
4.3.3.5 HOME_USE_INDEX
Specifies whether or not there is an index pulse. If the flag is true (HOME_USE_INDEX = YES), EMC will latch on the rising edge of the index pulse. If false, EMC will latch on either the rising or falling edge of the home switch (depending on the signs of HOME_SEARCH_VEL and HOME_LATCH_VEL). The default value is NO.
4.3.3.6 HOME_OFFSET
Contains the location of the home switch or index pulse, in joint coordinates. It can also be treated as the distance between the point where the switch or index pulse is latched and the zero point of the joint. After detecting the index pulse, EMC sets the joint coordinate of the current point to HOME_OFFSET. The default value is zero.
4.3.3.7 HOME
The position that the joint will go to upon completion of the homing sequence. After detecting the index pulse, and setting the coordinate of that point to HOME_OFFSET, EMC makes a move to HOME as the final step of the homing process. The default value is zero. Note that even if this parameter is the same as HOME_OFFSET, the axis will slightly overshoot the latched position as it stops. Therefore there will always be a small move at this time (unless HOME_SEARCH_VEL is zero, and the entire search/latch stage was skipped). This final move will be made at the joint’s maximum velocity. Since the axis is now homed, there should be no risk of crashing the machine, and a rapid move is the quickest way to finish the homing sequence.
2
4.3.3.8 HOME_IS_SHARED
If there is not a separate home switch input for this axis, but a number of momentary switches wired to the same pin, set this value to 1 to prevent homing from starting if one of the shared switches is already closed. Set this value to 0 to permit homing even if the switch is already closed.
2
The distinction between ’home’ and ’home_offset’ is not as clear as I would like. I intend to make a small drawing and
example to help clarify it.
23
Page 41
EMC V2.4 Integrator Manual Chapter 4. INI File
4.3.3.9 HOME_SEQUENCE
Used to define a multi-axis homing sequence HOME ALL and enforce homing order (e.g., Z may not be homed if X is not yet homed). An axis may be homed after all axes with a lower HOME_SEQUENCE have already been homed and are at the HOME_OFFSET. If two axes have the same HOME_SEQUENCE, they may be homed at the same time. If HOME_SEQUENCE is -1 or not specified then this joint will not be homed by the HOME ALL sequence. HOME_SEQUENCE numbers start with 0 and there may be no unused numbers.
24
Page 42
EMC V2.4 Integrator Manual Chapter 4. INI File
INDEX PULSES
INDEX PULSES
HOME SWITCH TRIPS
HOME SWITCH TRIPS
HOME SWITCH TRIPS
HOME SWITCH TRIPS
SEARCH FOR HOME SWITCH (SEARCH_VEL)
SEARCH FOR HOME SWITCH (SEARCH_VEL)
SEARCH FOR HOME SWITCH (SEARCH_VEL)
SEARCH FOR HOME SWITCH (SEARCH_VEL)
BACK OFF OF HOME SWITCH (SEARCH_VEL)
BACK OFF OF HOME SWITCH (SEARCH_VEL)
FINAL DETECTION OF SWITCH (LATCH_VEL)
FINAL DETECTION OF SWITCH AND
INDEX PULSE (LATCH_VEL)
FINAL DETECTION OF SWITCH (LATCH_VEL)
FINAL DETECTION OF SWITCH AND
INDEX PULSE (LATCH_VEL)
GO TO HOME POSITION (MAX_VEL)
GO TO HOME POSITION (MAX_VEL)
GO TO HOME POSITION (MAX_VEL)
GO TO HOME POSITION (MAX_VEL)
1.000
1.000
1.000
1.000
3.000
3.000
3.000
3.000
SEARCH_VEL = POSITIVE
SEARCH_VEL = POSITIVE
SEARCH_VEL = POSITIVE
SEARCH_VEL = POSITIVE
LATCH_VEL = NEGATIVE
LATCH_VEL = NEGATIVE
LATCH_VEL = POSITIVE
LATCH_VEL = POSITIVE
USE_INDEX = FALSE
USE_INDEX = TRUE
USE_INDEX = FALSE
USE_INDEX = TRUE
HOME_OFFSET = 3.000
HOME_OFFSET = 3.000
HOME_OFFSET = 3.000
HOME_OFFSET = 3.000
HOME = 1.000
HOME = 1.000
HOME = 1.000
HOME = 1.000
OVERSHOOT
HOME SWITCH RELEASES
HOME SWITCH RELEASES
HOME SWITCH RELEASES
HOME SWITCH RELEASES
Figure 4.1: Homing Sequences
25
Page 43
EMC V2.4 Integrator Manual Chapter 4. INI File

4.4 Lathe

4.4.1 Default Plane
When EMC’s interpreter was first written, it was designed for mills. That is why the default plane is XY (G17). A normal lathe only uses the XZ plane (G18). To change the default plane place the following line in the .ini file in the RS274NGC section.
RS274NGC_STARTUP_CODE = G18
4.4.2 INI Settings
The following .ini settings are needed for lathe mode in addition to or replacing normal settings in the .ini file.
[DISPLAY] DISPLAY = axis LATHE = 1 [TRAJ] AXES = 3 COORDINATES = X Z [AXIS_0] ... [AXIS_2] ...
26
Page 44
Chapter 5

EMC2 and HAL

See also the manual pages motion(9) and iocontrol(1).

5.1 motion (realtime)

5.1.1 Options
Motion is loaded with the motmod command. A kins should be loaded before motion.
loadrt motmod [base_period_nsec=period] [servo_period_nsec=period] [traj_period_nsec=period] [num_joints=[0-9] ([num_dio=1-64] num_aio=1-16])]
If the number of digital I/O needed is above the default of 4 you can add up to 64 digital I/O by using the num_dio option when loading motmod.
If the number of analog I/O needed is more that the default of 4 you can add up to 16 analog I/O by using the num_aio option when loading motmod.
5.1.2 Pins
These pins, parameters, and functions are created by the realtime motmod module.
motion.adaptive-feed (float, in) When adaptive feed is enabled with M52 P1, the commanded ve-
locity is multiplied by this value. This effect is multiplicative with the NML-level feed override value and motion.feed-hold.
motion.analog-in-00 (float, in) These pins (00, 01, 02, 03 or more if configured) are controlled by
M66.
motion.analog-out-00 (float, out) These pins (00, 01, 02, 03 or more if configured) are controlled
by M67 or M68.
motion.coord-error (bit, out) TRUE when motion has encountered an error, such as exceeding a
soft limit
motion.coord-mode (bit, out) TRUE when motion is in "coordinated mode", as opposed to "teleop
mode"
motion.current-vel (float, out) The current tool velocity in user units per second.
27
Page 45
EMC V2.4 Integrator Manual Chapter 5. EMC2 and HAL
motion.digital-in-00 (bit, in) These pins (00, 01, 02, 03 or more if configured) are controlled by
M62-65.
motion.digital-out-00 (bit, out) These pins (00, 01, 02, 03 or more if configured) are controlled by
the M62-65.
motion.distance-to-go (float,out) The distance remaining in the current move.
motion.enable (bit, in) If this bit is driven FALSE, motion stops, the machine is placed in the
"machine off" state, and a message is displayed for the operator. For normal motion, drive this bit TRUE.
motion.feed-hold (bit, in) When Feed Stop Control is enabled with M53 P1, and this bit is TRUE,
the feed rate is set to 0.
motion.in-position (bit, out) TRUE if the machine is in position.
motion.motion-enabled (bit, out) TRUE when in "machine on" state.
motion.on-soft-limit (bit, out) TRUE when the machine is on a soft limit.
motion.probe-input (bit, in) G38.x uses the value on this pin to determine when the probe has
made contact. TRUE for probe contact closed (touching), FALSE for probe contact open.
motion.program-line (s32, out) The current program line while executing. Zero if not running or
between lines while single stepping.
motion.requested-vel (float, out) The current requested velocity in user units per second from the
F=n setting in the G Code file. No feed overrides or any other adjustments are applied to this pin.
motion.spindle-at-speed (bit, in) Motion will pause until this pin is TRUE, under the following
conditions: before the first feed move after each spindle start or speed change; before the start of every chain of spindle-synchronized moves; and if in CSS mode, at every rapid to feed transition. This input can be used to ensure that the spindle is up to speed before starting a cut, or that a lathe spindle in CSS mode has slowed down after a large to small facing pass before starting the next pass at the large diameter. Many VFDs have an "at speed" output. Otherwise, it is easy to generate this signal with the HAL near component, by comparing requested and actual spindle speeds.
motion.spindle-brake (bit, out) TRUE when the spindle brake should be applied.
motion.spindle-forward (bit, out) TRUE when the spindle should rotate forward.
motion.spindle-index-enable (bit, I/O) For correct operation of spindle synchronized moves, this
pin must be hooked to the index-enable pin of the spindle encoder.
motion.spindle-on (bit, out) TRUE when spindle should rotate.
motion.spindle-reverse (bit, out) TRUE when the spindle should rotate backward
motion.spindle-revs (float, in) For correct operation of spindle synchronized moves, this signal
must be hooked to the position pin of the spindle encoder. The spindle encoder position should be scaled such that spindle-revs increases by 1.0 for each rotation of the spindle in the clockwise (M3) direction.
motion.spindle-speed-in (float, in) Feedback of actual spindle speed in rotations per second. This
is used by feed-per-revolution motion (G95). If your spindle encoder driver does not have a velocity output, you can generate a suitable one by sending the spindle position through a ddt component.
motion.spindle-speed-out (float, out) Commanded spindle speed in rotations per minute. Positive
for spindle forward (M3), negative for spindle reverse (M4).
28
Page 46
EMC V2.4 Integrator Manual Chapter 5. EMC2 and HAL
motion.spindle-speed-out-rps (float, out) Commanded spindle speed in rotations per second. Pos-
itive for spindle forward (M3), negative for spindle reverse (M4).
motion.teleop-mode (bit, out) TRUE when motion is in "teleop mode", as opposed to "coordinated
mode"
motion.tooloffset.w (float, out) shows the w offset in effect; it could come from the tool table (G43
active), or it could come from the gcode (G43.1 active)
motion.tooloffset.x (float, out) shows the x offset in effect; it could come from the tool table (G43
active), or it could come from the gcode (G43.1 active)
motion.tooloffset.z (float, out) shows the z offset in effect; it could come from the tool table (G43
active), or it could come from the gcode (G43.1 active)
5.1.3 Parameters
Many of these parameters serve as debugging aids, and are subject to change or removal at any time.
motion-command-handler.time (s32, RO)
motion-command-handler.tmax (s32, RW)
motion-controller.time (s32, RO)
motion-controller.tmax (s32, RW)
motion.debug-bit-0 (bit, RO) This is used for debugging purposes.
motion.debug-bit-1 (bit, RO) This is used for debugging purposes.
motion.debug-float-0 (float, RO) This is used for debugging purposes.
motion.debug-float-1 (float, RO) This is used for debugging purposes.
motion.debug-float-2 (float, RO) This is used for debugging purposes.
motion.debug-float-3 (float, RO) This is used for debugging purposes.
motion.debug-s32-0 (s32, RO) This is used for debugging purposes.
motion.debug-s32-1 (s32, RO) This is used for debugging purposes.
motion.servo.last-period (u32, RO) The number of CPU cycles between invocations of the servo
thread. Typically, this number divided by the CPU speed gives the time in seconds, and can be used to determine whether the realtime motion controller is meeting its timing constraints
motion.servo.last-period-ns (float, RO)
motion.servo.overruns (u32, RW) By noting large differences between successive values of motion.servo.last-
period, the motion controller can determine that there has probably been a failure to meet its timing constraints. Each time such a failure is detected, this value is incremented.
5.1.4 Functions
Generally, these functions are both added to the servo-thread in the order shown.
motion-command-handler Processes motion commands coming from user space
motion-controller Runs the EMC motion controller
29
Page 47
EMC V2.4 Integrator Manual Chapter 5. EMC2 and HAL

5.2 axis.N (realtime)

These pins and parameters are created by the realtime motmod module. These are actually joint values, but the pins and parameters are still called "axis.N".1They are read and updated by the motion-controller function.
5.2.1 Pins
axis.N.active (bit, out)
axis.N.amp-enable-out (bit, out) TRUE if the amplifier for this joint should be enabled
axis.N.amp-fault-in (bit, in) Should be driven TRUE if an external fault is detected with the ampli-
fier for this joint
axis.N.backlash-corr (float, out)
axis.N.backlash-filt (float, out)
axis.N.backlash-vel (float, out)
axis.N.coarse-pos-cmd (float, out)
axis.N.error (bit, out)
axis.N.f-error (float, out)
axis.N.f-error-lim (float, out)
axis.N.f-errored (bit, out)
axis.N.faulted (bit, out)
axis.N.free-pos-cmd (float, out)
axis.N.free-tp-enable (bit, out)
axis.N.free-vel-lim (float, out)
axis.N.home-sw-in (bit, in) Should be driven TRUE if the home switch for this joint is closed.
axis.N.homed (bit, out)
axis.N.homing (bit, out) TRUE if the joint is currently homing
axis.N.in-position (bit, out)
axis.N.index-enable (bit, I/O)
axis.N.jog-counts (s32, in) Connect to the "counts" pin of an external encoder to use a physical jog
wheel.
axis.N.jog-enable (bit, in) When TRUE (and in manual mode), any change in "jog-counts" will result
in motion. When false, "jog-counts" is ignored.
axis.N.jog-scale (float, in) Sets the distance moved for each count on "jog-counts", in machine
units.
axis.N.jog-vel-mode (bit, in) When FALSE (the default), the jogwheel operates in position mode.
The axis will move exactly jog-scale units for each count, regardless of how long that might take. When TRUE, the wheel operates in velocity mode - motion stops when the wheel stops, even if that means the commanded motion is not completed.
1
In "trivial kinematics" machines, there is a one-to-one correspondence between joints and axes.
30
Page 48
EMC V2.4 Integrator Manual Chapter 5. EMC2 and HAL
axis.N.joint-pos-cmd (float, out) The joint (as opposed to motor) commanded position. There may
be an offset between the joint and motor positions–for example, the homing process sets this offset.
axis.N.joint-pos-fb (float, out) The joint (as opposed to motor) feedback position.
axis.N.joint-vel-cmd (float, out)
axis.N.kb-jog-active (bit, out)
axis.N.motor-pos-cmd (float, out) The commanded position for this joint.
axis.N.motor-pos-fb (float, in) The actual position for this joint.
axis.N.neg-hard-limit (bit, out)
axis.N.pos-lim-sw-in (bit, in) Should be driven TRUE if the positive limit switch for this joint is
closed
axis.N.pos-hard-limit (bit, out)
axis.N.neg-lim-sw-in (bit, in) Should be driven TRUE if the negative limit switch for this joint is
closed
axis.N.wheel-jog-active (bit, out)
5.2.2 Parameters
axis.N.home-state Reflects the step of homing currently taking place

5.3 iocontrol (userspace)

These pins are created by the userspace IO controller, usually called io.
5.3.1 Pins
iocontrol.0.coolant-flood (bit, out) TRUE when flood coolant is requested
iocontrol.0.coolant-mist (bit, out) TRUE when mist coolant is requested
iocontrol.0.emc-enable-in (bit, in) Should be driven FALSE when an external E-Stop condition
exists
iocontrol.0.lube (bit, out) TRUE when lube is commanded
iocontrol.0.lube_level (bit, in) Should be driven TRUE when lube level is high enough
iocontrol.0.tool-change (bit, out) TRUE when a tool change is requested
iocontrol.0.tool-changed (bit, in) Should be driven TRUE when a tool change is completed
iocontrol.0.tool-number (s32, out) The current tool number
iocontrol.0.tool-prep-number (s32, out) The number of the next tool, from the RS274NGC T-word
iocontrol.0.tool-prepare (bit, out) TRUE when a tool prepare is requested
iocontrol.0.tool-prepared (bit, in) Should be driven TRUE when a tool prepare is completed
iocontrol.0.user-enable-out (bit, out) FALSE when an internal E-Stop condition exists
iocontrol.0.user-request-enable (bit, out) TRUE when the user has requested that E-Stop be
cleared
31
Page 49
Part II
HAL
32
Page 50
Chapter 6

Getting Started

6.1 Hal Commands

More detailed information can be found in the man page for halcmd "man halcmd" in a terminal window. To see the HAL configuration and check the status of pins and parameters use the HAL Configuration window on the Machine menu in AXIS. To watch a pin status open the Watch tab and click on each pin you wish to watch and it will be added to the watch window.
Figure 6.1: HAL Configuration Window
33
Page 51
EMC V2.4 Integrator Manual Chapter 6. Getting Started
6.1.1 loadrt
The command "loadrt" loads a real time HAL component. Real time component functions need to be added to a thread to be updated at the rate of the thread. You cannot load a user space component into the real time space.
The syntax and an example:
loadrt <component> <options> loadrt mux4 count=1
6.1.2 addf
The command "addf" adds a real time component function to a thread. You have to add a function from a HAL real time component to a thread to get the function to update at the rate of the thread.
If you used the Stepper Config Wizard to generate your config you will have two threads.
base-thread (the high-speed thread): this thread handles items that need a fast response, like making step pulses, and reading and writing the parallel port.
servo-thread (the slow-speed thread): this thread handles items that can tolerate a slower response, like the motion controller, ClassicLadder, and the motion command handler.
The syntax and an example:
addf <component> <thread> addf mux4 servo-thread
6.1.3 loadusr
The command "loadusr" loads a user space HAL component. User space programs are their own separate processes, which optionally talk to other HAL components via pins and parameters. You cannot load real time components into user space.
Flags may be one or more of the following:
-W to wait for the component to become ready. The component is assumed to have the same name
as the first argument of the command.
-Wn <name> to wait for the component, which will have the given <name>.
-w to wait for the program to exit
-i to ignore the program return value (with -w)
The syntax and examples:
loadusr <component> <options> loadusr halui loadusr -Wn spindle gs2_vfd -n spindle in English it means "loadusr wait for name spindle component gs2_vfd name spindle." the -n spindle is part of the gs2_vfd component not the loadusr command.
34
Page 52
EMC V2.4 Integrator Manual Chapter 6. Getting Started
6.1.4 net
The command "net" creates a "connection" between a signal and and one or more pins. If the signal does not exist net creates the new signal. This replaces the need to use the command newsig. The direction indicators "<= and =>" are only to make it easier for humans to follow the logic and are not used by the net command.
The syntax and an example:
net <signal-name> <pin-name> <opt-direction> <opt-pin-name> net both-home-y <= parport.0.pin-11-in
Each signal can only have one source (a HAL "Dir out” pin) and as many readers (a HAL "Dir in" pin) as you like. In the Dir column of the HAL Configuration window you can see which pins are "in" and which are "out". The following figure shows the "direction" of the signal from the source, through the signal, and then out to the reader(s).
Figure 6.2: Signal Direction
This example shows the signal xStep with the source being stepgen.0.out and with two readers, parport.0.pin-02-out and parport.0.pin-08-out. Basically the value of stepgen.0.out is send to the signal xStep and that value is then sent to parport.0.pin-02-out and parport.0.pin-08-out.
signal source destination destination
net xStep stepgen.0.out => parport.0.pin-02-out parport.0.pin-08-out
Since the signal xStep contains the value of stepgen.0.out (the source) you can use the same signal again to send the value to another reader. To do this just use the signal with the readers on another line.
net xStep <= stepgen.0.out => parport.0.pin-02-out net xStep => parport.0.pin-08-out
The so called I/O pins like index-enable do not follow this rule.
35
Page 53
EMC V2.4 Integrator Manual Chapter 6. Getting Started
6.1.5 setp
The command "setp" sets the value of a pin or parameter. The valid values will depend on the type of the pin or parameter. It is an error if the data types do not match.
Some components have parameters that need to be set before use. Parameters can be set before use or while running as needed. You cannot use setp on a pin that is connected to a signal.
The syntax and an example:
setp <pin/parameter-name> <value> setp parport.0.pin-08-out TRUE
6.1.6 unlinkp
The command "unlinkp" unlinks a pin from the connected signal. If no signal was connected to the pin prior running the command, nothing happens.
The syntax and an example:
unlinkp <pin-name> unlinkp parport.0.pin-02-out
6.1.7 Obsolete Commands
6.1.7.1 linksp
The command "linksp" creates a "connection" between a signal and one pin.
The syntax and an example:
linksp <signal-name> <pin-name> linksp X-step parport.0.pin-02-out
The "linksp" command has been superseded by the "net" command.
6.1.7.2 linkps
The command "linkps" creates a "connection" between one pin and one signal. It is the same as linksp but the arguments are reversed.
The syntax and an example:
linkps <pin-name> <signal-name> linkps parport.0.pin-02-out X-Step
The "linkps" command has been superseded by the "net" command.
6.1.7.3 newsig
the command "newsig" creates a new HAL signal by the name <signame> and the data type of <type>. Type must be "bit", "s32", "u32" or "float". Error if <signame> all ready exists.
The syntax and an example:
newsig <signame> <type> newsig Xstep bit
More information can be found in the HAL manual or the man pages for halrun.
36
Page 54
EMC V2.4 Integrator Manual Chapter 6. Getting Started

6.2 Hal Data

6.2.1 Bit
A bit value is an on or off.
bit values = true or 1 and false or 0 (True, TRUE, true are all valid)
6.2.2 Float
A "float" is a floating point number. In other words the decimal point can move as needed.
float values = a 32 bit floating point value, with approximately 24 bits of resolution and over 200 bits of dynamic range.
For more information on floating point numbers see:
http://en.wikipedia.org/wiki/Floating_point
6.2.3 s32
An "s32" number is a whole number that can have a negative or positive value.
s32 values = integer numbers -2147483648 to 2147483647
6.2.4 u32
A "u32" number is a whole number that is positive only.
u32 values = integer numbers 0 to 4294967295

6.3 Hal Files

If you used the Stepper Config Wizard to generate your config you will have up to three HAL files in your config directory.
my-mill.hal (if your config is named "my-mill") This file is loaded first and should not be changed if you used the Stepper Config Wizard.
custom.hal This file is loaded next and before the GUI loads. This is where you put your custom HAL commands that you want loaded before the GUI is loaded.
custom_postgui.hal This file is loaded after the GUI loads. This is where you put your custom HAL commands that you want loaded after the GUI is loaded. Any HAL commands that use pyVCP widgets need to be placed here.
37
Page 55
EMC V2.4 Integrator Manual Chapter 6. Getting Started

6.4 HAL Components

Two parameters are automatically added to each HAL component when it is created. These param­eters allow you to scope the execution time of a component.
.time .tmax
Time is the number of CPU cycles it took to execute the function.
Tmax is the maximum number of CPU cycles it took to execute the function. Tmax is a read/write parameter so the user can set it to 0 to get rid of the first time initialization on the function’s execution time.

6.5 Logic Components

Hal contains several real time logic components. Logic components follow a "Truth Table" that states what the output is for any given input. Typically these are bit manipulators and follow electrical logic gate truth tables.
6.5.1 and2
The "and2" component is a two input "and" gate. The truth table below shows the output based on each combination of input.
Syntax
and2 [count=N] or [names=name1[,name2...]]
Functions
and2.n
Pins
and2.N.in0 (bit, in) and2.N.in1 (bit, in) and2.N.out (bit, out)
Truth Table
in0 in1 out
False False False
True False False
False True False
True True True
38
Page 56
EMC V2.4 Integrator Manual Chapter 6. Getting Started
6.5.2 not
The "not" component is a bit inverter.
Syntax
not [count=n] or [names=name1[,name2...]]
Functions
not.all not.n
Pins
not.n.in (bit, in) not.n.out (bit, out)
Truth Table
in out
True False
False True
6.5.3 or2
The "or2" component is a two input OR gate.
Syntax
or2[count=n] or [names=name1[,name2...]]
Functions
or2.n
Pins
or2.n.in0 (bit, in) or2.n.in1 (bit, in) or2.n.out (bit, out)
in0 in1 out
True False True
True True True False True True False False False
Truth Table
39
Page 57
EMC V2.4 Integrator Manual Chapter 6. Getting Started
6.5.4 xor2
The "xor2" component is a two input XOR (exclusive OR)gate.
Syntax
xor2[count=n] or [names=name1[,name2...]]
Functions
xor2.n
Pins
xor2.n.in0 (bit, in) xor2.n.in1 (bit, in) xor2.n.out (bit, out)
Truth Table
in0 in1 out
True False True
True True False False True True False False False
6.5.5 Logic Examples
An "and2" example connecting two inputs to one output.
loadrt and2 count=1 addf and2.0 servo-thread net my-sigin1 and2.0.in0 <= parport.0.pin-11-in net my-sigin2 and2.0.in1 <= parport.0.pin-12-in net both-on parport.0.pin-14-out <= and2.0.out
In the above example one copy of and2 is loaded into real time space and added to the servo thread. Next pin 11 of the parallel port is connected to the in0 bit of the and gate. Next pin 12 is connected to the in1 bit of the and gate. Last we connect the and2 out bit to the parallel port pin 14. So following the truth table for and2 if pin 11 and pin 12 are on then the output pin 14 will be on.

6.6 Conversion Components

6.6.1 weighted_sum
The weighted_sum converts a group of bits to an integer. The conversion is the sum of the "weights" of the bits that are on plus any offset. This is similar to a binary coded decimal but with more options. The "hold" bit stops processing the input changes so the "sum" will not change.
The following syntax is used to load the weighted_sum component.
loadrt weighted_sum wsum_sizes=size[,size,...]
40
Page 58
EMC V2.4 Integrator Manual Chapter 6. Getting Started
Creates weighted sum groups each with the given number of input bits (size).
To update the weighted_sum you need to attach process_wsums to a thread.
addf process_wsums servo-thread
This updates the weighted_sum component.
In the following example clipped from the HAL Configuration window in Axis the bits "0" and "2" are true and there is no offset. The "weight" of 0 is 1 and the "weight" of 2 is 4 so the sum is 5.
Figure 6.3: weighted_sum
41
Page 59
EMC V2.4 Integrator Manual Chapter 6. Getting Started

6.7 Halshow

The script halshow can help you find your way around a running HAL. This is a very specialized system and it must connect to a working HAL. It cannot run standalone because it relies on the ability of HAL to report what it knows of itself through the halcmd interface library. It is discovery based. Each time halshow runs with a different EMC configuration it will be different.
As we will soon see, this ability of HAL to document itself is one key to making an effective CNC system.
6.7.1 Starting Halshow
Halshow is in the AXIS menu under Machine/Show Hal Configuration.
Halshow is in the TkEMC menu under Scripts/Hal Show.
6.7.2 Hal Tree Area
At the left of its display as shown in figure 6.4 is a tree view, somewhat like you might see with some file browsers. At the right is a tabbed notebook with tabs for show and watch.
Figure 6.4: Halshow Layout
42
Page 60
EMC V2.4 Integrator Manual Chapter 6. Getting Started
The tree shows all of the major parts of a HAL. In front of each is a small plus (+) or minus (-) sign in a box. Clicking the plus will expand that tree node to display what is under it. If that box shows a minus sign, clicking it will collapse that section of the tree.
You can also expand or collapse the tree display using the Tree View menu at the upper left edge of the display. Under Tree View you will find: Expand Tree, Collapse Tree; Expand Pins, Expand Parameters, Expand Signals; and Erase Watch. (Note that Erase Watch erasesall previously set watches, you cannot erase just one watch.)
Figure 6.5: Show Menu
6.7.3 Hal Show Area
Clicking on the node name, the word "Components" for example, will show you (under the "Show" tab) all that hal knows about the contents of that node. Figure 6.4 shows a list exactly like you will see if you click the "Components" name while you are running a standard m5i20 servo card. The information display is exactly like those shown in traditional text based HAL analysis tools. The advantage here is that we have mouse click access, access that can be as broad or as focused as you need.
If we take a closer look at the tree display we can see that the six major parts of a HAL can all be expanded at least one level. As these levels are expanded you can get more focused with the reply when you click on the rightmost tree node. You will find that there are some hal pins and parameters that show more than one reply. This is due to the nature of the search routines in halcmd itself. If you search one pin you may get two, like this:
Component Pins: Owner Type Dir Value Name 06 bit -W TRUE parport.0.pin-10-in 06 bit -W FALSE parport.0.pin-10-in-not
The second pin’s name contains the complete name of the first.
Below the show area on the right is a set of widgets that will allow you to play with the running HAL. The commands you enter here and the effect that they have on the running HAL are not saved. They will persist as long as EMC remains up but are gone as soon as EMC is.
The entry box labeled "Test Hal Command:" will accept any of the commands listed for halcmd. These include:
loadrt, unloadrt (load/unload real-time module)
43
Page 61
EMC V2.4 Integrator Manual Chapter 6. Getting Started
loadusr, unloadusr (load/unload user-space component)
addf, delf (add/delete a function to/from a real-time thread)
net (create a connection between two or more items)
setp (set parameter (or pin) to a value)
This little editor will enter a command any time you press <enter> or push the execute button. An error message from halcmd will show below this entry widget when these commands are not properly formed. If you are not certain how to set up a proper command you’ll need to read again the documentation on halcmd and the specific modules that you are working with.
Let’s use this editor to add a differential module to a hal and connect it to axis position so that we could see the rate of change in position, i.e., acceleration. We first need to load a hal module named blocks, add it to the servo thread, then connect it to the position pin of an axis. Once that is done we can find the output of the differentiator in halscope. So let’s go. (Yes, I looked this one up.)
loadrt blocks ddt=1
Now look at the components node and you should see blocks in there someplace.
Loaded HAL Components: ID Type Name 10 User halcmd29800 09 User halcmd29374 08 RT blocks 06 RT hal_parport 05 RT scope_rt 04 RT stepgen 03 RT motmod 02 User iocontrol
Sure enough there it is. Notice that its ID is 08. Next we need to find out what functions are available with it so we look at functions:
Exported Functions: Owner CodeAddr Arg FP Users Name 08 E0B97630 E0DC7674 YES 0 ddt.0 03 E0DEF83C 00000000 YES 1 motion-command-handler 03 E0DF0BF3 00000000 YES 1 motion-controller 06 E0B541FE E0DC75B8 NO 1 parport.0.read 06 E0B54270 E0DC75B8 NO 1 parport.0.write 06 E0B54309 E0DC75B8 NO 0 parport.read-all 06 E0B5433A E0DC75B8 NO 0 parport.write-all 05 E0AD712D 00000000 NO 0 scope.sample 04 E0B618C1 E0DC7448 YES 1 stepgen.capture-position 04 E0B612F5 E0DC7448 NO 1 stepgen.make-pulses 04 E0B614AD E0DC7448 YES 1 stepgen.update-freq
Here we look for owner #08 and see that blocks has exported a function named ddt.0. We should be able to add ddt.0 to the servo thread and it will do its math each time the servo thread is updated. Once again we look up the addf command and find that it uses three arguments like this:
addf <functname> <threadname> [<position>]
We already know the functname=ddt.0 so let’s get the thread name right by expanding the thread node in the tree. Here we see two threads, servo-thread and base-thread. The position of ddt.0 in the thread is not critical. So we add the function ddt.0 to the servo-thread:
44
Page 62
EMC V2.4 Integrator Manual Chapter 6. Getting Started
addf ddt.0 servo-thread
This is just for viewing, so we leave position blank and get the last position in the thread. Figure 6.6 shows the state of halshow after this command has been issued.
Figure 6.6: Addf Command
Next we need to connect this block to something. But how do we know what pins are available? The answer is to look under pins. There we find ddt and see this:
Component Pins: Owner Type Dir Value Name 08 float R- 0.00000e+00 ddt.0.in 08 float -W 0.00000e+00 ddt.0.out
That looks easy enough to understand, but what signal or pin do we want to connect to it? It could be an axis pin, a stepgen pin, or a signal. We see this when we look at axis.0:
Component Pins: Owner Type Dir Value Name 03 float -W 0.00000e+00 axis.0.motor-pos-cmd ==> Xpos-cmd
So it looks like Xpos-cmd should be a good signal to use. Back to the editor where we enter the following command:
45
Page 63
EMC V2.4 Integrator Manual Chapter 6. Getting Started
linksp Xpos-cmd ddt.0.in
Now if we look at the Xpos-cmd signal using the tree node we’ll see what we’ve done:
Signals: Type Value Name float 0.00000e+00 Xpos-cmd <== axis.0.motor-pos-cmd ==> ddt.0.in ==> stepgen.0.position-cmd
We see that this signal comes from axis.o.motor-pos-cmd and goes to both ddt.0.in and stepgen.0.position­cmd. By connecting our block to the signal we have avoided any complications with the normal flow of this motion command.
The Hal Show Area uses halcmd to discover what is happening in a running HAL. It gives you complete information about what it has discovered. It also updates as you issue commands from the little editor panel to modify that HAL. There are times when you want a different set of things displayed without all of the information available in this area. That is where the Hal Watch Area is of value.
6.7.4 Hal Watch Area
Clicking the watch tab produces a blank canvas. You can add signals and pins to this canvas and watch their values.1You can add signals or pins when the watch tab is displayed by clicking on the name of it. Figure 6.7 shows this canvas with several "bit" type signals. These signals include enable-out for the first three axes and two of the three iocontrol "estop" signals. Notice that the axes are not enabled even though the estop signals say that EMC is not in estop. A quick look at TkEMC shows that the condition of EMC is ESTOP RESET. The amp enables do not turn true until the machine has been turned on.
1
The refresh rate of the watch display is much lower than Halmeter or Halscope. If you need good resolution of the timing
of signals those tools are much more effective.
46
Page 64
EMC V2.4 Integrator Manual Chapter 6. Getting Started
Figure 6.7: Watch Display
Watch displays bit type (binary) values using colored circles representing LEDs. They show as dark brown when a bit signal or pin is false, and as light yellow whenever that signal is true. If you select a pin or signal that is not a bit type (binary) signal, watch will show it as a numerical value.
Watch will quickly allow you to test switches or see the effect of changes that you make to EMC while using the graphical interface. Watch’s refresh rate is a bit slow to see stepper pulses, but you can use it for these if you move an axis very slowly or in very small increments of distance. If you’ve used IO_Show in EMC, the watch page in halshow can be set up to watch a parport much as IO_Show did.
47
Page 65
Chapter 7
Basic Configuration

7.1 Introduction

The preferred way to set up a standard stepper machine is with the Step Configuration Wizard. See the Getting Started Guide.
This chapter describes some of the more common settings for manually setting up a stepper based system. Because of the various possibilities of configuring EMC2, it is very hard to document them all, and keep this document relatively short.
The most common EMC2 usage is for stepper based systems. These systems are using stepper motors with drives that accept step & direction signals.
It is one of the simpler setups, because the motors run open-loop (no feedback comes back from the motors), yet the system needs to be configured properly so the motors don’t stall or lose steps.
Most of this chapter is based on the sample config released along with EMC2. The config is called stepper, and usually it is found in /etc/emc2/sample-configs/stepper.

7.2 Maximum step rate

With software step generation, the maximum step rate is one step per two BASE_PERIODs for step­and-direction output. The maximum requested step rate is the product of an axis’ MAX_VELOCITY and its INPUT_SCALE. If the requested step rate is not attainable, following errors will occur, par­ticularly during fast jogs and G0 moves.
If your stepper driver can accept quadrature input, use this mode. With a quadrature signal, one step is possible for each BASE_PERIOD, doubling the maximum step rate.
The other remedies are to decrease one or more of: the BASE_PERIOD (setting this too low will cause the machine to become unresponsive or even lock up), the INPUT_SCALE (if you can select different step sizes on your stepper driver, change pulley ratios, or leadscrew pitch), or the MAX_VELOCITY and STEPGEN_MAXVEL.
If no valid combination of BASE_PERIOD, INPUT_SCALE, and MAX_VELOCITY is acceptable, then consider using hardware step generation (such as with the emc2-supported Universal Stepper Con­troller, Mesa cards, and others.)

7.3 Pinout

One of the major flaws in EMC was that you couldn’t specify the pinout without recompiling the source code. EMC2 is far more flexible, and now (thanks to the Hardware Abstraction Layer) you
48
Page 66
EMC V2.4 Integrator Manual Chapter 7. Basic Configuration
can easily specify which signal goes where. See the HAL manual for more detailed information on HAL.
As it is described in the HAL Introduction and tutorial, we have signals, pins and parameters inside the HAL.
The ones relevant for our pinout are1:
signals: Xstep, Xdir & Xen pins: parport.0.pin-XX-out & parport.0.pin-XX-in
2
Depending on what you have chosen in your .ini file you are using either standard_pinout.hal or xylotex_pinout.hal. These are two files that instruct the HAL how to link the various signals & pins. Further on we’ll investigate the standard_pinout.hal.
7.3.1 standard_pinout.hal
This file contains several HAL commands, and usually looks like this:
# standard pinout config file for 3-axis steppers # using a parport for I/O # # first load the parport driver loadrt hal_parport cfg="0x0378" # # next connect the parport functions to threads # read inputs first addf parport.0.read base-thread 1 # write outputs last addf parport.0.write base-thread -1 # # finally connect physical pins to the signals net Xstep => parport.0.pin-03-out net Xdir => parport.0.pin-02-out net Ystep => parport.0.pin-05-out net Ydir => parport.0.pin-04-out net Zstep => parport.0.pin-07-out net Zdir => parport.0.pin-06-out
# create a signal for the estop loopback net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in
# create signals for tool loading loopback net tool-prep-loop iocontrol.0.tool-prepare iocontrol.0.tool-prepared net tool-change-loop iocontrol.0.tool-change iocontrol.0.tool-changed
# connect "spindle on" motion controller pin to a physical pin net spindle-on motion.spindle-on => parport.0.pin-09-out
### ### You might use something like this to enable chopper drives when machine ON ### the Xen signal is defined in core_stepper.hal ###
1
Note: we are only presenting one axis to keep it short, all others are similar.
2
Refer to section 9.1 for additional information
49
Page 67
EMC V2.4 Integrator Manual Chapter 7. Basic Configuration
# net Xen => parport.0.pin-01-out
### ### If you want active low for this pin, invert it like this: ###
# setp parport.0.pin-01-out-invert 1
### ### A sample home switch on the X axis (axis 0). make a signal, ### link the incoming parport pin to the signal, then link the signal ### to EMC’s axis 0 home switch input pin ###
# net Xhome parport.0.pin-10-in => axis.0.home-sw-in
### ### Shared home switches all on one parallel port pin? ### that’s ok, hook the same signal to all the axes, but be sure to ### set HOME_IS_SHARED and HOME_SEQUENCE in the ini file. See the ### user manual! ###
# net homeswitches <= parport.0.pin-10-in # net homeswitches => axis.0.home-sw-in # net homeswitches => axis.1.home-sw-in # net homeswitches => axis.2.home-sw-in
### ### Sample separate limit switches on the X axis (axis 0) ###
# net X-neg-limit parport.0.pin-11-in => axis.0.neg-lim-sw-in # net X-pos-limit parport.0.pin-12-in => axis.0.pos-lim-sw-in
### ### Just like the shared home switches example, you can wire together ### limit switches. Beware if you hit one, EMC will stop but can’t tell ### you which switch/axis has faulted. Use caution when recovering from this. ###
# net Xlimits parport.0.pin-13-in => axis.0.neg-lim-sw-in axis.0.pos-lim-sw-in
The files starting with ’#’ are comments, and their only purpose is to guide the reader through the file.
7.3.2 Overview of the standard_pinout.hal
There are a couple of operations that get executed when the standard_pinout.hal gets executed / interpreted:
1. The Parport driver gets loaded (see 9.1 for details)
2. The read & write functions of the parport driver get assigned to the base thread
3
the fastest thread in the EMC2 setup, usually the code gets executed every few microseconds
3
50
Page 68
EMC V2.4 Integrator Manual Chapter 7. Basic Configuration
3. The step & direction signals for axes X,Y,Z get linked to pins on the parport
4. Further IO signals get connected (estop loopback, toolchanger loopback)
5. A spindle-on signal gets defined and linked to a parport pin
7.3.3 Changing the standard_pinout.hal
If you want to change the standard_pinout.hal file, all you need is a text editor. Open the file and locate the parts you want to change.
If you want for example to change the pin for the X-axis Step & Directions signals, all you need to do is to change the number in the ’parport.0.pin-XX-out’ name:
net Xstep parport.0.pin-03-out net Xdir parport.0.pin-02-out
can be changed to:
net Xstep parport.0.pin-02-out net Xdir parport.0.pin-03-out
or basically any other numbers you like.
Hint: make sure you don’t have more than one signal connected to the same pin.
7.3.4 Changing the polarity of a signal
If external hardware expects an “active low” signal, set the corresponding -invert parameter. For instance, to invert the spindle control signal:
setp parport.0.pin-09-invert TRUE
7.3.5 Adding PWM Spindle Speed Control
If your spindle can be controlled by a PWM signal, use the pwmgen component to create the signal:
loadrt pwmgen output_type=0 addf pwmgen.update servo-thread addf pwmgen.make-pulses base-thread net spindle-speed-cmd motion.spindle-speed-out => pwmgen.0.value net spindle-on motion.spindle-on => pwmgen.0.enable net spindle-pwm pwmgen.0.pwm => parport.0.pin-09-out setp pwmgen.0.scale 1800 # Change to your spindle’s top speed in RPM
This assumes that the spindle controller’s response to PWM is simple: 0% PWM gives 0 RPM, 10% PWM gives 180 RPM, etc. If there is a minimum PWM required to get the spindle to turn, follow the example in the nist-lathe sample configuration to use a scale component.
51
Page 69
EMC V2.4 Integrator Manual Chapter 7. Basic Configuration
7.3.6 Adding an enable signal
Some amplifiers (drives) require an enable signal before they accept and command movement of the motors. For this reason there are already defined signals called ’Xen’, ’Yen’, ’Zen’.
To connect them use the following example:
net Xen parport.0.pin-08-out
You can either have one single pin that enables all drives; or several, depending on the setup you have. Note, however, that usually when one axis faults, all the other drives will be disabled as well, so having only one enable signal / pin for all drives is a common practice.
7.3.7 Adding an external ESTOP button
As you can see in 7.3.1 by default the stepper configuration assumes no external ESTOP button.
To add a simple external button you need to replace the line:
net estop-loop iocontrol.0.user-enable-out iocontrol.0.emc-enable-in
with
net estop-loop parport.0.pin-01-in iocontrol.0.emc-enable-in
This assumes an ESTOP switch connected to pin 01 on the parport. As long as the switch will stay pushed5, EMC2 will be in the ESTOP state. When the external button gets released EMC2 will imediately switch to the ESTOP-RESET state, and all you need to do is switch to Machine On and you’ll be able to continue your work with EMC2.
4
4
An extensive explanation of hooking up ESTOP circuitry is explained in the wiki.linuxcnc.org and in the Integrator
Manual
5
make sure you use a maintained switch for ESTOP.
52
Page 70
Chapter 8

HAL Components

8.1 Commands and Userspace Components

Some of these will have expanded descriptions from the man pages. Some will have limited descrip­tions. All of the components have man pages. From this list you know what components exist and can use man n name to get additional information. For example in a terminal window type
man 1 axis
to view the information in the man page.
axis-remote.1 = AXIS Remote Interface
axis.1 = AXIS EMC (The Enhanced Machine Controller) Graphical User Interface
bfload.1 = A program for loading a Xilinx Bitfile program into the FPGA of an Anything I/O board
from Mesa
comp.1 = Build, compile and install EMC HAL components
emc.1 = EMC (The Enhanced Machine Controller)
hal_input.1 = control HAL pins with any Linux input device, including USB HID devices
halcmd.1 = manipulate the Enhanced Machine Controller HAL from the command line
halmeter.1 = observe HAL pins, signals, and parameters
halrun.1 = manipulate the Enhanced Machine Controller HAL from the command line
halsampler.1 = sample data from HAL in realtime
halstreamer.1 = stream file data into HAL in real time
halui.1 = observe HAL pins and command EMC through NML
io.1 = accepts NML I/O commands, interacts with HAL in userspace
iocontrol.1 = accepts NML I/O commands, interacts with HAL in userspace
pyvcp.1 = Virtual Control Panel for EMC2
53
Page 71
EMC V2.4 Integrator Manual Chapter 8. HAL Components

8.2 Realtime Components

Some of these will have expanded descriptions from the man pages. Some will have limited descrip­tions. All of the components have man pages. From this list you know what components exist and can use man n name to get additional information in a terminal window.
8.2.1 abs
Compute the absolute value and sign of the input signal
8.2.1.0.0.1 Loading
loadrt abs [count=N|names=name1[,name2...]]
8.2.1.0.0.2 Functions
addf abs.N|name thread-name
8.2.1.0.0.3 Pins
abs.N.in (float in) Input value abs.N.out (float out) Output Value, always positive abs.N.sign (bit out) Sign of Input, false = positive, true = negative
The first abs loaded will be abs.0 and each one after that the "N" number will increment.
8.2.2 and2
Two-input AND gate. For out to be true both inputs must be true
8.2.2.0.0.4 Loading
loadrt and2 [count=N|names=name1[,name2...]]
8.2.2.0.0.5 Functions
addf and2.N|name thread-name
8.2.2.0.0.6 Pins
and2.N.in0 (bit in) Input 0 and2.N.in1 (bit in) Input 1 and2.N.out (bit out) Output
8.2.3 at_pid
proportional/integral/derivative controller with auto tuning
54
Page 72
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.4 axis
accepts NML motion commands, interacts with HAL in realtime
8.2.5 biquad
Biquad IIR filter
8.2.6 bldc_hall3
3-wire Bipolar trapezoidal commutation BLDC motor driver using Hall sensors
8.2.7 blend
Perform linear interpolation between two values
8.2.7.0.0.7 Loading
loadrt blend [count=N|names=name1[,name2...]]
8.2.7.0.0.8 Functions
addf blend.N|name thread-name
8.2.7.0.0.9 Pins
blend.N.in1 (float in) First input. blend.N.in2 (float in) Second input. blend.N.select (float in) Select input. blend.N.out (float out) Output value.
8.2.7.0.0.10 Parameters
blend.N.open (bit r/w)
8.2.7.0.0.11 Description If select is equal to 0.0 output is equal to in1.
If select is equal to 1.0, the output is equal to in2.
For select values between 0.0 and 1.0, the output changes linearly from in1 to in2.
If blend.N.open is true, select values outside the range 0.0 to 1.0 give values outside the range in1 to in2. If false, outputs are clamped to the the range in1 to in2
8.2.8 charge_pump
Create a square-wave for the "charge pump" input of some controller boards
55
Page 73
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.8.0.0.12 Loading
loadrt charge_pump
8.2.8.0.0.13 Functions
addf charge-pump
8.2.8.0.0.14 Pins
charge-pump.out (bit out) charge-pump.enable (bit in) default = TRUE
8.2.8.0.0.15 Description Outputs a square wave if enable is TRUE or unconnected, low if enable is FALSE
8.2.9 clarke2
Two input version of Clarke transform
8.2.9.0.0.16 Loading
loadrt clarke2 [count=N|names=name1[,name2...]]
8.2.9.0.0.17 Functions
addf clarke2.N | name
8.2.9.0.0.18 Pins
clarke2.N.a (float in) phase a input clarke2.N.b (float in) phase b input clarke2.N.x (float out) cartesian components of output clarke2.N.y (float out) cartesian components of output
8.2.9.0.0.19 Description The Clarke transform can be used to translate a vector quantity from a three phase system (three components 120 degrees apart) to a two phase Cartesian system.
clarke2 implements a special case of the Clarke transform, which only needs two of the three input phases. In a three wire three phase system, the sum of the three phase currents or voltages must always be zero. As a result only two of the three are needed to completely define the current or voltage. clarke2 assumes that the sum is zero, so it only uses phases A and B of the input. Since the H (homopolar) output will always be zero in this case, it is not generated.
8.2.10 clarke3
Clarke (3 phase to cartesian) transform
56
Page 74
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.10.0.0.20 Loading
loadrt clarke3 [count=N|names=name1[,name2...]]
8.2.10.0.0.21 Functions
addf clarke3.N | name
8.2.10.0.0.22 Pins
clarke3.N.a (float in) three phase input vector clarke3.N.b (float in) three phase input vector clarke3.N.c (float in) three phase input vector clarke3.N.x (float out) cartesian components of output clarke3.N.y (float out) cartesian components of output clarke3.N.h (float out) homopolar component of output
8.2.10.0.0.23 Description The Clarke transform can be used to translate a vector quantity from a three phase system (three components 120 degrees apart) to a two phase Cartesian system (plus a homopolar component if the three phases don’t sum to zero).
clarke3 implements the general case of the transform, using all three phases. If the three phases are known to sum to zero, see clarke2 for a simpler version.
8.2.11 clarkeinv
Inverse Clarke transform
8.2.11.0.0.24 Loading
loadrt clarkeinv [count=N|names=name1[,name2...]]
8.2.11.0.0.25 Functions
addf clarkeinv.N | name
8.2.11.0.0.26 Pins
clarkeinv.N.x (float in) cartesian components of input clarkeinv.N.y (float in) cartesian components of input clarkeinv.N.h (float in) homopolar component of input (usually zero) clarkeinv.N.a (float out) three phase output vector clarkeinv.N.b (float out) three phase output vector clarkeinv.N.c (float out) three phase output vector
8.2.11.0.0.27 Parameters
8.2.11.0.0.28 Description The inverse Clarke transform can be used to translate a vector quan-
tity from Cartesian coordinate system to a three phase system (three components 120 degrees apart).
57
Page 75
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.12 classicladder
Realtime software plc based on ladder logic
8.2.13 comp
Two input comparator with hysteresis
8.2.14 constant
Use a parameter to set the value of a pin
8.2.15 conv_bit_s32
Convert a value from bit to s32
8.2.16 conv_bit_u32
Convert a value from bit to u32
8.2.17 conv_float_s32
Convert a value from float to s32
8.2.18 conv_float_u32
Convert a value from float to u32
8.2.19 conv_s32_bit
Convert a value from s32 to bit
8.2.20 conv_s32_float
Convert a value from u32 to bit
8.2.21 conv_s32_u32
Convert a value from s32 to u32
8.2.22 conv_u32_bit
Convert a value from u32 to bit
58
Page 76
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.23 conv_u32_float
Convert a value from u32 to float
8.2.24 conv_u32_s32
Convert a value from u32 to s32
8.2.25 counter
counts input pulses (deprecated)
8.2.26 ddt
Compute the derivative of the input function
8.2.27 deadzone
Return the center if within the threshold
8.2.28 debounce
filter noisy digital inputs, for more information see 8.9
8.2.29 edge
Edge detector
8.2.30 encoder
software counting of quadrature encoder signals, for more information see 8.6
8.2.31 encoder_ratio
an electronic gear to synchronize two axes
8.2.32 estop_latch
ESTOP latch
8.2.33 feedcomp
Multiply the input by the ratio of current velocity to the feed rate
59
Page 77
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.34 flipflop
D type flip-flop
8.2.35 freqgen
software step pulse generation
8.2.36 gantrykins
A kinematics module that maps one axis to multiple joints
8.2.37 gearchange
Select from one two speed ranges
8.2.38 genhexkins
Gives six degrees of freedom in position and orientation (XYZABC). The location of the motors is defined at compile time.
8.2.39 genserkins
Kinematics that can model a general serial-link manipulator with up to 6 angular joints.
8.2.40 hm2_7i43
HAL driver for the Mesa Electronics 7i43 EPP Anything IO board with HostMot2
8.2.41 hm2_pci
HAL driver for the Mesa Electronics 5i20, 5i22, 5i23, 4i65, and 4i68 Anything IO boards, with HostMot2 firmware
8.2.42 hostmot2
HAL driver for the Mesa Electronics HostMot2 firmware
8.2.43 hypot
Three-input hypotenuse (Euclidean distance) calculator
8.2.44 ilowpass
Low-pass filter with integer inputs and outputs
60
Page 78
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.45 integ
Integrator
8.2.46 invert
Compute the inverse of the input signal
8.2.47 joyhandle
sets nonlinear joypad movements, deadbands and scales
8.2.48 kins
kinematics definitions for emc2
8.2.49 knob2float
Convert counts (probably from an encoder) to a float value
8.2.50 limit1
Limit the output signal to fall between min and max
8.2.51 limit2
Limit the output signal to fall between min and max
8.2.52 limit3
Limit the output signal to fall between min and max
8.2.53 logic
Experimental general logic function component
8.2.54 lowpass
Low-pass filter
8.2.55 lut5
Arbitrary 5-input logic function based on a look-up table
61
Page 79
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.56 maj3
Compute the majority of 3 inputs
8.2.57 match8
8-bit binary match detector
8.2.58 maxkins
Kinematics for a tabletop 5 axis mill named "max" with tilting head (B axis) and horizintal rotary mounted to the table (C axis). Provides UVW motion in the rotated coordinate system. The source file, maxkins.c, may be a useful starting point for other 5-axis systems.
8.2.59 minmax
Track the minimum and maximum values of the input to the outputs
8.2.60 motion
accepts NML motion commands, interacts with HAL in realtime
8.2.61 mult2
Product of two inputs
8.2.62 mux2
Select from one of two input values
8.2.63 mux4
Select from one of four input values
8.2.64 mux8
Select from one of eight input values
8.2.65 near
Determine whether two values are roughly equal
8.2.66 not
Inverter
62
Page 80
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.67 offset
Adds an offset to an input, and subtracts it from the feedback value
8.2.68 oneshot
one-shot pulse generator
8.2.69 or2
Two-input OR gate
8.2.70 pid
proportional/integral/derivative controller, for more information see 8.7
8.2.71 pluto_servo
Hardware driver and firmware for the Pluto-P parallel-port FPGA, for use with servos
8.2.72 pluto_step
Hardware driver and firmware for the Pluto-P parallel-port FPGA, for use with steppers
8.2.73 pwmgen
software PWM/PDM generation, for more information see 8.5
8.2.74 rotatekins
The X and Y axes are rotated 45 degrees compared to the joints 0 and 1.
8.2.75 sample_hold
Sample and Hold
8.2.76 sampler
sample data from HAL in real time
8.2.77 scale
applies a scale and offset to its input
63
Page 81
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.78 scarakins
kinematics for SCARA-type robots
8.2.79 select8
8-bit binary match detector
8.2.80 serport
Hardware driver for the digital I/O bits of the 8250 and 16550 serial port
8.2.81 siggen
signal generator, for more information see 8.10
8.2.82 sim_encoder
simulated quadrature encoder, for more information see 8.8
8.2.83 sphereprobe
Probe a pretend hemisphere
8.2.84 stepgen
software step pulse generation, for more information see 8.4
8.2.85 steptest
Used by Stepconf to allow testing of acceleration and velocity values for an axis
8.2.86 streamer
stream file data into HAL in real time
8.2.87 sum2
Sum of two inputs (each with a gain) and an offset
8.2.88 supply
set output pins with values from parameters (deprecated)
64
Page 82
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.89 thc
Torch Height Control using a Mesa THC card.
8.2.90 threads
creates hard realtime HAL threads
8.2.91 threadtest
component for testing thread behavior
8.2.92 timedelay
The equivalent of a time-delay relay
8.2.93 timedelta
component that measures thread scheduling timing behavior
8.2.94 toggle
push-on, push-off from momentary pushbuttons
8.2.95 toggle2nist
toggle button to nist logic
8.2.96 tripodkins
The joints represent the distance of the controlled point from three predefined locations (the motors), giving three degrees of freedom in position (XYZ)
8.2.97 tristate_bit
Place a signal on an I/O pin only when enabled, similar to a tristate buffer in electronics
8.2.98 tristate_float
Place a signal on an I/O pin only when enabled, similar to a tristate buffer in electronics
8.2.99 trivkins
There is a 1:1 correspondence between joints and axes. Most standard milling machines and lathes use the trivial kinematics module.
65
Page 83
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.2.100 updown
Counts up or down, with optional limits and wraparound behavior
8.2.101 wcomp
Window comparator
8.2.102 weighted_sum
convert a group of bits to an integer
8.2.103 xor2
Two-input XOR (exclusive OR) gate
8.2.103.0.0.29 Loading
8.2.103.0.0.30 Functions
8.2.103.0.0.31 Pins
8.2.103.0.0.32 Parameters
8.2.103.0.0.33 Description
66
Page 84
EMC V2.4 Integrator Manual Chapter 8. HAL Components

8.3 Hal Meter

Hal Meter can be loaded from a terminal or from Axis. Hal Meter is faster than Hal Show displaying values. Hal Meter has two windows, one to pick the pin, signal, or parameter to monitor and one that displays the value. Multiple Hal Meters can be open at the same time. If you use a script to open multiple Hal Meters you can set the position of each one with -g X Y relative to the upper left corner of your screen. See the man page for more options.
loadusr halmeter pin hm2.0.stepgen.00.velocity-fb -g 0 500
Figure 8.1: Hal Meter

8.4 Stepgen

This component provides software based generation of step pulses in response to position or velocity commands. In position mode, it has a built in pre-tuned position loop, so PID tuning is not required. In velocity mode, it drives a motor at the commanded speed, while obeying velocity and acceleration limits. It is a realtime component only, and depending on CPU speed, etc, is capable of maximum step rates of 10kHz to perhaps 50kHz. Figure 8.2 shows three block diagrams, each is a single step pulse generator. The first diagram is for step type ’0’, (step and direction). The second is for step type ’1’ (up/down, or pseudo-PWM), and the third is for step types 2 through 14 (various stepping patterns). The first two diagrams show position mode control, and the third one shows velocity mode. Control mode and step type are set independently, and any combination can be selected.
67
Page 85
EMC V2.4 Integrator Manual Chapter 8. HAL Components
velocity-cmd
position-cmd
position-cmd
phase-B
phase-E
phase-D
down
step
phase-A
phase-Cupdir
pos err
pos err
vel err
vel err
counts
counts
counts
position-fb
position-fb
position-fb
maxaccel
maxaccel
maxaccel
maxfreq
maxfreq
maxfreq
position
position
position
accumulator
accumulator
accumulator
lookup
table
ramp
ramp
ramp
ramp
latch
latch
latch
state
up/down
step/dir
counter
logic
logic
and
and
and
timing
timing
timing
frequency
frequency
frequency
stepspace
stepspace
dirsetup
dirdelay
dirdelay
dirhold
steplen
steplen
steplen
rawcounts
rawcounts
rawcounts
position-scale
position-scale
position-scale
dddTdTstate
hold
hold
hold
make_pulses()
make_pulses()
make_pulses()
STEP TYPE = 1
STEP TYPE = 2 - 14
CTRL TYPE = VELOCITY
CTRL TYPE = POSITION
CTRL TYPE = POSITION
STEP TYPE = 0
update_freq()
update_freq()
update_freq()
capture_position()
capture_position()
capture_position()
stepgen.0
stepgen.0
stepgen.0
1/x
1/x
1/x
control
control
equation
equation
Figure 8.2: Step Pulse Generator Block Diagram (position mode)
68
Page 86
EMC V2.4 Integrator Manual Chapter 8. HAL Components
velocity
velocity
velocity
phase-B
phase-E
phase-D
down
step
phase-A
phase-Cupdir
counts
counts
counts
position
position
position
maxfreq
maxfreq
maxfreq
frequency
generator
frequency
generator
frequency
generator
state
counter
lookup
table
ramp
ramp
ramp
latch
latch
latch
counter
counter
counter
step/dir
logic
and
timing
maxaccel
maxaccel
maxaccel
frequency
frequency
frequency
stepspace
dirsetup
dirhold
steplen
rawcounts
rawcounts
rawcounts
velocity-scale
velocity-scale
velocity-scale
position-scale
position-scale
position-scale
up/dn
up/dn
up/dn
up/dn
up/dn
up/dn
count
count
count
count
count
count
make_pulses()
make_pulses()
STEP TYPE = 1
STEP TYPE = 2 - 14
STEP TYPE = 0
make_pulses()
update_freq()
update_freq()
update_freq()
capture_position()
capture_position()
capture_position()
freqgen.0
freqgen.0
freqgen.0
Figure 8.3: Step Pulse Generator Block Diagram (velocity mode)
69
Page 87
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.4.1 Installing
emc2$ halcmd loadrt stepgen step_type=<type-array> [ctrl_type=<ctrl_array>]
<type-array> is a series of comma separated decimal integers. Each number causes a single step pulse generator to be loaded, the value of the number determines the stepping type. <ctrl_array> is a comma separated series of “p” or “v” characters, to specify position or velocity mode. ctrl_type is optional, if ommitted, all of the step generators will be position mode. For example:
emc2# halcmd loadrt stepgen step_type=0,0,2 ctrl_type=p,p,v
will install three step generators. The first two use step type ’0’ (step and direction) and run in position mode. The last one uses step type ’2’ (quadrature) and runs in velocity mode. The default value for <config-array> is “0,0,0” which will install three type ’0’ (step/dir) generators. The maximum number of step generators is 8 (as defined by MAX_CHAN in stepgen.c). Each generator is independent, but all are updated by the same function(s) at the same time. In the following descriptions, <chan> is the number of a specific generator. The first generator is number 0.
8.4.2 Removing
emc2$ halcmd unloadrt stepgen
8.4.3 Pins
Each step pulse generator will have only some of these pins, depending on the step type and control type selected.
(F L O A T) stepgen.<chan>.position-cmd – Desired motor position, in position units (position mode only).
(F L O A T) stepgen.<chan>.velocity-cmd – Desired motor velocity, in position units per sec­ond (velocity mode only).
• (S32) stepgen.<chan>.counts – Feedback position in counts, updated by capture_position().
• (F L O A T) stepgen.<chan>.position-fb – Feedback position in position units, updated by
capture_position().
• (B I T) stepgen.<chan>.enable – Enables output steps - when false, no steps are generated.
• (B I T) stepgen.<chan>.step – Step pulse output (step type 0 only).
• (B I T) stepgen.<chan>.dir – Direction output (step type 0 only).
• (B I T) stepgen.<chan>.up – UP pseudo-PWM output (step type 1 only).
• (B I T) stepgen.<chan>.down – DOWN pseudo-PWM output (step type 1 only).
• (B I T) stepgen.<chan>.phase-A – Phase A output (step types 2-14 only).
• (B I T) stepgen.<chan>.phase-B – Phase B output (step types 2-14 only).
• (B I T) stepgen.<chan>.phase-C – Phase C output (step types 3-14 only).
• (B I T) stepgen.<chan>.phase-D – Phase D output (step types 5-14 only).
• (B I T) stepgen.<chan>.phase-E – Phase E output (step types 11-14 only).
70
Page 88
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.4.4 Parameters
(F L O A T) stepgen.<chan>.position-scale – Steps per position unit. This parameter is used for both output and feedback.
(F L O A T) stepgen.<chan>.maxvel – Maximum velocity, in position units per second. If 0.0, has no effect.
(F L O A T) stepgen.<chan>.maxaccel – Maximum accel/decel rate, in positions units per sec­ond squared. If 0.0, has no effect.
• (F L O A T) stepgen.<chan>.frequency – The current step rate, in steps per second.
• (F L O A T) stepgen.<chan>.steplen – Length of a step pulse (step type 0 and 1) or minimum
time in a given state (step types 2-14), in nano-seconds.
(F L O A T) stepgen.<chan>.stepspace – Minimum spacing between two step pulses (step types 0 and 1 only), in nano-seconds.
(F L O A T) stepgen.<chan>.dirsetup – Minimum time from a direction change to the begin­ning of the next step pulse (step type 0 only), in nanoseconds.
(F L O A T) stepgen.<chan>.dirhold – Minmum time from the end of a step pulse to a direction change (step type 0 only), in nanoseconds.
(F L O A T) stepgen.<chan>.dirdelay – Minmum time any step to a step in the opposite direc­tion (step types 1-14 only), in nano-seconds.
(S32) stepgen.<chan>.rawcounts – The raw feedback count, updated by make_pulses().
In position mode, the values of maxvel and maxaccel are used by the internal position loop to avoid generating step pulse trains that the motor cannot follow. When set to values that are appropriate for the motor, even a large instantaneous change in commanded position will result in a smooth trapezoidal move to the new location. The algorithm works by measuring both position error and velocity error, and calculating an acceleration that attempts to reduce both to zero at the same time. For more details, including the contents of the “control equation” box, consult the code.
In velocity mode, maxvel is a simple limit that is applied to the commanded velocity, and maxaccel is used to ramp the actual frequency if the commanded velocity changes abruptly. As in position mode, proper values for these parameters ensure that the motor can follow the generated pulse train.
8.4.5 Step Types
The step generator supports 15 different “step types”. Step type 0 is the most familiar, standard step and direction. When configured for step type 0, there are four extra parameters that determine the exact timing of the step and direction signals. See figure 8.4 for the meaning of these parameters. The parameters are in nanoseconds, but will be rounded up to an integer multiple of the thread period for the threaed that calls make_pulses(). For example, if make_pulses() is called every 16uS, and steplen is 20000, then the step pulses will be 2 x 16 = 32uS long. The default value for all four of the parameters is 1nS, but the automatic rounding takes effect the first time the code runs. Since one step requires steplen nS high and stepspace nS low, the maximum frequency is 1,000,000,000 divided by (steplen+stepspace). If maxfreq is set higher than that limit, it will be lowered automatically. If maxfreq is zero, it will remain zero, but the output frequency will still be limited.
Step type 1 has two outputs, up and down. Pulses appear on one or the other, depending on the direction of travel. Each pulse is steplen nS long, and the pulses are separated by at least stepspace nS. The maximum frequency is the same as for step type 0. If maxfreq is set higher
71
Page 89
EMC V2.4 Integrator Manual Chapter 8. HAL Components
steplen
steplen
stepspace
(min)
stepspace
(min)
dirsetup
(min)
dirsetup
(min)
dirhold
(min)
steplen
step
direction
Figure 8.4: Step and Direction Timing
than the limit it will be lowered. If maxfreq is zero, it will remain zero but the output frequency will still be limited.
Step types 2 through 14 are state based, and have from two to five outputs. On each step, a state counter is incremented or decremented. Figures 8.5, 8.6, and 8.7 show the output patterns as a function of the state counter. The maximum frequency is 1,000,000,000 divided by steplen, and as in the other modes, maxfreq will be lowered if it is above the limit.
8.4.6 Functions
The component exports three functions. Each function acts on all of the step pulse generators ­running different generators in different threads is not supported.
(F U N C T) stepgen.make-pulses – High speed function to generate and count pulses (no float­ing point).
(F U N C T) stepgen.update-freq – Low speed function does position to velocity conversion, scaling and limiting.
(F U N C T) stepgen.capture-position – Low speed function for feedback, updates latches and scales position.
The high speed function stepgen.make-pulses should be run in a very fast thread, from 10 to 50uS depending on the capabilities of the computer. That thread’s period determines the maximum step frequency, since steplen, stepspace, dirsetup, dirhold, and dirdelay are all rounded up to a integer multiple of the thread periond in nanoseconds. The other two functions can be called at a much lower rate.
72
Page 90
EMC V2.4 Integrator Manual Chapter 8. HAL Components
00011122214003325100211322003
4
STEP TYPE 3
STEP TYPE 4
STEP TYPE 2
phase-A
phase-A
phase-A
phase-B
phase-B
phase-B
phase-C
phase-C
Figure 8.5: Three-Phase step types
73
Page 91
EMC V2.4 Integrator Manual Chapter 8. HAL Components
0
000
0011111122222200004433333311115522226633337700000
0 STEP TYPE 5
STEP TYPE 6
STEP TYPE 7
STEP TYPE 8
STEP TYPE 9
STEP TYPE 10
phase-A
phase-A
phase-A
phase-A
phase-A
phase-A
phase-B
phase-B
phase-B
phase-B
phase-B
phase-B
phase-C
phase-C
phase-C
phase-C
phase-C
phase-C
phase-D
phase-D
phase-D
phase-D
phase-D
phase-D
Figure 8.6: Four-Phase Step Types
74
Page 92
EMC V2.4 Integrator Manual Chapter 8. HAL Components
00000011111122222244444433333355667788990000STEP TYPE 11
STEP TYPE 12
STEP TYPE 14
STEP TYPE 13
phase-A
phase-A
phase-A
phase-A
phase-B
phase-B
phase-B
phase-B
phase-C
phase-C
phase-C
phase-C
phase-D
phase-D
phase-D
phase-D
phase-E
phase-E
phase-E
phase-E
Figure 8.7: Five-Phase Step Types
75
Page 93
EMC V2.4 Integrator Manual Chapter 8. HAL Components

8.5 PWMgen

This component provides software based generation of PWM (Pulse Width Modulation) and PDM (Pulse Density Modulation) waveforms. It is a realtime component only, and depending on CPU speed, etc, is capable of PWM frequencies from a few hundred Hertz at pretty good resolution, to perhaps 10KHz with limited resolution.
8.5.1 Installing
emc2$ halcmd loadrt pwmgen output_type=<config-array>
<config-array> is a series of comma separated decimal integers. Each number causes a single
PWM generator to be loaded, the value of the number determines the output type. For example:
emc2$ halcmd loadrt pwmgen output_type=0,1,2
will install three PWM generators. The first one will use output type ’0’ (PWM only), the next uses output type 1 (PWM and direction) and the last one uses output type 2 (UP and DOWN). There is no default value, if <config-array> is not specified, no PWM generators will be installed. The maximum number of frequency generators is 8 (as defined by MAX_CHAN in pwmgen.c). Each generator is independent, but all are updated by the same function(s) at the same time. In the following descriptions, <chan> is the number of a specific generator. The first generator is number
0.
8.5.2 Removing
emc2$ halcmd unloadrt pwmgen
8.5.3 Pins
Each PWM generator will have the following pins:
(F L O A T) pwmgen.<chan>.value – Command value, in arbitrary units. Will be scaled by the scale parameter (see below).
(B I T) pwmgen.<chan>.enable – Enables or disables the PWM generator outputs.
Each PWM generator will also have some of these pins, depending on the output type selected:
• (B I T) pwmgen.<chan>.pwm – PWM (or PDM) output, (output types 0 and 1 only).
• (B I T) pwmgen.<chan>.dir – Direction output (output type 1 only).
• (B I T) pwmgen.<chan>.up – PWM/PDM output for positive input value (output type 2 only).
• (B I T) pwmgen.<chan>.down – PWM/PDM output for negative input value (output type 2 only).
76
Page 94
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.5.4 Parameters
(F L O A T) pwmgen.<chan>.scale – Scaling factor to convert value from arbitrary units to duty cycle.
(F L O A T) pwmgen.<chan>.pwm-freq – Desired PWM frequency, in Hz. If 0.0, generates PDM instead of PWM. If set higher than internal limits, next call of update_freq() will set it to the internal limit. If non-zero, and dither is false, next call of update_freq() will set it to the nearest integer multiple of the make_pulses() function period.
(B I T) pwmgen.<chan>.dither-pwm – If true, enables dithering to achieve average PWM fre­quencies or duty cycles that are unobtainable with pure PWM. If false, both the PWM frequency and the duty cycle will be rounded to values that can be achieved exactly.
(F L O A T) pwmgen.<chan>.min-dc – Minimum duty cycle, between 0.0 and 1.0 (duty cycle will go to zero when disabled, regardless of this setting).
• (F L O A T) pwmgen.<chan>.max-dc – Maximum duty cycle, between 0.0 and 1.0.
• (F L O A T) pwmgen.<chan>.curr-dc – Current duty cycle - after all limiting and rounding (read
only).
8.5.5 Output Types
The PWM generator supports three different “output types”. Type 0 has a single output pin. Only positive commands are accepted, negative values are treated as zero (and will be affected by min-dc if it is non-zero). Type 1 has two output pins, one for the PWM/PDM signal and one to indicate direction. The duty cycle on the PWM pin is based on the absolute value of the command, so negative values are acceptable. The direction pin is false for positive commands, and true for negative commands. Finally, type 2 also has two outputs, called up and down. For positive commands, the PWM signal appears on the up output, and the down output remains false. For negative commands, the PWM signal appears on the down output, and the up output remains false. Output type 2 is suitable for driving most H-bridges.
8.5.6 Functions
The component exports two functions. Each function acts on all of the PWM generators - running different generators in different threads is not supported.
(F U N C T) pwmgen.make-pulses – High speed function to generate PWM waveforms (no floating point).
(F U N C T) pwmgen.update – Low speed function to scale and limit value and handle other paremeters.
The high speed function pwmgen.make-pulses should be run in a very fast thread, from 10 to 50uS depending on the capabilities of the computer. That thread’s period determines the maximum PWM carrier frequency, as well as the resolution of the PWM or PDM signals. The other function can be called at a much lower rate.
77
Page 95
EMC V2.4 Integrator Manual Chapter 8. HAL Components
reset
index-enable
phase-Z
phase-B
phase-A
counts
position
latch
counter
edge
detect
quad
decode
rawcounts
position-scale
up/dn
count
clear
update-counters()
capture-position()
encoder.0

8.6 Encoder

This component provides software based counting of signals from quadrature encoders. It is a realtime component only, and depending on CPU speed, latency, etc, is capable of maximum count rates of 10kHz to perhaps up to 50kHz. Figure 8.8 is a block diagram of one channel of encoder counter.
Figure 8.8: Encoder Counter Block Diagram
8.6.1 Installing
emc2$ halcmd loadrt encoder [num_chan=<counters>]
<counters> is the number of encoder counters that you want to install. If numchan is not specified,
three counters will be installed. The maximum number of counters is 8 (as defined by MAX_CHAN in encoder.c). Each counter is independent, but all are updated by the same function(s) at the same time. In the following descriptions, <chan> is the number of a specific counter. The first counter is number 0.
8.6.2 Removing
emc2$ halcmd unloadrt encoder
78
Page 96
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.6.3 Pins
encoder.<chan>.counter-mode (bit, I/O) (default: FALSE) – Enables counter mode. When true, the counter counts each rising edge of the phase-A input, ignoring the value on phase-B. This is useful for counting the output of a single channel (non-quadrature) sensor. When false, it counts in quadrature mode.
encoder.<chan>.counts (s32, Out) – Position in encoder counts.
encoder.<chan>.counts-latched (s32, Out) – Not used at this time.
encoder.<chan>.index-enable (bit, I/O) – When True, counts and position are reset to
zero on next rising edge of Phase Z. At the same time, index-enable is reset to zero to indicate that the rising edge has occoured. The index-enable pin is bi-directional. If index-enable is False, the Phase Z channel of the encoder will be ignored, and the counter will count normally. The encoder driver will never set index-enable True. However, some other component may do so.
encoder.<chan>.latch-falling (bit, In) (default: TRUE) – Not used at this time.
encoder.<chan>.latch-input (bit, In) (default: TRUE) – Not used at this time.
encoder.<chan>.latch-rising (bit, In) – Not used at this time.
encoder.<chan>.min-speed-estimate (float, in) – Determine the minimum true velocity
magnitude at which velocity will be estimated as nonzero and postition-interpolated will be interpolated. The units of min-speed-estimate are the same as the units of velocity. Scale factor, in counts per length unit. Setting this parameter too low will cause it to take a long time for velocity to go to 0 after encoder pulses have stopped arriving.
encoder.<chan>.phase-A (bit, In) – Phase A of the quadrature encoder signal.
encoder.<chan>.phase-B (bit, In) – Phase B of the quadrature encoder signal.
encoder.<chan>.phase-Z (bit, In) – Phase Z (index pulse) of the quadrature encoder signal.
encoder.<chan>.position (float, Out) – Position in scaled units (see position-scale).
encoder.<chan>.position-interpolated (float, Out) – Position in scaled units, interpolated
between encoder counts. The position-interpolated attempts to interpolate between en­coder counts, based on the most recently measured velocity. Only valid when velocity is ap­proximately constant and above min-speed-estimate. Do not be used for position control, since its value is incorrect at low speeds, during direction reversals, and during speed changes. However, it allows a low ppr encoder (including a one pulse per revolution "encoder") to be used for lathe threading, and may have other uses as well.
encoder.<chan>.position-latched (float, Out) – Not used at this time.
encoder.<chan>.position-scale (float, I/O) – Scale factor, in counts per length unit.
For example, if position-scale is 500, then 1000 counts of the encoder will be reported as a position of 2.0 units.
encoder.<chan>.rawcounts (s32, In) – The raw count, as determined by update-counters. This value is updated more frequently than counts and position. It is also unaffected by reset or the index pulse.
encoder.<chan>.reset (bit, In) – When True, force counts and position to zero immedi- ately.
encoder.<chan>.velocity (float, Out) – Velocity in scaled units per second. encoder uses an algorithm that greatly reduces quantization noise as compared to simply differentiating the position output. When the magnitude of the true velocity is below min-velocity-estimate, the velocity output is 0.
79
Page 97
EMC V2.4 Integrator Manual Chapter 8. HAL Components
encoder.<chan>.x4-mode (bit, I/O) (default: TRUE) – Enables times-4 mode. When true, the counter counts each edge of the quadrature waveform (four counts per full cycle). When false, it only counts once per full cycle. In counter-mode, this parameter is ignored. The 1x mode is usefull for some jogwheels.
8.6.4 Parameters
encoder.<chan>.capture-position.time (s32, RO)
encoder.<chan>.capture-position.tmax (s32, RW)
encoder.<chan>.update-counters.time (s32, RO)
encoder.<chan>.update-counter.tmax (s32, RW)
8.6.5 Functions
The component exports two functions. Each function acts on all of the encoder counters - running different counters in different threads is not supported.
• (F U N C T) encoder.update-counters – High speed function to count pulses (no floating point).
• (F U N C T) encoder.capture-position – Low speed function to update latches and scale po-
sition.
80
Page 98
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.7 PID
This component provides Proportional/Integeral/Derivative control loops. It is a realtime compo­nent only. For simplicity, this discussion assumes that we are talking about position loops, however this component can be used to implement other feedback loops such as speed, torch height, tem­perature, etc. Figure 8.9 is a block diagram of a single PID loop.
8.7.1 Installing
emc2$ halcmd loadrt pid [num_chan=<loops>] [debug=1]
<loops> is the number of PID loops that you want to install. If numchan is not specified, one loop
will be installed. The maximum number of loops is 16 (as defined by MAX_CHAN in pid.c). Each loop is completely independent. In the following descriptions, <loopnum> is the loop number of a specific loop. The first loop is number 0.
If debug=1 is specified, the component will export a few extra parameters that may be useful during debugging and tuning. By default, the extra parameters are not exported, to save shared memory space and avoid cluttering the parameter list.
8.7.2 Removing
emc2$ halcmd unloadrt pid
8.7.3 Pins
The three most important pins are
(F L O A T) pid.<loopnum>.command – The desired position, as commanded by another system component.
(F L O A T) pid.<loopnum>.feedback – The present position, as measured by a feedback device such as an encoder.
(F L O A T) pid.<loopnum>.output – A velocity command that attempts to move from the present position to the desired position.
For a position loop, ’command’ and ’feedback’ are in position units. For a linear axis, this could be inches, mm, meters, or whatever is relevant. Likewise, for an angular axis, it could be degrees, radians, etc. The units of the ’output’ pin represent the change needed to make the feedback match the command. As such, for a position loop ’Output’ is a velocity, in inches/sec, mm/sec, degrees/sec, etc. Time units are always seconds, and the velocity units match the position units. If command and feedback are in meters, then output is in meters per second.
Each loop has two pins which are used to monitor or control the general operation of the component.
• (F L O A T) pid.<loopnum>.error – Equals .command minus .feedback.
• (B I T) pid.<loopnum>.enable – A bit that enables the loop. If .enable is false, all integrators
are reset, and the output is forced to zero. If .enable is true, the loop operates normally.
Pins used to report saturation. Saturation occurs when the output of the PID block is at its maxi­mum or minimum limit.
• (B I T) pid.<loopnum>.saturated – True when output is saturated.
• (F L O A T) pid.<loopnum>.saturated_s – The time the output has been saturated.
• (S32) pid.<loopnum>.saturated_count – The time the output has been saturated.
81
Page 99
EMC V2.4 Integrator Manual Chapter 8. HAL Components
output
enable
command
feedback
error
max-cmdDD
max-cmdD
max-errorD
Pgain
FF2
bias
FF0
FF1
Dgain
Igain
max-errorI
max-output
max-error
deadband
pid.0
ddddTdT
dT
Figure 8.9: PID Loop Block Diagram
82
Page 100
EMC V2.4 Integrator Manual Chapter 8. HAL Components
8.7.4 Parameters
The PID gains, limits, and other ’tunable’ features of the loop are implemented as parameters.
• (F L O A T) pid.<loopnum>.Pgain – Proportional gain
• (F L O A T) pid.<loopnum>.Igain – Integral gain
• (F L O A T) pid.<loopnum>.Dgain – Derivative gain
• (F L O A T) pid.<loopnum>.bias – Constant offset on output
• (F L O A T) pid.<loopnum>.FF0 – Zeroth order feedforward - output proportional to command
(position).
(F L O A T) pid.<loopnum>.FF1 – First order feedforward - output proportional to derivative of command (velocity).
(F L O A T) pid.<loopnum>.FF2 – Second order feedforward - output proportional to 2nd deriva­tive of command (acceleration)1.
• (F L O A T) pid.<loopnum>.deadband – Amount of error that will be ignored
• (F L O A T) pid.<loopnum>.maxerror – Limit on error
• (F L O A T) pid.<loopnum>.maxerrorI – Limit on error integrator
• (F L O A T) pid.<loopnum>.maxerrorD – Limit on error derivative
• (F L O A T) pid.<loopnum>.maxcmdD – Limit on command derivative
• (F L O A T) pid.<loopnum>.maxcmdDD – Limit on command 2nd derivative
• (F L O A T) pid.<loopnum>.maxoutput – Limit on output value
All of the max??? limits are implemented such that if the parameter value is zero, there is no limit.
If debug=1 was specified when the component was installed, four additional parameters will be exported:
• (F L O A T) pid.<loopnum>.errorI – Integral of error.
• (F L O A T) pid.<loopnum>.errorD – Derivative of error.
• (F L O A T) pid.<loopnum>.commandD – Derivative of the command.
• (F L O A T) pid.<loopnum>.commandDD – 2nd derivative of the command.
8.7.5 Functions
The component exports one function for each PID loop. This function performs all the calculations needed for the loop. Since each loop has its own function, individual loops can be included in different threads and execute at different rates.
(F U N C T) pid.<loopnum>.do_pid_calcs – Performs all calculations for a single PID loop.
If you want to understand the exact algorithm used to compute the output of the PID loop, refer to figure 8.9, the comments at the beginning of emc2/src/hal/components/pid.c, and of course to the code itself. The loop calculations are in the C function calc_pid().
1
FF2 is not currently implemented, but it will be added. Consider this note a “FIXME” for the code
83
Loading...