Kollmorgen AkD BASlC Basic User Manual

AKD BASIC™
User Guide
Edition March 30, 2012, Revision A
Valid for Hardware Revision C
Patents Pending
Part Number 903-2000014-00
Keep all manualsas a product component during the life span ofthe product.
Passallmanuals to future users/owners of the product.
Record of Document Revisions:
Revision Remarks
06/2011, Rev A Launch Version for M_01-06-00-000
Windows is a registered trademark of Microsoft Corporation AKD is a registered trademark of Kollmorgen Corporation
Current patents:
US Patent 5,646,496 (used in control card R/D and 1 Vp-p feedback interface)
US Patent 5,162,798 (used in control card R/D)
US Patent 6,118,241 (used in control card simple dynamic braking)
Technical changes which improve the performance of the device may be made without prior notice.
Printed in the United States of America This document is the intellectual property of Kollmorgen™. All rights reserved. No part of this work may be reproduced in any form (by photocopying, microfilm or any other method) or stored, processed, copied or distributed by electronic means without the written permission of Kollmorgen™.
Kollmorgen™ | March 30, 2012 2
This page intentionally left blank.
3 Kollmorgen™ | March 30, 2012
Table of Contents
1 About this User Guide 16 2 Program View 17
2.1 Toolbar Options 17
2.1.1 New ... 17
2.1.2 Save / Save As 17
2.1.3 Open 18
2.1.4 Edit Parameters Section 18
2.1.5 Compile / Download / Run 18
2.1.6 Continue / Pause / Stop 18
2.1.7 Debug 18
2.1.8 View 19
2.1.9 Format Document 19
2.1.10 Insert Code Snippet 19
2.1.11 Upload? 19
2.1.12 Lock 19
3 AKDBASICLanguage 20
3.1 AKD BASIC Program Structure 20
3.1.1 Local Variables 20
3.1.2 Global Variables 20
3.2 Program Sections 21
3.2.1 Program Template 21
3.2.2 Setup Parameter Definitions 21
3.2.3 Global Variables, Constants, and Aliases 22
3.2.4 Variable Definitions 22
3.2.5 Constant Definitions 22
3.2.6 Alias Definitions 23
3.3 Main Program, Subroutines, Functions & Interrupt Handlers 23
3.3.1 Main Definitions 23
3.3.2 Subroutine Definition 24
3.3.3 Function Definition 25
3.3.4 Interrupt Handler Definition 25
3.4 Language Definition 26
3.4.1 Lexical Conventions 26
3.4.2 Identifiers 26
3.4.3 Data Types 26
3.4.4 Literal Constants 27
3.4.5 Decimal Integer Constants 27
3.4.6 Hexadecimal Constants 27
3.4.7 Floating-Point Constants 27
3.5 Statements 28
3.5.1 Alias 28
3.5.2 Call 28
Kollmorgen™ | March 30, 2012 4
3.5.3 Cls 28
3.5.4 Const 28
3.5.5 Dim 29
3.5.6 Exit 29
3.5.7 For…Next 29
3.5.8 Function 30
3.5.9 GoTo 30
3.5.10 If…Then…Else 30
3.5.11 $Include 31
3.5.12 Input 31
3.5.13 Interrupt … End Interrupt 31
3.5.14 MOVE.ABORT 31
3.5.15 MOVE.GOABS 31
3.5.16 MOVE.GOHOME 31
3.5.17 MOVE.GOREL 32
3.5.18 MOVE.GOUPDATE 32
3.5.19 MOVE.GOVEL 32
3.5.20 On Error GoTo 32
3.5.21 Pause( ) 33
3.5.22 Print 33
3.5.23 Example 33
3.5.24 VM.RESTART 33
3.5.25 Select Case 33
3.5.26 Static 34
3.5.27 Stop 34
3.5.28 Sub…End Sub 34
3.5.29 Swap 35
3.5.30 When 35
3.5.31 While…Wend 35
3.6 Built-in Functions 35
3.6.1 Parameters and Commands 36
3.7 Expressions 37
3.7.1 Arithmetic Expressions 37
3.7.2 Numeric Operators 37
3.7.3 Logical Operators 37
3.7.4 String Operators 38
3.7.5 Example 38
3.8 Function Invocation 38
3.8.1 $INCLUDE 38
3.9 Arrays and Function Parameter Lists 39
3.9.1 Optimizations 39
3.10 ModBus TCP/IP 41
3.10.1 ModBus Parameter Table 41
3.10.2 ModBus Register and Data Types 41
3.10.3 User Created Variables with Assigned Modbus Address Numbers 41
5 Kollmorgen™ | March 30, 2012
3.10.4 Drive Fault Table 42
3.10.5 Drive Parameter Scaling Over Modbus 42
3.10.6 Special Modbus AKD Parameters 42
3.10.7 ModBus Dynamic Mapping 43
3.11 Cam Profiling 43
3.11.1 Procedure 43
3.11.2 Related Variables 43
3.11.3 Cam Wizard 44
3.11.4 Example 45
3.11.5 Program 45
3.11.6 Virtual encoder (virtual master) 46
3.11.7 Move Parameters 47
3.11.8 Move Statements 47
3.11.9 Other Variables 47
4 Quick Reference: Parameters, Functions, Operators 48
4.1 AKD Parameters and Commands 48
4.2 AKDBASICParameters and Commands 55
5 AKD BASIC Functions 63
5.1 ABS() 64
5.2 ASC() 65
5.3 ATAN() 66
5.4 CHR$() 67
5.5 CINT() 68
5.6 COS() 69
5.7 EXP() 70
5.8 FIX() 71
5.9 HEX$() 72
5.10 INKEY$() 73
5.11 INSTR() 74
5.12 INT() 75
5.13 LCASE$() 76
5.14 LEFT$() 77
5.15 LEN() 78
5.16 LOG() 79
5.17 LOG10() 80
5.18 LTRIM$() 81
5.19 MID$ 82
5.20 OCT$() 83
5.21 RIGHT$() 84
5.22 RTRIM$() 85
5.23 SGN() 86
5.24 SIN() 87
5.25 SPACE$() 88
5.26 SQR() 89
5.27 STR$() 90
Kollmorgen™ | March 30, 2012 6
5.28 STRING$() 91
5.29 TAN() 92
5.30 TRIM$() 93
5.31 UCASE$() 94
5.32 VAL() 95
6 AKD BASIC Parameters, Operators, Statements 96
6.1 Additional Statements 97
6.1.1 $Include 98
6.1.2 Alias 99
6.1.3 Call 100
6.1.4 Cls 101
6.1.5 Const 102
6.1.6 Dim 103
6.1.7 Exit 104
6.1.8 For...Next 105
6.1.9 Function 106
6.1.10 GoTo 107
6.1.11 If...Then...Else 108
6.1.12 Input 109
6.1.13 On Error GoTo 110
6.1.14 Pause() 112
6.1.15 Print 113
6.1.16 Restart 114
6.1.17 Select Case 115
6.1.18 Static 116
6.1.19 Stop 117
6.1.20 Sub...End Sub 118
6.1.21 Swap 119
6.1.22 While...Wend 120
6.2 Operators 121
6.2.1 MOD 122
6.3 AIN Parameters 123
6.3.1 AIN.CUTOFF 124
6.3.2 AIN.DEADBAND 125
6.3.3 AIN.DEADBANDMODE 127
6.3.4 AIN.ISCALE 129
6.3.5 AIN.MODE 130
6.3.6 AIN.OFFSET 131
6.3.7 AIN.PSCALE 132
6.3.8 AIN.VALUE 134
6.3.9 AIN.VSCALE 135
6.3.10 AIN.ZERO 137
6.4 AOUT Parameters 139
6.4.1 AOUT.CUTOFF 140
6.4.2 AOUT.DEBUGADDR 141
7 Kollmorgen™ | March 30, 2012
6.4.3 AOUT.DEBUGDATATYPE 142
6.4.4 AOUT.DEBUGSCALE 143
6.4.5 AOUT.ISCALE 144
6.4.6 AOUT.MODE 145
6.4.7 AOUT.OFFSET 146
6.4.8 AOUT.PSCALE 147
6.4.9 AOUT.VALUE 149
6.4.10 AOUT.VALUEU 150
6.4.11 AOUT.VSCALE 151
6.5 CAM Parameters 152
6.5.1 CAM.ACTIVATE 153
6.5.2 CAM.ADDPOINT 155
6.5.3 CAM.CORRECTDIR 157
6.5.4 CAM.CREATE 158
6.5.5 CAM.MASTER 160
6.5.6 CAM.MASTERPOS 161
6.5.7 CAM.SLAVEOFFSET 162
6.5.8 CAMVM.DIR 163
6.5.9 CAMVM.FREQ 164
6.5.10 CAMVM.GOREL 165
6.5.11 CAMVM.GOUPDATE 166
6.5.12 CAMVM.GOVEL 167
6.5.13 CAMVM.MOVING 168
6.5.14 CAMVM.POSITION 169
6.5.15 CAMVM.RELATIVEDIST 170
6.5.16 CAMVM.STOP 171
6.6 CAP Parameters 172
6.6.1 CAP0.EDGE, CAP1.EDGE 173
6.6.2 CAP0.EN, CAP1.EN 174
6.6.3 CAP0.EVENT, CAP1.EVENT 175
6.6.4 CAP0.FILTER, CAP1.FILTER 178
6.6.5 CAP0.MODE, CAP1.MODE 179
6.6.6 CAP0.PLFB, CAP1.PLFB 180
6.6.7 CAP0.PREEDGE, CAP1.PREEDGE 181
6.6.8 CAP0.PREFILTER, CAP1.PREFILTER 182
6.6.9 CAP0.PRESELECT, CAP1.PRESELECT 183
6.6.10 CAP0.STATE, CAP1.STATE 184
6.6.11 CAP0.T, CAP1.T 185
6.6.12 CAP0.TRIGGER, CAP1.TRIGGER 186
6.7 CS Parameters 188
6.7.1 CS.DEC 189
6.7.2 CS.STATE 190
6.7.3 CS.TO 191
6.7.4 CS.VTHRESH 192
6.8 DIN Parameters 193
Kollmorgen™ | March 30, 2012 8
6.8.1 DIN.ROTARY 194
6.8.2 DIN.STATES 195
6.8.3 DIN1.FILTER TO DIN7.FILTER 196
6.8.4 DIN1.INV to DIN7.INV 197
6.8.5 DIN1.MODE to DIN19.MODE 198
6.8.6 DIN1.STATE TO DIN7.STATE 200
6.8.7 DIN9.STATE to DIN11.STATE 201
6.9 DIO Parameters 202
6.9.1 DIO9.INV to DIO11.INV 203
6.9.2 DIO9.DIR to DIO11.DIR 204
6.10 DOUT Parameters 205
6.10.1 DOUT.RELAYMODE 206
6.10.2 DOUT.STATES 207
6.10.3 DOUT8.MODE to DOUT11.MODE 208
6.10.4 DOUT1.PARAM AND DOUT2.PARAM 209
6.10.5 DOUT1.STATE AND DOUT2.STATE 210
6.10.6 DOUT1.STATEU AND DOUT2.STATEU 211
6.10.7 DOUT9.STATE to DOUT11.STATE 212
6.10.8 DOUT9.STATEU to DOUT11.STATEU 213
6.11 DRV Parameters 214
6.11.1 DRV.ACC 215
6.11.2 DRV.ACTIVE 217
6.11.3 DRV.BLINKDISPLAY 218
6.11.4 DRV.CLRFAULTHIST 219
6.11.5 DRV.CLRFAULTS 220
6.11.6 DRV.CMDSOURCE 221
6.11.7 DRV.DBILIMIT 222
6.11.8 DRV.DEC 223
6.11.9 DRV.DIR 224
6.11.10 DRV.DIS 226
6.11.11 DRV.DISSOURCES 227
6.11.12 DRV.DISTO 228
6.11.13 DRV.EMUEDIR 229
6.11.14 DRV.EMUEMODE 230
6.11.15 DRV.EMUEMTURN 232
6.11.16 DRV.EMUERES 233
6.11.17 DRV.EMUEZOFFSET 234
6.11.18 DRV.EN 235
6.11.19 DRV.FAULT1 to DRV.FAULT10 236
6.11.20 DRV.HANDWHEEL 237
6.11.21 DRV.HANDWHEELSRC 238
6.11.22 DRV.HWENABLE 239
6.11.23 DRV.ICONT 240
6.11.24 DRV.IPEAK 241
6.11.25 DRV.NAME 242
9 Kollmorgen™ | March 30, 2012
6.11.26 DRV.NVLOAD 243
6.11.27 DRV.NVSAVE 244
6.11.28 DRV.OPMODE 245
6.11.29 DRV.RSTVAR 246
6.11.30 DRV.SETUPREQBITS 247
6.11.31 DRV.STOP 248
6.11.32 DRV.SWENABLE 249
6.11.33 DRV.TIME 250
6.11.34 DRV.WARNING1 to DRV.WARNING10 251
6.12 EGEAR Parameters 252
6.12.1 EGEAR.ACCLIMIT 253
6.12.2 EGEAR.DECLIMIT 254
6.12.3 EGEAR.ERROR 255
6.12.4 EGEAR.LOCK 256
6.12.5 EGEAR.ON 257
6.12.6 EGEAR.PULSESIN 258
6.12.7 EGEAR.PULSEOUT 259
6.12.8 EGEAR.RATIO 260
6.12.9 EGEAR.TYPE 261
6.13 EXTENCODER Parameters 262
6.13.1 EXTENCODER.FREQ 263
6.13.2 EXTENCODER.POSITION 264
6.13.3 EXTENCODER.POSMODULO 265
6.14 FAULT Parameters 266
6.14.1 FAULTx.ACTION 267
6.15 FB1 Parameters 268
6.15.1 FB1.BISSBITS 269
6.15.2 FB1.ENCRES 270
6.15.3 FB1.HALLSTATE 271
6.15.4 FB1.HALLSTATEU 272
6.15.5 FB1.HALLSTATEV 273
6.15.6 FB1.HALLSTATEW 274
6.15.7 FB1.IDENTIFIED 275
6.15.8 FB1.INITSIGNED 276
6.15.9 FB1.MECHPOS 277
6.15.10 FB1.MEMDUMP 278
6.15.11 FB1.MEMVER 279
6.15.12 FB1.ORIGIN 280
6.15.13 FB1.P 282
6.15.14 FB1.PDIR 283
6.15.15 FB1.POFFSET 284
6.15.16 FB1.POLES 285
6.15.17 FB1.PSCALE 286
6.15.18 FB1.PUNIT 287
6.15.19 FB1.SELECT 288
Kollmorgen™ | March 30, 2012 10
6.16 FB2 Parameters 290
6.16.1 FB2.ENCRES 291
6.16.2 FB2.MODE 292
6.16.3 FB2.P 293
6.16.4 FB2P.DIR 294
6.16.5 FB2.POFFSET 294
6.16.6 FB2.PUNIT 295
6.16.7 FB2.SOURCE 296
6.17 FB3 Parameters 297
6.17.1 FB3.MODE 298
6.17.2 FB3.POFFSET 299
6.17.3 FB3.PUNIT 300
6.18 HWLS Parameters 301
6.18.1 HWLS.NEGSTATE 302
6.18.2 HWLS.POSSTATE 303
6.19 IL Parameters 304
6.19.1 IL.BUSFF 305
6.19.2 IL.CMD 306
6.19.3 IL.CMDU 307
6.19.4 IL.DFOLDT 308
6.19.5 IL.DIFOLD 309
6.19.6 IL.FB 310
6.19.7 IL.FF 311
6.19.8 IL.FOLDFTHRESH 312
6.19.9 IL.FOLDWTHRESH 313
6.19.10 IL.IFOLD 314
6.19.11 IL.IUFB 315
6.19.12 IL.IVFB 316
6.19.13 IL.KP 317
6.19.14 IL.KPDRATIO 318
6.19.15 IL.LIMITN 319
6.19.16 IL.LIMITP 320
6.19.17 IL.MFOLDD 321
6.19.18 IL.MFOLDR 322
6.19.19 IL.MFOLDT 323
6.19.20 IL.MIFOLD 324
6.19.21 IL.VCMD 325
6.19.22 IL.VUFB 326
6.19.23 IL.VVFB 327
6.20 INTR Parameters 328
6.20.1 Interrupt {Source} 329
6.20.2 Interrupt...End Interrupt 332
6.21 LOAD Parameters 333
6.21.1 LOAD.INERTIA 334
6.22 MODBUS Paramters 335
11 Kollmorgen™ | March 30, 2012
6.22.1 MODBUS.READFLOAT 336
6.22.2 MODBUS.WRITEFLOAT 337
6.23 MOTOR Parameters 338
6.23.1 MOTOR.BRAKE 339
6.23.2 MOTOR.BRAKEIMM 340
6.23.3 MOTOR.BRAKERLS 341
6.23.4 MOTOR.ICONT 342
6.23.5 MOTOR.INERTIA 343
6.23.6 MOTOR.IPEAK 344
6.23.7 MOTOR.KE 345
6.23.8 MOTOR.KT 346
6.23.9 MOTOR.LQLL 347
6.23.10 MOTOR.NAME 348
6.23.11 MOTOR.PHASE 349
6.23.12 MOTOR.PITCH 350
6.23.13 MOTOR.POLES 351
6.23.14 MOTOR.R 352
6.23.15 MOTOR.TBRAKEAPP 353
6.23.16 MOTOR.TBRAKERLS 354
6.23.17 MOTOR.TEMP 355
6.23.18 MOTOR.TEMPFAULT 356
6.23.19 MOTOR.TEMPWARN 357
6.23.20 MOTOR.TYPE 358
6.23.21 MOTOR.VOLTMAX 359
6.24 MOVE Parameters 360
6.24.1 MOVE.ABORT 361
6.24.2 MOVE.ACC 362
6.24.3 MOVE.DEC 364
6.24.4 MOVE.DIR 366
6.24.5 MOVE.DWELLTIME 367
6.24.6 MOVE.GOABS 368
6.24.7 MOVE.GOHOME 369
6.24.8 MOVE.GOREL 370
6.24.9 MOVE.GOUPDATE 371
6.24.10 MOVE.GOVEL 372
6.24.11 MOVE.INPOSITION 373
6.24.12 MOVE.INPOSLIMIT 374
6.24.13 MOVE.MOVING 375
6.24.14 MOVE.POSCOMMAND 376
6.24.15 MOVE.RELATIVEDIST 377
6.24.16 MOVE.RUNSPEED 378
6.24.17 MOVE.SCURVETIME 379
6.24.18 MOVE.TARGETPOS 380
6.25 PL Parameters 381
6.25.1 PL.CMD 382
Kollmorgen™ | March 30, 2012 12
6.25.2 PL.ERR 383
6.25.3 PL.ERRFTHRESH 384
6.25.4 PL.ERRMODE 386
6.25.5 PL.ERRWTHRESH 388
6.25.6 PL.FB 390
6.25.7 PL.FBSOURCE 391
6.25.8 PL.INTINMAX 392
6.25.9 PL.INTOUTMAX 394
6.25.10 PL.KI 396
6.25.11 PL.KP 397
6.25.12 PL.MODP1 398
6.25.13 PL.MODP2 399
6.25.14 PL.MODPDIR 400
6.25.15 PL.MODPEN 401
6.26 PLS Parameters 402
6.26.1 PLS.EN 403
6.26.2 PLS.MODE 404
6.26.3 PLS.P1 TO PLS.P8 405
6.26.4 PLS.RESET 406
6.26.5 PLS.STATE 407
6.26.6 PLS.T1 TO PLS.T8 408
6.26.7 PLS.UNITS 409
6.26.8 PLS.WIDTH1 TO PLS.WIDTH8 411
6.27 REC Parameters 413
6.27.1 REC.ACTIVE 413
6.27.2 REC.DONE 414
6.27.3 REC.OFF 415
6.27.4 REC.TRIG 416
6.28 REGEN Parameters 417
6.28.1 REGEN.POWER 418
6.28.2 REGEN.REXT 419
6.28.3 REGEN.TEXT 420
6.28.4 REGEN.TYPE 421
6.28.5 REGEN.WATTEXT 422
6.29 STO Parameters 423
6.29.1 STO.STATE 424
6.30 SWLS Parameters 425
6.30.1 SWLS.EN 426
6.30.2 SWLS.LIMIT0 427
6.30.3 SWLS.LIMIT1 428
6.30.4 SWLS.STATE 429
6.31 UNIT Parameters 430
6.31.1 UNIT.ACCLINEAR 431
6.31.2 UNIT.ACCROTARY 432
6.31.3 UNIT.LABEL 433
13 Kollmorgen™ | March 30, 2012
6.31.4 UNIT.PIN 434
6.31.5 UNIT.PLINEAR 435
6.31.6 UNIT.POUT 436
6.31.7 UNIT.PROTARY 437
6.31.8 UNIT.VLINEAR 438
6.31.9 UNIT.VROTARY 439
6.32 VBUS Parameters 440
6.32.1 VBUS.OVFTHRESH 441
6.32.2 VBUS.OVWTHRESH 442
6.32.3 VBUS.RMSLIMIT 443
6.32.4 VBUS.UVFTHRESH 444
6.32.5 VBUS.UVMODE 445
6.32.6 VBUS.UVWTHRESH 446
6.32.7 VBUS.VALUE 447
6.33 VL Parameters 448
6.33.1 VL.ARPF1 TO VL.ARPF4 449
6.33.2 VL.ARPQ1 TO VL.ARPQ4 451
6.33.3 VL.ARTYPE1 TO VL.ARTYPE4 453
6.33.4 VL.ARZF1 TO VL.ARZF4 454
6.33.5 VL.ARZQ1 TO VL.ARZQ4 456
6.33.6 VL.BUSFF 458
6.33.7 VL.CMD 459
6.33.8 VL.CMDU 460
6.33.9 VL.ERR 461
6.33.10 VL.FB 462
6.33.11 VL.FBFILTER 463
6.33.12 VL.FBSOURCE 464
6.33.13 VL.FBUNFILTERED 465
6.33.14 VL.FF 466
6.33.15 VL.GENMODE 467
6.33.16 VL.KBUSFF 468
6.33.17 VL.KI 469
6.33.18 VL.KP 470
6.33.19 VL.KVFF 471
6.33.20 VL.LIMITN 472
6.33.21 VL.LIMITP 473
6.33.22 VL.LMJR 474
6.33.23 VL.THRESH 475
6.34 VM Parameters 477
6.34.1 VM.AUTOSTART 478
6.34.2 VM.ERR 479
6.34.3 VM.INTRTIMER 481
6.34.4 VM.RESTART 482
6.35 WHEN Parameters 483
6.35.1 When 484
Kollmorgen™ | March 30, 2012 14
6.35.2 WHEN.DRVHANDWHEEL 486
6.35.3 WHEN.DRVTIME 487
6.35.4 WHEN.FB1MECHPOS 488
6.35.5 WHEN.PLCMD 489
6.35.6 WHEN.PLFB 490
6.36 WS Parameters 491
6.36.1 WS.ARM 492
6.36.2 WS.DISARM 493
6.36.3 WS.DISTMAX 494
6.36.4 WS.DISTMIN 495
6.36.5 WS.IMAX 496
6.36.6 WS.MODE 497
6.36.7 WS.NUMLOOPS 498
6.36.8 WS.STATE 499
6.36.9 WS.T 500
6.36.10 WS.TDELAY1 501
6.36.11 WS.TDELAY2 502
6.36.12 WS.TDELAY3 503
6.36.13 WS.VTHRESH 504
15 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 1 About this User Guide

