Docstoc

ADMC330 DSP Motor Controller Developer's Reference Manual

Document Sample
ADMC330 DSP Motor Controller Developer's Reference Manual Powered By Docstoc
					a




    ADMC330
DSP Motor Controller

       Developer’s
    Reference Manual

           Rev. 4.0
      30 September 1998
(Reverse side of front cover.
     To be left blank.)
                                                                                                                    ADMC330 DSP Motor Controller
                                                                                                                      Developer’s Reference Manual


                                                                       CONTENTS
SECTION                                                                                                                                                  PAGE
1. INTRODUCTION .....................................................................................................................................7

2. REFERENCED DOCUMENTS ...............................................................................................................7

3. UPGRADE INFORMATION...................................................................................................................8

4. GETTING STARTED ...............................................................................................................................8

5. IMPORTANT SAFETY INFORMATION .............................................................................................8

6. SOFTWARE DEVELOPMENT ..............................................................................................................9
   6.1 EVALUATION KIT SOFTWARE................................................................................................................11
   6.2 GETTING STARTED WITH THE MOTION CONTROL DEBUGGER ...............................................................11
      6.2.1 Automatic Program Exit Function................................................................................................13
      6.2.2 Troubleshooting............................................................................................................................13
      6.2.3 Error Messages.............................................................................................................................14
   6.3 CHANGING DEBUGGER COMMUNICATIONS USING COMMCFG .............................................................15
   6.4 PROGRAMMING SERIAL PROMS WITH MAKEPROM ..........................................................................15
   6.5 USING INCLUDE FILES IN YOUR CODE ..................................................................................................16
7. ADMC330 HARDWARE OVERVIEW ................................................................................................16
   7.1 MOTOR CONTROL PERIPHERAL REGISTERS ..........................................................................................16
8. MEMORY MAP......................................................................................................................................21

9. ON-CHIP ROM OPERATION ..............................................................................................................22
   9.1 POWER-UP / RESET SEQUENCE .............................................................................................................22
   9.2 SPORT1...............................................................................................................................................22
   9.3 THE ROM CODE MONITOR...................................................................................................................22
      9.3.1 Communication Interfaces............................................................................................................22
          9.3.1.1 Boot Loader............................................................................................................................................23
          9.3.1.2 UART Debugger.....................................................................................................................................23
   9.4 ROM CODE UTILITIES ..........................................................................................................................23
      9.4.1 PUT_VECTOR..............................................................................................................................24
      9.4.2 SIN12B and COS12B....................................................................................................................24
      9.4.3 CAL_INV_TAN .............................................................................................................................24
      9.4.4 LOG1 ............................................................................................................................................25
      9.4.5 ALOG1..........................................................................................................................................25
      9.4.6 SQRT1...........................................................................................................................................25
      9.4.7 DIVIDE.........................................................................................................................................25
      9.4.8 X_Y_TO_ANG ..............................................................................................................................26
      9.4.9 APPROX10_ST.............................................................................................................................26
      9.4.10 APPROX_N_ST ..........................................................................................................................26
10. INTERRUPT OPERATION.................................................................................................................27
   10.1 USING PUT_VECTOR.......................................................................................................................28
   10.2 PERIPHERAL INTERRUPT OPERATION ..................................................................................................29
     10.2.1 Example Interrupt Servicing Scheme..........................................................................................30
11. WATCHDOG TIMER OPERATION .................................................................................................35




                                                                     Rev 4.0         09/30/98                                                                            3
ADMC330 DSP Motor Controller
Developer’s Reference Manual

12. SOFTWARE PERIPHERAL RESET FUNCTION ...........................................................................36

13. TUTORIAL............................................................................................................................................37
    13.1 EXAMPLE 1: SIMPLE CONFIGURATION EXAMPLE ................................................................................37
    13.2 EXAMPLE 2: SINE-TRIANGLE PWM EXAMPLE ...................................................................................38
      13.2.1 Introduction ................................................................................................................................38
      13.2.2 Hardware Modifications.............................................................................................................38
      13.2.3 Algorithm Description ................................................................................................................39
      13.2.4 File Description..........................................................................................................................40
      13.2.5 Demonstration Execution ...........................................................................................................40
14. APPENDICES........................................................................................................................................41

Appendix A Source Code for ROM Utilities.................................................................................................41
Appendix B System Specification File ..........................................................................................................48
Appendix C Architecture Description File ....................................................................................................49
Appendix D ADMC330 Include File (ADMC330.H) ...................................................................................50
Appendix E ROM Utility Include File (ROMUtil.h) .....................................................................................52
Appendix F Constant Include File (Constant.h).............................................................................................53
Appendix G Macro Include File (Macro.h) ...................................................................................................55
Appendix H SROM/EEPROM Boot Loader Protocol...................................................................................57
Appendix I UART Debugger Protocol ..........................................................................................................60




4                                                                Rev 4.0 09/30/98
                                                                                                         ADMC330 DSP Motor Controller
                                                                                                           Developer’s Reference Manual


                                                                   FIGURES
NUMBER & TITLE                                                                                                                            PAGE
Figure 1. The Software Development Process................................................................................................9
Figure 2. PWMTM, PWMDT, PWMPD, and PWMCH Registers ..............................................................17
Figure 3. PWMGATE and PWMSEG Registers ..........................................................................................18
Figure 4. PIO Registers.................................................................................................................................19
Figure 5. MODECTRL, SYSSTAT, and IRQFLAG Registers ....................................................................20
Figure 6. Example Timing Diagram for Peripheral Interrupts .......................................................................34
Figure 7. Watchdog Timer Register..............................................................................................................35
Figure 8. Hardware Modifications to ADMC330 Evaluation Board for Example 2 Demonstration .............39
Figure 9. Boot Load Timing (XC1765D or AT17C65) ................................................................................58
Figure 10. UART Protocol ...........................................................................................................................60




                                                               Rev 4.0       09/30/98                                                                   5
ADMC330 DSP Motor Controller
Developer’s Reference Manual


                                                                  TABLES
NUMBER & TITLE                                                                                                                       PAGE
Table 1. ADMC330 Memory Map ...............................................................................................................21
Table 2. ROM Code Utilities........................................................................................................................23
Table 3. Utility Data Base Tables.................................................................................................................24
Table 4. Interrupt Vector Addresses by Priority ...........................................................................................27
Table 5. SROM / EEPROM Pin Connections ..............................................................................................57
Table 6. Boot Load File Format ...................................................................................................................59
Table 7. Available Commands (Debugger Interface) ...................................................................................61
Table 8. Data Memory Write Command ......................................................................................................61
Table 9. Data Memory Read Command .......................................................................................................62
Table 10. 16 Bit Program Memory Write Command ...................................................................................62
Table 11. 16 Bit Program Memory Read Command ....................................................................................62
Table 12. 24 Bit Program Memory Write Command ...................................................................................62
Table 13. 24 Bit Program Memory Read Command ....................................................................................63
Table 14. Monitor Variables for Executing User Code ................................................................................63
Table 15. DM Write Commands to Start Program at 0x0030.......................................................................63




6                                                             Rev 4.0 09/30/98
                                                                     ADMC330 DSP Motor Controller
                                                                       Developer’s Reference Manual


1. Introduction
The ADMC330 is a single chip DSP motor controller optimized for standalone ac motor control
applications. The device combines a 20MHz fixed point ADSP-2171 core with on-chip memory, two serial
ports, a programmable timer, and a set of on-chip motor control peripherals.

Together with the list of referenced documents, this manual provides the information necessary to
understand and evaluate the processors’ architecture and to develop an ADMC330-based system.

2. Referenced Documents
        Reference 1. ADMC330 Single Chip DSP Motor Controller Data Sheet, Analog Devices.

        Reference 2. ADSP-2100 Family User’s Manual, Third Edition, 9/95, Analog Devices.

        Reference 3. ADSP-2100 Family Assembler Tools & Simulator Manual, Second Edition, 11/94,
                     Analog Devices.

        Reference 4. ADSP-2100 Family C Tools Manual, Second Edition, 11/94, Analog Devices.

        Reference 5. Digital Signal Processing Applications using the ADSP-2100 Family, Volume 1,
                     Analog Devices, 1992. This document is available on the Analog Devices web site
                     at http://www.analog.com/support/product_documentation/dsp_prdoc.html. Click
                     on the document “Using the ADSP-2100 Family Volume 1”.




                                         Rev 4.0   09/30/98                                            7
ADMC330 DSP Motor Controller
Developer’s Reference Manual


3. Upgrade Information
Each evaluation kit is shipped with a version of software that is fully functional for basic DSP development
operations such as assembling, linking, debugging, and serial PROM formatting. This version is powerful
enough to fill the needs of most users, but those who want to use software simulators, burn EPROMs, write
C code, or define a target system architecture file may want to add in the standard development software for
the ADSP-2100 Family (part number ADDS-21XX-SW-PC).

In addition to the features found in the software shipped with the evaluation kit the ADSP-2100 Family
Development Software adds:

•   System Builder
    Define your target system hardware in an architecture description file. The linker and the simulators
    use this information to know how much memory is in your system, which memory is RAM and which is
    ROM, which memory is internal to the processor and which is external, and what memory-mapped
    peripherals you have. You don’t need this tool since the kit software includes an architecture
    description file for the ADMC330. If you need to modify the file, you can do this simply by editing the
    file and following the syntax contained therein. You should not need to modify the file unless you want
    to create your own memory segments.

•   Simulators
    Run an instruction level simulation of any ADSP-2100 Family processor. All of the ADSP-2100
    Family Simulators provide an interactive, instruction-level simulation, displaying the cycle-by-cycle
    operation of different portions of the processor and system hardware through a window-based graphical
    user interface. NOTE: Currently the simulators run on MS-DOS. On a Windows 95 system you must
    reboot in MS-DOS mode. The simulators currently can’t be run from Windows NT.

•   Librarian, C Compiler, C Runtime Library, C Debugger
    The C level software tools that come with the development software may be used to develop user code,
    though the efficiency of the code that is produced is questionable. NOTE: Currently the C tools do not
    work under Windows NT.

4. Getting Started
Start by reading the release notes that accompany the evaluation kit you received. They describe what is
new in the latest release and how to install the development software on the disks that accompany each
board. In addition to the software development tools, a number of application notes and some
demonstration software will also be installed. Take the time to become familiar with these application notes
so that you know where to find the information you are looking for. Typically, there will be application
notes about how to set up the evaluation kit and how to run the software examples. Some of this
information is duplicated in this manual. Also familiarize yourself with the documents referenced by this
document. The ADMC330 is a combination of an ADSP-2171 DSP core and a set of motor control
peripherals, so the technical information is distributed among the ADSP-2100 Family User’s Manual, the
ADMC330 data sheet, any application notes, and this document.

5. Important Safety Information
The Motion Control Debugger should be used in a live system only with extreme caution. Your software
should first be developed with an ADMC330 evaluation kit or target board that is not connected to a motor.

WARNING: PWM SIGNALS TO THE MOTOR REMAIN ACTIVE AT A BREAKPOINT!
If you want the motor shut down, use the HALT function to stop your program from executing. The halt
function performs a peripheral reset when halting your program. The halt function is executed by selecting
Halt from the Debug menu or by clicking the Halt button . DO NOT use breakpoints with a live system
as the PWM stage will remain active.


8                                           Rev 4.0 09/30/98
                                                                                                       ADMC330 DSP Motor Controller
                                                                                                         Developer’s Reference Manual


6. Software Development
Figure 1 shows the software development process that a user will follow to create an application that runs
on the ADMC330. The software tools shown in boxes in the figure run on an IBM compatible PC. The
System Builder, Assembler, Linker, Simulator, C Compiler, and MAKEPROM utility must be run in a DOS
window. The Motion Control Debugger is invoked from Windows 95 or Windows NT. While ADMC330
specific information is contained in this document, the tools’ basic operation is discussed in the references.
The System Builder, Assembler, Linker, and Simulator are discussed in Reference 3. The C Compiler is
discussed in Reference 4. The Motion Control Debugger is discussed in this document and in the latest
version of its release notes. The MAKEPROM utility is discussed in this document. The tools shown as
optional are not needed by most users and, therefore, are not included in the ADMC330 evaluation kit.
They can be acquired by ordering the standard development software for the ADSP-2100 Family (part
number ADDS-21XX-SW-PC).


          STEP 1:
                                      System                           System                             System
          Describe
                                    Specification                      Builder                          Architecture
          Architecture
                                        File                                                               File



                                                                      ANSI
                                      C Source
                                                                    C Compiler
                                        Files

          STEP 2:
                                                                                                                                      Executable
          Generate                                                   Libraries                             Linker
                                                                                                                                         File
          Code

                                     Assembler
                                      Source                         Assembler
                                       Files


                                                                 Software Simulator


          STEP 3:                                   ADMCxxx
          Debug                                                   Motion Control
                                                    Evaluation
          Software                                                 Debugger
                                                      Board


                                                                   Target             Motion Control
                                                                   Board               Debugger




          STEP 4:
          Final                                           MAKEPROM
          Version for                                  (SROM or EEPROM)
          Production



                        User File or Hardware                    Software Development Tool                          Hardware Development Tool

                                                                 Optional Software Development Tool




                                          Figure 1. The Software Development Process




                                                             Rev 4.0        09/30/98                                                               9
ADMC330 DSP Motor Controller
Developer’s Reference Manual

The software development process begins with the task of defining the target system architecture. To do
this you use the system builder. You must write a system specification file as input to the system builder;
this file describes the target hardware configuration and memory map. The system builder reads the file
and generates an architecture description file which passes this information to the linker and simulator.
This step may be skipped if you choose to use the ADMC330 architecture description file that is installed
along with the development software. The system specification file that was used to create this architecture
description file is also installed and can be used as a starting point for your own target hardware. These
files are also available in Appendix B and Appendix C. If you do not have the system builder tool and
wish to make a change to the .ach file you can edit it since it is just a text file. Just follow the syntax
observed in the file.

You begin code generation by creating assembly language source code modules. An assembly code module
is a unit of assembly language comprising a main program, subroutine, or data variable declarations.
Include files are provided in the appendices that contain things like ADMC330 specific constants and
macros that can be used in your code. These files can be included in source routines to provide a simple
interface to the ADMC330’s motor peripheral registers, interrupt vector table addresses, and ROM code
utilities. These files are also installed along with the development software and used in the tutorial given in
this document. They can be found in the main installation directory in a subdirectory called TgtFiles.

Each code module is assembled separately by the assembler into ADSP-2171 machine code. Alternatively,
the C compiler can be used to generate machine code from C source code, although this is not
recommended for motor control applications that require highly efficient code.

The linker reads the target hardware information from the architecture description file to determine
placement of code and data fragments. In the assembly modules you may specify each code/data fragment
as completely relocatable, relocatable within a defined memory segment, or non-relocatable (placed at an
absolute address). Non-relocatable code or data modules are placed at the specified memory address,
provided the memory area has the correct attributes. Relocatable objects are placed in memory by the
linker.

Using the architecture description file and assembled code modules, the linker determines the placement of
relocatable code and data modules, and places all modules in memory locations with the correct attributes
(CODE or DATA, RAM or ROM). The linker generates a memory image file containing a single
executable program which may be loaded into a simulator, or downloaded to the evaluation kit or target
hardware, using the Motion Control Debugger, for testing.

The simulator provides windows that display different portions of the hardware environment. To replicate
the target hardware, the simulator configures its memory according to the architecture description file. To
simulate ADMC330 code you must use the ADSP-2101 simulator because the ADSP-2171 simulator does
not support the memory map of the ADMC330. The ADMC330 peripherals are not supported on any of the
ADSP-21XX family simulators. You can configure the peripheral registers as I/O ports on the simulator to
verify that you are initializing them correctly, but you can’t view the operation of the peripherals. For this
reason it is recommended that you use the simulator only for basic DSP core programming issues and that
you use the ADMC330 evaluation kit with the Motion Control Debugger for true application development.

The Motion Control Debugger allows you to download your executable file to an ADMC330 processor
board or your own target hardware, to debug your code, and to test your application directly over a standard
UART interface. Similar to the simulators, the debugger displays the hardware environment of the
ADMC330 through a series of windows. However, with the debugger you have full access to all of the
registers and memory on the ADMC330.

As Figure 1 shows the software development process is an iterative one as you continue to debug and add
to your application code. Once your code is stable you have the option of programming an SROM or
EEPROM so that your code is boot loaded automatically to the ADMC330 on power-up or reset. To do
this you run the MAKEPROM utility which takes your executable file and converts it into a PROM


10                                            Rev 4.0 09/30/98
                                                                           ADMC330 DSP Motor Controller
                                                                             Developer’s Reference Manual

