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

Compare with Current View Page History

« Previous Version 4 Next »

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 steps/encoder counts to equal 11.25 degrees of motion.

  • Dr - Motor-encoder [Dr]ift, or the difference between the encoder count and the motor count. Equals C2-P.

  • 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)
    • 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=4)
  • Signal state change to 11 (One-Shot Loop)
  • One-Shot Loop START (forever):
    • Increment heartbeat
    • Hold for 100ms
    • If movement is complete (Sd=90)
      • Signal state change to 12 (One-Shot Complete)
  • One-Shot Loop END

NOTE: Once in the one-shot loop, you must reset 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=4)
  • Signal state change to 21 (Flip-Flop Loop)
  • Flip-Flop Loop START (forever):
    • Increment heartbeat
    • Hold for 100ms
    • If at least one movement is complete (Sd=90)
      • Signal state change to 22 (Flip-Flop Loop Active)
  • Flip-Flop Loop END

NOTE: Once in the flip-flop loop, you must reset 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=4) every time it runs.

  • No labels