1 About this User Guide

This guide describes the operation and use of the AKD drive. Each section details a specific topic related to the use of the product in simple terms which will help you get the most from the product. Each section includes examples to help guide you in setting up and using the various features available in the drive.
This guide is for users who have installed and tested the drive according to the AKD Installation Manual. The AKD Installation Manual is included on the product CD and contains critical safety information.
Kollmorgen™ | March 30, 2012 16
AKD BASIC User Guide | 2 Program View

2 Program View

The program view in AKD WorkBench is specific to AKD BASIC drives and can only be accessed using an AKD BASIC drive type in either online or offline mode. Programs can be compiled in offline mode, but an AKD BASIC drive must be connected to download and run a program.

2.1 Toolbar Options

The toolbar at the top of the program view contains a number of tools to assist you in programming.

2.1.1 New ...

The Program view loads as an empty window. Create a new program by clicking the new icon in the upper-left corner and selecting either BASIC or BASICUsing Current Drive Params. The BASIC selection will load an empty template. The BASICUsing Current Drive Params selection will populate the template with all current drive values. Then select the location and name of your new project file, and click save.
This will load the BASICtemplate from which you can begin programming.

2.1.2 Save / Save As

Once you have written your program, save it using the "Save" or "Save As" function on the toolbar .
17 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 2 Program View

