You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 44 Next »

Revision Info

This page currently corresponds to the Ns=80 revision of the MCode.

Global Variable Declarations

Legacy MCode Variables

Kept for compatibility. These are:

  • Ve - MCode version. if Ve != DVER, MCode gets uploaded by IOC.
  • Pu - Power-up status flag

Pulse Picker Variables

  • Se - Pulse Picker mode [Se]lect. Refer to Mode List for a complete list of Se modes.

  • Sd - Status indicator register. Used for debugging. Refer to Status List for a complete list of statuses.
  • Sw - [Sw]eep distance. Number of motor steps to equal 11.25 degrees of motion.

  • Sr - Encoder sweep distance. Number of encoder steps to equal 11.25 degrees of motion.
  • Dr - Encoder [Dr]ift, or the difference between the encoder count the predicted encoder position.

  • P0 - Center (open) position, in motor steps.
  • P1 - Positive closed position, in motor steps, nominally P0+Sw. (Repurposed from standard MCode program.)
  • P2 - Negative closed position, in motor steps, nominally P0-Sw.
  • N0 - Center (open) position, in encoder counts.
  • N1 - Positive closed position, in encoder counts, nominally N0+Sr.
  • N2 - Negative closed position, in encoder counts, nominally N0-Sr.
  • Ec - Error checking flag. (0=OFF, 1=ON)
  • Ns - Pulse Picker MCode version. (Repurposed from standard MCode program.)
  • Hb - Heartbeat counter, incremented approx. every 100ms.
  • Cs - Encoder counter shadow register (=C2)
  • Ud - Drift violation, motor drifting in + direction (0= NO ERROR, 1=VIOLATION)
  • Ld - Drift violation, motor drifting in - direction (0=NO ERROR, 1=VIOLATION)
  • Df - Motor position flag (see interpretation below)
  • Mo - Experimentally-determined magic offset, in motor steps, that is the distance between the negative side of the homing index mark and P1. This number will be negative so that it feeds directly into an MR command. This has no initializer and depends on being correctly set by the engineer!

Program 1

Initialization

Code:

  • If Se<>0, we are likely experiencing a hard reset. In that case:
    • Signal state change to 80 (Hard Reset Initialization)
    • Set EL (Encoder lines) to 4096, giving 4096 lines * 4 steps/line = 16384 steps/rev
    • Set MS (Microsteps) to 8, giving 8 uSteps/step * 200 step/rev = 1600 uSteps/rev
    • Set EE (Encoder enabled) to 0, forcing open-loop step mode. Closed-loop mode is too slow because of a 1kHz loop rate.
    • Set S3 (I/O 3 settings) to 16,0,1. This is used for encoder power - sourcing output, active low.
    • Set O3 (Output 3) to 1, turning the encoder on.
    • Set S4 (I/O 4 settings) to 16,0,0. This is used for fan power - sinking power, active low.
    • Set O4 (Output 4) to 1, turning the fan on.
    • Set S13 (I/O 13 settings) to 60,0,0. This is used for input signaling, and makes it available to the input capture trip (interrupt)
    • Set FC (Filter Capture) to 9. This sets a debounce filter on input 13 with a 12.9usec delay time.
    • Set HT (Hold Time) to 5, setting the hold current delay time to 5ms.
    • Set RC (Run Current) to 100, making 100% of current available for movement.
    • Set HC (Holding Current) to 5.
    • Set NE (Numeric Enable) to 0, to prevent errant communications as being interpreted as movement commands.
    • Set Pu (Power-Up Flag) to 0 to prevent IOC from locking itself.
    • Set Sw (Sweep Distance) to 50 steps.
    • Set Sr (Encoder Sweep Distance) to 512 counts.
    • Reset Dr (Drift) to 0.
    • Reset P0 (Open position) to 0.
    • Reset P1 (Positive closed position) to P0+Sw = 512.
    • Reset P2 (Negative closed position) to P0-Sw = -512.
    • Reset N0 (Open encoder position) to 0.
    • Reset N1 (Positive closed encoder position) to N0+Sr.
    • Reset N2 (Negative closed encoder position) to N0-Sr.
    • Pre-load shadow register Cs=C2
    • Set Ec=1 to turn error checking on.
    • Reset drift violation flags Ud and Ld to 0.
    • Reset Df to 99 (current slit position is unknown)
  • For both hard and soft resets, we do the following
    • Signal state change to 81 (Soft Reset Initialization)
    • Disable any trips (TE=0)
    • Hold for 100ms to let things stabilize.
    • Set Se (Mode Select) to 0
    • Goto Mode Select Loop

Mode Select Loop

  • Signal state change to 0 (Mode Select)
  • Mode Select Loop START (forever):
    • If Se=1, branch to Mode 1: One-Shot
    • If Se=2, branch to Mode 2: Flip-Flop
    • If Se=3, branch to Mode 3: Burst
    • If Se=4, branch to Mode 4: Fast Open
    • If Se=5, branch to Mode 5: Fast Close
    • Increment heartbeat
    • Hold for 100ms
  • Mode Select Loop END

