Silicon ChipAtmel's ICE 200 In-Circuit Emulator - April 2000 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Internet companies an unknown quantity
  4. Review: Jamo Concert 8 Loudspeaker System by Louis Challis
  5. Feature: How To Run A 3-Phase Induction Motor From 240VAC by Peter Laughton
  6. Project: A Digital Tachometer For Your Car by John Clarke
  7. Project: RoomGuard: A Low-Cost Intruder Alarm by John Clarke
  8. Back Issues
  9. Project: Build A Hot Wire Cutter by Leo Simpson
  10. Order Form
  11. Feature: Atmel's ICE 200 In-Circuit Emulator by Peter Smith
  12. Product Showcase
  13. Project: The OzTrip Car Computer; Pt.2 by Robert Priestley
  14. Project: Build A Temperature Logger by Mark Roberts
  15. Review: Mitsubishi's Diamond View DV180 LCD Monitor by Peter Smith
  16. Book Store
  17. Market Centre
  18. Outer Back Cover

This is only a preview of the April 2000 issue of Silicon Chip.

You can view 33 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "A Digital Tachometer For Your Car":
  • PIC16F84(A)-04/P programmed for the Digital Tachometer [TACHO.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC16F84 firmware and source code for the Digital Tachometer [TACHO.HEX] (Software, Free)
  • Digital Tachometer PCB patterns (PDF download) [05104001/05104002] (Free)
  • Digital Tachometer panel artwork (PDF download) (Free)
Items relevant to "RoomGuard: A Low-Cost Intruder Alarm":
  • RoomGuard PCB pattern (PDF download) [03104001] (Free)
  • RoomGuard panel artwork (PDF download) (Free)
Articles in this series:
  • The OzTrip Car Computer; Pt.1 (March 2000)
  • The OzTrip Car Computer; Pt.1 (March 2000)
  • The OzTrip Car Computer; Pt.2 (April 2000)
  • The OzTrip Car Computer; Pt.2 (April 2000)
This photo shows the Atmel ICE 200 (at right) plugged into an STK200 development board. The development board is also available from Atmel. Atmel's ICE 200 in-circuit emulator What’s the best way to develop and debug microcontroller software? Answer – use an in-circuit emulator (ICE) that interfaces to a PC. An ICE offers all sorts of useful debugging tools and there’s no need to add water! By PETER SMITH The Y2K problem highlighted something that many of us weren’t previously fully aware of – just how many pieces of equipment contain embedded computer chips. With so much equipment now relying on computer control, if you’re involved in electronics then you will almost certainly be involved with embedded systems in some way. Most embedded designs are based on microcontrollers (MCUs). These devices integrate a microprocessor core with memory and input/output (I/O) ports, as well as a variety of other 54  Silicon Chip commonly used functions. Effectively, this means that what once would have occupied an entire PC board now fits in a single chip, consumes a fraction of the power and runs perhaps 10-100 times faster! Due to their ever-increasing memory size and speed, microcontrollers can now be programmed effectively using high-level languages such as C and BASIC. Of course, serious design calls for serious debugging tools and in this review we look at the ICE 200. This is an “entry-level” in-circuit emulator (ICE) for Atmel’s range of popular AVR Enhanced RISC microcontrollers and should also appeal to novices. Atmel AVR microcontrollers In my opinion, Atmel has a real winner with their AVR series of microcontrollers. Using a modified RISC (Reduced Instruction Set) architecture, the AVR series is specifically optimised for running complied C code. Other key features such as in-circuit programmable flash memory (up to 128KB), EEPROM data memory, high throughput (all instructions are single-cycle) and low power consumption make this series hard to beat. As is common with all micro­ controllers today, it includes functions like A-D converters, serial ports (UARTs), real time clocks (RTCs), pulse width modulation (PWM) outputs, 16-bit timers and brown-out detectors. Do I need an ICE? When a microcontroller program Fig.1: the major components of the ICE 200 in-circuit emulator. Connection to your PC is via a standard serial port. doesn’t work as expected, how do you find out why? One way is to debug the program with a software simulator. Simulators do just that – they simulate the operation of a microcontroller in PC-based software. Your compiled program runs just as it would on a real microcontroller, the advantage being that you have control over the execution of each line of code. Instructions can be executed line-by-line (called single stepping), or “breakpoints” can be inserted at desired points to halt a running program. In addition, resources such as registers, memory and I/O ports can be examined and modified at will. The major disadvantage of simulators is that they are isolated from the devices that a typical microcontroller-based system would interface with. For example, if a design includes a pulse width modulated (PWM) output to control servo motors, the best that you can do is view the PWM registers – a poor substitute for seeing actual servo movement. The answer to this dilemma is in-circuit emulation. This approach replaces the microcontroller chip with hardware that emulates its operation and at the same time allows the pro- grammer to “get inside” to see what’s happening. The Atmel ICE 200 kit includes both hardware and software components. Let’s take a look at the hardware first. ICE hardware The kit consists of several major hardware components (see Fig.1). A small PC board called a “pod” contains the actual emulation hardware – all in a single chip mounted on the Fig.2: the Project window keeps all related files and settings nicely organised. Source files can be edited, compiled and run directly from this window. Fig.3: doubleclicking on an error in the Project Output window takes you directly to the problem line in your source file. underside of the board. The pod plugs into the microcontroller socket on the system to be debugged via a so-called “personality” adapter. The ICE 200 supports 11 different microcontrollers from the AVR series, so adapters are required to convert the varying package types and pinouts to suit the pod. Note that the kit only includes personality adapters for dualin-line (DIL) microcontroller packages (8, 20, 28 & 40 pin). If your application uses surface mount packages, you will need to obtain suitable SMD-to-DIL adapters or purchase the Atmel SMD personality adapter kit. The pod automatically detects which micro it should emulate and configures itself internally, so there are no jumpers or switches to be set. A “tiny” exception to this rule is the ATtiny 12/13 microcontroller, which has special oscillator pin features. Two 0Ω resistors on the pod must be set accordingly – the user guide has the full details. The pod connects to the main ICE 200 board via two flexible cables. The main board measures just 70 x 90mm but Atmel has squeezed on the program memory, pod control and host PC communication logic, as well as a power supply. A standard DC socket accepts input power, which is regulated and filtered to 5V on the board. Note that although the ICE 200 starter kit documentation states that 9-12V DC or 9V AC can be applied, more up-to-date information on the Atmel web site recommends applying 9V DC only. Atmel has included a length of cable with a DC jack on one end for connection to a lab supply but a trusty April 2000  55 9V DC 500mA plugpack would probably be the preferred choice. Also of note is that as the pod draws power from the target board it is connected to, its supply voltage can be anywhere from 2.7V to 5.5V. On the other hand, the main board has a 5V supply, so level converters on the main board do the necessary logic level shifts. Finally, the ICE 200 kit includes a 9-pin serial cable (about two metres long) to connect the main board to your PC. ICE software A brilliant set of software tools called AVR Studio controls the whole show. AVR Studio runs on Windows 95, 98, NT 3.51 and NT 4.0 and is supplied on CD-ROM, along with a bunch of useful product guides and technical data sheets. Our kit also included a copy of AVR Studio on diskette but both it and the CD-ROM version were out of date as Atmel has just released version 3.00. We downloaded our copy from At­ mel’s website at www.atmel.com AVR Studio provides all you need to edit, compile and debug your code. A macro assembler is included in the package and an optional C compiler is also available. Third party compilers and assemblers can be plugged in too but if you want to debug at the source code level, they must be object file compatible. Fig.4: the first time an object file is loaded, AVR Studio detects the ICE 200 and displays this Configuration window. The first step towards a working program is to enter the source file. AVR Studio includes a project manager that helps you keep source files associated with a particular project together (see Fig.2). A handy assembler source file editor is included (see Fig.3) and this can be launched directly from the Project window. Source files in a project can be assembled/compiled with a single keystroke, with the results displayed in the Project Output window. If one or more errors occur during assembly, finding the problem line of code is a simple matter of double-clicking on the error and the line is immediately highlighted in the Source window (see Fig.3). Once you’re ready to debug the code, the output from the assembler/ compiler (called an object file) can be loaded manually from the File menu. Fig.5: a typical debugging session in AVR Studio. The real work begins here! 56  Silicon Chip Alternatively, the source file(s) can be assembled/compiled and the object file loaded in one step by selecting Build & Run from the Project menu. The first time an object file is loaded, AVR Studio automatically detects and configures the ICE 200 and a configuration window appears to confirm a few important settings (see Fig.4). If an in-circuit emulator can’t be detected, AVR Studio enters software simulation mode instead. After closing the configuration window, various debug windows can be opened from the menu bar in preparation for the actual emulation session. The emulation display Fig.5 shows what a typical emulation session might look like. Naturally, window positions and sizes can be set according to personal preference and the settings are saved between sessions. If you’re a newcomer to emulators the display in Fig.5 might look a little intimidating, so let’s talk briefly about the function of each window. The largest window, titled avr­910. asm, is the source window – it lists the program being debugged. The small arrow on the left sidebar indicates the next line to be executed. Right-clicking on any line allows you to set or clear a breakpoint at that position, or a bookmark can be placed for easy location at a later stage. Note the small brown squares – these indicate the positions of active breakpoints. Breakpoints can be cleared globally from the main menu bar. Labels (or symbols) are listed in the source window just as they appear in the original program. This information is retrieved from the assembly or object file. If a file without this information is loaded (eg, a hex file), AVR studio lists the program in disassembly mode. The Memory window displays the contents of program, data, EEPROM or I/O memory. A drop-down menu lets you select one of the four types. Memory contents can be edited directly in this window by double-clicking on the desired location and typing a new value. Multiple Memory windows can be open at the same time. The Registers window displays all 32 general-purpose microcontroller registers and like the memory window, these can be edited by double-clicking on the desired entry. The Watches window provides a convenient way of displaying all the memory locations that you would like monitor. Rightclick in this window to enter a new location in symbolic form. AVR Studio updates the “Value” column each time program execution stops. If you are debugging a C program, both simple and complex (eg, structures and arrays) data types can be displayed. Key emulation information is displayed in the Processor window. The Program Counter field displays the address of the next instruction to be executed, while the Cycle Counter field displays the total number of cycles since the last reset. The Stack Pointer, Flags and X, Y and Z Register fields are all self-explanatory. As you’ve probably guessed, the Frequency field displays the target’s clock speed. All values except time elapsed and frequency can be changed when the program isn’t running. The I/O window is used to examine and alter the various I/O registers. Multiple I/O windows can be opened at the same time. Executing the code Basically, these windows are our view “inside” the microcontroller. They display the current state of every resource within the chip, as well as giving us the ability to modify many of them. Just as importantly, AVR Studio allows complete control over program execution. Using buttons on the menu bar or shortcut keys, you can single-step the program (execute a single line at a time) or run until a breakpoint is encountered or you click on the Break button. You also have the option of executing a subroutine (function call) until it ends (Step Out) or skip a subroutine completely (Skip Over). Other versatile options allow execution of a defined number of instructions (Multi Step), or executing each instruction and pausing for a predefined period before going on to the next (Auto Step). Fig.6: on-line help that really helps! All help menus should work like this. Documentation Documentation is often the weak link in technical products but Atmel have excelled with their HTML-based on-line help system (see Fig.6). We found it to be comprehensive, well organised and easy to navigate. Wrap up We mentioned before that AVR Studio enters simulation mode if an emulator (in our case, the ICE 200) is not detected. Simulation control and display is deliberately very similar to emulation, so much of the previous description still applies. Of course, simulation is very limited in comparison to emulation (as described above) but it does The underside of the pod reveals just one 100-pin IC and this is responsible for emulating all supported microcontrollers. Note the connectors on either side – these plug into the personality adapters. April 2000  57 T This photo shows a selection of the available DIL “personality” adapters supplied with the kit. provide an ideal introduction to the software and would be an excellent learning tool. AVR Studio is available for free download from the Atmel web site at www.atmel.com Sample assembler files are included with the installation (look in the Avrstudio\Appnotes directory), so you don’t even need to know AVR coding to give the simulator a go! Where to next? Experienced ICE users will have noticed that we haven’t mentioned tracers or triggers. To explain, in-circuit emulators often provide a program tracing feature. This feature records detailed information about the execution of each instruction (or even each machine cycle on some systems) in dedicated memory called a trace buffer, all in real time. The idea here is to allow detailed analysis of sections of code without interrupting program execution – something that can be important in real-time systems. In addition, trace buffer contents can be written to a file for later scrutiny. Triggers are associated with physical input and output pins, usually made available on a connector on the ICE pod. Output triggers are often used to trigger external test instruments like oscilloscopes and logic analysers. Markers are placed in the code to signal when the corresponding output pin should go high (or low). Input triggers can be used to halt program execution. They can also be used for simply logic analysis, as the pins are sampled and recorded in the trace buffer every cycle. Tracing and triggering is often used to solve difficult hardware and software design problems in advanced systems, hence it has not been included in the entry-level ICE 200. However, these features are available on the more advanced Atmel ICE Pro for those who need them. And the good news it that AVR Studio supports the ICE Pro and traces and triggers too, so there’s no need to learn a new platform if you decide to upgrade to the big guns later! Want further info? The main board shown approximately full size. All components except for the 9-pin D connector are surface-mounted. 58  Silicon Chip Further information on the Atmel ICE 200 in-circuit emulator kit, phone the REC Electronics office in your state (see advert on inside back cover for phone numbers). You can also visit their website at www.rec.com.au SC