2.1.3 Open

To open a previous project file click the "Open" function and locate your file in the explorer.

2.1.4 Edit Parameters Section

Clicking on the Edit Params Section tool will prompt you to populate the Params section of your code with all the current drive settings. Clicking yes will overwrite all current param defintions with the current drive values.

2.1.5 Compile / Download / Run

The Compile button will compile your source code to binary so that you may download the program to the drive.
The Download button will download your compiled code and source code to the drive by default. If you do not wish to download the source code to the drive, go to the options menu, choose download and de­select download source with binary.
The run button will issue a VM.START to start the BASIC program in the drive. If the active BASIC pro­gram in the editor is different than the program in the drive, the run button will compile and download the program before running.

2.1.6 Continue / Pause / Stop

The Continue, Pause, and Stop options allow you to control your program while it is running.

2.1.7 Debug

The Debugger allows you to set break points and step through your program.
Kollmorgen™ | March 30, 2012 18
AKD BASIC User Guide | 2 Program View

2.1.8 View

Use Find and Replace to find keywords in your program and replace them with a new keyword
Use the Go To Line to go to a specific line of code
Watch will open the expression evaluator tab. The expression evaluator is only valid while using the debugger. You can evaluate any drive parameter or user defined variable when the program is paused by the debugger.
Call Stack will open the call stack tab