Mode 1: One-Shot

  • Signal state change to 10 (One-Shot Init)
  • Load One-Shot speeds (V1)
  • Specify One-Shot ISR (J1) to run on Input Trip
  • Arm Input Trip (TE=TE|4)
  • Signal state change to 11 (One-Shot Loop)
  • One-Shot Loop START (forever):
    • Increment heartbeat
    • Hold for 100ms
    • If user sets the soft reset (Se=0)
      • Go back to mode select
    • EndIf
    • If movement is complete (Sd=90)
      • Signal state change to 12 (One-Shot Complete)
    • EndIf
  • One-Shot Loop END

NOTE: Once in the one-shot loop, you must set Se=0 to get back to Mode Select.

One-Shot ISR (J1)

  • Copy current position to shadow variables
  • If currently in the positive closed position (Df=1)
    • Move (MA) to negative closed position P2
    • If error checking is enabled (Ec=1), check drift at previous, negative closed position (call X9)
    • Hold until movement complete
    • Set Df=1, indicating current position is positive closed position
  • Else (any other position but P1)
    • Move (MA) to positive closed position P1
    • If error checking is enabled (Ec=1), check drift at previous, positive closed position (call X8)
    • Hold until movement complete
    • Set Df=-1, indicating current position is negative closed position
  • EndIf
  • Copy current encoder count (C2) to shadow register Cs
  • Signal state change to 90 (Toggle movement complete)
  • Return

Mode 2: Flip-Flop

  • Signal state change to 20 (Flip-Flop Init)
  • Load Flip-Flop speeds (V2)
  • Specify Flip-Flop ISR (J2) to run on Input Trip
  • Arm Input Trip (TE=TE|4)
  • Signal state change to 21 (Flip-Flop Loop)
  • Flip-Flop Loop START (forever):
    • Increment heartbeat
    • Hold for 100ms
    • If user sets the soft reset (Se=0)
      • Go back to mode select
    • EndIf
    • If at least one movement is complete (Sd=90)
      • Signal state change to 22 (Flip-Flop Loop Active)
    • EndIf
  • Flip-Flop Loop END

NOTE: Once in the flip-flop loop, you must set Se=0 to get back to Mode Select.

Flip-Flop ISR (J2)

This ISR is identical to the One-Shot ISR (J1), with the exception that it re-arms the Input Trip (TE=TE|4) every time it runs.

Mode 3: Burst

  • Signal state change to 30 (Burst Mode Init)
  • Load Burst speeds (V3)
  • Specify Burst Open ISR (J3) to run on Input Trip
  • Arm Input Trip (TE=TE|4)
  • Signal state change to 31 (Burst Loop)
  • Burst Loop START (forever):
    • Increment heartbeat
    • Hold for 100ms
    • If user sets the soft reset (Se=0)
      • Go back to mode select
    • EndIf
  • Burst Loop END

NOTE: Once in the burst loop, you must set Se=0 to get back to Mode Select. Burst mode is continuous, that is that each subsequent trigger pulse will open and close the shutter.

Burst Open ISR (J3)

  • Signal state change to 32 (Burst open signal received)
  • Move (MA) to open position (P0)
  • If error checking is enabled (Ec=1), check drift at previous, assumed positive closed position (call X8)
  • Hold until movement complete
  • Set Df=0 to indicate slits are at open position
  • Signal state change to 94 (Move to open position complete)
  • Specify Burst Close ISR (J4) to run on Input Trip
  • Re-arm input trip (TE=TE|4)
  • Return

Burst Close ISR (J4)

  • Signal state change to 33 (Burst close signal received)
  • Move (MA) to positive closed position (P1)
  • If error checking is enabled (Ec=1), check drift at previous, assumed negative closed position (call X9) (this is redundant here)
  • Hold until movement complete
  • Set Df=1 to indicate slits are at positive closed position
  • Copy current encoder count (C2) to shadow register Cs
  • Signal state change to 91 (Move to positive closed position complete)
  • Specify Burst Open ISR (J3) to run on Input Trip
  • Re-arm input trip (TE=TE|4)
  • Return

Mode 4: Fast Open

  • Signal state change to 40 (Fast Open Init)
  • Load fast open speeds
  • Move (MA) to the open position (P0)
  • If error checking is enabled (Ec=1), check drift at previous, assumed positive closed position (call X8)
  • Hold until movement complete
  • Set Df=0 to indicate that slits are in open position
  • Signal state change to 41 (Fast open complete)
  • Goto mode select

Mode 5: Fast Close

  • Signal state change to 50 (Fast close init)
  • Load fast close speeds
  • If neither at Df=1 (positive closed) nor at Df=-1 (negative closed), then
    • Move (MA) to the positive closed position (P1)
    • If error checking is enabled (Ec=1), check drift at previous, assumed negative closed position (call X8)
    • Hold until movement complete
    • Set Df=1 to indicate that slits are in positive closed position
    • Copy current encoder count to Cs for future drift checks
  • EndIf
  • Signal state change to 51 (Fast close complete)
  • Goto mode select

