DMX Five Channel Example
Moog Animatics Class 5 SmartMotor™ DMX Guide, Rev. C
Page 36 of 46
'Configure DMX data usage and motor variable storage:
IF
n>3
("n too large.",#13)
END ENDIF
'Limit "n" based on a max of 3 bytes.
IF
b>(513-n)
("b too large.",#13)
END ENDIF
'Limit "b" based on max data slot.
IF
s>(102-n)
("s too large.",#13)
END ENDIF
'Limit "s" to max array value.
q=b+n-1
'Last data channel used (will be trigger when data received).
nnn=n+2
COMCTL
(1,b)
'Set base DMX channel to value from CADDR.
COMCTL
(2,nnn)
'Accept "n" DMX channels of data.
COMCTL
(3,q)
'Status word 12 bit 2 is set to 1 when channel "q"
'arrives.
COMCTL
(4,s)
'Set start of array index storage (r bypass cam mode
'dynamic array).
OCHN
(DMX,1,N,250000,2,8,D)
'Open DMX channel: COM1, no parity,
'250 kBd, 2 stop, 8 data, datamode
GOSUB
(100)
'Always run a homing routine before DMX.
'===================================================================
' Set Initial Values
UR
(2)
'Clear flag so that we know when the end of the next
'data packet arrives.
MP
'Set to Position mode.
ADT
=800
'Accel/Decel Value (adjust as needed).
VT
=1500000
'Velocity (adjust as needed).
'===================================================================
' Set up interrupts to linger at higher values.
ITR
(0,0,0,0,0)
'Interrupt to catch all motor drive faults
EITR
(0)
'Enable Fault Interrupt
ITRE
'Enable Global interrupts
ss=s+2
'====================================================================
' Main Program Loop
WHILE
1
'NOTE: This loop constantly polls DMX data and scales it
'directly to target position.
IF
B
(12,2)==1
'Check for next data packet.
UR
(2)
'Clear flag so we know when next packet arrives.
nn=n-1
p=0
'Zero data value.
WHILE
nn>=0
'Byte shifting and summing data.
p=p*256+aw[nn+ss]
nn=nn-1
LOOP
'Loop takes 4 msec when using three
'channels (24 bit).
VT
=aw[s]*vvv
'Set velocity target off of first channel
'x multiplier.