2.1.9 Format Document

The format document tool implements correct line indentation across all code.

2.1.10 Insert Code Snippet

The Insert Code Snippet tool presents a list of existing code snippets, which can be selected and inserted into the program at the point where the cursor is currently placed.

2.1.11 Upload?

The upload tool uploads the source code from the drive. If the source code has not been downloaded, this option is not available. The tools menu allows you to select if the source code is to be downloaded with the binary.

2.1.12 Lock

The lock tool password protects the source code in the drive. If a new program is downloaded to a drive, the original source code and password protection is erased.
19 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
3 AKDBASICLanguage
This chapter describes the overall structure of an AKD BASIC program and the elements of the AKD BASIC language. Topics covered are:
l scope l program structure
l setup parameters l global variables, constants and aliases l ‘main’ program, subroutines, functions and interrupt handlers
l language description
l lexical conventions l identifiers l data types l constants l statements l built-in functions l parameters l expressions l function invocation l $include l arrays and parameter lists l optimizations

3.1 AKD BASIC Program Structure

3.1.1 Local Variables

The notion of ‘scope’ is a key concept in AKD BASIC programs. By ‘scope’, we mean those parts of the program in which a particular name is ‘visible’. There are two levels of scope in AKD BASIC — global and local. Variables (and constant definitions, aliases, etc.) defined inside a ‘main’ definition, or a subroutine, function, or interrupt handler definition, are considered to be ‘local’ in scope (visible only within that function).

