Using the MCU module in Multisim10 for microcontroller co-simulation

Publisher:闪耀之星Latest update time:2011-12-13 Keywords:Multisim10 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

MCU (Microcontroller Unit) is a familiar and commonly used electronic device. Due to its wide application, designing circuits with single-chip microcomputers is an essential skill for electronic technicians. For beginners, you can start with software simulation. We know that Proteus software can be used to simulate single-chip microcomputers, and Multisim can do the same. Multisim is a circuit simulation software based on SPICE. SPICE (Simulation Program with Integrated Circuit Emphasis) is the abbreviation of "Simulation Program Focused on Integrated Circuits" and was developed by the University of California, Berkeley in 1975. In Multisim9, MultiMCU needs to be installed separately for single-chip microcomputer simulation. NI (National Instruments) Multisim10 calls MuitiMCU MCUModule, which does not need to be installed separately. It can be simulated with the SPICE model circuit in Multisim, supports Intel/Atmel's 8051/8052 and Microchip's PIC16F84a, and has typical peripherals such as RAM and ROM, keyboard, graphic and text LCD, and has complete debugging functions, including setting breakpoints, viewing registers, rewriting memory, etc. It supports C language, can write header files and use libraries, and can also disassemble loaded external binary files.

Here we use a simple counter with reset function to illustrate how to develop microcontrollers in NI Multisim 10 and how to co-simulate with SPICE model circuits.

If you are familiar with Multisim, you must be impressed by the Agilent 54622D mixed signal oscilloscope and other instruments in it, because it is almost exactly the same as the real instrument panel and operation. Other instruments that imitate the actual instrument in Multisim include Agilent's 33120A arbitrary waveform function generator and 34401A multimeter, and Tektronix's TDS2024 four-channel oscilloscope. Making full use of these instruments is like having a real laboratory. You can use the 33120A arbitrary waveform function generator to provide input signals to the microcontroller, use the 54622D or TDS2024 oscilloscope to view analog signals, or use the logic analyzer function of the 54622D to view the output of digital signals of multiple pins of the microcontroller. In the following example, we will use the 54622D to observe the reset signal.

Build the circuit and set up the MCU

The constructed circuit diagram is shown in Figure 1, and the names of the components and other information are shown in the attached table. It should be noted that the MCU in the circuit diagram can be simulated without connecting a crystal oscillator. The setting of the clock frequency (speed) is shown below.

Figure 1 Circuit diagram of a simple counter with reset function

[page]

When building the circuit, when the microcontroller U1 is placed in the circuit diagram, the MCU wizard will appear, as shown in Figure 2. The first step is to enter the workspace path and workspace name respectively. The workspace name is arbitrary, here enter MCUCosimWS. The second step, as shown in Figure 3, there are two options in the Project type drop-down box: Standard and Load External Hex File. You can write assembly and C source programs in environments such as Keil, and then generate Hex files, and then import them through "Load External Hex File". Due to space limitations, select Standard here, and then there will be two options in the "Programming language" drop-down box: C and Assembly. If you choose C, Hi-Tech C51-Lite compiler will appear in the Assembler/Compiler tool drop-down box. We choose Assembly here, and 8051/8052 Metalink assembler will appear. Next, enter a name in the Project name, such as CosimProject. Step 3, as shown in Figure 4, there are two options in the dialog box: Create empty project and Add source file. Select Add source file and click Finish. Save the file, type M10Cosim as the file name, and then view the Design Toolbox, which should look like Figure 5.


You may prefer to write programs in C instead of assembly, or both, or want to introduce external Hex files. This can be solved by adding an MCU project using the "MCU Code Manager". Right-click MCUCosimWS in the design toolbox, select "MCU Code Manager" (MCUCodeManager), click the "New MCU Project" (NewMCUProject) button, select "Project Type" (ProjectType), which can be standard (Standard) or load an external Hex file (LoadExternalHexFile). Select "Standard" here, then enter a name, such as Cosim_C_Project, and after confirming, you can proceed to the next step in the MCU Code Manager dialog box. You can create a new file, set the assembler/compiler, etc. As shown in Figure 6, there is already an additional Cosim_C_Project project (no C code source file has been added), and the hollow box in front of the icon indicates that it is not the "currently used project" (ActiveMCUProject).


Figure 6 New project added using MCU Code Manager

Write and compile MCU source program

Double-click main.asm under CosimProject to input the program. The program list and comments are as follows:

Since the assembler is Metalinkassembler, you can refer to its user manual for detailed macro commands, etc. After writing the program, select the menu MCU→MCU8051U1→Build. The drop-down submenu here may be "MCU8051U2" or "U3", which mainly corresponds to the symbol name of the microcontroller in the circuit diagram. The build result will be output to SpreadsheetView.

[page]

Run the program and observe the reset process with an oscilloscope