Mode 7: Home to Index Mark

  • Signal state change to 70 (Homing init)
  • Load homing/alignment speeds
  • Execute home-to-index (HI) with option 3 (slew at VM in + direction, creep in - direction)
  • Hold until movement complete
  • Relative move (MR) by Mo to positive closed position
  • Set C1 to P1, C2 to N1, Cs to N1
  • Set Df to 1 (positive closed position, known)
  • Signal state change to 79 (Homing complete)
  • Goto mode select

Subroutines

Realign by computing new open-loop position (X7)

This routine updates the open-loop position based on the encoder reading. The target position of any subsequent move will be better aligned.

  • Declare local variables L1, L2
  • Compute the new open-loop position: C2 * <encoder counts per rev> / <microsteps per rev> = (C2 * EL * 8) / (MS * 200)
    • L1=C2*EL*8
    • L2=MS*200
  • Write the new open-loop position to C1. (C1=L1/L2)
  • Set Df=98 (Realigned)
  • Return

Drift Check at Positive Closed Position (X8)

  • If Df==1 (position is positive closed position), then
    • Let Dr=N1-Cs, such that Dr is positive if the motor is slipping (missing steps while traveling in the positive direction)
    • If Dr >= Dl (drift limit), then
      • Set Ld=1, indicating a drift limit violation in the negative direction
    • EndIf
  • EndIf
  • Return

Drift Check at Negative Closed Position (X9)

  • If Df==-1 (position is negative closed position), then
    • Let Dr=Cs-N2, such that Dr is positive if the motor is slipping (missing steps while traveling in the negative direction)
    • If Df >= Dl (drift limit), then
      • Set Ud=1, indicating a drift limit violation in the positive direction
    • EndIf
  • EndIf
  • Return

Mode/State Tables

Se - Mode Select

Se

Mode Description

0

Soft Reset - interpreted at start-up to bypass hard reset initialization routine

1

One-Shot mode: one pulse on the input line results in a single sweep of the pulse picker. Does not automatically return to mode select.

2

Flip-Flop mode: will sweep the pulse picker each time a pulse is received on the input line. Does not automatically return to mode select.

3

Burst mode: will open the pulse picker on the first input pulse received, and close on the second. Does not automatically return to mode select.

4

Fast Open: moves the pulse picker to the full open position (P0). Automatically returns to mode select.

5

Fast Close: moves the pulse picker to the positive closed position (P1). Automatically returns to mode select.

Sd - Status Indicator

Sd

Status Description

0

Waiting for Se mode selection

10

One-Shot Initialization

11

One-Shot Loop Waiting

12

One-Shot Complete

20

Flip-Flop Initialization

21

Flip-Flop Loop Waiting

22

Flip-Flop Loop Active

30

Burst Initialization

31

Burst Armed and Waiting

32

Burst Open Pulse Received

33

Burst Close Pulse Received

39

Burst Complete

40

Fast Open Initialization

41

Fast Open Complete

50

Fast Close Initialization

51

Fast Close Complete

70

Homing Initialization

79 

Homing Complete

80

Hard Reset/Power-Up Initialization

81

Soft Reset/Power-Up Initialization

90

Toggle Move Complete

91

Move to Positive Closed Position Complete

92

Move to Negative Closed Position Complete

94

Move to Open Position Complete

95

Close move did not execute because pulse picker is already closed

Df - Slit Open/Closed Status

Df

Status Description

-1

Closed in the negative position

0

Open

1

Closed in the positive position

98

Realigned; slits are in known position but not necessarily open or closed

99

Slit status is unknown

Velocity Tables

Maximum Velocity/Acceleration (V0)

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0d75a56b-12cc-413c-b8cb-0544b939ab87"><ac:plain-text-body><![CDATA[

Var

Value [step/s(^2)]

[deg/s(^2)]

[rev/s(^2)]

]]></ac:plain-text-body></ac:structured-macro>

VI

5300

1192.5

3.3125

VM

156250

35156

97.656

A

1875000

421880

1171.9

D

1875000

421880

1171.9

These speeds correspond to the fastest experimentally-determined speeds for continuous 60Hz operation.

One-Shot Velocity Defaults (V1)

Flip-Flop Velocity Defaults (V2)

Burst Velocity Defaults (V3)

Fast Open Velocity Defaults (V4)

Fast Close Velocity Defaults (V5)

Homing/Alignment Velocity Defaults (V9)

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="11ed808d-196f-4cf5-a459-abf94eee9f18"><ac:plain-text-body><![CDATA[

Var

Value [step/s(^2)]

[deg/s(^2)]

[rev/s(^2)]

]]></ac:plain-text-body></ac:structured-macro>

VI

640

144

0.4

VM

2560

576

1.6

A

640

144

0.4

D

640

144

0.4

  • No labels