3.1.2 Global Variables

All other definitions (those occurring outside functions) are considered ‘global’ in scope (visible inside main, and inside any subroutine, function, or interrupt handler). For example, consider the following simple AKD BASIC program:
'-------------- Define (dim) Global Variables -
-------
dim i as integer
'-------------- Main Program ------------------
-------
Main
dim i as integer for i = 1 to 10 print "the cube of "; i; "is "; cube(i) call increment next i
End Main
Kollmorgen™ | March 30, 2012 20
AKD BASIC User Guide | 3 AKDBASICLanguage
'-------------- Subroutines and Functions -----
-------
function cube(i as integer) as integer
cube = i * i * i
end function sub increment
i = i + 1
end sub
This program prints a table of the cubes of the integers from 1 to 10. The first (global) definition of ‘i’ is visible inside subroutine ‘increment’, but ‘shadowed’ by the ‘i’ in main and function ‘cube’. The definition of ‘i’ inside ‘main’ is local to ‘main’, and is NOT the same variable as the ‘i’ inside the function ‘cube’, or inside the subroutine ‘increment’. These same scope rules apply to constant definitions and aliases, as well.

3.2 Program Sections

The major sections of an AKD BASIC program are:
l setup parameter definitions l global variables, constants, and aliases l ‘main’ program, subroutines, functions, and interrupt handlers
Although these sections may appear in any order, we recommend that you keep them in the order shown, or at least, choose a single layout style and use it consistently.

