Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

Debugging microcontrollers using a ROM emulator. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Microcontrollers

Comments on the article Comments on the article

The complexity of developing and debugging the working program of an electronic device containing a microprocessor often determines the cost of its development as a whole. In microcontrollers (MC), which have integrated memory and some peripheral devices, this is especially pronounced. One of the tools that greatly facilitate debugging is the ROM emulator described in [1]. The proposed article describes the technology of working with it. Debugging capabilities are not limited to the methods outlined. This process, as well as designing in general, is to a certain extent an art: for the same instrument, everyone creates "his own music". We will be grateful to readers who will share their original tools and methods for debugging MK programs.

The complexity and laboriousness of the process of debugging MC software is determined by the following factors [2]:

  • strong interconnection between the software and hardware parts of the system;
  • lack of direct access to internal resources and control points of the MC;
  • multi-bit nature of signals, complexly distributed in time;
  • non-periodicity or very low frequency of repetition of signals in the system;
  • a wide variety of external devices and protocols for exchanging information with them.

Traditional test equipment (such as an oscilloscope) can only be used to a limited extent for debugging the MCU.

The simplest (and at the same time the most inefficient) debugging method is the “trial and error method”: loading the program into a reprogrammable read-only memory (EPROM), trying to execute it, detecting and correcting errors in the program and hardware, erasing the EPROM, reloading the program, etc. e. The processes of erasing and writing data to the EPROM chip take a long time, and after a certain number of reprogramming cycles, it generally fails. Repeated installation and removal of the microcircuit reduces the reliability of the electrical contacts in the EPROM socket. The possibility of obtaining debugging information about the system is practically absent.

Currently, MK is most often debugged by cross-tools based on a personal computer. This allows minimal distraction of MC resources. The device to be debugged, as shown in the figure, is connected to the computer through some tool, such as a ROM emulator. Such a complex allows you to download and edit the program, enter test modules into it, obtain certain information about the system, and much more, which we will discuss below.

Although ROM emulators are not the only and not the most powerful debugging tool, they are still popular. Their "longevity" is explained by independence from the type of MC (only the ability to work with external program memory is needed), real-time operation, low price and accessibility to a wide range of equipment developers and radio amateurs. We will consider the technology of debugging a program using a ROM emulator using the example of the MCS-51 family of MKs (8031, 8051, 80C31, 80C51. KR1816BE31, KR1816BE51, KR1830BE31, KR1830BE51, etc.).

Starting debugging, it is necessary to check the operability of the hardware of the system and the MC itself. To do this, you can use the "free count" tests [3]. which consist in the enumeration of all possible code combinations on the lines of the MK ports. During testing, the port lines will be set to the output state, so first of all, make sure, according to the device being debugged, that they are not loaded on the outputs of other elements. Temporarily disconnect such loads, if any.

Load the ROM emulator with No Operation (NOP) command codes within the entire address space of the MCU programs. For MCS-51 this is code 00H. When executing such a "program", the MK sequentially goes through all the addresses of the program memory. Monitor the signals of ALE, PME and ports P0, P2 with an oscilloscope. The waveforms on the port lines must match the timing diagrams of the binary counter, taking into account the multiplexing on P0 of the low byte of the address and data.

Next, check the ports P1 and P1 by loading the test program shown in Table 00 into the ROM emulator. 0. It outputs a sequence of codes from XNUMXH to XNUMXFFH on the lines of the specified ports, simulating an eight-bit binary counter. If the oscillograms correspond to the required ones, restore the loads disconnected from the ports and proceed to debugging the working program of the MC. Remember that you are debugging the software and hardware of the system at the same time, and do not forget to periodically monitor the signals at the test points with the oscilloscope. The inconsistency of the type of signals with your ideas about them is a reason for serious reflection and additional checks.

Debugging microcontrollers using a ROM emulator

To facilitate development and debugging, one should adhere to the modular principle of programming, i.e., divide the MK program into parts according to a functional feature. This will allow you to easily move individual modules, and if necessary, apply them in other projects. The module to which control is transferred after power is turned on or the MK is reset is called the main or main. Transferring control to the program entry point should be a jump command, not a subroutine call, so as not to pollute the stack with the return address.

To avoid unexpected program results, remember to assign an initial value to each of the variables before you use it for the first time. In some cases, you may need to initialize peripheral equipment. The initialization block is placed at the beginning of the main program module.