programmer compatible file that has the correct boot loader protocol. You also have the option of boot
loading your code from an external UART. For more information on the subject of boot loading, see the
section on the ROM code monitor program later in this manual.


6.1 Evaluation Kit Software
When you install the software that comes with the ADMC330 evaluation kit (labeled “ADMC330 Motion
Control Debugger”), a directory structure is created on your PC that contains not only the debugger, but
also other tools, documentation, and sample code. The following is a summary of the directory structure
and what it contains.

Drive:\Adi\Mcd330\                         Main installation directory
Drive:\Adi\Mcd330\ReleaseNotes             Release notes for hardware and software (if applicable)
Drive:\Adi\Mcd330\DataSheets               Contains data sheets
Drive:\Adi\Mcd330\ReferenceManual          Contains developer’s reference and user’s manuals
Drive:\Adi\Mcd330\bin                      Contains debugger executables
Drive:\Adi\Mcd330\Examples                 Contains the tutorial software
Drive:\Adi\Mcd330\ApplicationNotes         Contains any application notes
Drive:\Adi\Mcd330\TgtFiles           Contains target specific files such as .H, .SYS, and
                                                .ACH files
Drive:\Adi\Mcd330\SourceLibrary            Contains source code for library functions that can be
                                                compiled with your code
Drive:\Adi\Mcd330\Uninstall.exe            Executing this file will uninstall this directory
                                                structure
Drive:\Adi\Mcd330\Install.log              Used by Uninstall.exe (DO NOT MODIFY)
Drive:\Adi_dsp\21xx\Bin\Asm21.exe          ADSP-21XX Family Assembler
Drive:\Adi_dsp\21xx\Bin\Ld21.exe           ADSP-21XX Family Linker
Drive:\Adi_dsp\21xx\Bin\Makeprom.exe       MAKEPROM utility program
Drive:\Adi_dsp\21xx\Etc                    Support files for ADSP-21XX Family tools

6.2 Getting Started with the Motion Control Debugger
The following is a list of steps that can be taken to start using the Motion Control Debugger. They can be
followed alone or in conjunction with performing the tutorial in section 8. To install the debugger refer to
the release notes that came with the installation disks.

    a.   Install the debugger software. Refer to the Motion Control Debugger release notes for
         instructions.
    b.   Connect the ADMC330 processor board to your PC using a standard 9 pin male to female serial
         cable. Make sure it is connected on the same communication port that you selected when installing
         the debugger.
    c.   Turn power on to the target board and press the hardware reset button.
    d.   To start the debugger under Windows 95 select it from the start menu (Programs->Motion Control
         Debugger->ADMC330 Motion Control Debugger). If running Windows NT double click on the
         ADMC330 Motion Control Debugger icon found in the Motion Control Debugger program group.
         Once attached, the debugger will give you full emulation capabilities for your target design. Wait
         for the disassembly window to appear with the start location at 0x0030 highlighted. This is the
         point at which user code will begin execution when a run or single step command is executed (so
         your code’s start point MUST be linked at 0x0030). The greater-than sign (>) to the left of a line
         of code signifies the current position of the PC register.
    e.   To load a program, select Load from the File menu and navigate to the directory containing your
         executable file (.exe). Double click the desired executable file and the debugger will load the file.
    f.   To view user code, use the page up, page down, up arrow, and down arrow keys in the disassembly
         window. If the disassembly window is not visible, for example if it’s behind another window, you



                                             Rev 4.0   09/30/98                                            11
ADMC330 DSP Motor Controller
Developer’s Reference Manual

        can bring it to the front by selecting Disassembly from the Window menu, or by clicking the
        disassembly window button .
     g. To find the line of code where a symbol is defined, select Find from the Search menu, or press
        Ctrl-F, or click the find button     , and then enter the symbol name. The disassembly window will
        display the code at that symbol. This does not modify the current location in the PC register.
     h. To find the next occurrence of a symbol you just found, select Find Again from the Search menu,
        or press the F3 key, or click the Find Again button .
     i. To select a particular symbol from a list of all symbols, and then display the code at that symbol,
        select Go To from the Search menu, or press Ctrl-G, or click the Go To button , and then click
        the Browse button. Select the symbol from the list displayed. The disassembly window will
        display the code at that symbol. This does not modify the current location in the PC register.
     j. To display the code at a particular address, select Go To from the Search menu, or press Ctrl-G, or
        click the Go To button , and then enter the desired address. Hexadecimal numbers must be
        prefixed with 0x and octal numbers with a 0. Decimal numbers must be entered starting with the
        most significant non-zero digit.
     k. To display a file in its own window, select Open from the File menu or click the Open button       ,
        and then navigate to the desired file.
     l. To set a break point, double click on the desired line of code, or select Breaks from the Debug
        menu and Add the desired line of code to the list displayed, or click the break button     while the
        desired line of code is highlighted.
     m. To clear a break point, double click on the line of code where the break point is set, or select
        Breaks from the Debug menu and Delete the desired line of code on the list displayed, or click the
        Toggle Break button while the desired line of code is highlighted.
     n. To clear all break points, select Breaks from the Debug menu, and then select Clear All and OK, or
        click the Clear Breaks button      .

          WARNING: PWM SIGNALS TO THE MOTOR REMAIN ACTIVE AT A BREAKPOINT! If
          you want the motor shut down then use the HALT function to stop your program from executing.
          The halt function performs a peripheral reset when halting your program. The halt function is
          executed by selecting Halt from the Debug menu or by clicking the Halt button . DO NOT use
          breakpoints with a live system as the PWM stage will remain active.

     o.   To run your program, select Run from the Debug menu, or press the F5 key, or click on the run
          button     . Observe the processor status, found at the bottom of the main window, change from
          “Reset” to “Running”.
     p.   To halt a program when it is running, select Halt from the Debug menu or click on the halt button
             . Observe the processor status change from “Running” to “Halted”. The disassembly window
          will display the location at which your code halted. The greater-than sign (>) to the left of a line of
          code signifies the current location in the PC register.
     q.   To single step your code, select Step Into from the Debug menu, or press the F11 key, or click on
          the single step button       . Observe the processor status change from “Halted” to “Stepping” to
          “Halted” again.
     r.   To view register values while debugging your code, select them from the Register menu. Register
          values are updated each time the program is halted or a breakpoint is reached. Stacks are also
          selected from the Register menu.
     s.   For a more customized register window, select Custom from the Register menu. This allows you
          to select the specific registers you want to view and places them all in the same window. Some of
          the registers specific to the target board are available only from the Custom selection.
     t.   The Memory menu may be used to view the contents of program or data memory. Clicking the
          right mouse button while the cursor is in a memory window will bring up a menu that allows you to
          change the format of the displayed data.
     u.   To see the memory map for the target you are running, select Memory Map from the Memory
          menu.


12                                             Rev 4.0 09/30/98
                                                                         ADMC330 DSP Motor Controller
                                                                           Developer’s Reference Manual

    v. To dump memory to the output window or to a file, select Dump from the Memory menu and fill
       in the dialog box.
    w. To fill memory, select Fill from the Memory menu and fill in the dialog box. Memory can also be
       filled from a file.
    x. To plot memory, select Plot from the Memory menu and fill in the dialog box. The plot will be
       displayed in its own window. Clicking the right mouse button while the cursor is in a plot window
       will bring up a menu that allows you to configure the plot in different ways.
    y. To restart your program, select Reset from the Debug menu and then Run.
    z. To display the version of the Motion Control Debugger that you have installed, select About
       Debugger from the Help menu, or click the About button .

NOTE: The reset and halt functions perform a peripheral reset which puts the peripheral blocks in their
power-up state (disabled). Loading an executable file will also perform a peripheral reset. All breakpoints
are cleared on a reset or when loading an executable file.

6.2.1 Automatic Program Exit Function
Typically, when the debugger runs a user’s DSP program the only way to pass control back to the debugger
is by hitting a breakpoint or by executing a Halt from the debugger. The user usually creates an infinite
loop in the program so that the DSP will continue to run until the Halt is executed.

As another option, you may insert an automatic exit back to the debugger by linking the library function
Exit.dsp into your DSP code, and then jumping to it at the end of your program. Exit.dsp performs the
same DSP functions as the debugger’s Halt function so its effect is to return control back to the debugger
automatically when the user’s program has finished. You will see the debugger halt when this happens. If
you try to continue running the program it will immediately return back to the debugger. You can execute a
reset or reload the program to run it again. The Exit.dsp file can be found in the SourceLibrary directory
that is installed with the Motion Control Debugger software. Exit.dsp includes the ADMC330.H file.

6.2.2 Troubleshooting
The following is a list of remedies to problems you may encounter when using the Motion Control
Debugger.

    a.   If the debugger is not responding, your target could be in run mode. Try selecting Halt from the
         Debug pulldown menu.
    b.   If the debugger is hung, try resetting the target board. If the debugger does not recover, hit
         CNTRL+ALT+DEL then kill the “Analog Devices Motion Control Debugger” task, if one is
         listed. Also kill the “Debugapp” task if one is listed. Next press Reset on the target board and
         restart the debugger.
    c.   If the debugger hangs you could be writing to program or data memory that is being used by the
         debugger. See the ADMC330 memory map in this document which shows the memory locations
         that are reserved when running with the debugger and make sure you are not using that memory. If
         you created a .map file with the -x option when you linked your program it will show you where
         your program resides in memory.
    d.   The debugger uses the SPORT1 transmit and receive interrupts. Keep them enabled in your code
         and do not modify the corresponding interrupt vectors at locations 0x0020 and 0x0024. Failure to
         do this can cause the debugger to hang.
    e.   The debugger also uses locations 0x0001 and 0x0002 in the interrupt vector table. Do not modify
         these locations, or the debugger will hang.
    f.   If the debugger frequently hangs, and your PC is located in an electrically noisy environment try
         lowering the baud rate. This can be done by running the CommCFG.EXE script (from the start
         menu for Windows 95, for Windows NT double click the CommCFG.EXE icon). Lowering the
         baud rate will slow down the debugger, but may alleviate the problem.




                                           Rev 4.0    09/30/98                                          13
ADMC330 DSP Motor Controller
Developer’s Reference Manual

6.2.3 Error Messages
The following is a list of error messages that may be encountered while running the debugger. Following
each error message is an explanation for the error and possible steps to take to correct the problem. If the
problem can not be fixed, contact the Motion Control Group for help.

ERROR_MCG0001:: COM line status change or Host power failure
     The debugger has detected a change in the serial communications. Kill the debugger, reset the
     board, then restart the debugger.

ERROR_MCG0002:: Target communication not established
     The debugger is unable to communicate with the ROM Monitor Program. Kill the debugger,
     check all connections, reset the board, then restart the debugger. If you have multiple versions of
     the debugger installed, for example you bought an ADMC331 evaluation kit and an ADMC330
     evaluation kit, make sure you are running the correct one. Also, make sure the clock frequency for
     the board is correct by running the CommCFG tool.

ERROR_MCG0003:: Serial line status error. Check continuity of the serial cable and connections.
     The serial cable could be unconnected or broken. A board connector could be broken. Kill the
     debugger, reconnect or fix the serial line, reset the board, then restart the debugger.

ERROR_MCG0004:: Unable to open COM port
     The COM port is being used by another application, or by a previous debugger session that hasn’t
     terminated properly. Exit all other applications that might be using the COM port. Kill the
     debugger, make sure there are no debugger tasks still running, reset the board, then restart the
     debugger.

ERROR_MCG0005:: Registry parameters not found
     The registry has been corrupted. Reinstall the development software on your PC.

ERROR_MCG0006:: Failed to open Registry
     The registry has been corrupted. Reinstall the development software on your PC.

ERROR_MCG0007:: Host board Reset
     You have performed a H/W reset of the board while the debugger was running. Acknowledge the
     error windows that pop up, then select Reset on the Debug pulldown menu. If the debugger does
     not recover, kill all debugger tasks, reset the board, then restart the debugger.

ERROR_MCG0008:: Error Loading the Monitor Tasks
     The development software might be corrupted. Try reinstalling the software on your PC.

ERROR_MCG0009:: Invalid Target response
     The debugger can’t reconnect with the ROM Monitor Program after running a user program.
     Make sure that you have the SPORT1 interrupts enabled in your code, that you do not corrupt the
     SPORT1 interrupt vectors, and that you do not corrupt any of the SPORT1 configuration registers.

ERROR_MCG0010:: Unable to read target memory while target is running
     You’ve tried to access memory while your program is running. Halt the program and try again.

ERROR_MCG0011:: Unable to write to target memory while target is running
     You’ve tried to access memory while your program is running. Halt the program and try again.


ERROR_MCG0012:: Unable to find the DSP Monitor Task files
     The files might be corrupted. Reinstall the development software on your PC.



14                                          Rev 4.0 09/30/98
                                                                         ADMC330 DSP Motor Controller
                                                                           Developer’s Reference Manual


ERROR_MCG0013:: Target is RUNNING
     Cannot perform operation while the target is running. Halt the target first.

ERROR_MCG0014:: Target communication not established after reset
     The debugger is unable to communicate with the ROM Monitor Program. Kill the debugger,
     check all connections, reset the board, then restart the debugger. If you have the debugger
     installed for multiple targets make sure you are running the correct one.

ERROR_MCG0015:: Target communication not established after changing baud rate.
                   Check the specified baud rate in the registry
     The debugger is unable to communicate with the ROM Monitor Program after it has changed the
     baud rate to what you specified during installation or from running CommCFG. Kill the debugger,
     check all connections, reset the board, then restart the debugger. If the problem persists it could be
     due to noise or a hardware fault. Try lowering the baud rate using CommCFG, or reinstall the
     software.


6.3 Changing Debugger Communications using CommCFG
The CommCFG program is a tool that will allow you to change the debugger’s communications setup
without reinstalling the debugger software. CommCFG is executed in the same way as the Motion Control
Debugger from the start menu or from the program manager depending on which operating system you are
using. When you execute CommCFG it will prompt you for the same communications setups that you were
prompted for during installation of the debugger software, namely the desired COM port, clock (crystal)
frequency, and baud rate. All current settings for these parameters are displayed. CommCFG should be
used when you want to change any of these parameters, or you just want to find out what the current settings
are.

6.4 Programming Serial PROMs with MAKEPROM
By using the MAKEPROM utility and a standard PROM programmer, a user’s code may be programmed
into a serial PROM for boot loading the ADMC330 at reset. The MAKEPROM utility will convert an
executable file (.EXE) into a binary file (.DBS) for use with the PROM programmer. The binary file
created is automatically formatted to work with the boot loader of the ADMC330. The boot loading
protocol is compatible with the Xilinx XC1765D SROM and Atmel AT17C65 EEPROM. The
MAKEPROM Utility (MAKEPROM.EXE) is installed with the Motion Control Debugger software. It runs
from an MS-DOS box similar to the other development tools.

Follow these steps to create a serial device containing your executable image:
1. Your executable file must be linked to start executing at the beginning of user program memory
    (0x0030), to which the boot loader will jump after it has loaded the executable file. Consequently, you
    must have a minimum of 1 block of code linked into program memory for the boot loader to succeed.
    You are not required to have data linked into data memory, however, if this is the case, the boot loader
    will automatically write 4 zeros at the start of data memory (0x3800). NOTE: Do not try loading the
    interrupt vector table during a boot load. This would overwrite the default interrupt vector table which
    is needed by the boot loader. Instead you should modify the interrupt vector table from within your
    program by using the ROM code utility PUT_VECTOR.
2. Run MAKEPROM which has the following syntax:

       usage: MAKEPROM -i <input_file> -t <target> [-o <output_file>] [-c]
                 -i Input file
                 -t Target (ADMCxxx)
                 -o Output file (default = input_file.dbs)
                 -c Display checksums




                                            Rev 4.0   09/30/98                                           15
ADMC330 DSP Motor Controller
Developer’s Reference Manual

3.   Load the output file into your PROM programmer and select one of the devices listed above. The file
     data format is absolute binary. NOTE: Make sure the polarity option is set to program an active low
     reset ( RESET /OE).
4.   Program the device and place it in the SROM/EEPROM socket of the processor or target board.
5.   On power-up or reset your executable image will be loaded at the start of user memory and executed.