3.2.1 Program Template

The program below is an example of the template generated automatically by WorkBench:
'-------------- Device Params -----------------
------
Params
End Params
'-------------- Define (dim) Global Variables -
------­'-------------- Main Program ------------------
-------
Main
End Main
'-------------- Subroutines and Functions ----
--------
'-------------- Interrupt Routines -----------
--------
These sections are described in greater detail in the following paragraphs.

3.2.2 Setup Parameter Definitions

This section of the program defines the setup parameters for drive tuning and configuration. It is executed immediately upon power-up (if VM.AUTOSTART = 1), before entering main, and before any interrupts are enabled. The section begins with Param and ends with End Param
21 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
(this is similar to the format used to define a subroutine or function). The only statements per­mitted in this section are assignment statements of the form:
<parameter> = <constant expression>
This section can be automatically generated by WorkBench when a New Program is created. Choose "current drive parameters" to include the connected drive's setup parameters in your program. If you choose to not include the setup parameters in your program, be sure to save the setup parameters to the drive to ensure proper drive setup upon power up.

3.2.3 Global Variables, Constants, and Aliases

This section contains variables, constant definitions, and global alias expressions — they apply everywhere in the program, unless specifically overridden by another declaration at local scope (inside a subroutine, function, or interrupt handler). Global definitions may be placed almost anywhere in the program text — between subroutines, before or after ‘main’, and so on.
Global variables, constants, and aliases do not need to be defined before use — the only requirement is that they be defined at some point in the program text. You may have multiple instances of the global variables section throughout your program. However, as a matter of good programming style, we recommend that you keep all global definitions in one place, pref­erably at or near the beginning of your program.

3.2.4 Variable Definitions

The format of a global variable definition is:
dim a,b as integer, x,y,z as float dim ia(3,4) as integer dim s1, s2 as string*80 dim sa(5,2) as string dim j, k, l as integer NV
Line 1 declares a and b as integers, x,y, and z as floats. Line 2 declares a 3 x 4 array of integers. Line 3 declares s1 and s2 as strings, each of length 80. Line 4 declares sa as a 5 x 2 array of strings, each with the default length of 32 characters. Line 5 defines 3 integers, j, k, and l as NV.
In addition, global variables can be specified as ‘NV’ to indicate their values are retained when power is turned off. All other global variables are automatically initialized when the program begins (strings are set to empty, and floats and integers are set to 0). There are no restrictions on the ordering of volatile vs. non-volatile user-variables. For ease of program maintenance, place all non-volatile variables definitions in a single section at the beginning of the program, and add new variables to the end of that section.

3.2.5 Constant Definitions

The format of a constant declaration is:
const <name> = <constant_expression>
as in
const ARRAY_SIZE = 4 * NUMBER_OF_ENTRIES const PI_SQUARE = 3.1415926535 ^ 2 const GREETING = “Hello” const GREETING = “Hello” const NUMBER_OF_ENTRIES = 5
Kollmorgen™ | March 30, 2012 22
AKD BASIC User Guide | 3 AKDBASICLanguage
Names for constants follow the same rules as variable names. ‘Forward definitions’ are allowed. Circular definitions are detected and reported at compile-time. Although it is not required, it is convenient to adopt a convention of keeping all constants in UPPER_CASE, so you can easily distinguish between constants and variables in the program.
Constant definitions are entirely ‘folded’ at compile-time. Feel free to write maintainable con­stant expressions such as:
const LENGTH = 3 const WIDTH = 10 const AREA = LENGTH * WIDTH
The value of AREA is computed at compile-time, so the program does NOT need to compute this at run-time and the program is easier to maintain if LENGTH changes at some future date.

3.2.6 Alias Definitions

Aliases allow you to define your own names for system resources, such as input / output pins. The intention is to make it possible for you to use names that are meaningful to you in your par­ticular application. The format of an alias expression is:
alias <name> = <expression>
For example, the following alias defines application-specific uses of input # 1:
alias CONVEYOR_IS_RUNNING = (DIN1.STATE = 0) alias CONVEYOR_IS_STOPPED = (DIN1.STATE = 1) if CONVEYOR_IS_RUNNING then
print“running” else
print“stopped”
An alias is much more powerful than a constant. Constant expressions are computable at com­pile-time, while an alias has a value that is only known (in general) at the time it is used. Use ali­ases with care — too much aliasing can make it very difficult for you to understand the program.

3.3 Main Program, Subroutines, Functions & Interrupt Handlers

These sections share the same fundamental structure:
<section>
<declarations>
<statements>
<section end>
An example of each of these sections follows, with an explanation of key points.

3.3.1 Main Definitions

For main, a typical definition is:
Main
dim i as integer
i = 1
print i End Main
23 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The variable ‘i’ defined above in the ‘dim’ statement is a local variable — it is not accessible to other functions, and inside ‘main’, its definition overrides any other variable named ‘i’ that might exist at global scope.
Unlike global variables, local variables MUST be defined at the beginning of the section — they must appear before any executable statement in main. For example, the following is illegal:
Main
dim i as integer
i = 1
dim j as integer ‘this is an error!
j = i
End Main
You may also define local constant definitions and aliases, provided that like local variables, they appear before any executable statement. Local constant definitions override global def­initions of the same name. For example, given the following global definitions,
const N = 1 Main
const N = “Hello, world!”
print N
call sub1 End Main
'-------------- Subroutines and Functions -----
-------
sub sub1
print N end sub
The program prints to the console:
Hello world! 1
Because the N visible inside main is the constant defined there, while the N visible to sub1 is the global constant N, whose value is 1.
The main program is the section of your program that is executed immediately after the‘params section, regardless of its position in the program text. Other functions, subroutines, and inter­rupt handlers are executed according to the flow of control defined in the program.
main does not accept arguments, and cannot be called from any other subroutine, function, or interrupt handler.

3.3.2 Subroutine Definition

