54/317
3 - Programming a microcontroller
the correct values, so as to avoid having to edit and make the program each time an error is
found.
In fact, simulation is limited to pieces of code that do not access the input-outputs, since this
would require a complex program at simulator level to also simulate the behaviour of the ex-
ternal world that the application is supposed to interact with. But still, most simulators can cor-
rectly emulate the operation of the built-in peripherals, in particular the programmable timers,
and can trigger interrupts whose servicing can be monitored on screen.
Simulation, though limited in its possibilities, has the advantage that it allows to you start de-
bugging the application program before the hardware becomes available,. It can speed up the
debugging process by ensuring that some pieces of code are already functional when the time
comes to test and debug the hardware.
3.1.2.7 In-circuit emulators
In-circuit emulators are complex and expensive instruments that, for the application hardware,
behave exactly like the intended microcontroller would do. From the user's point of view, an
emulator is an inspection device that shows the calculations in progress in the application
hardware and the state of the input-outputs, as well as the contents of the memory at any time.
It is the electronic equivalent of a spy in the real world: an intermediate entity that, while
playing its role correctly in the real world (the application hardware), at the same time informs
an external intelligence (the programmer) of everything that happens in that world.
An emulator offers exactly the same features as a simulator does, in terms of running an ap-
plication either at full speed or step-by-step, setting breakpoints, examining registers, memory
and input-outputs. The major difference is that while running the program, the microcontroller
actually interacts with the external world, producing actions on the product to be tested, and
acquiring real data that it can process in a realistic way.
The simulator and the emulator are so close together in functionality that the manufacturer en-
deavours to provide the same user interface, i.e. the same presentation on the screen and the
same controls through the keyboard and the mouse for both tools, so that the user has very
little additional learning to do when switching from the simulator to the emulator.
One last feature that is found on top-range emulators (the very expensive ones) is so-called
real-time tracing. This is a hardware system that records all events on the buses (address,
control and data) and attaches a time tag to them. The memory capacity is at least one thou-
sand events, and can exceed ten thousand in the most expensive emulators. This allows you
to run the program at full speed, record what is going on, then quietly analyze the record to see
what happened. In real-time applications, this may be the only way to understand what hap-
pens and the problems that occur, as most of these applications do not permit step-by-step
debugging, since the processor must follow the activities of the external world in real-time. In