6.5 Using Include Files in Your Code
Include files are useful for reusing code and data items that are shared between programs without having to
duplicate them in each program. The ADMC330 development software contains a number of include files
that can be used throughout your code. For example, the ADMC330.h file contains constants set equal to
the memory-mapped registers and interrupt vector table addresses. If you include this file you can refer to
the ADMC330 registers and interrupt vector table locations by name instead of by address. Similarly, the
ROMutil.h file contains constants set equal to the ROM library routine starting addresses. By including this
file you can call library routines contained in the ROM by name. The code snippet below illustrates how to
use the ADMC330.h and ROMUtil.h include files for setting up the PWMSYNC interrupt vector table
entry. PWMSYNC_INT_ADDR is a constant defined in ADMC330.h. PUT_VECTOR is defined in
ROMUtil.h.

       #include <ADMC330.h>;
       #include <ROMUtil.h>;

       Initialize_Interrupts:              I4   =        PWMSYNC_INT_ADDR;
                                           MR0 = ^       YOUR_PWMSYNC_ISR
                                           CALL          PUT_VECTOR;

IMPORTANT: The last line of an include file must contain a carriage return or subsequent include
statements will be ignored.


7. ADMC330 Hardware Overview
The ADMC330 takes from the ADSP-21XX family an ADSP-2171 core, 2K of on-chip program RAM, 2K
of on-chip program ROM, 1K of on-chip data RAM, two serial ports, and a programmable timer. The
operation of each of these units is described fully in Data Sheet, Analog Devices.
Reference 2.

7.1 Motor Control Peripheral Registers
In addition to the ADSP-2171 core peripherals, the ADMC330 contains a set of motor control peripherals
that are controlled through registers that are memory-mapped into the core’s data memory. The operation
of the peripherals is described in Reference 1. The peripheral registers are shown below for reference.




16                                          Rev 4.0 09/30/98
                                                               ADMC330 DSP Motor Controller
                                                                 Developer’s Reference Manual




                                        P W M T M (W)

               15 14 13 12 11 10        9      8     7    6     5     4    3        2     1    0
D M (0x2008)                                 P W M T M = ( f H C L K )/(f P W M )




                                                                                        N O T E : f H C L K = 1 /2 C L K I N


                                        P W M D T (W)

               15 14 13 12 11 10        9      8     7    6     5     4    3        2     1    0
D M (0x2009)                                                           PWMDT

                             P W M D T = fH C L K * [Deadtime (s)]




                                        P W M PD (W)

               15 14 13 12 11 10         9      8    7     6     5    4     3       2     1     0
D M (0x200A)
                                                                       PWMPD

                      P W M P D = f H C L K * [ M inim u m P u lse W idth (s)]




                               P W M C H A (W)                 DM(0x200C)
                               P W M C H B (W)                 DM(0x200D)
                               P W M C H C (W)                 DM(0x200E)
               15 14 13 12 11 10        9      8     7    6     5     4    3        2     1    0
                                     P W M T C H = P W M T M ( V o )/(V B U S )




   Figure 2. PWMTM, PWMDT, PWMPD, and PWMCH Registers




                       Rev 4.0     09/30/98                                                               17