For a subroutine such as print_sum, a typical definition is:
sub print_sum(i,j as integer)
print i+j end sub
The arguments to this subroutine are specified as integer variables, and are passed by value ­any assignments to these variables has no effect on the arguments supplied by the caller. Sub­routines are invoked by ‘call’ instructions, as in call print_sum(3,4).
Kollmorgen™ | March 30, 2012 24
AKD BASIC User Guide | 3 AKDBASICLanguage

3.3.3 Function Definition

For a function such as sum_squares, a typical definition is:
function sum_squares(i,j as integer) as integer
sum_squares = i^2 + j^2
end function
The function above returns a value of type integer. The value of the function is assigned by assigning to the name of the function, as if it were a variable.
It is not legal to use the function name as a variable name on the left-hand-side of an assignment - a function name on the leftt-hand-side is always an INVOCATION of that function.
There must be at least one statement in the function that assigns a value to the function. It is not possible to detect at compile-time if the statement will actually execute. Functions are invoked by name, as in print sum_squares(3,4). This is syntactically identical to an array ref­erence.

3.3.4 Interrupt Handler Definition

The Interrupt statment marks the beginning of an Interrupt Service Routine. The Interrupt Serv­ice Routine is defined by a program structure resembling a subroutine. The interrupt feature per­mits execution of a user-defined subroutine upon receipt of a hardware interrupt signal or a pre­defined interrupt event.
Interrupts are triggered by pre-defined events or external hardware sources. The interrupt­source-name and interrupt enable flag are unique for each interrupt source. For a list of interrupt sources see Interrupt {Source}.
Receiving an interrupt will suspend program execution and the interrupt service routine will be executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag. Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically disabled until it is enabled again in your program.
Main
DRV.TIME = 0 INTR.DIN1LO = 1 'enables interrupt
while 1
pause(0.5)
DOUT1.STATEU=0 : Pause(0.005):DOUT1.STATEU=1
wend
end main
'the following interrupt defines what occurs for interrupt DIN1LO
Interrupt DIN1LO
print "I'm awake" If DRV.TIME > 10 then
print "OK. That's it."
else
INTR.DIN1LO = 1 're-enables interrupt
end if
End Interrupt
25 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
The interrupt is re-enabled by the statement INTR.DIN1LO = 1. A similar statement must be executed once before the interrupt is serviced. It is a run-time error to attempt to enable an inter­rupt for which no handler is defined.
Interrupt handlers do not return values and cannot have arguments. They declare local var­iables, constants, and aliases. Interrupt handlers are invoked when the AKD hardware detects that the designated interrupt condition is satisfied (provided that the interrupt is enabled).
Interrupts are triggered by pre-defined events or external hardware sources. The interrupt­source-name and interrupt enable flag are unique for each interrupt source.
Receiving an interrupt will suspend program execution and the interrupt service routine will be executed. Then program execution will resume at the point that it was interrupted.
Interrupts are enabled (or disabled) by setting (or clearing) the associated interrupt enable flag. Interrupts are disabled until explicitly enabled. After an interrupt is triggered it is automatically disabled until it is enabled again in your program.

3.4 Language Definition

3.4.1 Lexical Conventions

AKD BASIC is case-insensitive. String literals are not modified, but all other text is treated as if it were entered in upper case. This means that the identifiers spin, Spin, and SPIN all refer to the same entity.

3.4.2 Identifiers

Identifiers are alphanumeric and must start with an alphabetic character or underscore. In addi­tion, they may include the underscore character (‘_’) and dollar sign (‘$’). Identifiers denote var­iables, functions, subroutines, and statement labels, symbolic constants, and aliases. Identifiers are a maximum of 40 characters. User-defined identifiers may not include the period (‘.’). Use of a longer identifier is a compile-time error.
Although both forms are accepted for compatibility, the latter form is preferred. Although AKD BASIC is case-insensitive, we recommend that you adopt a consistent naming convention, such as Move.Acc, and avoid having Move.acc, move.acc, and move.Acc in the same pro­gram.

3.4.3 Data Types

The pre-defined types are INTEGER, FLOAT, and STRING. LONG is used for INTEGER. INTEGER variables are 32-bit signed integers. FLOAT variables are IEEE single-precision floating point numbers. STRING variables are represented internally as a maximum length, a current length, and an array of ASCII characters (can contain null characters).
When a FLOAT result is assigned to an INTEGER variable, or when a FLOAT argument is used where an INTEGER is expected, the value is coerced to an integer before use. Coercion from FLOAT to INT always rounds to the nearest integer. For example:
1.2 rounds to 1
1.7 rounds to 2
-1.2 rounds to –1
-1.7 rounds to -2
Scalar INTEGER and FLOAT coercion is automatically provided for function arguments. When passing ARRAYS as arguments, the types must match exactly because coercion is pro­hibitively expensive at run-time.
Kollmorgen™ | March 30, 2012 26
AKD BASIC User Guide | 3 AKDBASICLanguage
String assignment is checked at run-time. An attempt to copy a string to a destination too small results in a run-time error. String indexing is 1-origin. For example, mid$(“abc”,1,1) returns the string, a.
STRING variables have a firmware-imposed maximum length of 230 characters and a default maximum length of 32 characters. They may be assigned a different maximum length by declaring them to be of type STRING*n where n is a positive integer between 1 and 230 (inclu­sive).
Declare arrays of the pre-defined types. Arrays have a maximum rank of four dimensions. The upper-bound of each dimension has no compiler-defined limit. However, because of the limited data space of the controller, there is a logical upper-bound that depends on the controller model.
Array indexing is 1-origin. The indices in each dimension range from 1 to the upper-bound of the dimension. Every reference to an array element is checked at run-time. Any attempt to ref­erence beyond the bounds of the array causes a run-time error. New types cannot be defined.

3.4.4 Literal Constants

