DIVA logo

DiMACTM - Diva Macro Control Language



DiMAC is based on an unnamed control language that was developed in 1985 by Howard Speegle and Dave Kadonoff. Dave presented the need for a control language that could be used by anyone and helped define the functions to be implemented. Howard wrote the code and designed the hardware to implement it. Since that time, it has been copied, expanded and adopted by numerous companies in the motion control field.

DiMAC has proven to be easily learned and very powerful, and has been ported to several microprocessors and microcontrollers. The code size is compact and commands are easily added.

All commands use two-letter mnemonics, contained in a table, to specify the desired function to be performed. Up to four bytes of numeric data pertaining to the function may be entered after the mnemonic. If there is a channel number associated with the mnemonic, it is entered as the first character.

Example: 2MR1000. This command selects the motor attached to channel 2 and commands it to move 1000 encoder counts in the positive direction relative to the present ideal position. (Move Relative).

All commands are scanned on entry for proper syntax. An error is generated when the mnemonic is not found in the table or when the data entered is not within specified limits.

Commands are executed immediately on receipt of a carriage return character. Multiple commands may be entered if separated by commas. A special mnemonic code, MDn, is used as the first command in a line to direct the system to store the remainder of the command line as a macro command for deferred execution. After definition, the macro may be executed by use of the MCn command.

On entry, commands are converted to a fixed length format consisting of the channel number, memory address of the execution routine and four bytes of data. When a macro command is defined, the contents of the converted command buffer are stored at an indexed location. Execution of a macro involves directing an address pointer to the location stored in the macro index.

Execution of a command string involves setting a pointer to the start of the string and calling the routine pointed to by the first two bytes after the pointer. The called routine accepts its input argument from the next four bytes after the pointer. On completion of the command, control is returned to a routine that advances the pointer to the next command. If there is none, control is returned to the command interpreter, which waits for a new command to be entered. If there is another command in the string, the process is repeated until all have been executed.

Execution of a macro command involves nothing more than moving the command buffer pointer to the address in the macro index table in a linked list sequence. Each stored macro command must provide RAM storage for an associated set of system run time variables, such as repeat loop count. On completion of the macro, the pointer is restored to the next command following the macro call. The return pointer is one of the run time variables mentioned.

Some command implementations are as simple as setting or clearing a system configuration flag. MN is the command to turn the Motor servo loop oN. Its only function is to set a flag which can be cleared by the MF command. Such a command requires no data argument and simply returns to the execution module after setting the flag. Other commands are much more complex and may involve hundreds of machine level instructions to implement.

One of the more complex commands to implement is the TM or Tell Macro command. It must convert the fixed length internal code back to human readable format similar to the string used to enter the command initially.

If there is adequate memory space available, free format names may be assigned to macros to aid in program documentation. A command string such as CN5, WA125, CF5 which instructs the machine to open the valve connected to output channel 5, wait 125 mS and close it, could be defined as macro command #8 with the entry MD8,CN5, WA125, CF5. Subsequent use of the command MC8 would repeat the valve control sequence, or macro #8 might be assigned the name, "Dispense Glue", which is much more useful. Afterwards, MC8 and Dispense Glue can be used interchangeably.

One of the valuable benefits to a table-driven syntax is that the table entries may be expanded or modified at will. There have been customers who preferred the mnemonic ST for STop, to the term ABort, which is more commonly used by programmers. Adding an ST to the mnemonic table was a simple matter. It simply pointed to the same address as the AB command.

Implementation of the real time execution routine in microcode is not especially difficult. It is based on the manipulation of pointers. All that is required is that the architecture of the processor provide for the necessary indirect addressing involved. The potential benefits of this implementation are enormous. Emulation of other processors or high level languages becomes much faster, for instance.

Complex control sequences can be converted to a single macro definition and executed at nearly native language speed. A close approximation to the operation would be an assembly language instruction such as "Jump to a named subroutine with parameters". Note that this architecture is not proposed for general purpose computing applications. It was designed for data acquisition and control functions which can operate successfully with only 32-bit integer data types. An exception is the limited use of strings, which can be defined and displayed, but no other operations are supported.

Firmware implementation of the real time execution module is relatively fast. How much performance can be gained by implementing the operation in microcode? At present, the firmware includes polling tests for the communication channel, to allow for operator termination. This time could be saved by modifying the firmware to use an interrupt by the Comm channel.

We now use 16 microsec to call the command and 7 microsec to test for end of loop. A simple command such as the MN, which only sets a flag, now execute in about 25 microsec, total, including the test for Comm channel escape. Removing the Comm channel escape can save 4 microsec. Implementing the sequence in microcode could save 23 microsec, increasing the rate at which macros can be called from 40 KHz to 500 KHz. Seems to be worth doing!

Note that the 500 KHz rate is for calling the routine. Execution of the called routine is not changed. Commands that report system parameters to the Comm channel are limited in speed by the number of characters to be reported and the baud rate. A command to report the setting of the acceleration register reports 13 characters. At 9600 baud, the operation requires 13 ms and will not be faster with any implementation.

On the other hand, commands to implement a programmable logic function can be executed much faster, greatly extending the value of the controller. In many industrial applications, the performance of the device is measured in how many I/O points can be scanned in a fixed period of time. The delay time between the change of state of a controlling signal and the controlled signal can be very important.

The current DiMAC firmware creates a virtual 32-bit special purpose controller, based on an 8-bit microcontroller. Much of the virtual machine is involved in the creation of virtual registers. For instance, the DiMAC command to turn on output channel 37 may refer to bit 6 of hardware port 4, creating a virtual range of port numbers 1-128 from the physical reality of bits 0-7 and addresses scattered throughout the address space. It also allows the creation of true virtual channels by defining a condition as a channel, such as an analog input being above or below a selected threshold voltage.

Conditional execution of commands based on logical combinations of physical inputs and outputs as well as virtual channels as described above, is a very powerful and easily applied tool for automation control. The ability to define a channel template and a mask allows execution of very complex Boolean or ladder logic equations in one or two microseconds.

DiMAC includes support for a 32-bit virtual processor and stack. It provides for integer math functions as well as logical operations such as AND, OR, NOT and EXCLUSIVE-OR. Entire applications may be implemented using only the virtual machine. An example of the utility of this feature is to read the voltage from an operator control pot, adjust the voltage with an offset, scale the remainder to convert it to internal units, test it for limits and store it as a system parameter, such as velocity.

The program to implement this somewhat complex procedure would be:

GA3,AA-1234,AM4321,AD56,DL678,SV@0

This cryptic string performs the entire function and can be made into a macro command as described previously. To explain it in detail:

GA3---Get analog channel #3 into the accumulator
AA-1234---Add value (-1234) to accumulator contents (remove offset)
AM4321---Multiply accumulator contents by 4321
AD56---Divide accumulator contents by 56
DL678---Do following command if accumulator contents < 678
SV@0---Set Velocity according to accumulator contents.

Note that the combination of AM4321 and AD56 results in an equivalent multiplication of 77.161. Since all quantities in the DiMAC language must be expressed as integers, this is a means of multiplying by a real number.


Last Updated: 6 October, 2007
Copyright 2007 DIVA Automation