After the assembly program is compiled, you can return to the circuit diagram window and click the run button on the toolbar. At this time, 0 to 9 should be displayed cyclically on the seven-segment digital tube. If the display is too fast or too slow, you can adjust the COUNT_NUM in the source program, change the delay time, or double-click U1 and set the "Clock Speed" (ClockSpeed) in the Value tab of the 805x dialog box.

The function of C1 and R1 in the circuit, which are SPICE models, is to extend the time that the reset pin maintains a high level to avoid reset failure caused by a short duration of the reset voltage. Double-click the oscilloscope XSC1, press the Power button on the oscilloscope panel, turn on the oscilloscope, and click the Run button on the toolbar. At this time, adjust the voltage and time scale of the oscilloscope to obtain the change of the reset pin voltage shown in Figure 7. Each scale is 100μs, and the high level lasts for about one scale. It can be seen that when the power is turned on, the microcontroller does not run immediately, and there is a delay. The delay time should be enough to make its internal voltage and oscillation in a steady state. The waveform when the reset button S1 is pressed is shown in Figure 8. At this time, each scale is 50μs. The flat-top part of the waveform is the time when the button is pressed, which is about 20μs. After that, the voltage gradually decreases. When it drops to about 3V, the 7-segment digital tube starts counting, indicating that the microcontroller starts working. It can be seen from Figure 8 that the reset time is extended to about 100μs.

The principle is that at the moment of power-on or between the time when the button is pressed and released, the capacitor has no charge and the voltage across the two ends is 0V, and the voltage of the RST pin of the microcontroller is instantly raised to VCC (5V). After power-on or the button is released, the capacitor begins to charge, the voltage across the two ends gradually increases, and the voltage of the resistor (RST pin voltage) gradually decreases from 5V, thereby extending the time that the reset pin remains at a high level. The actual device generally requires two machine cycles for the duration of the reset, so the reset time of 100 microseconds requires the crystal oscillator frequency of the 51 microcontroller to be no less than 0.24MHz. Of course, in general, the values ​​of C1 and R1 are determined according to the crystal oscillator frequency, which can be obtained by solving the first-order differential equation to obtain its charging and discharging time, or referring to the user manual of the microcontroller.

Debugging Programs

Select the menu MCU→MCU8051U1→DebugView, you can see a drop-down menu above the text area with two options, corresponding to disassembly and listing assembly. Simply put, the former is obtained from the content of ROM, and the latter is the result of source file compilation. Double-click main.asm in the "Design Toolbox", right-click the line with the statement "MOVCA, @A+DPTR" in the source file editing window, select "Set/Clear Breakpoint" (ToggleBreakpoint), a solid circle will appear on the left, click "Run", the program will stop at this line, but in the listing assembly window of "Debug View" (DebugView), and there is an additional yellow arrow on the solid circle. Click MCU->MCU8051U1->MemoryView to open the MCU memory view, in which you can view the special function registers (SFR), internal RAM (IRAM), internal ROM (IROM), and external RAM (XRAM). Observe the value of ACC in the SFR table, which should be "00" at this time. Observe the value of address 21H in IRAM, because the "MOVSP, #20H" statement uses 21H as the address of the first storage byte of the stack. The previous statement "PUSHACC" of the breakpoint makes the byte store the value of ACC, which is also "00" at this time. Click "Run" again, and the program stops at the breakpoint for the second time. Observe the ACC in SFR and 21H in IRAM. As shown in Figure 9, the values ​​in both cells should be "01". You can also double-click the cell to modify it. This value is also the next number that the seven-segment digital tube will display. Click the MCU menu, and you can see that in addition to setting breakpoints, you can also step into (Stepinto), enter the function when encountering a function; skip (Stepover), that is, not enter the function; jump out (Stepout), that is, jump out of the function to the next statement that calls the function.

Figure 9 MCU memory view

Conclusion

This article uses a simple circuit to introduce how to perform co-simulation of SPICE models (mainly C1 and R1 here) and 8051MCU under NIMultisim. NIMultisim10 not only has a variety of compilation and debugging functions, but also provides peripherals such as RAM, ROM, keyboard, LCD screen, etc. It is an ideal tool for beginners of single-chip microcomputers. After mastering the basic hardware structure, assembly instructions and debugging methods, readers can use Multisim to develop more complex systems and simulate them, preparing for the next step of designing actual hardware circuits.

Note: Because the current of the MCU is limited, it cannot be too large, otherwise it will burn the MCU. Therefore, a current limiting resistor (100 ohms) should be connected between the CA terminal and the VCC terminal of the digital tube; or a resistor array (7) can be connected between the MCU and the digital tube, so that the MCU will not be burned during simulation.

Keywords:Multisim10 Reference address:Using the MCU module in Multisim10 for microcontroller co-simulation

Previous article:Research on Data Protection of Farad Capacitor in Single Chip Microcomputer System
Next article:Talk about how to improve the analog-to-digital conversion accuracy of single-chip microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号