Example Program

Closed loop with homing

Description

This program demonstrates the use of the home to home switch instruction (HM) in closed loop, also there is a move on input routine. The Homing method used is HM1, which will slew at VM (Max Velocity) in the negative direction, when input 1 is activated, the axis will creep in the plus direction at VI (Initial Velocity).

See the MCode Home to home switch command and change the homing method to experiment with different methods of homing. Output 1 is set to activate when the axis is moving. Stalling the motor will generate an error, activating output 2.

The code shown on the right may be copied and pasted into the program editor window of the Motion Control Programmer application, or a zip file containing the program files may be downloaded below.

Topics

  • Closed Loop/Encoder
  • MCode OS

Applicable Product

  • Lexium MDrive
  • MDrive Linear Actuator
  • MDrive Plus
  • MForce

Resource Files

'Global variable declarations Ee=1 Vm=4096 Vi=Vm/50 A=20480 D=A Hc=50 Rc=50 Mt=50 'Encoder setup Sf=20 Sm=0 Db=5 'I/O setup Is = 1, 1, 0 'Homing input Is = 2, 0, 1 'General purpose input Os = 1, 17, 1 'Moving output Os = 2, 18, 1 'Error output D1=100 '[PROGRAMS] 'Main program will home in mode 1 'Slew minus @ VM until to find 'home switch then creep plus @ VI PG 1 LB G1 H 1000 PR C1 ,C1 PR C2 ,C2 Pm=1 PR "Position counter: " C1 PR "Encoder counter: " C2 H 5000 HM 1 H P=0 'After homing, motor will 'move @ 7186 steps each move 'printing position each time LB G2 BR G2,I2=1 MR 7186 H PR "Position: " P BR G2 E PG
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'LEXIUM MDRIVE DEMO PROGRAM
'Last modified 02/21/2013
'Sample test program for demonstration purposes only
'Not tested or verified for safety or any function
CP 'preclear program space
 
'[VARIABLES]
'Global variable declarations
Ee=1
Vm=4096
Vi=Vm/50
A=20480
D=A
Hc=50
Rc=50
Mt=50
 
'Encoder setup
Sf=20
Sm=0
Db=5
 
'I/O setup
Is = 1, 1, 0  'Homing input
Is = 2, 0, 1  'General purpose input
Os = 1, 17, 1  'Moving output
Os = 2, 18, 1  'Error output
D1=100
 
'[PROGRAMS]
'Main program will home in mode 1
'Slew minus @ VM until to find
'home switch then creep plus @ VI
 
PG 1
  LB G1
     H 1000
     PR C1 ,C1
     PR C2 ,C2
     Pm=1
     PR "Position counter: " C1
     PR "Encoder counter: " C2
     H 5000
     HM 1
     H
     P=0
    
    'After homing, motor will
    'move @ 7186 steps each move
    'printing position each time
   LB G2
      BR G2,I2=1
     MR 7186
     H
     PR "Position: " P
     BR G2
  E
PG