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.
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- National Technology N32 MCU RF Resource Library (official, practical information)
- Raspberry Pi Pico Windows Development Environment - Compile under Visual Studio Code...
- Power circuit problem
- View Circuit-ADC and System (1)
- Teach you to understand the role of resistors in circuits
- EEWORLD University Hall----High-efficiency power architecture for smart door locks, battery-free light switches and wireless sensors
- 【E840-DTU】TCP connection
- Tank-1 test stand description (for burning and testing ESP8266 series)
- How to implement software reset and restart on HGI MCU
- Understanding digital signal processing