ADMC330 DSP Motor Controller
Developer’s Reference Manual




                                               PWMGATE (W)

                              15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
                DM(0x200B)                           0 0        0 0 0 0 0 0




                                                                      {
           1=enable      Low side gate chopping
                                                                      GATETM
           0=disable     High side gate chopping
                                                                           Gate Drive chopping frequency
                                                                           fchop = (fHCLK)/(2GATETM+1)


                                                                           NOTE: fHCLK = 1/2 CLKIN




                                               PWMSEG (W)

                        15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
        DM(0x200F)                                 0 0 0 0 0 0 0 0 0

                         A channel crossover                                   CH output disable
      1= crossover
                         B channel crossover                                   CL output disable
      0= no crossover
                         C channel crossover                                   BH output disable
                                                                                                     1=disable
                                                                               BL output disable     0=enable
                                                                               AH output disable
                                                                               AL output disable




                             Figure 3. PWMGATE and PWMSEG Registers




18                                                 Rev 4.0 09/30/98
                                                        ADMC330 DSP Motor Controller
                                                          Developer’s Reference Manual




                                    PIODIR (W)
               15 14 13 12 11 10    9   8   7   6   5    4   3   2   1   0
                                                                             1= output
D M (0x2004)                                0   0   0   0    0   0   0   0   0= input




                                    P I O D A T A (R/W )
               15 14 13 12 11 10    9   8   7   6   5    4   3   2   1   0
                                                                             1= HI
D M (0x2005)                                0   0   0   0    0   0   0   0   0= LO




                                    PIOINTEN (W )

               15 14 13 12 11 10    9   8   7   6   5    4   3   2   1   0
                                                                             1= enable interrupt
D M (0x2006)                                0   0   0   0    0   0   0   0   0= disable interrupt




                                    PIOFLAG (R)
               15 14 13 12 11 10    9   8   7   6   5    4   3   2   1   0
                                                                             1= interrupt flagged
D M (0x2007)                                0   0   0   0    0   0   0   0   0= no interrupt




                       Figure 4. PIO Registers




                          Rev 4.0   09/30/98                                         19
ADMC330 DSP Motor Controller
Developer’s Reference Manual




                                         M O D E C T R L (R/W )

            15 14 13 12 11 10 9          8       7       6       5       4       3       2       1    0
                                                                 0       0       0       0       0    0       D M (0x2015)


                                                                                                              ADC   M U X c o n trol
                                                                                                               00   = VAUX0
                                                                                                               01   = VAUX1
                                                                                                               10   = VAUX2
                                                                                                               11   = VAUX3

                                                                                                     P W M T R IP interrupt enable          1 = enable
                                                                                                     P W M S Y N C interrupt enable         0 = disable

                                                                                                                                            1 = DR1B
                                                                                                     SPORT1 data receive select
                                                                                                                                            0 = DR1A

                                                                                                                                            1 = UART
                                                                                                     SPORT1 mode select
                                                                                                                                            0 = SPORT



                                   S Y S S T A T (R)

       15 14 13 12 11 10 9     8     7       6       5       4       3       2       1       0
                                                                             1       0       1            D M (0x2016)


                                                                                                                                       1 = HI
                                                                                                     P W M T R IP pin status
                                                                                                                                       0 = LO

                                                                                                                                       1 = reset occurred
                                                                                             W D F L A G (watchdog status)
                                                                                                                                       0 = normal

                                                                                                                                       1 = HI
                                                                                                     P W M P O L p in status
                                                                                                                                       0 = LO


                                   I R Q F L A G (R)

       15 14 13 12 11 10 9     8     7       6       5       4       3       2       1       0
                                                                                     0       0            D M (0x2017)


                                                                                                     P W M T R IP interrupt status
                                                                                                                                            1 = pending
                                                                                                                                            0 = cleared
                                                                                                     P W M S Y N C interrupt status




                 Figure 5. MODECTRL, SYSSTAT, and IRQFLAG Registers




20                                           Rev 4.0 09/30/98
                                                                          ADMC330 DSP Motor Controller
                                                                            Developer’s Reference Manual


8. Memory Map
The ADMC330 memory map is shown in the following table. When boot loading from SROM the user
program space is 2000 locations long. When running from the debugger the user program space is 1600
locations long. In either mode the user data space is 911 locations long. The shaded areas are locations that
are used by the Motion Control Debugger. When running with the debugger your code and data can not
reside in the areas marked “Debugger Reserved” or the debugger will crash. You can link code or data in
the program memory area marked “Debugger Swap Area” but this code cannot contain DO LOOPS or the
debugger may crash. When the debugger uses this memory it pages itself in and out and always restores the
memory’s original contents. If there were an active DO LOOP from a user’s program in this segment when
the debugger tried to use it, the loop comparator would crash the debugger.

The debugger also uses locations 0x0001, 0x0002, 0x0020, and 0x0024 of the interrupt vector table. Do
not modify these locations in your code when running it with the debugger.

NOTE: If your program is boot loaded from an SROM, EEPROM, or some other device, and thus the
debugger is not in use, then your code and data can occupy all shaded areas of memory.

                            0x0000 - 0x002F    Interrupt Vector Table
                            0x0030 - 0x066F    User Program Space
                            0x0670 - 0x0720    Debugger Swap Area
                            0x0721 - 0x07FF    Debugger Reserved
                            0x0800 - 0x0BFF    ROM Monitor
                            0x0C00 - 0x0FFF    ROM Motor Utilities
                                          Program Memory


                          0x2000 - 0x201F       Peripherals

                          0x3800 - 0x3B8E      User Data Space
                          0x3B8F - 0x3B8F      Debugger Reserved
                          0x3B90 - 0x3BFF      Reserved for ROM Monitor Use
                                              Data Memory

                                           Table 1. ADMC330 Memory Map




                                            Rev 4.0    09/30/98                                           21
ADMC330 DSP Motor Controller
Developer’s Reference Manual


9. On-Chip ROM Operation
The ADMC330 has a 2K ROM which contains a monitor program that facilitates boot loading, serial port
communications, and a complete debugger interface. It also contains a set of math utilities that can be
called by user programs.

9.1 Power-up / Reset Sequence
The ADMC330 is similar to a ADSP-2172 in its booting sequence. The MMAP and BMODE pins are
internally tied high which enables the on-chip ROM and starts execution of the monitor at location 0x800
on reset.

9.2 SPORT1
The ADMC330 has two synchronous serial ports, SPORT0 and SPORT1, that support a variety of serial
data communication protocols. Both SPORTs are identical to the serial ports described in Reference 2 and
so can be programmed by user code to support the timing and framing options described therein. In
addition, the ADMC330 contains added circuitry on SPORT1 to configure it as a UART. The monitor
program contained in the ADMC330 ROM uses SPORT1 as its interface to external devices for booting
and debugging user code. After boot loading, a user application can reconfigure SPORT1 for general serial
word operation.


9.3 The ROM code Monitor
The monitor program's basic function is to do one of two things at startup:

•    Download and execute a user program (serial ROM, EEPROM, UART supported).

•    Enter debug mode in which commands are received and processed from a host. Any host can be used
     that can be configured as a UART and can handle the given command protocol. An example of such a
     host is the Analog Devices Motion Control Debugger.

Typically, an application is developed and debugged using the debug mode. Once the application is stable
it is programmed into serial ROM (SROM), EEPROM, or some other external device and boot loaded to
the ADMC330 on reset.

At startup the monitor first performs initialization and copies a default interrupt vector table to locations
0x0000 - 0x002F of program memory RAM. The section on interrupts in this document contains
information about how the ADMC330 processes interrupts and what is provided for a default interrupt
vector table by the ROM monitor. Following initialization the monitor tries to boot load and execute a user
program from SROM or EEPROM connected to SPORT1 through the DR1A pin. If successful, execution
then starts at location 0x0030.

Failing a boot load, the monitor enters debug mode and receives commands from an external device
(configured as a Universal Asynchronous Receiver/Transmitter (UART)) over SPORT1 through the DR1B
pin. These commands allow an external device to read and write to the ADMC330’s program or data
memory and to control the execution of code through the underlying debugger interface. The protocol
allows anything from a simple serial bit stream that loads and executes a user program, to a more complex
debugger interface, such as the Motion Control Debugger.

9.3.1 Communication Interfaces
The ADMC330 has two synchronous serial ports, SPORT0 and SPORT1, that support a variety of serial
data communication protocols. Both SPORTs are identical to the serial ports described in Reference 2 and
so can be programmed by user code to support the timing and framing options described therein. In



22                                           Rev 4.0 09/30/98
                                                                         ADMC330 DSP Motor Controller
                                                                           Developer’s Reference Manual

addition, the ADMC330 contains added circuitry on SPORT1 to multiplex the DR1 line between two input
pins (DR1A and DR1B), and to connect the DR1 line to the RFS1 line to configure SPORT1 as a UART.
The monitor program uses this circuitry to provide two different built-in options for input to the ADMC330,
a synchronous serial boot loader and an asynchronous debugger interface.

9.3.1.1 Boot Loader
The boot loader interface was designed to be used with a Xilinx XC1765D serial configuration PROM or
Atmel AT17C65 EEPROM. If using either of these devices the MAKEPROM utility can be used to format
an executable file into a .DBS file that can be programmed into the device. The MAKEPROM utility
automatically formats the code and data to boot properly from the device.

The boot loader can be used with devices other than those listed above if they adhere to the same timing and
protocol. This information is contained in Appendix H.

9.3.1.2 UART Debugger
Upon failing a boot load, the monitor activates debug mode. In this mode the monitor becomes a debugger
interface in which commands are received and processed over SPORT1. The ADMC330 emulates a
standard Universal Asynchronous Receiver / Transmitter (UART). It is this interface that is used when the
Motion Control Debugger is invoked to debug user code on the ADMC330. While this interface is
designed to be used with the debugger it can also be used for boot loading programs from devices that are
configured for UART communication, such as microcontrollers. Detailed information on this interface is
contained in Appendix I.

9.4 ROM Code Utilities
The following utilities are contained in the on-chip ROM and can be called by user programs:

                                 Function                      Routine Name         Address
               Place a vector in program memory               PUT_VECTOR           0x0B73
              SINE                                            SIN12B               0x0DC4
              COSINE                                          COS12B               0x0DD3
              Inverse Tangent                                 CAL_INV_TAN          0x0E61
              LOG base 10                                     LOG1                 0x0E14
              Inverse LOG base 10                             ALOG1                0x0E20
              Square Root                                     SQRT1                0x0E27
              Unsigned Division                               DIVIDE               0x0DE2
              Cartesian to Polar Conversion                   X_Y_TO_ANG           0x0E35
              Straight line approximation of 10 bit number    APPROX10_ST          0x0DEC
              Straight line approximation of N bit number     APPROX_N_ST          0x0DFF
                                      Table 2. ROM Code Utilities
The following data tables, which are used by the above functions, are also available in ROM. The data can
be dumped using the Motion Control Debugger if desired.


                              Table Function                Table Name         Address
                   16 bit by 64 point signed COS table    COS64               0x0B80
                   16 bit by 64 point COS table           COS6_64             0x0C00
                   16 bit by 64 point SIN table           SIN6_64             0x0C40
                   64 point 1/X table                     ONE_BY_X            0x0BC0
                   64 point 1/RMS table                   ONE_BY_RMS          0x0C80
                   64 point TAN table                     TAN64               0x0CC0
                   64 point ARCTAN table                  ATN64               0x0D01


                                            Rev 4.0   09/30/98                                           23
ADMC330 DSP Motor Controller
Developer’s Reference Manual

                   64 point LOG base 10 table               LOG64              0x0D42
                   64 point inverse LOG base 10 table       ALOG64             0x0D83
                                    Table 3. Utility Data Base Tables
A description of each utility follows as well as its calling convention. The ADMC330.h file that is installed
with the development software contains constant definitions for each of the routine names to link them with
their addresses in memory. To call a function, include the ADMC330.h file in the routine that calls the
function. Then make a call to the routine name defined in the include file. Input parameters are passed to a
function in the registers listed as INPUT. The function returns results in the registers listed as OUTPUT.
Registers listed as DESTROYED are those that are modified by the function. A user program must save
and restore any needed registers when calling a function if they are listed under INPUT, OUTPUT, or
DESTROYED.

The source code for each utility is listed in Appendix A.

9.4.1 PUT_VECTOR
{ INPUT       MR0 = address to vector to
              I4 = address where vector is to be stored
              M4 = desired post modify value
              L4 = desired circular buffer value

 OUTPUT       None

 DESTROYED           AR, AX1, AY0, SR, MR, PX

 FUNCTION Overwrites the contents of program memory whose address is
             contained in I4 with a JUMP to the address contained in MR0.              }

9.4.2 SIN12B and COS12B
{ INPUT       SR0 = ANGLE in Counts (0x0000 - 0x0FFF)
              i.e. 360/4096 = 0.087 Degree Resolution.
              Initialize M4=0x40, L4=0, M5=0x30, L5=0x40 before
              using these routines.

 OUTPUT       MR1 Result from 0x0000 - 0xffff

 DESTROYED           I4, I5, AR, AY0, SR, MR, MY0

 FUNCTION SIN12B and COS12B routines calculate SINE and COS values on
          12 bit data using COS64, COS6_64, and SIN6_64 tables.
          The algorithms used for these routines are:
          SIN(A+B) = SINA * COSB + COSA * SINB
          COS (A+B) = COSA * COSB - SINA*SINB                   }



9.4.3 CAL_INV_TAN
{ INPUT       AY0 = 12 Bit Input X

 OUTPUT       SR0 = Result

 DESTROYED           AY1, AX0, AX1, SR




24                                           Rev 4.0 09/30/98
                                                                       ADMC330 DSP Motor Controller
                                                                         Developer’s Reference Manual

CALLS       APPROX_N_ST

FUNCTION Calculate inverse tangent of input value to 12 bits
            SR0 = ARCTAN (X) (from 0 - 2047)                       }

9.4.4 LOG1
{ INPUT     MR0, MR1 = 31 Bit Input

OUTPUT      AR = LOG(X), MX1 = Exponent of X

DESTROYED          AR, AX1, AY0, SR, SE

CALLS       APPROX10_ST

FUNCTION Calculate the LOG base 10 of 31 bit input.
         LOG(MR1 MR0) = [(30+MX1) + (AR/32767)] * LOG(2)
         LOG table contains LOG values from LOG(1) to LOG(2) in
         64 steps divided by LOG(2) so value is from 0 - 32767.            }

9.4.5 ALOG1
{ INPUT     AR = X, MY0 = Y of X^Y, Y < 1

OUTPUT      AR = ALOG (X)

DESTROYED          AR, AX1, AY0, SR, MR

CALLS       APPROX10_ST

FUNCTION Calculate X^Y for Y < 1                     }

9.4.6 SQRT1
{ INPUT     MR0, MR1 = 31 Bit Input

OUTPUT      SR0 = Result

DESTROYED          AR, AY0, SR, SE, MR, MX1, MY0

CALLS       LOG1, ALOG1

FUNCTION Calculate square root of 31 bit input                 }



9.4.7 DIVIDE
{ INPUT     AY0 = Numerator LSB, SR1 = Numerator MSB, AX0 = Denominator

OUTPUT      AY0 = Quotient

DESTROYED          AF, SR1, CNTR, AX0, ASTAT

FUNCTION Unsigned Division              }




                                         Rev 4.0   09/30/98                                       25
ADMC330 DSP Motor Controller
Developer’s Reference Manual

9.4.8 X_Y_TO_ANG
{ INPUT      AX0 = SIN(ANGLE), AX1 = COS(ANGLE)
             AX0 and AX1 values from 0 - 0xFFFF

 OUTPUT      AR = ANGLE (in counts from 0 - 0x4000)

 DESTROYED          AR, AF, AX0, AX1, AY0, AY1, SR, MR, MX0, MX1, MY0, MY1,

 CALLS       DIVIDE, CAL_INV_TAN

 FUNCTION Convert from Cartesian to Polar coordinates
          X = COS(ANGLE), Y = SIN(ANGLE)
          ANGLE = ARCTAN (Y / X)                                 }

9.4.9 APPROX10_ST
{ INPUT      SR1 = 10 Bit Data Input (0x0000 - 0x03FF)
             AX1 = 16 Bit Pointer to Start of 6 Bit Data Table

 OUTPUT      AR = Result

 DESTROYED          I4, M4, L4, AR, AX0, AY0, AY1, SR, MR, MY0

 FUNCTION Calculate approximation using straight line approximation method.
          Calculates approximation on 10 bit input in SR1 using 6 bit table pointed
              to by AX1.                                                   }

9.4.10 APPROX_N_ST
{ INPUT      AX0 = N (Number of Bits)
               AY1 = N Bit Data Input
             AX1 = 16 Bit Pointer to Start of 6 Bit Data Table

 OUTPUT      AR = Result

 DESTROYED          I4, M4, L4, AR, AX0, AY0, AY1, SR, SE, MR, MY0

 FUNCTION Calculate approximation using straight line approximation method.
          Calculates approximation on N bit input in SR1 using 6 bit table pointed
              to by AX1.                                                   }




26                                         Rev 4.0 09/30/98
                                                                                       ADMC330 DSP Motor Controller
                                                                                         Developer’s Reference Manual


10. Interrupt Operation
Interrupts work as described for an ADSP-2171 core in Reference 2 with the following exceptions:

         •    Peripheral interrupts ( PWMTRIP , PWMSYNC, and PIO) are internally wired to
               IRQ2 (vector at 0x0004). Software further determines which interrupt is activated and jumps
              to the appropriate interrupt service routine.
         •    The PIO vector replaces the HIP Write vector at location 0x0008.
         •    The PWMSYNC vector replaces the HIP Read vector at location 0x000C.
         •    The PWMTRIP vector shares location 0x002C with the Powerdown interrupt.

The interrupt controller allows the processor core to respond to nine possible interrupts with the minimum
of overhead. The ADMC330 supports eight internal interrupts from the timer, the two serial ports, the
software interrupts, and the software forced powerdown interrupt. The ninth interrupt, IRQ2 on the 2171
core, is actually wired internally to the ADMC330 peripheral interrupt sources. This peripheral interrupt is
generated on a PWMTRIP , PWMSYNC (once each PWM cycle), or from any of the 8 PIO ports.

All interrupts are internally prioritized and individually maskable (except for powerdown). The interrupt
vector addresses and priorities are shown in Table 4. Interrupts can be masked or unmasked with the
IMASK register. Individual interrupt requests are logically ANDed with the bits in IMASK; the highest
priority unmasked interrupt is then selected. The software forced powerdown interrupt is nonmaskable.
The ADMC330 masks all interrupts for one instruction cycle following the execution of an instruction that
modifies the IMASK register. This does not affect autobuffering.

                               Interrupt Source                         Interrupt Vector Address
                1
                    Peripheral Interrupt ( IRQ2 )                     0x0004
                1
                  PWMTRIP and Power Down                              0x002C (Highest Priority)
                1
                  PWMSYNC                                             0x000C
                1
                  PIO                                                 0x0008
                SPORT0 Transmit                                       0x0010
                SPORT0 Receive                                        0x0014
                Software Interrupt 1                                  0x0018
                Software Interrupt 0                                  0x001C
                SPORT1 Transmit Interrupt or IRQ1                     0x0020
                SPORT1 Receive Interrupt or IRQ0                      0x0024
                Timer                                                 0x0028      (Lowest Priority)
                1
                 peripheral interrupt ( IRQ2 ) starts execution at 0x0004 from which it jumps to address
                0x002C, 0x000C, or 0x0008 as determined by the code at location 0x0004.

                               Table 4. Interrupt Vector Addresses by Priority

The interrupt control register, ICNTL, allows the external interrupts to be either edge or level-sensitive.
Since the IRQ2 line is a combination of all peripheral interrupt sources they will all be set to edge or level-
sensitive. The ICNTL register also allows interrupts to be processed sequentially or nested with higher
priority interrupts taking precedence. Since the peripheral interrupts are all on the same level ( IRQ2 ) they
can only be nested by manually unmasking them with the IMASK register from inside the interrupt service
routine.

The IFC register is a write-only register that is used to force and clear interrupts from software.



                                                   Rev 4.0     09/30/98                                           27
ADMC330 DSP Motor Controller
Developer’s Reference Manual

On-chip stacks preserve the processor status and are automatically maintained during interrupt handling.
The stacks are 12 levels deep to allow interrupt nesting. A set of shadow registers are provided for single
cycle context switching.

The following instructions allow global enabling or disabling of interrupts (including powerdown),
regardless of the state of IMASK. Disabling the interrupts does not affect autobuffering.

       ENA INTS;
       DIS INTS;

When you reset the processor, interrupt servicing is disabled.

During initialization, the ADMC330 monitor creates a default interrupt vector table at location 0. Interrupt
vector locations are spaced four locations apart which allows short interrupt service routines to be coded in
place, with no jump to the service routine required. For interrupt service routines with more than four
instructions, a jump (or vector) to the interrupt service routine must be placed at the interrupt vector
location. The PUT_VECTOR utility routine can be used to perform this task. As a default, interrupt vector
locations that are not in use contain RTI instructions so that inadvertent activation of the interrupt will only
cause it to return and not to jump to some unknown instruction.

For peripheral interrupts ( IRQ2 ) the default code at location 0x0004 is slightly different, and so is shown
below:

       Location_0x0004:              ASTAT=DM(IRQFLAG);
                                     dm(IRQFLAG_SAVE)=ASTAT;              {save last IRQFLAG}
                                     IF EQ JUMP H#002C;                   {PWMTRIP interrupt}
                                     IF LT JUMP H#000C;                   {PWMSYNC interrupt}
       Location_0x0008:              RTI;                                 {PIO interrupt}

As can be seen, the IRQFLAG register is used to determine if the interrupt source is the PWMTRIP,
PWMSYNC, or PIO. The appropriate interrupt service routine is then executed. The code falls through to
the PIO ISR at location 0x0008 if the conditions for PWMTRIP and PWMSYNC are both false. The user
must replace locations 0x0008, 0x000C, and 0x002C with a jump to their interrupt service routine for the
corresponding interrupt. The PUT_VECTOR library routine, described below, can be used to accomplish
this.

The default interrupt vector table contains code at locations 0x0001 and 0x0002 and at the SPORT1
transmit and receive interrupt vector locations (0x0020 and 0x0024) which is used when in debug mode to
talk to the Motion Control Debugger. These locations must not be changed when operating in this mode or
the debugger may crash. Also, the SPORT1 transmit and receive interrupts must be kept enabled by your
code in order to run it with the debugger.

10.1 Using PUT_VECTOR
The PUT_VECTOR routine, contained in ROM, can be called to replace the default RTI in the interrupt
vector table with a JUMP to your interrupt service routine. The following example illustrates how to use
PUT_VECTOR.

Given the following default interrupt vector table code for the PWMSYNC interrupt:

       Location_0x000C:              RTI;

the following call to PUT_VECTOR in your initialization code:

                                     I4 = PWMSYNC_INT_ADDR;
                                     MR0 = ^YOUR_PWMSYNC_ISR


28                                            Rev 4.0 09/30/98
                                                                           ADMC330 DSP Motor Controller
                                                                             Developer’s Reference Manual

                                     CALL PUT_VECTOR;

would change the code at 0x000C to:

       Location_0x000C:              JUMP YOUR_PWMSYNC_ISR;

In this example YOUR_PWMSYNC_ISR is the label at the start of your PWMSYNC interrupt service
routine. PWMSYNC_INT_ADDR is a constant equal to 0x000C in the ADMC330.h file that you would
include in your code module. And, PUT_VECTOR is a routine contained in ROM that you can call by
including the file ROMUtil.h.

10.2 Peripheral Interrupt Operation
The PWMSYNC interrupt is detected on a low to high transition on the PWMSYNC pulse. The
 PWMTRIP interrupt is detected on a high to low transition on the PWMTRIP pin. A PIO interrupt is
detected on any change of state (high to low or low to high) on the PIO line. When a peripheral interrupt is
detected, a flag bit is set in the IRQFLAG register for PWMSYNC and PWMTRIP or in the PIOFLAG
register for a PIO interrupt. The IRQ2 line is also pulled low (the IRQ2 line is held low until all pending
peripheral interrupts are acknowledged). Execution then begins at the IRQ2 (or peripheral) interrupt
vector location (0x0004). Software at this location in the default vector table determines which peripheral
interrupt is active, by reading the IRQFLAG register, and then jumps to the correct interrupt service routine,
 PWMTRIP , PWMSYNC, or PIO. Therefore, a user need only put their desired interrupt service routine
(or vector if it’s larger than 4 locations) at the corresponding vector locations 0x002C, 0x000C, and 0x0008
respectively. If more than one interrupt occurs simultaneously the higher priority interrupt service routine
is executed.

The user should be aware of some important peripheral interrupt considerations:

1.   While the default code will determine that a PIO interrupt has occurred, it does not determine which
     PIO pin is the source of the interrupt. The user’s routine at 0x0008 must also read the PIOFLAG
     register to determine which PIO pin is the source of the interrupt.

2.   The IRQ2 line is not deactivated until all pending peripheral interrupts are acknowledged. The
      PWMTRIP and PWMSYNC interrupts are acknowledged by reading IRQFLAG, which is done
     automatically by the code in the default interrupt vector table. Reading IRQFLAG also clears the
      PWMTRIP and PWMSYNC bits. The PIO interrupts are acknowledged by reading the PIOFLAG
     which clears all bits in this register. Since this is not done by the code in the default interrupt vector
     table, it must be done from the user’s code.

3.   Reading the IRQFLAG register clears the PWMTRIP and PWMSYNC bits and acknowledges the
     interrupts. Reading the PIOFLAG register clears all bits in the register and acknowledges the PIO
     interrupts.

4.   The PWMSYNC, PWMTRIP , and PIO interrupts are logically Ored. Although they are internally
     edge detected by the interrupt controller, the IRQ2 line is only driven low when an interrupt edge is
     detected and all peripheral interrupts are clear (acknowledged). Therefore, if simultaneous interrupts
     occur, or if a second interrupt occurs before the first has been acknowledged, only one edge will be
     present on the IRQ2 line. Therefore, if interrupts are set to be edge-sensitive (in the ICNTL register)
     only one IRQ2 interrupt will occur and it will be incumbent on the interrupt service routine to check to
     see if simultaneous interrupts have occurred and then to acknowledge all of them. Failure to
     acknowledge the simultaneous interrupt will result in locking out all future peripheral interrupts




                                             Rev 4.0    09/30/98                                            29
ADMC330 DSP Motor Controller
Developer’s Reference Manual

     because IRQ2 will remain low. This problem does not exist if interrupts are set to be level-sensitive
     because the IRQ2 line is held low until all peripheral interrupts are acknowledged, and once the first
     interrupt is processed and interrupts are unmasked a second IRQ2 interrupt will occur. The behavior
     of the peripheral interrupts is summarized in the following example.


10.2.1 Example Interrupt Servicing Scheme
The following example demonstrates how to program the ADMC330 interrupts so that they are processed
sequentially according to their priorities as shown in Table 4 while PWMTRIP , PWMSYNC, and PIO
interrupts are nested. That is, they can interrupt when interrupts of lower priority are being serviced.

The IRQ2 sensitivity bit in the ICNTL register is set to level-sensitive for the peripheral interrupts. The
interrupt nesting bit is set to disabled because we wish to process most of the interrupts sequentially. All
lower priority interrupts will unmask the IRQ2 interrupt from inside their interrupt service routines by
setting the IRQ2 enable bit in the IMASK register. This will allow the peripheral interrupts to interrupt
lower priority interrupts. In this example the PWMTRIP and PWMSYNC are high priority interrupts that
must be processed immediately no matter what is executing at the time. The PWMSYNC and PWMTRIP
interrupt service routines will keep lower priority interrupts masked so that they do not interrupt. No code
is necessary to do this because the IMASK value is automatically set to zero during interrupt processing
when interrupt nesting is disabled. Similar to the lower priority interrupts, the PIO interrupt service routines
will unmask the IRQ2 interrupt to allow PWMSYNC and PWMTRIP interrupts. This must be done after
the PIOFLAG register is read so that the current interrupt is acknowledged before re-enabling interrupts.
As a consequence, this allows PIO interrupts to interrupt other PIO interrupts which may or may not be
higher priority. Therefore, the PIO interrupt service routine will have to decide whether an interrupt is
processed immediately or queued for later execution.

Code snippets from each of the routines of interest follow. An example timing diagram is shown in Figure
6. It shows the relative position of the signals of interest and the resulting code execution. Times are not
given because they vary by application. Only the peripheral interrupts are shown. All other interrupts
operate as described for an ADSP-2171 core in Reference 2. The following is a discussion explaining the
code and timing diagram.

The main program first initializes PWM interrupts by creating a JUMP (or vector) to PWMSYNC_ISR and
PWMTRIP_ISR at locations 0x000C and 0x002C respectively. The PUT_VECTOR utility routine,
described in the ROM Code Utilities section, can be used to perform this task. The PWMSYNC and
PWMTRIP interrupts are then enabled in the MODECTRL register.

The PIO interrupts are initialized in a similar manner. A vector to the PIO_ISR routine is placed at location
0x0008 in the interrupt vector table. PIO2 is set to be an input in the PIODIR register, and is cleared in the
PIODATA register. The PIO2 interrupts are then enabled in the PIOINTEN register. The main program
then unmasks peripheral interrupts in the IMASK register and enters the main processing loop.

As shown in Figure 6, when the first PWMSYNC pulse is received the IRQ2 line is pulled low and an
IRQ2 interrupt is generated. The IRQ2 interrupt service routine at the IRQ2 interrupt vector location
(0x0004) in the default interrupt vector table then executes. The IRQFLAG register is read and saved in the
IRQFLAG_SAVE variable at location 0x3BFE in data memory. Which peripheral interrupt to process is
determined based on priority if simultaneous interrupts have been received. Since only the PWMSYNC bit
in the IRQFLAG is set, the routine jumps to the PWMSYNC interrupt vector location at 0x000C. At this
location there exists a vector to the PWMSYNC_ISR routine which is executed next.




30                                            Rev 4.0 09/30/98
                                                                           ADMC330 DSP Motor Controller
                                                                             Developer’s Reference Manual

As can be seen in the diagram the PIO2 line changes state while the PWMSYNC ISR is executing. The
PIO2 bit in the PIOFLAG register is set, and since all peripheral interrupts are clear at the time, the IRQ2
line is pulled low. If the interrupts were set to be edge-sensitive this would cause an IRQ2 interrupt at this
point that would be latched by the DSP core and held off since interrupts are masked by the PWMSYNC
ISR. However, since in this example interrupts are set to be level-sensitive, an IRQ2 interrupt does not
occur until the PWMSYNC ISR is exited thus unmasking the IRQ2 line. Since the IRQ2 line is still low,
and because the PIOFLAG has not been read yet, the IRQ2 interrupt is generated and the IRQ2 ISR
executes. This time it is determined to be a PIO interrupt so the PIO ISR is executed. In the PIO ISR the
PIOFLAG is read which brings the IRQ2 line high again. Because the interrupt source is PIO2, the PIO2
ISR routine is executed.

When the second PWMSYNC pulse is received, the IRQ2 line is pulled low and an IRQ2 interrupt is
generated. This time before the IRQFLAG is read, a change of state occurs on the PIO2 line which sets the
PIO2 bit in the PIOFLAG register. The IRQFLAG is then read which indicates a PWMSYNC interrupt has
occurred so the PWMSYNC ISR is executed. The IRQ2 line is held low because the PIO interrupt is
pending in the PIOFLAG register. When the PWMSYNC ISR exits, an IRQ2 interrupt occurs because the
IRQ2 line is still low. This would not have happened if interrupts were set to be edge-sensitive, because
there was no edge for the PIO interrupt. The IRQ2 ISR determines that it’s a PIO interrupt and the PIO
ISR reads the PIOFLAG register and determines it’s a PIO2 interrupt so the PIO2 ISR is executed. Reading
the PIOFLAG register acknowledges the PIO interrupt which brings IRQ2 high again.

On the third PWMSYNC pulse the IRQ2 line is pulled low again and the IRQ2 ISR executes again. This
time, before the IRQFLAG is read, both the PWMTRIP line is driven low and the PIO2 line changes state.
When the IRQFLAG is read, the IRQ2 line is held low because the PIO interrupt is pending. The IRQ2
ISR determines that the PWMTRIP interrupt is active first so it jumps to the PWMTRIP interrupt vector
location and executes the PWMTRIP ISR.

Prior to exiting, the PWMTRIP interrupt service routine could optionally check the IRQFLAG_SAVE
variable to see if a simultaneous PWMSYNC was received and do any appropriate processing. If this is not
done, then it should be understood that the PWMSYNC interrupt will be skipped upon exiting the
PWMTRIP ISR because it was cleared when the original read of the IRQFLAG register was performed.

Upon exiting the PWMTRIP ISR the IRQ2 line is still low, due to the pending PIO interrupt, so that an
 IRQ2 interrupt is generated and subsequently the PIO2 ISR is executed. Again, if interrupts had been set
to edge-sensitive, this interrupt would have been missed.




                                             Rev 4.0   09/30/98                                            31
ADMC330 DSP Motor Controller
Developer’s Reference Manual

Main Program
                       .
                       .
                       .
                 CALL INIT_PWM;                  {Initialize PWM Interrupts}
                 CALL INIT_PIO;                  {Initialize PIO Interrupts}
                 ICNTL = 0x03;                   {Nest=0,IRQ2=level,IRQ0,1=edge}
                 AY0 = 0x200;                    {Unmask IRQ2 interrupts}
                 AR = IMASK;
                 AR = AR OR AY0;
                 IMASK = AR;
Mainloop:
                         .
                         .
                         .
                 JUMP Mainloop;

Initialize PWM

INIT_PWM:
                         .
                         .
                         .
                 I4 = PWMSYNC_INT_ADDR;          {Initialize jump to PWMSYNC ISR}
                 MR0 = ^PWMSYNC_ISR;             {Vector address (0x000C) in I4}
                 CALL PUT_VECTOR;                {Start address of ISR in MR0}

                 I4 = PWMTRIP_INT_ADDR;          {Initialize jump to PWMTRIP ISR}
                 MR0 = ^PWMTRIP_ISR;             {Vector address (0x002C) in I4}
                 CALL PUT_VECTOR;                {Start address of ISR in MR0}

                 AY0 = 0x000C;                   {Enable PWMSYNC & PWMTRIP}
                 AR = DM(MODECTRL);              {interrupts from MODECTRL}
                 AR = AR OR AY0;                 {of ADMC330. Preserve other}
                 DM(MODECTRL) = AR;              {bits of MODECTRL by ORing}
                 RTS;

Initialize PIO
INIT_PIO:
                         .
                         .
                         .
                 I4 = PIO_INT_ADDR;       {Initialize jump to PIO ISR}
                 MR0 = ^PIO_ISR;          {Vector address (0x0008) in I4}
                 CALL PUT_VECTOR;         {Start address of ISR in MR0}
                 AR = 0x0004;             {enable pio2 interrupts}
                 DM(PIOINTEN) = AR;
                 RTS;




32                                    Rev 4.0 09/30/98
                                                              ADMC330 DSP Motor Controller
                                                                Developer’s Reference Manual

IRQ2 Interrupt Service Routine (from default Interrupt Vector Table)
                                .
                                .
{location 0x0004} ASTAT=DM(IRQFLAG);                      {PWMTRIP,PWMSYNC, OR PIO}
                         DM(IRQFLAG_SAVE)=ASTAT; {save last IRQFLAG}
                         IF EQ JUMP H#002C;               {PWMTRIP interrupt}
                         IF LT JUMP H#000C;               {PWMSYNC interrupt}
{location 0x0008}               .                         {otherwise it’s a PIO}
                                .
                                .
PWMTRIP Interrupt Service Routine

PWMTRIP_ISR:
                          .             {save registers}
                          .             {PWMTRIP interrupt processing}
                          .             {restore registers}
      {Optionally read value of IRQFLAG that was saved off to see if a
      simultaneous PWMSYNC interrupt was received and process it.}
                AR = DM(IRQFLAG_SAVE); {IRQFLAG_SAVE=0x3BFE}
                RTI;

PWMSYNC Interrupt Service Routine

PWMSYNC_ISR:
                                .                   {save registers}
                                .                   {PWMSYNC interrupt processing}
                                .                   {restore registers}
                   RTI;

PIO Interrupt Service Routine

PIO_ISR:
                                    .
                                    .               {save registers}
                                    .

                   AY0 = DM(PIOFLAG);               {ack and determine pio}
                   IMASK = 0x0200;                  {enable IRQ2 interrupts}
                   AX0 = 0x0004;
                   AR = AX0 AND AY0;
                   IF NE CALL PIO2_ISR;             {go process pio2 interrupt}
                       .
                       .                            {restore registers}
                       .
                   RTI;

PIO2_ISR:
                       .
                       .                            {process pio2 interrupt}
                       .
                   RTS;




                                        Rev 4.0   09/30/98                               33
ADMC330 DSP Motor Controller
Developer’s Reference Manual

       PW M T R I P                                                                                                                                      ...



                                                                                                                                       PWMTRIP
                                                                                                                                         ISR


       PW M SY N C                                                                                                                                       ...


                                     PWMSYNC                                           PWMSYNC
                                       ISR                                               ISR



                                                                                                                                                         ...

          PI O 2


                                                            PIO2 ISR                                           PIO2 ISR




                        IRQ2 ISR                   IRQ2 ISR                 IRQ2 ISR              IRQ2 ISR                  IRQ2 ISR              IRQ2 ISR


                             IRQFLAG                   PIOFLAG                   IRQFLAG               PIOFLAG                   IRQFLAG
                               Read                      Read                      Read                  Read                      Read


          IRQ2

                                                                                                                                                         ...

                        IRQ2                      IRQ2                      IRQ2                 IRQ2                       IRQ2                 IRQ2
                      Interrupt                 Interrupt                 Interrupt            Interrupt                  Interrupt            Interrupt
                                   latched if                                                  (missed if                                      (missed if
                                                                                  held low   edge-sensitive)                      held low   edge-sensitive)
                                  edge-sensitive



                      Figure 6. Example Timing Diagram for Peripheral Interrupts




34                                                                     Rev 4.0 09/30/98
                                                                           ADMC330 DSP Motor Controller
                                                                             Developer’s Reference Manual


11. Watchdog Timer Operation
The watchdog timer is used to time critical control loops and to reset the peripherals and DSP if a loop
takes too long to complete. The watchdog timer is enabled by writing a value to the watchdog timer
register, WDTIMER, shown in Figure 7. A counter in the watchdog hardware counts down from this value
at the peripheral clock rate (CLKIN). In the event of the DSP “hanging” the counter will count down to
zero and the watchdog timer hardware will force a DSP and peripheral reset. Under normal operation a
section of DSP code at the end of the control loop would reset the counter to its initial value, preventing it
from reaching zero. Thus only under incorrect operation of the DSP will the watchdog timer trip.

Once the watchdog timer has been enabled, to prevent it from timing out, the user need only include the
following line of code at the end of the control loop:

                  DM(WDTIMER) = AX0;

The value in AX0 is irrelevant. Once the watchdog timer is enabled, rewriting to WDTIMER will reset the
timer to the original value that was written when the watchdog timer was initially enabled.

When a watchdog trip occurs and the peripheral block is reset, all peripheral registers are set to zero and the
PWM signals to the motor are shut down. The WDFLAG (bit 1 of the SYSSTAT register) is set when a
watchdog trip occurs. The DSP can read this flag during its boot up sequence to determine if the reset came
from a watchdog trip. The watchdog remains disabled while the WDFLAG is set. Writing a nonzero value
to the WDTIMER register will reset the WDFLAG bit and enable the watchdog timer. Writing zero to the
WDTIMER register will reset the WDFLAG bit and disable the watchdog timer.

The watchdog timer is disabled on power-up.




                                                         WDTIMER (W)

                                15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
               DM(0x2018)                         TIMEOUT (# of CLKINcycles)




                                   Figure 7. Watchdog Timer Register




                                             Rev 4.0    09/30/98                                            35
ADMC330 DSP Motor Controller
Developer’s Reference Manual


12. Software Peripheral Reset Function
A full reset of the peripherals can be performed from software by executing the following code:

         PER_RST:            SET FL2;
                             TOGGLE FL2;
                             TOGGLE FL2;
                             RTS;

This resets all peripheral registers to their power on state and turns off PWM signals to the motor.




36                                            Rev 4.0 09/30/98
                                                                        ADMC330 DSP Motor Controller
                                                                          Developer’s Reference Manual


13. Tutorial
The following tutorial leads the user through some demonstration examples on the ADMC330 evaluation
board. The example source code files are installed during the Motion Control Debugger installation. The
two examples are installed automatically into the subdirectories \Mcd330\Examples\Example1 and
\Mcd330\Examples\Example2:

        •    EXAMPLE1: This simple example sets up the PWM system of the
                       ADMC330 and produces constant duty cycle outputs on the
                       six PWM output pins. In addition, the lower three PWM
                       signals are chopped with a 1 MHz signal. No additional
                       hardware is required to run this example on the ADMC330
                       evaluation board using the debugger. This file is a
                       good template from which it is possible to build more
                       complex programs.

        •    EXAMPLE2: This example is more advanced and builds on that of
                       EXAMPLE1. It produces three-phase sine-triangle PWM
                       that could be used to drive an induction motor with simple
                       V/f control. Both the magnitude and frequency of the
                       fundamental voltage produced by the PWM are varied
                       based on a value read in from one of the analog to digital
                       converters. This example also makes use of the auxiliary
                       PWM outputs as simple digital to analog converters. Some
                       simple hardware additions to the evaluation board are
                       needed to run this example successfully.

13.1 Example 1: Simple Configuration Example
This demonstration example is located in the \Example1 subdirectory. It is a simple program that can be
used to validate the operation of the ADMC330 evaluation board. It can also be used as a learning tool for
the Motion Control Debugger and as a template from which more complex programs can be developed.
The subdirectory contains the following files:

        •    example1.dsp          Assembly language source code
        •    ADMC330.h             Include file of device specific constant definitions
        •    ADMC330.sys           System description file used as input to BLD21 in order to
                                   create the architecture file
        •    ADMC330.ach           Architecture file output from BLD21
        •    build.bat             Batch file to assemble and link example file to create
                                   executable module. The executable module can be loaded
                                   using the debugger.

This demo program may be summarized with the following pseudocode.
       STARTUP:           Initialize PWM registers for 10 kHz, 1µs dead time, 1.5 µs pulse
                          deletion.
                          Enable high frequency chopping on the low-side PWM signals at
                          1.0 MHz and enable all PWM outputs.
                          Use PUT_VECTOR routine to place jumps in the interrupt vector
                          table to the appropriate routines for both the PWMSYNC and
                           PWMTRIP interrupts.
                          Enable both PWMSYNC and PWMTRIP interrupts by writing to
                          the MODECTRL register of the ADMC330.




                                           Rev 4.0   09/30/98                                          37
ADMC330 DSP Motor Controller
Developer’s Reference Manual

                              Clear any pending interrupts, disable interrupt nesting and set level
                              sensitivity using IFC and ICNTL registers.
                              Enable peripheral interrupt ( IRQ2 ) on ADMC330 using IMASK
                              register.

       MAINLOOP:              Do nothing. Wait for either PWMSYNC or PWMTRIP interrupt.

       PWMSYNC_ISR:           At each PWMSYNC interrupt, execute this code. In this
                              example, the three PWM registers PWMCHA,
                              PWMCHB and PWMCHC are written with constant
                              values.

       PWMTRIP_ISR:           At each PWMTRIP interrupt, execute this code. In this
                              example, do nothing.


Running the batch file build.bat will create some additional files. These include the object file (.obj), the
code file (.cde) and the initialization file (.int) created by the assembler and the map listing file (.map), the
symbol table file (.sym) and the executable file (.exe) created by the linker. The executable file
EXAMPLE1.EXE can be run on the evaluation board using the debugger.


13.2 Example 2: Sine-Triangle PWM Example

13.2.1 Introduction
This demonstration example is located in the \Example2 subdirectory. The example produces balanced
three-phase sine-triangle PWM outputs that could be used to drive an induction motor with simple V/f
control. However, the example is for illustration only and does not include all of the features needed for
correct V/f control such as low-voltage boosting, acceleration and deceleration control etc.

13.2.2 Hardware Modifications
In order to run this demonstration some simple hardware modifications are required on the ADMC330
evaluation board. These modifications are shown in Figure 8 and are:
         1. Ability to supply an analog voltage to analog input V1 (input to ADC1 of ADMC330). In the
             figure, this is achieved using a potentiometer. Alternatively, a bench power supply or function
             generator may be used.
         2. Two pole RC filters are applied at the outputs of the auxiliary PWM outputs. The cut-off
             frequency is about 1.2 kHz. This attenuates the ripple at 39 kHz produced by these outputs
             and permits display of two analog outputs.
         3. A 300 pF ADC timing capacitor should be placed at jumper JP6 of the ADMC330 evaluation
             board. For a PWM switching frequency of 10 kHz, this will provide the required sawtooth
             ADC reference voltage from 0 to 3.5V.




38                                             Rev 4.0 09/30/98
                                                                              ADMC330 DSP Motor Controller
                                                                                Developer’s Reference Manual




                                                                            13 kΩ       13 kΩ
                                                   AUX0


                              +5V
                                                                            10 nF         10 nF

                                      V 1 (A D C 1 )
                  P o t.



                                                                            13 kΩ       13 kΩ
                                                   AUX1




                                                                            10 nF         10 nF




  Figure 8. Hardware Modifications to ADMC330 Evaluation Board for Example 2 Demonstration


13.2.3 Algorithm Description
The algorithm produces three PWM signals whose fundamental outputs may be described in normalized
variables as:
                                           VrefA = ξ sin(θ)
                                                            2π 
                                           VrefB = ξ sin θ + 
                                                             3
                                                            4π 
                                           VrefC = ξ sin θ + 
                                                             3
where ξ ∈ [0,1] is the amplitude and frequency scale factor derived from the ADC input, V1. The angle, θ,
is calculated incrementally each PWM cycle as:
                                        θ( k ) = θ( k − 1) + 2 πξf max Ts
                                              = θ( k − 1) + ξ∆
where Ts is the PWM switching period and fmax is the maximum fundamental frequency at ξ=1. For an
assumed maximum frequency of 100 Hz and a PWM switching frequency of 10 kHz, ∆ = 0.0628 rad. The
sine approximating function used in this example accepts angle input in 1.15 format corresponding to [-
π,π]. As a result, the hexadecimal equivalent of ∆ may be written:
                                       0.0628        
                           ∆ = HEX INT        × 2 15  = HEX[655] = 0x028F .
                                       π             
where INT implies the integer part of the argument. Using a similar approach the 1.15 hex. equivalent of
2π/3 is 0x5555.



                                              Rev 4.0    09/30/98                                        39
ADMC330 DSP Motor Controller
Developer’s Reference Manual

A suitable sine approximating function is described in Reference 5 and is given by:
          sin( x) = 3140625x + 0.02026367 x 2 − 5.325196x 3 + 0.5446778x 4 + 1800293x 5
                     .                                                        .
Having calculated the sine functions and scaled by ξ to produce the reference voltages, the PWM on-times
may be calculated as:
                                                  Ts Ts
                                           TA =     + VrefA .
                                                  2  2
Similar equations can be written for the other two phases.

13.2.4 File Description
This demonstration is made up of more files than example 1 and shows how multiple code modules can be
written in separate files and linked together to create a single executable module. The example includes the
following files:

• example2.dsp:      Assembly language file that contains the main program
                     control. The initialization, main and interrupt service
                     routines are in this file.
• pwm_funs.dsp:      Assembly language file that contains various pwm functions.
                     This file includes the functions to initialize the pwm system
                     (INIT_PWM), to calculate and load the pwm timers
                     (SINE_PWM) and to write to both auxiliary pwm timers
                     (WR_AUXPWM0 and WR_AUXPWM1).
• mth_funs.dsp:      Assembly language file that contains the sine approximation
                     function.
• ADMC330.h:         Include file of device specific constant definitions.
• consts.h:          Include file of constant definitions specific to this example.
• ADMC330.sys:       System description file.
• ADMC330.ach:       Architecture file.
• build.bat:         Batch file that assembles all assembly language file and links
                     them to create a single executable file (example2.exe) that can
                     be run on the evaluation board.


13.2.5 Demonstration Execution
Having created the executable file example2.exe, it can be downloaded to the ADMC330 evaluation board
using the debugger. When the program is running, it is possible to change the analog input voltage at V1 by
adjusting either the potentiometer or the bench power supply. The corresponding changes to the analog
outputs (filtered outputs of auxiliary pwm timers) and the six pwm outputs (AH to CL) can be observed on
an oscilloscope. Notice that as the voltage at V1 is increased, both the amplitude and frequency of the two
sinusoidal voltages at the auxiliary pwm outputs also increase. The output pwm patterns on AH to CL are
affected accordingly.




40                                           Rev 4.0 09/30/98
Appendix A                                                         ADMC330 DSP Motor Controller
                                                                     Developer’s Reference Manual


14. Appendices
Appendix A Source Code for ROM Utilities


A.1 PUT_VECTOR
{ INPUT      MR0 = address to vector to
             I4 = address where vector is to be stored
             M4 = desired post modify value
             L4 = desired circular buffer value

 OUTPUT      None

 DESTROYED          AR, AX1, AY0, SR, MR, PX

 FUNCTION Overwrites the contents of program memory whose address is
             contained in I4 with a JUMP to the address contained in MR0.     }

PUT_VECTOR:         ax1=imask ;                 {DIS INTS}
                    imask=0;
                     ay0=h#f;
                    ar=mr0 and ay0;
                    sr=lshift ar by 4 (lo);
                    ar=sr0 or ay0;
                    px=ar; {Now PX = 4 Bits LSB of ENTRY,4 Bits “1” for}
                            {unconditional jump}
                    sr=lshift mr0 by -4 (lo);
                    ay0=h#1800;                 {18 for jump}
                    ar=sr0 or ay0;
                    pm(i4,m4)=ar;               {*** replaces inst.}
                    imask=ax1;                  {ENA INTS}
                    rts;


A.2 SIN12B and COS12B
{ INPUT      SR0 = ANGLE in Counts (0x0000 - 0x0FFF)
             i.e. 360/4096 = 0.087 Degree Resolution.
             Initialize M4=0x40, L4=0, M5=0x30, L5=0x40 before
             using these routines.

 OUTPUT      MR1 Result from 0x0000 - 0xffff

 DESTROYED          I4, I5, AR, AY0, SR, MR, MY0

 FUNCTION SIN12B and COS12B routines calculate SINE and COS values on
          12 bit data using COS64, COS6_64, and SIN6_64 tables.
          The algorithms used for these routines are:
          SIN(A+B) = SINA * COSB + COSA * SINB
          COS (A+B) = COSA * COSB - SINA*SINB                   }

SIN12B:             ay0 = 0x003f;
                ar = sr0 and ay0;
                sr = lshift sr0 by -6 (lo);



                                              Rev 4.0   09/30/98                              41
ADMC330 DSP Motor Controller                                                    Appendix A
Developer’s Reference Manual

                 ar = sr0 and ay0, sr1 = ar;          {now AR = AA: SR1 = BB}
                 ay0 = COS64;
                 ar = ar + ay0;
                 i5 = ar;
                 ay0 = ^COS6_64;
                 ar = sr1 + ay0, sr0 = pm(i5,m5);{SR0=COS64(AA)}
                 mr0 = pm(i5,m5);                {MR0=COS64(AA2)}
                 i4 = ar;
                 my0 = pm(i4,m4);                     {MY0=COS6_64(BB)}
                 mr = mr0 * my0 (ss), my0 = pm(i4,m4);
                 mr = mr + sr0 * my0 (rnd);           {MY0=SIN6_64(BB)}
                 rts;

COS12B:      ay0 = 0x003f;
                ar = sr0 and ay0;
                sr = lshift sr0 by -6 (lo);
                ar = sr0 and ay0, sr1 = ar;         {now AR=AA: SR1=BB}
                ay0 = COS64;
                ar = ar + ay0;
                i5 = ar;
                ay0 = ^COS6_64;
                ar = sr1 + ay0, mr0 = pm(i5,m5);    {MR0=COS64(AA)}
                sr0 = pm(i5,m5);                    {SR0=COS64(AA2)}
                i4 = ar;
                my0 = pm(i4,m4);                    {MY0=COS6_64(BB)}
                mr = mr0 * my0 (ss), my0 = pm(i4,m4);
                mr = mr - sr0 * my0 (rnd);          {MY0=SIN6_64(BB)}
                rts;


A.3 CAL_INV_TAN
{ INPUT      AY0 = 12 Bit Input X

 OUTPUT      SR0 = Result

 DESTROYED          AY1, AX0, AX1, SR

 CALLS       APPROX_N_ST

 FUNCTION Calculate inverse tangent of input value to 12 bits
             SR0 = ARCTAN (X) (from 0 - 2047)                      }

CAL_INV_TAN:                ay1 = ay0;
                          ax0 = 0x000c;
                          ax1 = ^ATN64;
                         call APPROX_N_ST;
                          sr = lshift ar by -4 (lo);    {ATN(X/Y)=[0..2047]}
                          rts;




A.4 LOG1
{ INPUT      MR0, MR1 = 31 Bit Input


42                                           Rev 4.0 09/30/98
Appendix A                                                           ADMC330 DSP Motor Controller
                                                                       Developer’s Reference Manual


 OUTPUT      AR = LOG(X), MX1 = Exponent of X

 DESTROYED         AR, AX1, AY0, SR, SE

 CALLS       APPROX10_ST

 FUNCTION Calculate the LOG base 10 of 31 bit input.
          LOG(MR1 MR0) = [(30+MX1) + (AR/32767)] * LOG(2)
          LOG table contains LOG values from LOG(1) to LOG(2) in
          64 steps divided by LOG(2) so value is from 0 - 32767.         }

LOG1:              se = exp mr1 (hi);
                         se = exp mr0 (lo);
                        mx1 = se;                        {R}
                         sr = norm mr1 (hi);
                         sr = sr or norm mr0 (lo);
                         sr = lshift sr1 by -4 (lo);
                         ay0 = 0x03ff;
                         ar = sr0 and ay0;
                         sr1 = ar;                       {I}
                         ax1 = ^LOG64;
                         call APPROX10_ST;               {AR=LOG(X):MX1=Exp of X}
                         rts;


A.5 ALOG1
{ INPUT      AR = X, MY0 = Y of X^Y, Y < 1

 OUTPUT      AR = ALOG (X)

 DESTROYED         AR, AX1, AY0, SR, MR

 CALLS       APPROX10_ST

 FUNCTION Calculate X^Y for Y < 1                        }

ALOG1:                    mr = ar * my0 (rnd);
                        sr = lshift mr1 by -5 (hi);
                        ax1 = ^ALOG64;
                        call APPROX10_ST;
                        ay0 = 0x8000;
                        ar = ar + ay0;                   {AR=ALOG(X)}
                        rts;




                                           Rev 4.0     09/30/98                                 43
ADMC330 DSP Motor Controller                                                      Appendix A
Developer’s Reference Manual


A.6 SQRT1
{ INPUT      MR0, MR1 = 31 Bit Input

 OUTPUT      SR0 = Result

 DESTROYED          AR, AY0, SR, SE, MR, MX1, MY0

 CALLS       LOG1, ALOG1

 FUNCTION Calculate square root of 31 bit input                  }


SQRT1:                      call LOG1;
                          my0 = 0x4000;
                          call ALOG1;
                          mr1 = ar;                      {MR1=ALOG(X)}
                          ay0 = mx1;                     {R-1}
                          ar = ay0 + 1;
                          sr = ashift ar by -1 (lo);     {R2=R/2}
                          se = sr0;
                          ay0 = 0x0001;
                          ar = ar and ay0;               {R3=R MOD 2}
                          my0 = 0x5a81;                  {KX2=.707106 * 0x7FFF}
                          if eq mr = mr1 * my0 (uu);     {IF R3=1 THEN Y=Y*KX2}
                          sr = lshift mr1 (lo);          {Y=Y * 2^R2}
                          rts;                           {SR0=SQRT(MR1_MR0)}


A.7 DIVIDE
{ INPUT      AY0 = Numerator LSB, SR1 = Numerator MSB, AX0 = Denominator

 OUTPUT      AY0 = Quotient

 DESTROYED          AF, SR1, CNTR, AX0, ASTAT

 FUNCTION Unsigned Division               }

DIVIDE:              af = pass sr1;
                           astat = 0x0000;
                           cntr = 0x0010;
                           do DIV until ce;
DIV:                divq ax0;
                           rts;                   {QUOTIENT=AY0}

A.8 X_Y_TO_ANG
{ INPUT      AX0 = SIN(ANGLE), AX1 = COS(ANGLE)
             AX0 and AX1 values from 0 - 0xFFFF

 OUTPUT      AR = ANGLE (in counts from 0 - 0x4000)

 DESTROYED          AR, AF, AX0, AX1, AY0, AY1, SR, MR, MX0, MX1, MY0, MY1,




44                                            Rev 4.0 09/30/98
Appendix A                                                          ADMC330 DSP Motor Controller
                                                                      Developer’s Reference Manual

 CALLS       DIVIDE, CAL_INV_TAN

 FUNCTION Convert from Cartesian to Polar coordinates
          X = COS(ANGLE), Y = SIN(ANGLE)
          ANGLE = ARCTAN (Y / X)                             }

X_Y_TO_ANG:                ar = abs ax0, mx1 = ax0;
                        ay1 = ar;
                         ar = abs ax1, my1 = ax1;
                         af = ar - ay1;
                         if ac jump COS_GREATER;
                         my0 = 0x1000;
                         mr = ar * my0 (uu);
                         ay0 = mr0;                   {LSB_NUMERATOR=MR0}
                        sr1 = mr1;                    {MSB_NUMERATOR=MR1}
                         ax0 = ay1;                   {DENOMINATOR=AY1}
                         call DIVIDE;
                         call CAL_INV_TAN;
                         ay0 = 0x1000;
                         ar = ay0 - sr0;
                         ay1 = ar;                    {AY1=ANGLE(45..90)}
                         jump ESTIM_COORD;
COS_GREATER:       mx0 = 0x1000;                      {4096.}
                         my0 = ay1;
                         mr = mx0 * my0 (uu);
                         ay0 = mr0;                   {LSB_NUMERATOR=MR0}
                         sr1 = mr1;                   {MSB_NUMERATOR=MR1}
                         ax0 = ar;                    {DENOMINATOR=AR}
                         call DIVIDE;
                         call CAL_INV_TAN;            {SR0=ANGLE(0..45)}
                         ay1 = sr0;
ESTIM_COORD:       ax0 = mx1;                         {MX1=SIN(ANGLE)}
                         ax1 = my1;                   {MY1=COS(ANGLE)}
                         ar = pass ax0;
                         if lt jump STEP1;
                         ar = pass ax1;
                         if le jump STEP2;
                         mr0 = 0x0000;                {0}
                         jump CARRY_ON_AD;
STEP2:                     mr0 = 0x2000;              {FOR+0x90 => (180 - 0)}
                         jump CARRY_ON_SB;
STEP1:                     ar = pass ax1;
                         if lt jump STEP3;
                         mr0 = 0x4000;                {FOR+0x270 => (360 - 0)}
                         jump CARRY_ON_SB;
STEP3:                     mr0 = 0x2000;              {FOR+0x180 => (180 + 0)}
CARRY_ON_AD:       ar = mr0 + ay1;                    {AY1=ANGLE(0..90)}
                         rts;                         {ANGLE+AR}
CARRY_ON_SB:       ar = mr0 - ay1;
                         rts;                         {ANGLE=AR}


A.9 APPROX10_ST
{ INPUT      SR1 = 10 Bit Data Input (0x0000 - 0x03FF)



                                        Rev 4.0   09/30/98                                     45
ADMC330 DSP Motor Controller                                                          Appendix A
Developer’s Reference Manual

             AX1 = 16 Bit Pointer to Start of 6 Bit Data Table

 OUTPUT      AR = Result

 DESTROYED          I4, M4, L4, AR, AX0, AY0, AY1, SR, MR, MY0

 FUNCTION Calculate approximation using straight line approximation method.
          Calculates approximation on 10 bit input in SR1 using 6 bit table pointed
              to by AX1.                                                   }

APPROX10_ST:                l4 = 0x0000;
                          m4 = 0x0001;                    {AX1=^DATA_BASE}
APPROX10:           ay0 = 0x000f;                  {valid for (X2-X1) < 0x7FF}
                         ar = sr1 and ay0, ay1 = ax1; {B}
                          sr = lshift sr1 by -4 (lo);     {A}
                          ar = sr0 + ay1, my0 = ar;
                          i4 = ar;
                          ay0 = pm(i4,m4);                {X1}
                          ax0 = pm(i4,m4);                {X2}
                          ar = ax0 - ay0;                 {X2-X1}
                          sr = ashift ar by 0x0fe (lo); {SHIFT 2 BITS}
                          mr = sr0 * my0 (su);            {X3}
                          sr = ashift mr0 by 0x0fd (lo); {SHIFT n-1 Bits}
                          ar = sr0 + ay0;                 {Y=X1+X3}
                         rts;


A.10 APPROX_N_ST
{ INPUT      AX0 = N (Number of Bits)
               AY1 = N Bit Data Input
             AX1 = 16 Bit Pointer to Start of 6 Bit Data Table

 OUTPUT      AR = Result

 DESTROYED          I4, M4, L4, AR, AX0, AY0, AY1, SR, SE, MR, MY0

 FUNCTION Calculate approximation using straight line approximation method.
          Calculates approximation on N bit input in SR1 using 6 bit table pointed
              to by AX1.                                                   }

APPROX_N_ST:               l4 = 0x0000;
                         m4 = 0x0001;                  {AX1=^DATA_BASE}
                    ay0 = 0x0006;
                         ar = ax0 - ay0;
                         ar = - ar, se = ar;
                         sr0 = 0xffff;
                         sr = lshift sr0 (lo);         {SR1=(2^n)-1}
                         ar = sr1 and ay1, se = ar;
                         my0 = ar;                     {B}
                         ar = pass ay1, ay0 = ax1;
                         sr = lshift ar (lo);               {A}
                        ar = sr0 + ay0, ay0 = se;
                        i4 = ar;
                        ar = ay0 - 1, ay0 = pm(i4,m4); {X1}



46                                         Rev 4.0 09/30/98
Appendix A                                               ADMC330 DSP Motor Controller
                                                           Developer’s Reference Manual

             ax0 = pm(i4,m4);                {X2}
             ar = ax0 - ay0, se = ar;        {X2-X1}
             mr = ar * my0 (su);             {X3}
             sr = ashift mr1 (hi);
             sr = sr or lshift mr0 (lo);
             ar = sr0 + ay0;                 {Y=X1+X3}
             rts;




                                Rev 4.0    09/30/98                                 47
ADMC330 DSP Motor Controller                                                             Appendix B
Developer’s Reference Manual


Appendix B System Specification File

.SYSTEM ADMC330;

{ For the ADMC330 the following line must be ADSP2101 when you run the
 System Builder. Then you must edit the .ACH file that is generated
 and change the target to ADSP2171. The System Builder won't take a
 target of ADSP2171 in this case because for the ADMC330 data RAM has
 been modified to start at location 0x3800 instead of 0x3000 as for the
 the basic 2171 core. }

.ADSP2101;
.MMAP0;

.SEG/ROM/BOOT=0              BOOT_PAGE_0[2048];

{ User Program Memory Area }
.SEG/PM/RAM/ABS=H#30/CODE/DATA USER_PM1[1600];
.SEG/PM/RAM/ABS=H#670/CODE/DATA USER_PM2[177];                { if using debugger, don't put DO
LOOPs here }

.SEG/PM/RAM/ABS=H#721/CODE/DATA RES_PM[223];                { if using debugger, don't put ANY code
here }

