#A
AT0;'set initial AT time reference
WT 1000,1;'wait 1000 samples
t1=TIME
AT 4000,1;'wait 4000 samples from last time reference
t2=TIME-t1
REM in the above scenario, t2 will be ~3000 because AT 4000,1 will have
REM paused program execution from the time reference of AT0
REM since the WT 1000,1 took 1000 samples, there was only 3000 samples left
REM of the “4000” samples for AT 4000,1
MG t,t2;'this should output 1000,3000
EN;'End program
Where the functionality of the operation of the AT command is very useful is when it is required to have a
deterministic loop operating on the controller. These instances range from writing PLC-type scan threads to writing
custom control algorithms. The key to having a deterministic loop time is to have a trippoint that will wait a
specified time independent of the time it took to execute the loop code. In this definition, the AT command is a
perfect fit. The below code is an example of a PLC-type scan thread that runs at a 500ms loop rate. A typical
implementation would be to run this code in a separate thread (ex XQ#plcscan,2).
REM this code will set output 3 high if
REM inputs 1 and 2 are high, and input 3 is low
REM else output 3 will be low
REM if input 4 is low, output 1 will be high
REM and ouput 3 will be low regardless of the
REM states of inputs 1,2 or 3
#plcscan
AT0;'set initial time reference
#scan
REM mask inputs 1-4
ti=_TI0&$F
REM variables for bit 1 and bit 3
b1=0;b3=0
REM if input 4 is high set bit 1 and clear bit 3
REM ti&8 - gets 4th bit, if 4th bit is high result = 8
IF ti&8=8;b1=1;ELSE
REM ti&7 get lower 3 bits, if 011 then result = 3
IF ti&7=3;b3=1;ENDIF;ENDIF
REM set output bits 1 and 3 accordingly
REM set outputs at the end for a PLC scan
OB1,b1;OB3,b3
REM wait 500ms (for 500 samples use AT-500,1)
REM the '-' will reset the time reference
AT-500
JP#scan
Mathematical and Functional Expressions
Mathematical Operators
For manipulation of data, the DMC-42x0 provides the use of the following mathematical operators:
Operator
Function
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus
&
Logical And (Bit-wise)
|
Logical Or (On some computers, a solid vertical line appears as a broken line)
()
Parenthesis
Chapter 7 Application Programming ▫ 121
DMC-42x0 User Manual
Summary of Contents for DMC-42 0 Series
Page 195: ...ICM 2900 PCB Layout Appendices 191 DMC 42x0 User Manual...
Page 205: ...CB 50 100 Drawings Appendices 201 DMC 42x0 User Manual...
Page 206: ...Appendices 202 DMC 42x0 User Manual...
Page 207: ...Appendices 203 DMC 42x0 User Manual...
Page 208: ...Appendices 204 DMC 42x0 User Manual...
Page 209: ...Appendices 205 DMC 42x0 User Manual...
Page 210: ...Appendices 206 DMC 42x0 User Manual...
Page 211: ...Appendices 207 DMC 42x0 User Manual...
Page 214: ...CB 50 80 Drawing Appendices 210 DMC 42x0 User Manual...