String constants begin and end with the double-quotes (‘"’). They cannot extend past the end of the input line. Any printable ASCII character appears in a string constant. An attempt to gen­erate a string literal with non-ASCII characters causes a compile-time error. No check is made to verify that non-ASCII strings are not created at run-time, so avoid doing so.

3.4.5 Decimal Integer Constants

Decimal integer constants are a string of decimal digits with no decimal point. A leading ‘-’ sign is optional and is parsed as a unary minus. For example:
1
-1
314159
are all valid decimal constants.

3.4.6 Hexadecimal Constants

Hexadecimal constants are denoted by a leading &H or &h, and cannot have a sign or decimal point. Hexadecimal constants are composed from the set [0-9A-Fa-f]. Upper- and lower-case may be mixed.
For example:
&h00ff
&HFF00
&H1234abcd
are all valid hexadecimal constants. Octal and binary constants are not supported.

3.4.7 Floating-Point Constants

Floating-point constants are specified in fixed-point or mantissa-exponent notation. A floating­point constant consists of one of the following.
digit [0-9] optsign ‘+’ | ‘-’ | /* nothing */ fixed optsign {digit}+ ‘.’ {digit}*optsign ‘.’ {digit}+ exp fixed ‘e’ optsign {digit}+ float fixed | exp
For example:
27 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage
0.1 .1
-.1
-0.1
3.14159E-6
-1.0E6
are all valid floating point constants. By design, “.” is not a legal floating-point constant.

3.5 Statements

Statements are separated by a new line (CR-LF) or a colon (‘:’). The statements of the language are:

3.5.1 Alias

Create an alias for an identifier (not just any identifier). Alias is either a parameter or another alias. ID must be a legal variable name. You cannot create an alias for an array element.
Like Const definitions, Alias definitions can be made to identifiers not yet defined. Circular def­initions are not allowed.
Any duplicate definition of an identifier in the same scope is illegal. However, a local definition can shadow a definition from the global scope. Using a single identifier to denote two different objects is NOT allowed (i.e., you cannot have both a label and a variable named all_done).
Like constant, variable, and function declarations, Alias declarations made in the global scope are imported into all functions (including the main function).
Example:
Alias speed = MOTOR.SPEED ‘save some key-
strokes

3.5.2 Call

Call sub[(arg1, arg2, ...)]
sub is the name of a subroutine. The current program counter is saved and sub is invoked. When sub finishes (by reaching either an exit sub or end sub statement, control is returned to the statement logically following Call.
A subroutine is essentially a function with no return value. The parameter passing conventions followed by subroutines are the same as those followed by functions.

3.5.3 Cls

This statement transmits 40 line-feed characters (ASCII code = 10) to the serial port. Cls clears the display of the console.

3.5.4 Const

const name = x
Declares symbolic constants to be used instead of numeric values. Forward references are allowed, but circular references are not supported.
'supported
const x = y + 2
Kollmorgen™ | March 30, 2012 28
AKD BASIC User Guide | 3 AKDBASICLanguage
const y = 17
'unsupported
const x = y + 2 const y = x - 2
Like alias, variable, and function declarations, Const declarations made in the global scope are imported into all functions (including the main function).

3.5.5 Dim

Dim var1 [, var2 [...]] as type [NV]
All variables must be declared. Local variables must be declared in the function before use.
The NV specifier is used on a Dim statement in the global scope.
Variables in the global scope are automatically imported into functions and subroutines. Var­iables in function scope (including inside the main function) are not accessible in other func­tions.
Arrays cannot be assigned directly.
'This is not allowed
dim x(5), y(5) as integer
x = y
'Instead, a loop is needed:
dim x(5), y(5), i as integer for i = 1 to 5
next i

3.5.6 Exit

Exit {{Sub|Function|Interrupt|For|While}]
Exits the closest enclosing context of the specified type. It is a compile-time error to EXIT a construct not currently in scope.

3.5.7 For…Next

For loop_counter = Start_Value To End_Value [Step increment]
...statements...
Next
If step increment is not specified, uses 1 as the step increment. If step increment is positive, continues to the value of End_Value. If step increment is negative, continues to the value of var = limit.
The loop index variable must be a simple identifier, not an array element or a parameter and must be a numeric variable (integer or float).
x(i) = y(i)
for var = init to limit step delta
stlist
next var
Substantially more efficient code is generated if delta is a constant (i.e., the default value of 1 is used, or specified as an expression that is evaluated at compile-time).
29 Kollmorgen™ | March 30, 2012
AKD BASIC User Guide | 3 AKDBASICLanguage

3.5.8 Function

Function function-name [(argument-list)] as function-type
...statements...
End Function
On function entry, all local variable strings are “” and all numeric locals are zero (including all ele­ments of local arrays). If the function takes no arguments, omit the argument-list. An empty argument-list is illegal. The value returned from the function is specified by assigning an iden­tifier with the name of the function.
Example:
function cube(x as float) as float
cube = x * x * x
end function
Arguments are passed by value. Arrays can not be returned by a function. Arrays passed to a function are passed by value.
If the return value is not set, a runtime error condition is generated (caught with ON ERROR).
Array actuals must conform with formals to the extent that they have the same number of dimensions, and EXACTLY the same type. The size of each dimension is available to the func­tion through the use of local constants that are bound on function entry.
Example:
function sum(x(n) as integer) as integer
dim i, total as integer
sum = 0
for i = 1 to n
next
sum = total
end function
This function exploits the fact that the variable N is automatically assigned a value when the function is called and the value is the extent of the array passed on invocation. N is a read-only variable in this context. Attempts to write to N cause compile-time errors.
The local variable, total is automatically initialized to 0 upon function entry.

3.5.9 GoTo

GoTo label
A program can only GoTo a label in the same scope. A GoTo may jump out of a For or While loop, but not INTO one.

3.5.10 If…Then…Else

if condition1 then
...statement block1...
elseif condition2 then
...statement block2...
else
...statement block3...
end if
total = total + x(i)
Kollmorgen™ | March 30, 2012 30
Loading...
+ 476 hidden pages