{ Rom Code Program Memory Area }
.SEG/PM/ROM/ABS=H#800/CODE ROMCODE[2048];

{ User Data Memory Area }
.SEG/DM/RAM/ABS=H#3800/DATA            USER_DM[911];
.SEG/DM/RAM/ABS=H#3B8F/DATA            RES_DM[1];    { if using debugger, don't put ANY data here
}
.SEG/DM/RAM/ABS=H#3B90/DATA            ROMDATA[112];

.ENDSYS;




48                                       Rev 4.0 09/30/98
Appendix C                                                  ADMC330 DSP Motor Controller
                                                              Developer’s Reference Manual


Appendix C Architecture Description File

     $ADMC330
     $ADSP2171
     $MMAP0
     $0000 07FF     bomBOOT_PAGE_0 t
     $0030 066F     paxUSER_PM1 t
     $0670 0720     paxUSER_PM2 t
     $0721 07FF     paxRES_PM t
     $0800 0FFF     pomROMCODE t
     $3800 3B8E     dadUSER_DM t
     $3B8F 3B8F     dadRES_DM t
     $3B90 3BFF     dadROMDATA t
     $




                                       Rev 4.0   09/30/98                              49
ADMC330 DSP Motor Controller                                                Appendix D
Developer’s Reference Manual


