1. Intro 

The dmc41.h/.c and testdmc code was initially developed in /home/s2/src/dmc41-mt/
for a lab test motor setup as a prototype for spex, ishell.
So some of the notes refer to his  dmc41-mt/ setup.
Copied where then given to spex, and ishell.

The motor tower hardware is a lab test system consisting of:
  Galil DMC-4183...(the upgraded and repurposed TCS DMC-4153 for the chopper upgrade).
  M-2222-6.0D - IMS Stepper (size 23 frame).
  IM483-34P1  - IMS Microstepping Drivers.
  Phytron ZSS 32.200.1.2 - warm motor, ishell will use a cryo version of the motor.
  Old IRTF Geneva Drive.


2. Hardware Notes

2.1 Controller DMC-41x3

   DMC-4153-BOX8(-16BIT)D3020-DIN purchased on 2010-11 for servo chopper
   secondary upgrade. Project was abandon about 2012-05 for lack to
   manpower/interest.

   The DMC-4183 was RMA in july 2012 to be reused as the hilo lab controller.
   8 axis were added, plus 2 axis were configured with stepper amps.
   It's current configuration is:

      DMC-4183
      A1-AMP-43020(-D3020) - two axis amplifiers 500 watts. These servo amplifiers
                             are installed on axis A and B.

      A7-SDM-44140(-D4140) - micro stepper moudules drivers with 1/64 microstep
          resolution. Selectable current options of 0.5, 1.0, 2.0 and 3.0 amps per axis.
          The stepper driver are on Axis E and F.

   ID command says:
      :ID
      DMC4103 rev 1
      Servo Amplifier Board AMP-43020 500 watt   rev 1
      Stepper Amplifier Board AMP-44140  rev 1

   Spex uses a DMC-4183-BOX8(-16BITS) pruchased in 2012-11 for controlling it's stepper motors.

2.2 IMS Motor

   M-2222-6.0D - IMS Stepper (size 23 frame).
   IM483-34P1  - IMS Microstepping Drivers.

   System is setup as 1/64 micro steps, priving 12800 steps per revolution.

2.3 Phytron Motor

   Phytron ZSS 32.200.1.2
      200 steps per revolution.
      First connected to axis_e, DMC4183+SMD-44140 provide 200*64 = 12800 steps revolution.

2.4 Motor Tower Notes

   Est. Motor staft to cam shaft geaing: 3.20:1
   CAM take 1/2 trun to move from Detent to Detent.
   Wheel has 48 cam positions
   Motor:   1 RPM=12800 steps/rev
   To rotate CAM staft 1 RPM = 12800 * 3.20            =  40960 steps.
   To rotate To CAM Detent   = 12800 * 3.20 * 0.5      =  20480 steps.
   To rotate entire Wheel    = 12800 * 3.20 * 0.5 * 48 = 983040 steps.

   Measured sized is about 983022.

3. Software Files 

   testdmc.c                     - stand alone test application for the DMC41.

   src/spex/lib/dmc41.c, dmc41.h - lower level DMC-41x3 code to be linked into applications.
                                   These routines are linked into the spex ldog applications.

4. Configuration/Setup  - updated 2025/01 when setting new spare

4.1 Galil Tool Method

   Used USB port to talked to dmc4183 from PC and GDK (Galil Design Kit, v1.36.6.
   USB driver is CDM20824_Setup.exe from http://www.ftdichip.com/Drivers/VCP.htm
   archived in ~s2/public_html/vendor_info/galilmc)
   This is a USB-to-serial interface.

4.2 Hilo Ethernet setup:  128.171.110.157   hosthname: dmc41-mt (hilo motor tower)
   DH0
   IA 128,171,110,157
   BN                      'to burn these paramters

   TH - command is 'Tell Ethernet Handler'

4.3 Hilo Ethernet setup:  192.168.1.13  hosthname: spex-dmc41
   DH0
   IA 192,168,1,13
   BN                      'to burn these paramters

   TH - command is 'Tell Ethernet Handler'
   response was:
      CONTROLLER IP ADDRESS 192,168,1,13 ETHERNET ADDRESS 00-50-4C-38-07-A7


4.4 IO Channel setup:

4.5 #AUTO:

#AUTO defines code to run a power up, something like this:
(note ' comment are not part of the program)

   #AUTO
   CN 1,1  'active high for limit and home
   MO      'turn off all motors
   OE      'Off-on-error'
   #A_SE
   ha=_HMA
   #A_SE_1;JP #A_SE_1,ha=_HMA
   ST A
   EN
   ....

   The spex-dmc41.dmc is located in ~s2/src/spex/ldog


How to download program to controller.
   Use Galil tool to write/download a program.
   The BP to Burn Program.
   Cold Boot the controller.
   Telnet in, and do a UL to view the program.

   The spex-dmc41.dmc using used for the spex 
   (Felix is similar but CN values is different)
   (ishell DMC have no program loaded).

5. Simple Digial and Analog IO

Analog Inputs 

analog input configuration.

   AQn,m  default is +/- 10 V. We have 8 ADC.
   _AQn   display configureation, ie MG_AQ1

  41x3 has no general purpose analog outputs.

  MG _AQ1,_AQ2,_AQ3,_AQ4,_AQ5,_AQ6,_AQ7,_AQ8

  MG @AN[1],@AN[2],@AN[3],@AN[4],@AN[5],@AN[6],@AN[7],@AN[8]

Analog Output 

  AOm,n ie: AO1,2.5

Digital Inputs 

TI0
TI1 - tell input bank 0 and 1, return 0 to 255, state of 8 bits

_@IN[n] - controller variable, where n is 1 to 16.
   ie, MG @IN[1]

+5v is logical 0
+0v is logical 1

Digital Output 

OB n,v
   n is bit# 1 to 17
   v is value( 0 or 1 ). Can be logical expression.

OP$FFFF - to set all bits.

6. Stepper Motor Commands

limit switch
   Could use AEN (Amp Enable) output on drivers. MO, OE3 command disable AMPs.

limit switch

   Default is active low, use CN comamnd to change polarity of the switch (CN is controller wide).
   CN 1,1

   To disable 'LD'

   Stop in direction of input; Motor left ON.
   To turn off motor, use #LIMSWI subroutine. Or use OE to turn off on limit switch.

   SD - set deceleration
   OE - On Error  - so you can turn off on ERROR.

   read state: LFx, LRx, to print MG _LRE _LFE or MG_LFE, MG_LRE

Homing
   FE - find edge
   FI - find index
   HM - standard Home.

Define Position
   DPA=0

Turn on motor; find egde (toward positive); begin
   SHE; FEE; BGE;

stop

ST

examples

MTA=-2.0;ACA=50000;DCA=100000;SPA=12800;KSA=1;LDA=3;
MOA;             // motor off
SHA;             // motor on (servo here).

PRA=500000;BGA
PRA=100;BGA;
PRA=-100;BGA;

PAA=0;BGA;

PAA=12850;BGA;
PAA=12850;BGA;

MOA;             // motor off
SHA;             // motor on (servo here).


7. Slide vs Continuous_Wheel vs Detented_Wheel

CN is a global setting on the DMC41. A single setting applies to all axis.
 Sets limit switches active high or low for all axis. Active Low is desired.
 Sets "InHome" to active low or hi for all axis. Active Low is desired.
 Sets the Latch input active high or low for all axis.

Linear Slides

  Reverse and Forward limits switch are used with the DMC41's Rev/Fwd Limit inputs.

  Reverse and Forward limit can be used to home.
  Drive the stage to one extreme, and set the postion.

  Mechanical safety are required to prevent damage from run aways.
  Mechicanism need to be stronger that the motor torque.

  If the range of travel is small, and a sensor can absolutely encode the position,
  then we can home by reading the sensor and calculating it's position.
  The Array Focus mechanism is an example, is uses 2 magnets at the end, one flipped.
  The sensor in the middle read a unique volt anywhere between the 2 magnets.
  End of travel safety is built into the mechanism.

Continous_Wheel

  A home swich on the wheel is used to initialize the wheel using the
  HOME input on the DMC41.

  Homing is done by using the home input. FE (Find Edge) is used.
  if not "InHome", the wheel move in reverse until home is found.
  If "InHome", the wheel moves foward, until home turn off.
  The home position is define at this On-to-Off change of state.

  If high accuracy is need, then the voltage of the hall-effect sensor can
  been sampled, then home is defined as the peak voltage value from a curve fit.

Detent_Wheel

   2 outputs are needed. 1 for Home, and 1 for InDetent. A single HE sensor
   is used, with multiple magnets. All "InDetent" magnent in one orientation to
   indicate the mechanism in a detented position. A single "Home" magnet can be put
   between the detent to provide a homing location.

   For homing, the DMC-41's Forward (or Reverse) Input are used. We will used forward
   for this explanition.
   Enable the forward limit, and HOME the mechanism by driving the wheel into the
   limit (see the dmc41_st_home_onlimits() function).
   Once homed, the limits are disabled on the DMC41.

   The DMC-41 home input is used as an InDetent signal in order. This provide
   better flexible to stop when the indent signal (HOME) is enabled.

   Spex used 2 method for detent wheel moves:

   1. dmc41_st_detent_moveto():
      1. Moves in front of the detent (using step counts).
      2. Find the Beg Edget of the detent using dmc41_st_pr_SE()
      3. Move a fixed step counts to "center into the detent".

   2. dmc41_st_detent_center(): Move to the center of the detent by:
      1. Move to front of detent using step counts.
      2. Drving forward the detent until InDetent turns ON. Save it's position.
      3. Continue driving forward, until the IndDtent turns OFF. Save it position.
      4. Goto the Center of the 2 saved positioned.

dmc41_st_pr_SE() - HOME Problem and Stop Edge (SE) code

The DMC-41 home routine FE is not very flexible. It chooses the direction
and speed based on the state of the HOME input.

 (find edge)
  if(Home high) then move forward at AC, SP. DC until Home==low
  if(Home low)  them move reverse at AC, SP, DC until Home=high

Another issue, the the logic state of the limit and home input, are
set by the CN command. The command sets the logic across all axis, so
for example we can not have axis A be home HIGH, and B be HOME low.
The all must be the same.

To overcome this issue, we burn the following code into the DMC-41x8 for each axis.

   REM -----------------------------------------------
   REM  Axis A Stop Edge - ST at HOME change of state
   REM
   #A_SE
   ha=_HMA
   #A_SE_1;JP #A_SE_1,ha=_HMA
   ST A
   EN

The host can then do the follow to allow the axis to move, then stop when
the HOME input changes state, the "SE" means Stop Edge.

   HX 0;XQ #A_SE,0;       // halt, then start SE thread.
   PRA=wheel_size;BGA;    // move to find an edge
   // wait until motor stops.
   HX 0;                  // Halt Execute.
   //read postion, and state of home input

The code for each axis was written.
There are 8 threads available, so each axis take a thread.

This has been implement in the dmc41.c and testdmc.c code.