An approximate view of the main program module at the beginning of debugging is shown in Table. 2. It contains only the entry point to the program and the exit handler. Although such an output is rarely used in microcontroller systems, it must be provided for the correct termination of emergency situations. In the example under consideration, after the completion of the work, the program "loops". Only restarting the system with a hardware reset signal will bring it out of this state.

Debugging microcontrollers using a ROM emulator

During debugging, other program modules are added to the main module as they are ready. The order of their connection and debugging plays an important role. You should start with the drivers for information output devices (display, digital-to-analog converter, etc.), placing their calls in the main module. Then they debug the drivers of other peripheral devices, data processing routines, and only after that they check the joint operation of all program modules. If there is an alphanumeric display, its driver is debugged first and used later to display debugging information, for example, the contents of the internal data memory of the MK. If such a ROM emulator is used that the information contained in it can be written and read by both the control computer and the device being debugged, the MK can place the debug data in the free memory area of ​​the ROM emulator, and the control computer reads them and displays them on its display.

For example, to output the contents of the MCU's internal data RAM, connect its external data memory write (WR) signal output to the ROM emulator's write signal input and use the subroutine shown in Table 3. 32. It is assumed that the amount of program memory of the device being debugged does not exceed 8000 KB, so the debug information placed in the emulator's memory starts at address 0H. The contents of the registers R1 and R8000 are sent separately, since they are later used in the subroutine to organize the loop. After the debugging information is output, the MK program is suspended, the contents of the memory cells of the 807H-XNUMXFH ROM emulator are read by the control computer, displayed and analyzed. Similarly, the contents of all programmatically accessible MC registers can be displayed.

Debugging microcontrollers using a ROM emulator

When starting to debug a peripheral device driver, temporarily disable the control signals generated by the MK from it in order to avoid possible device failure due to errors in the program. If the process is of a one-time nature, "loop" it and program the oscilloscope clock signal if necessary. Debug the driver by monitoring the signals generated by the oscilloscope. After making sure that the timing diagrams of the control signals correspond to the required ones, connect the peripheral device and continue debugging the driver on real hardware. Finally, remove the debugging elements from the program module and check its operation in the final form.

The use of shared MK resources by different modules quite often leads to the fact that the debugged program stops working when another subroutine is added. Therefore, after debugging the next module, make sure that all previously debugged drivers and subroutines continue to work correctly. If your program uses interrupts, do not disable them unless absolutely necessary. A debugged module should not be removed from the program, even if it is not currently needed.

When the MK "freezes", the following error localization method is useful: enter control points into the program that display sequentially increasing numbers. After "hanging" the display will show the number corresponding to the last successfully passed control point. If several such points are caught in an infinite loop, the numbers on the display will change rapidly. In order to determine exactly which points are in the cycle, you will have to artificially slow down the change of numbers by setting a program delay when outputting each of them, for example, in the form of an idle cycle. If the system being debugged does not have a built-in display, information can be displayed on the display of the host computer through the free memory area of ​​the ROM emulator.

After debugging all device drivers, start debugging other subroutines. If any of them implements a complex algorithm for processing or converting data, displaying one or more intermediate values ​​of variables often does not provide information sufficient for error analysis. Overcoming difficulties and writing debugging information of the required amount into the free memory area of ​​the ROM emulator will help to overcome difficulties.

Having achieved the normal operation of all program modules, you can debug them together. The difficulties that arise in this case are divided into two groups. The first includes the problems of sharing common MK resources: arithmetic logic unit, data memory, input-output ports. The second is related to the operation of microcontroller devices in real time.

Real-time systems are usually multi-threaded. Several program tasks (threads) are executed in parallel, interacting with each other and using common resources. But at each moment, the MC, due to its structure, solves only one of them, switching to others in turn, taking into account the priority. Conflicts between tasks arise both due to lack of resources and due to lack of time for data processing. Therefore, pay special attention to the MK resources used in program modules, often control the change in their state by displaying debug information. Try to reduce the number of global variables, replacing them with local ones whenever possible. Monitor the state of the stack. Estimate the execution time of critical sections of the program, check the system with various values ​​of input signals that are possible in practice.

Using the ROM emulator, you can also debug a program designed to work in the internal memory of the MK, if you temporarily place it in the external program memory. Since in this case the ports P0 and P2 will be occupied by servicing external memory, then if the remaining free I / O lines of the MK are not enough, P0 and P2 are replaced with I / O ports addressed as external data memory cells. They are connected according to standard schemes, using trigger registers to increase the number of output lines, and the number of input lines - elements with three output states.