Appendix D ADMC330 Include File (ADMC330.H)
     #ifndef ADMC330
     #define ADMC330
     {
       This include file defines important ADMC330 addresses. The names
       defined below can be used in user programs by "including" this
     file.
       This file defines:
         - names for the peripheral registers of the ADMC330
         - names for the memory mapped core registers of the ADMC330
         - interrupt vector table addresses
         - addresses of ROM utilities that can be called from user
     programs
     }

     { peripheral registers of the ADMC330 }

     .CONST    ADC1        =   0x2000;         {Four ADC registers}
     .CONST    ADC2        =   0x2001;
     .CONST    ADC3        =   0x2002;
     .CONST    ADCAUX      =   0x2003;

     .CONST    PIODIR      =   0x2004;         {PIO   direction register}
     .CONST    PIODATA     =   0x2005;         {PIO   data register}
     .CONST    PIOINTEN    =   0x2006;         {PIO   interrupt enable}
     .CONST    PIOFLAG     =   0x2007;         {PIO   interrupt status}

     .CONST    PWMTM       =   0x2008;         {PWM   timer register}
     .CONST    PWMDT       =   0x2009;         {PWM   dead time register}
     .CONST    PWMPD       =   0x200A;         {PWM   pulse deletion}
     .CONST    PWMGATE     =   0x200B;         {PWM   gate register}
     .CONST    PWMCHA      =   0x200C;         {PWM   channel A register}
     .CONST    PWMCHB      =   0x200D;         {PWM   channel B register}
     .CONST    PWMCHC      =   0x200E;         {PWM   channel C register}
     .CONST    PWMSEG      =   0x200F;         {PWM   segment selection}

     .CONST    AUX0        =   0x2010;        {Auxiliary PWM timer 0}
     .CONST    AUX1        =   0x2011;        {Auxiliary PWM timer 1}

     .CONST    MODECTRL    =   0x2015;          {MODE control register}
     .CONST    SYSSTAT     =   0x2016;          {System status register}
     .CONST    IRQFLAG     =   0x2017;        {Interrupt status register}
     .CONST    WDTIMER     =   0x2018;        {Watchdog timer register}

     { memory mapped core registers of the ADMC330 }

     .CONST    SYSCNTL          =  0x3fff;
     .CONST    MEMWAIT          =  0x3ffe;
     .CONST    TPERIOD              =   0x3ffd;
     .CONST    TCOUNT               =   0x3ffc;
     .CONST    TSCALE               =   0x3ffb;
     .CONST    Sport0_Rx_Words1     =   0x3ffa;
     .CONST    Sport0_Rx_Words0     =   0x3ff9;
     .CONST    Sport0_Tx_Words1     =   0x3ff8;
     .CONST    Sport0_Tx_Words0     =   0x3ff7;
     .CONST    Sport0_Ctrl_Reg      =   0x3ff6;
     .CONST    Sport0_Sclkdiv       =   0x3ff5;
     .CONST    Sport0_Rfsdiv        =   0x3ff4;
     .CONST    Sport0_Autobuf_Ctrl =    0x3ff3;
     .CONST    Sport1_Ctrl_Reg      =   0x3ff2;


