Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

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

  • Wiki Markup
    *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.
  • Wiki Markup
    *Sw* \- \[Sw\]eep distance. Number of steps/encoder counts to equal 11.25 degrees of motion.
  • Wiki Markup
    *Dr* \- Motor-encoder \[Dr\]ift, or the difference between the encoder count and the motor count. Equals C2-P. Added to P0, P1, P2 for robustness in case of slippage.
  • P0 - Center (open) position.
  • P1 - Positive closed position, nominally P0+Sw. (Repurposed from standard MCode program.)
  • P2 - Negative closed position, nominally P0-Sw.
  • 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.

Program 1

Initialization

Declare local variables:

  • Po - Position counter shadow register (=P or =C1)
  • Cs - Encoder counter shadow register

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 82, giving 82 uSteps/step * 200 step/rev = 16400 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,1,1. This is used for encoder power - sourcing output, active high.
    • 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 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.
    • Pre-load shadow registers: Po=P, Cs=C2
    • Set Ec=1 to turn error checking on.
  • 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)
  • Calculate target position using drift of current position (X9)
  • 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 P1
    • Move (MA) to negative closed position P2
    • Calculate new drift based on stored shadow variables
    • Calculate new positive closed position P1 based on drift
  • Else (any other position but P1)
    • Move (MA) to positive closed position P1
    • Calculate new drift based on stored shadow variables
    • Calculate new negative closed position P2 based on drift
  • EndIf
  • Hold until movement complete
  • 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)
  • Calculate target position using drift of current position (X9)
  • 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)
  • Calculate target position using drift of current position (X9)
  • 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
    • If the close movement is complete (Sd=92), then
      • Signal state change to 39 (Burst complete)
    • EndIf
  • Burst Loop END

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

Burst Open ISR (J3)

  • Signal state change to 32 (Burst open signal received)
  • Store current position in shadow variables
  • Move (MA) to open position (P0)
  • Calculate drift based on shadow variables
  • Use new drift to update closed positions P1 and P2
  • Hold until movement complete
  • 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)
  • Store current position in shadow variables
  • Move (MA) to positive closed position (P1)
  • Calculate drift based on shadow variables
  • Use new drift to update open position P0 and closed position P2
  • Hold until movement complete
  • Signal state change to 91 (Move to positive closed position complete)
  • Return

Mode 4: Fast Open

  • Signal state change to 40 (Fast Open Init)
  • Load fast open speeds
  • Calculate target position using drift of current position (X9)
  • Move (MA) to the open position (P0)
  • Hold until movement complete
  • 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
  • Calculate target position using drift of current position (X9)
  • If neither at position P1 (positive closed) nor at position P2 (negative closed), then
    • Move (MA) to the positive closed position (P1)
    • Hold until movement complete
  • EndIf
  • Signal state change to 51 (Fast close complete)
  • Goto mode select

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

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