After debugging the system using the emulator, remove debugging elements from it, write the program to ROM (or to the internal program memory of the MK) and check the operation of the device in its final form.

Literature

  1. Vydolob G., Kudryashov V., Samoilov V. ROM/RAM emulator RE020. - Radio, 1997. No. 11, S. 30-32.
  2. Zelenko GV, Ivannikov AD, Sypchuk PP Design and debugging of microprocessor systems. - M. Engineering. 1982.
  3. William G. B. Debugging microprocessor systems: Per. from English. - M Energoatomizdat. 1988

Authors: G.Vydolob, V.Samoylov, Moscow (Zelenograd)

See other articles Section Microcontrollers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Machine for thinning flowers in gardens 02.05.2024

In modern agriculture, technological progress is developing aimed at increasing the efficiency of plant care processes. The innovative Florix flower thinning machine was presented in Italy, designed to optimize the harvesting stage. This tool is equipped with mobile arms, allowing it to be easily adapted to the needs of the garden. The operator can adjust the speed of the thin wires by controlling them from the tractor cab using a joystick. This approach significantly increases the efficiency of the flower thinning process, providing the possibility of individual adjustment to the specific conditions of the garden, as well as the variety and type of fruit grown in it. After testing the Florix machine for two years on various types of fruit, the results were very encouraging. Farmers such as Filiberto Montanari, who has used a Florix machine for several years, have reported a significant reduction in the time and labor required to thin flowers. ... >>

Advanced Infrared Microscope 02.05.2024

Microscopes play an important role in scientific research, allowing scientists to delve into structures and processes invisible to the eye. However, various microscopy methods have their limitations, and among them was the limitation of resolution when using the infrared range. But the latest achievements of Japanese researchers from the University of Tokyo open up new prospects for studying the microworld. Scientists from the University of Tokyo have unveiled a new microscope that will revolutionize the capabilities of infrared microscopy. This advanced instrument allows you to see the internal structures of living bacteria with amazing clarity on the nanometer scale. Typically, mid-infrared microscopes are limited by low resolution, but the latest development from Japanese researchers overcomes these limitations. According to scientists, the developed microscope allows creating images with a resolution of up to 120 nanometers, which is 30 times higher than the resolution of traditional microscopes. ... >>

Air trap for insects 01.05.2024

Agriculture is one of the key sectors of the economy, and pest control is an integral part of this process. A team of scientists from the Indian Council of Agricultural Research-Central Potato Research Institute (ICAR-CPRI), Shimla, has come up with an innovative solution to this problem - a wind-powered insect air trap. This device addresses the shortcomings of traditional pest control methods by providing real-time insect population data. The trap is powered entirely by wind energy, making it an environmentally friendly solution that requires no power. Its unique design allows monitoring of both harmful and beneficial insects, providing a complete overview of the population in any agricultural area. “By assessing target pests at the right time, we can take necessary measures to control both pests and diseases,” says Kapil ... >>

Random news from the Archive

Solar-powered ultralight self-propelled trains 11.01.2021

Testing of a self-propelled ultra-light rail vehicle designed for rural railways or underutilized railway lines should start by the end of 2021 in France.

The first Taxirail route is expected to be launched in 2023, when regional routes are opened for operation in accordance with a competitive tender.

Discussions were held with almost all regions of France, including Brittany, where the company is based. The company is also considering exporting Taxirail to other countries, potential buyers have already been identified - Switzerland and Canada.

Taxirail will weigh less than eight tons and carry up to forty passengers. The cars are powered by battery or hybrid traction, as well as the use of artificial intelligence. The vehicle will operate autonomously, but in constant contact with the control center.

Solar energy will be used to power lighting, heating, air conditioning and entertainment systems, and information will be provided to passengers in real time.

Other interesting news:

▪ Toshiba Canvio Alu Portable Drive

▪ OLED panel 0,97 mm thick

▪ FTR-H3 relay series from FUJITSU COMPONENTS

▪ City lights

▪ AnkerMake M3 5D printer

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site Car. Article selection

▪ article There are only girls in jazz. Popular expression

▪ article Where did the first schools originate? Detailed answer

▪ article Partial use of insurance premiums by policyholders for the prevention of insured events

▪ article Electronic relay for turning on the cooling fan. Encyclopedia of radio electronics and electrical engineering

▪ article Domestic coaxial cables RK50-3-11 - RK50-4-111. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024