50                                 Rev 4.0 09/30/98
Appendix D                                                   ADMC330 DSP Motor Controller
                                                               Developer’s Reference Manual

     .CONST   Sport1_Sclkdiv            =    0x3ff1;
     .CONST   Sport1_Rfsdiv             =    0x3ff0;
     .CONST   Sport1_Autobuf_Ctrl       =    0x3fef;

     { interrupt vector table addresses for ADMC330 }

     .CONST PWMTRIP_INT_ADDR        = 0x2C;            {PWMTRIP interrupt}
     .CONST PDOWN_INT_ADDR          = 0x2C;                 {Powerdown, note same as
     PWMTRIP}
     .CONST PWMSYNC_INT_ADDR        =   0x0C;          {PWMSYNC interrupt}
     .CONST PIO_INT_ADDR            =   0x08;          {PIO interrupt}
     .CONST TX0_INT_ADDR            =   0x10;          {SPORT0 transmit interrupt}
     .CONST RX0_INT_ADDR            =   0x14;          {SPORT0 receive interrupt}
     .CONST SW1_INT_ADDR            =   0x18;               {software interrupt 1}
     .CONST SW0_INT_ADDR            =   0x1C;               {software interrupt 0}
     .CONST TX1_INT_ADDR            =   0x20;          {SPORT1 transmit interrupt}
     .CONST RX1_INT_ADDR            =   0x24;          {SPORT1 receive interrupt}
     .CONST TIMER_INT_ADDR          =   0x28;          {Timer interrupt}


     #endif




                               Rev 4.0      09/30/98                                    51
ADMC330 DSP Motor Controller                                                  Appendix E
Developer’s Reference Manual


Appendix E ROM Utility Include File (ROMUtil.h)

#ifndef ROMUTIL_INCLUDE
#ifdef ROMUTIL_INCLUDE

{ start addresses of ROM utilities }

.CONST PUT_VECTOR                 =   0x0B73;     {int vector table set up}
.CONST SIN12B                     =   0x0DC4;          {sine function}
.CONST COS12B                     =   0x0DD3;          {cosine function}
.CONST CAL_INV_TAN                =   0x0E61;          {inverse tangent function}
.CONST LOG1                       =   0x0E14;          {log base 10 function}
.CONST ALOG1                      =   0x0E20;          {inverse log base 10}
.CONST SQRT1                      =   0x0E27;          {square root}
.CONST DIVIDE                     =   0x0DE2;          {unsigned divide}
.CONST X_Y_TO_ANG                 =   0x0E35;          {cartesian to polar
conversion}
.CONST APPROX10_ST                = 0x0DEC;               {10 bit interpolation}
.CONST APPROX_N_ST                = 0x0DFF;               {N bit interpolation}

.CONST    COS64                   =   0x0B80;             {cosine table}
.CONST    COS6_64                 =   0x0C00;             {cosine table}
.CONST    SIN6_64                 =   0x0C40;             {sine table}
.CONST    ATN64                   =   0x0D01;             {tangent table}
.CONST    LOG64                   =   0x0D42;             {log base 10 table}
.CONST    ALOG64                  =   0x0D83;             {inverse log base 10 table}

{ Monitor Variables }

.CONST HALT_FLAG                  = 0x3B9A;       {used by exit library function}
.CONST IDE_SP                     = 0x745;        {used by exit library function}
.CONST IRQFLAG_SAVE               = 0x3BFE;       {IRQFLAG saved here each
interrupt}
.CONST SCOM2                = 0x944;         {used by peak/poke library function}

#endif




52                                     Rev 4.0 09/30/98
Appendix F                                                   ADMC330 DSP Motor Controller
                                                               Developer’s Reference Manual


Appendix F Constant Include File (Constant.h)
{This include file contains many useful constants. To use include the
file in the module where you want to use the constants. Then refer to
the constants by the names given below in your code.

AUTHOR:          Paul.Kettle@analog.com on

VERSION # 1.1 08/07/97
              Name      Date     Description
              ----     --------       -----------
MOD/HISTORY: Correction made to some constants P.Kettle 1/15/98

CALLED BY:
}

#ifndef CONSTANT_INCLUDE
#define CONSTANT_INCLUDE

.CONST    OnePiOverTwo      =         0x4000;   { Hex equivalent of 1pi/2         }
.CONST    OnePiOverFour     =         0x2000;   { Hex equivalent of 1pi/4         }
.CONST    OnePiOverTwelve =           0x0AAA;   { Hex equivalent of 1pi/12 }
.CONST    OnePiOverThree    =         0x2AAA;   { Hex equivalent of 1pi/3         }
.CONST    PiOverTwo         =         0x4000;   { Hex equivalent of      pi/2     }
.CONST    PiOverFour        =         0x2000;   { Hex equivalent of      pi/4     }
.CONST    PiOverTwelve      =         0x0AAA;   { Hex equivalent of      pi/12 }
.CONST    PiOverThree       =         0x2AAA;   { Hex equivalent of      pi/3     }
.CONST    TwoPiOverThree    =         0x5555;   { Hex equivalent of 2pi/3         }
.CONST    ThreePiOverThree =          0x7FFF;   { Hex equivalent of 3pi/3         }
.CONST    FourPiOverThree =           0xAAAA;   { Hex equivalent of 4pi/3         }
.CONST    FivePiOverThree =           0xD555;   { Hex equivalent of 5pi/3         }
.CONST    NOnePiOverThree =           0xD555;   { Hex equivalent of -1pi/3        }
.CONST    NTwoPiOverThree =           0xAAAA;   { Hex equivalent of -2pi/3        }
.CONST    HALF              =         0x4000;
.CONST    OnePiOverSix      =         0x1555;   { Hex equivalent of 1pi/6         }
.CONST    PiOverSix         =         0x1555;   { Hex equivalent of      pi/6     }
.CONST    TwoPiOverSix      =         0x2AAA;   { Hex equivalent of 2pi/6         }
.CONST    ThreePiOverSix    =         0x4000;   { Hex equivalent of 3pi/6         }
.CONST    FourPiOverSix     =         0x5555;   { Hex equivalent of 4pi/6         }
.CONST    FivePiOverSix     =         0x6AAA;   { Hex equivalent of 5pi/6         }
.CONST    SixPiOverSix      =         0x7FFF;   { Hex equivalent of 6pi/6         }
.CONST    SevenPiOverSix    =         0x9555;   { Hex equivalent of 7pi/6         }
.CONST    EightPiOverSix    =         0xAAAA;   { Hex equivalent of 8pi/6         }
.CONST    NinePiOverSix     =         0xC000;   { Hex equivalent of 9pi/6         }
.CONST    TenPiOverSix      =         0xD555;   { Hex equivalent of 10pi/6        }
.CONST    ElevenPiOverSix =           0xEAAA;   { Hex equivalent of 11pi/6        }
.CONST    TwelvePiOverSix =           0xFFFF;   { Hex equivalent of 12pi/6        }
.CONST    Pi                =         0x7FFF;   { Hex equivalent of      pi       }
.CONST    NPi               =         0x8000;   { Hex equivalent of -pi           }
.CONST    Zero              =         0x0;
.CONST    NULL              =         0x0;
.CONST    TwoPiOverTwelve =           2*PiOverTwelve;     { Hex equivalent of 2pi/12}
.CONST    ThreePiOverTwelve =         3*PiOverTwelve; { Hex equivalent of 3pi/12}
.CONST    FourPiOverTwelve =          4*PiOverTwelve;     { Hex equivalent of 4pi/12}
.CONST    FivePiOverTwelve =          5*PiOverTwelve;     { Hex equivalent of 5pi/12}
.CONST    SixPiOverTwelve =           6*PiOverTwelve;     { Hex equivalent of 6pi/12}
.CONST    SevenPiOverTwelve =         7*PiOverTwelve;     { Hex equivalent of 7pi/12}
.CONST    EightPiOverTwelve =         8*PiOverTwelve;     { Hex equivalent of 8pi/12}
.CONST    NinePiOverTwelve =          9*PiOverTwelve;     { Hex equivalent of 9pi/12}
.CONST    TenPiOverTwelve =           10*PiOverTwelve;    { Hex equivalent of 10pi/12}
.CONST    ElevenPiOverTwelve =        11*PiOverTwelve;    { Hex equivalent of 11pi/12}



                                       Rev 4.0   09/30/98                               53
ADMC330 DSP Motor Controller                                                      Appendix F
Developer’s Reference Manual

.CONST   TwelvePiOverTwelve =    12*PiOverTwelve;     {   Hex   equivalent   of   12pi/12}
.CONST   ThirteenPiOverTwelve    = 13*PiOverTwelve;   {   Hex   equivalent   of   13pi/12}
.CONST   FourteenPiOverTwelve    = 14*PiOverTwelve;   {   Hex   equivalent   of   14pi/12}
.CONST   FifteenPiOverTwelve =   15*PiOverTwelve;     {   Hex   equivalent   of   15pi/12}
.CONST   SixteenPiOverTwelve =   16*PiOverTwelve;     {   Hex   equivalent   of   16pi/12}
.CONST   SeventeenPiOverTwelve   = 17*PiOverTwelve;   {   Hex   equivalent   of   17pi/12}
.CONST   EighteenPiOverTwelve    = 18*PiOverTwelve;   {   Hex   equivalent   of   18pi/12}
.CONST   NineteenPiOverTwelve    = 19*PiOverTwelve;   {   Hex   equivalent   of   19pi/12}

#endif




54                                Rev 4.0 09/30/98
Appendix G                                                    ADMC330 DSP Motor Controller
                                                                Developer’s Reference Manual


Appendix G Macro Include File (Macro.h)

{This include contains useful macros.

AUTHOR:            Paul.Kettle@analog.com on

VERSION # 1.0 08/07/97
          Name      Date                     Description
          ----     --------                  -----------
MOD/HISTORY: none                                 }

#ifndef MACRO_INCLUDE
#define MACRO_INCLUDE

.MACRO Write_dm(%0,%1);
          ar=%1;
          dm(%0)=ar;
.ENDMACRO;


.MACRO Copy_dm(%0,%1);
          ar=dm(%0);
          dm(%1)=ar;
.ENDMACRO;


.MACRO    SetVect(%0,%1);
          I4 = %0;
          MR0 =^%1;
          CALL PUT_VECTOR;
.ENDMACRO;


.MACRO    Sin(%0);
          PUSH STS;
          DIS M_MODE, DIS AR_SAT;
          ax0 =%0;
          M5 = 1;
          L5 = 0;
          call ADMC_SIN;
          POP STS;
.ENDMACRO;


.MACRO    Cos(%0);
          PUSH STS;
          DIS M_MODE, DIS AR_SAT;
          ax0 =%0;
          M5 = 1;
          L5 = 0;
          call ADMC_COS;
          POP STS;
.ENDMACRO;


.MACRO PWM_DAC(%0,%1);
          ar=%0;
          sr = LSHIFT ar BY -8 (LO);                {Value to be written in ar }
          ay0=0x80;                                 {Shift to 8 LSBs and add   }



                                        Rev 4.0   09/30/98                               55
ADMC330 DSP Motor Controller                                        Appendix G
Developer’s Reference Manual

          ar=sr0+ay0;                     {offset of 0x80 = 2.5V     }
          ay0= 0xff;
          ar = ar AND ay0;
          DM(%1) = ar;                    {Write value to PWMTIM0    }
.ENDMACRO;

#endif




56                             Rev 4.0 09/30/98
Appendix H                                                                 ADMC330 DSP Motor Controller
                                                                             Developer’s Reference Manual


Appendix H SROM/EEPROM Boot Loader Protocol
The boot loader uses a two-wire (data and clock) serial protocol in which the ADMC330 provides a clock
to the device equal to 1/20 of CLKOUT.

On the ADMC330 evaluation board the device socket (U3) is connected as follows:

                   PIN #     SROM/EEPROM pin                     Connected to
                     1            DATA                     DR1A pin on ADMC330
                     2             CLK                     SCLK1 pin on ADMC330
                     3            RESET /OE             PIO bit 0 (P0 pin on ADMC330)
                      4              CE                              GND
                      5             GND                              GND
                      6             CEO                             Floating
                      7          VPP/SER_EN                        VCC (+5V)
                      8             VCC                            VCC (+5V)
                              Table 5. SROM / EEPROM Pin Connections
The ROM monitor program resets the DR1SEL bit of the MODECTRL register (see Reference 1) to
connect the DR1A pin (the device’s data line) to the DR1 input of SPORT1. It then sets the UARTEN bit
which connects the DR1 and RFS1 inputs together so that the first word in the input data will act as the
receive frame synch. SPORT1 is then configured for synchronous communications as follows:

         SPORT1 control register = 0x5E07
               • internal serial clock (SCLK) used
               • external receive frame synch (RFS) enabled
               • RFS required on 1st word only
               • active high RFS
               • alternate receive framing used
               • right justify, zero-fill unused MSBs
               • serial word length is 8 bits

         SPORT1 SCLKDIV register = 9 (1MHz SCLK freq. @ 20MHz DSP CLKOUT)

PIO bit 0 is then set causing data to be clocked from the device in a continuous stream. When the SPORT
receives the RFS (the leading edge of the first header byte 0xFF) it starts clocking in a continuous stream of
bits. When each byte is accumulated, an interrupt is generated and the byte is loaded by the DSP. The DSP
can start taking in data immediately, however, it will wait up to 2400 cycles (120us @ 20MHz) to receive
the first header byte. This allows for different startup times if a different device is being used to download
the data. The data receive line must be held low until the first header byte is received. The format of the
data expected by the boot loader is given in Table 6. The MAKEPROM utility, described in section 7,
automatically converts a user’s executable file into a PROM programmer file having the format given in
Table 6. The boot load timing from reset (PIO0) is summarized in Figure 9.

The program memory is loaded starting at 0x0030 and can go up to 0x07FF. The program memory header
portion of the boot load file contains the number of program memory locations to load divided by 8. For
example, to load the entire memory from 0x0030 - 0x07FF, a value of 250 is programmed. The monitor
always limits this value to between 1 and 250 to protect against accessing invalid memory locations.
Similarly, the data memory header contains the number of data memory locations to load divided by 4. The
monitor limits this value to 1 - 224 so the total amount of data memory that can be boot loaded is 896
locations, or from 0x3800 - 0x3B7F.




                                             Rev 4.0   09/30/98                                            57
ADMC330 DSP Motor Controller                                                                           Appendix H
Developer’s Reference Manual

Both the program and data memory portions of the boot load file contain checksums that are used by the
monitor to verify correct loading operation. The PM checksum is calculated by the monitor by
accumulating, in the MR0 register, the upper 16 bits of each PM location received. The lower 8 bits are
accumulated in the MR1 register. When all locations have been received, the MR1 register is masked with
0xFF, removing any overflow out of the 8 bits. The MR0 register is then compared to the upper 16 bits of
the received checksum and the MR1 register is compared to the lower 8 bits of the received checksum. The
DM checksum is calculated in the same way as the upper 16 bits of the PM checksum.

If the monitor detects a header or checksum miscompare, or times out when it tries to boot load, it will
switch over to debug mode and try to communicate over the UART debugger interface.




                                             ...                                                         ...
          SCLK
          (1MHz @ 20MHz DSP CLK)




                                     32 us                8 us              8 us                8 us
          PI O 0
          (Reset from ADM C 330)


                                              RFS
                                                                                                           ...
        D R 1/RFS1
        (Data from device)
                                   4 ZEROs                0xFF             0xA A                0x33       PM
                                                                                                         length

                                                                 Program Memory Header Record




                             Figure 9. Boot Load Timing (XC1765D or AT17C65)




58                                                  Rev 4.0 09/30/98
Appendix H                                                        ADMC330 DSP Motor Controller
                                                                    Developer’s Reference Manual


                     BYTE                                            Description
                        0                        0x00 (Can be from 0 - 14 zero bytes
                        1                        0x00 MAKEPROM utility inserts 4 for
                        2                        0x00 XC1765D or AT17C65)
                        3                        0x00
                        4                        0xFF Header Word 1
                        5                        0xAA Header Word 2
                        6                        0x33 Header Word 3
                        7                        # Program Memory Locations / 8
                        8                        User Program 1st Location (Upper Byte)
                        9                        User Program 1st Location (Middle Byte)
                       10                        User Program 1st Location (Lower Byte)
                        .                                                 .
                        .                                                 .
                        .                                                 .
                  #PM * 3 + 8                    PM Checksum (Upper Byte)
                  #PM * 3 + 9                    PM Checksum (Middle Byte)
                 #PM * 3 + 10                    PM Checksum (Lower Byte)
                 #PM * 3 + 11                    0x00 (Can be from 0 - 14 zero bytes
                 #PM * 3 + 12                    0x00 MAKEPROM utility inserts 4 for
                 #PM * 3 + 13                    0x00 XC1765D or AT17C65)
                 #PM * 3 + 14                    0x00
                 #PM * 3 + 15                    0xFF Header Word 1
                 #PM * 3 + 16                    0xAA Header Word 2
                 #PM * 3 + 17                    0x33 Header Word 3
                 #PM * 3 + 18                    # Data Memory Locations / 4
                 #PM * 3 + 19                    User Data 1st Location (Upper Byte)
                 #PM * 3 + 20                    User Data 1st Location (Lower Byte)
                        .                                                 .
                        .                                                 .
                        .                                                 .
             #PM * 3 + #DM * 2 + 19              DM Checksum (Upper Byte)
             #PM * 3 + #DM * 2 + 20              DM Checksum (Lower Byte)
                                 Table 6. Boot Load File Format




                                       Rev 4.0   09/30/98                                    59
ADMC330 DSP Motor Controller                                                                          Appendix H
Developer’s Reference Manual


Appendix I UART Debugger Protocol
If a boot load fails, the monitor activates debug mode. In this mode the DR1B pin is connected to the DR1
input (MODECTRL DR1SEL bit) and RFS1 is connected to DR1 (MODECTRL UARTEN bit). To
communicate in this mode an external device need only connect its transmit data line to DR1B and its
receive data line to DT1. SPORT1 is configured as follows:

         SPORT1 control register = 0x5E4F
               • internal serial clock (SCLK) used
               • external receive frame synch (RFS) enabled
               • RFS required on 1st word only
               • active low RFS (start bit acts as RFS)
               • alternate receive framing used
               • right justify, zero-fill unused MSBs
               • serial word length is 16 bits

         SPORT1 SCLKDIV register = 347 (~ 28.8KHz SCLK freq. @ 20MHz DSP CLKOUT)

In this mode each byte is represented by 11 bits (1 start bit, 8 data bits, and 2 stop bits) as shown in Figure
10. The default baud rate is 9600 bps. Since the incoming data is sampled at three times the baud rate each
bit is represented by 3 bits in the received data. Thus each 11 bit word transmitted to the ADMC330 at
9600 baud is received as a 33 bit word (actually the last stop bit is dropped to make 32 bits). In the
ADMC330 the 32 bits are received as two 16 bit serial word transfers. Words are transmitted and received
LSB first. The ADMC330 monitor extracts the byte of information from the 32 bits of received data.




                           Start                                                            Stop
                                     L SB                 Data Bits                M SB
                            Bit                                                             Bits
                              0          1   0      1       1    0     1     0      0     1      1

                             000    111      000    111    111   000   111   000   000    111   111



        D ata received by ADM C330
       (sampl ed at 3 times baud rate)




                                                   Figure 10. UART Protocol




60                                                        Rev 4.0 09/30/98
Appendix H                                                                ADMC330 DSP Motor Controller
                                                                            Developer’s Reference Manual

Debug Mode Commands
The following commands are available when in debug mode:

         •   data memory write
         •   data memory read
         •   16 bit program memory write
         •   16 bit program memory read
         •   24 bit program memory write
         •   24 bit program memory read

Not only can these commands be used to read and write to the ADMC330 memories, the data memory write
command can also be used to modify any memory-mapped registers. In addition, it can be used to set
variables in the monitor to start the execution of user code (see Starting User Code).

Each of the commands consist of a unique 8 byte sequence that is sent to the ADMC330. For each byte that
is received, the ADMC330 will transmit a corresponding response byte. The external device has the option
of reading this known response as a means of synchronizing with the ADMC330. While not necessarily
required, this is highly recommended.

It is important to note that when the data memory write command is used to modify memory-mapped
registers, the register will be modified after the 7th byte of the command is received. The 8th byte is still
required to stay synchronized but this is its only purpose. In some cases it is advantageous to write only 7
bytes of the data memory write command to the ADMC330 and then re-synchronize with it after the register
modification takes place (see Synchronizing Communication). One such example is changing SPORT1’s
baud rate in the SCLKDIV register. If an 8 byte command were used the baud rate would actually change
while the 8th byte is being transferred, resulting in unpredictable behavior.

The ADMC330 monitor command syntax is given in Table 8 through Table 13. For each command byte 0
is the first byte sent over the interface. Bytes listed as “dummy bytes” can be any value as they are ignored
by the monitor; each byte that is sent will be echoed back verbatim.

                            Command Code                   Command
                                 0               Data memory write
                                 1               Data memory read
                                 2               16 bit program memory write
                                 3               16 bit program memory read
                                 4               24 bit program memory write
                                 5               24 bit program memory read
                          Table 7. Available Commands (Debugger Interface)


               BYTE                    Description                     Expected Response
                 0        0x00 (dummy byte)                           Byte 0 is echoed back
                 1        Lower Byte of DM Data Word                  Byte 1 is echoed back
                 2        Upper Byte of DM Data Word                  Byte 2 is echoed back
                 3        Lower Byte of DM Destination Address        Byte 3 is echoed back
                 4        Upper Byte of DM Destination Address        Byte 4 is echoed back
                 5        0x00 (Command code - from Table 7)          Byte 5 is echoed back
                 6        0x00 (dummy byte)                           0xAA
                 7        0x00 (dummy byte)                           0x55
                                Table 8. Data Memory Write Command




                                            Rev 4.0    09/30/98                                           61
ADMC330 DSP Motor Controller                                                             Appendix H
Developer’s Reference Manual


           BYTE                 Description                    Expected Response
             0     0x00 (dummy byte)                         Byte 0 is echoed back
             1     0x00 (dummy byte)                         Byte 1 is echoed back
             2     0x00 (dummy byte)                         Byte 2 is echoed back
             3     Lower Byte of DM Address                  Byte 3 is echoed back
             4     Upper Byte of DM Address                  Byte 4 is echoed back
             5     0x01 (Command code - from Table 7)        Byte 5 is echoed back
             6     0x00 (dummy byte)                         Lower byte of DM word
             7     0x00 (dummy byte)                         Upper byte of DM word
                           Table 9. Data Memory Read Command


            BYTE                  Description                   Expected Response
              0      0x00 (dummy byte)                         Byte 0 is echoed back
              1      Middle Byte of PM Data Word               Byte 1 is echoed back
              2      Upper Byte of PM Data Word                Byte 2 is echoed back
              3      Lower Byte of PM Destination Address      Byte 3 is echoed back
              4      Upper Byte of PM Destination Address      Byte 4 is echoed back
              5      0x02 (Command code - from Table 7)        Byte 5 is echoed back
              6      0x00 (dummy byte)                         0xAA
              7      0x00 (dummy byte)                         0x55
                     Table 10. 16 Bit Program Memory Write Command



         BYTE                  Description                      Expected Response
           0      0x00 (dummy byte)                         Byte 0 is echoed back
           1      0x00 (dummy byte)                         Byte 1 is echoed back
           2      0x00 (dummy byte)                         Byte 2 is echoed back
           3      Lower Byte of PM Address                  Byte 3 is echoed back
           4      Upper Byte of PM Address                  Byte 4 is echoed back
           5      0x03 (Command code - from Table 7)        Byte 5 is echoed back
           6      0x00 (dummy byte)                         Lower byte of PM data word
           7      0x00 (dummy byte)                         Upper byte of PM data word
                     Table 11. 16 Bit Program Memory Read Command


            BYTE                  Description                   Expected Response
              0      Lower Byte of PM Data Word                byte 0 is echoed back
              1      Middle Byte of PM Data Word               byte 1 is echoed back
              2      Upper Byte of PM Data Word                byte 2 is echoed back
              3      Lower Byte of PM Destination Address      byte 3 is echoed back
              4      Upper Byte of PM Destination Address      byte 4 is echoed back
              5      0x04 (Command code - from Table 7)        byte 5 is echoed back
              6      0x00 (dummy byte)                         0xAA
              7      0x00 (dummy byte)                         0x55
                     Table 12. 24 Bit Program Memory Write Command


           BYTE                 Description                     Expected Response



62                                    Rev 4.0 09/30/98
Appendix H                                                               ADMC330 DSP Motor Controller
                                                                           Developer’s Reference Manual

                0      0x00 (dummy byte)                           byte 0 is echoed back
                1      0x00 (dummy byte)                           byte 1 is echoed back
                2      0x00 (dummy byte)                           byte 2 is echoed back
                3      Lower Byte of PM Address                    byte 3 is echoed back
                4      Upper Byte of PM Address                    byte 4 is echoed back
                5      0x05 (Command code - from Table 7)          Lower byte of PM word
                6      0x00 (dummy byte)                           Middle byte of PM word
                7      0x00 (dummy byte)                           Upper byte of PM word
                          Table 13. 24 Bit Program Memory Read Command
Starting User Code
A user program can be started on the ADMC330 by writing the program’s starting address to the
START_ADR variable and then writing the code 0xABCD to the EXECUTE_FLAG variable, both
contained in the monitor’s data memory. This can be done with two data memory write commands to the
addresses contained in Table 14. For example, Table 15 shows the two command sequence that an external
device would send to the ADMC330 to start a user program at 0x0030 in program memory. As can be
seen, the second data memory write is only a 7 byte command. This is because the ADMC330 actually
writes the value following the 7th byte thus causing the execution of the user program. There is no need to
send an 8th byte because it would never be received by the ADMC330.

      Variable            Address                             Description
    START_ADR             0x3BF8      START_ADR contains location where execution will begin
   EXECUTE_FLAG           0x3BFA      0xABCD written here causes execution to begin
                        Table 14. Monitor Variables for Executing User Code


               BYTE                    Description                    Expected Response
                 0       0x00                                        0x00
                 1       0x30                                        0x30
                 2       0x00                                        0x00
                 3       0xF8                                        0xF8
                 4       0x3B                                        0x3B
                 5       0x00                                        0x00
                 6       0x00                                        0xAA
                 7       0x00                                        0x55
                 0       0x00                                        0x00
                 1       0xCD                                        0xCD
                 2       0xAB                                        0xAB
                 3       0xFA                                        0xFA
                 4       0x3B                                        0x3B
                 5       0x00                                        0x00
                 6       0x00                                        0xAA
                     Table 15. DM Write Commands to Start Program at 0x0030


Synchronizing Communication
For the ADMC330 to properly handle incoming commands it must be synchronous with an external device.
In other words, it must know when it’s receiving the first word of a command. This step must be
performed prior to issuing the first of any commands in debug mode. The external device can synchronize
with the ADMC330 by using the monitor protocol given above and detecting when it receives the two byte
sequence 0xAA, 0x55 from the ADMC330. At this point both devices know that the next byte sent will be




                                           Rev 4.0    09/30/98                                          63
ADMC330 DSP Motor Controller                                                                  Appendix H
Developer’s Reference Manual

the first byte of a command. It is only necessary to synchronize once at the beginning of a series of debug
commands as long as 8 bytes are sent for each command.

The easiest way to perform the synchronization is to continually transmit a byte and receive its echo. When
the received echo of two subsequent bytes is 0xAA, 0x55, the synchronization is complete. The byte that is
continually sent to the ADMC330 for this purpose can be any byte except 0x00 - 0x05, 0xAA, or 0x55.




64                                          Rev 4.0 09/30/98

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:4
posted:8/14/2011
language:English
pages:64