Build a robot electronic control system - how to draw a main control board from scratch? ——Build the minimum system circuit schematic diagram

How to draw a master control?

We usually use AD or EDA to draw a circuit board, and its overall idea is:


Build the minimum system circuit schematic

After you have the library, you can start to draw the board. The first thing we need to build is a minimum circuit system around the selected chip . This system can ensure that I can burn normally after the drawing is completed, and write control instructions to the MCU. It can also output my command from the corresponding pin (for example, pull a certain pin high or low). At this time, although the output does not correspond to any peripherals, we can also get the effect we want through physical connection (you can also use a voltmeter to test).

This minimum circuit system includes : crystal oscillator circuit (to generate clock), reset circuit, download circuit, power supply circuit, special pin circuit (to prevent MCU instability). For any single-chip microcomputer, the input and output pins of its minimum system circuit must be special and meaningful.


Take STM32F407ZET6 as an example:

Crystal oscillator circuit principle

Crystal oscillator, the full name is quartz crystal oscillator, is a high-precision and high-stability oscillator. Through a certain external circuit, a sine wave with stable frequency and peak value can be generated. When the single-chip microcomputer is running, it needs a pulse signal as a trigger signal to execute instructions. It can be simply imagined as: the single-chip microcomputer receives a pulse and executes one or more instructions.

The crystal oscillator itself can be equivalent to a two-terminal network in which a capacitor and a resistor are connected in parallel and a capacitor is connected in series. In terms of electrical engineering, this network has two resonance points, and the lower frequency is the series resonance according to the frequency. High frequency is parallel resonance. Due to the characteristics of the crystal itself, the distance between the two frequencies is quite close. In this extremely narrow frequency range, the crystal oscillator is equivalent to an inductor, so as long as the two ends of the crystal oscillator are connected in parallel with appropriate capacitors, it will form a parallel resonant circuit. .

This parallel resonant circuit can be added to a negative feedback circuit to form a sine wave oscillation circuit. Since the crystal oscillator is equivalent to an inductance, the frequency range is very narrow, so even if the parameters of other components change greatly, the frequency of this oscillator will not change. a big change.

The crystal oscillator circuit is connected to the crystal oscillator at both ends of an inverting amplifier, and then two capacitors are respectively connected to the two ends of the crystal oscillator, and the other capacitor is grounded. The capacitance of these two capacitors in series is equal to the load capacitance.

The crystal oscillator has an important parameter, that is, the load capacitance value, and the nominal resonant frequency of the crystal oscillator can be obtained by selecting a parallel capacitor equal to the load capacitance value. Through experiments, it can be obtained that the load capacitance value is about 15pF, so it is most appropriate to choose a parallel capacitance of 22pF. (Constants 0 and 4 are PCB and chip internal circuit capacitance)
insert image description here
The crystal oscillator is like the heart of the single-chip microcomputer. If there is no heartbeat, the single-chip microcomputer will not be able to work normally. The larger the crystal oscillator, the faster the running speed, but there will be interference when the speed increases circuit risk.

Generally, there are two types of crystal oscillators: passive and active. Passive crystal oscillators require an internal oscillator, but the passive signal quality is poor, the accuracy is poor, and it is troublesome to replace. Usually an active crystal oscillator is used.

Crystal vibration: According to the piezoelectric effect, when an alternating voltage is applied between the plates, mechanical deformation vibration will be generated. The amplitude of this mechanical vibration is relatively small, and its vibration frequency is very stable. When the frequency of the applied alternating voltage is equal to the natural frequency of the chip (determined by the size of the chip), the amplitude of the mechanical vibration will increase sharply. This phenomenon is called piezoelectric resonance, so the quartz crystal is also called a quartz crystal resonator. It is characterized by high frequency stability.

How to build a crystal oscillator circuit?

insert image description here
insert image description here
insert image description here

There are two crystal oscillator entrances in the chip:
PH0-OSC_IN and PH1-OSC_OUT are connected to 4-16MZH crystal oscillators, which are used to generate the main frequency of the microcontroller;

PC14-OSC32_IN and PC15-OSC32_OUT are used to access the 32.768KHZ RTC crystal oscillator.

(The real-time clock can be understood to be used in areas that require precise timing. 32768 is exactly 2 to the 15th power. After 15 times of frequency division, a 1HZ signal can be obtained. If precise timing is not required, it can be used.)

The same is true for crystal oscillator circuits of other single-chip microcomputers. The crystal oscillator is usually marked as X or XTAL on the chip schematic diagram. Generally speaking, an external crystal oscillator (that is, a 4-16MZH crystal oscillator that generates the main frequency) is required.
insert image description here
insert image description here


Reset Circuit Principle

The purpose of the reset circuit is to restore the circuit to the initial state. Generally speaking, the single-chip microcomputer must ensure that it can automatically reset when it is powered on, so as to prevent the CPU from issuing wrong instructions, and start working after the reset is completed. It can be imagined as using reset to unify the "starting line" of single-chip operation.

Generally, the principle that the voltage of the capacitor cannot be changed suddenly is used to connect the capacitor and the resistor in series. At power-on, the capacitor is not charged and the voltage across the capacitor is zero. At this time, a reset pulse is provided, and the power supply continuously charges the capacitor until the voltage at both ends of the capacitor is the power supply voltage, and the circuit enters a normal working state.

In order to ensure the reliable reset of the microcontroller, the high level of RST must be maintained for a long enough time. This time is to prepare the microcontroller and let the program start from the correct initial position.

Why is it reset when booting?
insert image description here

In the circuit diagram, the size of the capacitor is 10uf, and the size of the resistor is 10k. Therefore, according to the formula, it can be calculated that the capacitor is charged to 0.7 times the power supply voltage (the power supply of the microcontroller is 5V, so charging to 0.7 times is 3.5V), and the time required is 10K*10UF=0.1S.

That is to say, within 0.1S when the computer is started, the voltage across the capacitor increases at 0 to 3.5V. At this time, the voltage across the 10K resistor is reduced from 5 to 1.5V (the sum of the voltages across the series circuit is the total voltage).

So within 0.1S, the voltage received by the RST pin is 5V~1.5V. In the 51 single-chip microcomputer that works normally at 5V, the voltage signal less than 1.5V is a low-level signal, and the voltage signal greater than 1.5V is a high-level signal. Therefore, within 0.1S of starting up, the single-chip system automatically resets (the time for the high-level signal received by the RST pin is about 0.1S).

How to build a reset circuit?

insert image description here
insert image description here

For the STM32F407ZET6 chip, the pin of the reset circuit is also fixed, and it is only necessary to connect the NRST pin according to the working principle of the reset circuit. The same is true for other microcontrollers, just find the corresponding reset pin RESET.
insert image description here
insert image description here


download circuit

For single-chip microcomputers, there are three main types of mainstream download circuits : ISP, SWD, and JTAG. Among them, SWD and JTAG are very similar and have some connection, and ISP should be the first burning method I came into contact with.

①ISP method: This method is realized through the serial port TX and RX of the single-chip microcomputer, so basically all single-chip microcomputers can be downloaded through the ISP method. Its essence is a tool for converting USB to TTL, as shown in the figure below:

insert image description here
insert image description here
insert image description here

As shown in the figure below, you can buy a USB to TTL (single chip microcomputer serial port) module, or you can design the circuit of the conversion module yourself, as shown in the figure below, the core of which is a chip called CH340, you can also use it to do other USB Function of converting to TTL:
insert image description here

After building the hardware, you can download it through a separate burning software such as STC-ISP. The software interface is as follows:
insert image description here
insert image description here

②SWD and JTAG methods: The reason why these two methods are put together is precisely because the two are basically transformed into each other. For a microcontroller that can be programmed by SWD or JTAG, there must be corresponding special pins on the schematic diagram.

  • For the SWD method, the key lies in two lines - the data line SWDIO and the clock line SWCLK. That is to say, when the microcontroller is powered on, I can complete the programming of the program with only two wires, so usually the SWD port you can see is four wires (that is, there are VCC and GND).

  • For the JATG method, there are six necessary lines, as shown in the figure below:
    insert image description here
    insert image description here

We can easily see from the figure that the JTAG interface itself contains the SWD interface. That is to say, if your microcontroller is an interface with four SWD wires, then you can directly use wires to lead out the SWDIO and SWCLK in the JTAG port plus VCC and GND.

Take the 32 development boards of punctual atom as an example, they are usually programmed by ISP or JTAG interface:

(If the ISP method is used, then you use a USB cable to connect the PC and the microcontroller, and use the ISP download software mentioned above to download; if you use the JTAG download method, then you may use a downloader called JLINK [as follows] Picture on the right] Connect the PC and the microcontroller, and then download it directly in the compiler [such as KEIL, IAR].)
insert image description here
insert image description here

How to transfer JTAG to SWD?
insert image description here

Download method: Find the position of the four wires corresponding to SWD on the JLINK downloader, connect it to the single-chip microcomputer with the SWD download interface through the wire, and then download directly through the compiler.

For STM32F407ZET6, the pins corresponding to the download circuit are as follows:
insert image description here

It can be seen that in addition to SWD and JTAG downloads, there are two BOOT0 and BOOT1 pins, which are two unique STM32 pins for managing download functions:
insert image description here

Usually use the program code stored in the main flash memory, configuration: BOOT0=0, BOOT1=X;

* Flash lock solution:
During the development and debugging process, the internal Flash is locked due to some reason, unable to connect to SWD and Jtag debugging, unable to read the device, you can re-write the code by modifying the BOOT mode. Modify it to BOOT0=1, BOOT1=0 to start from the system memory. ST comes with a Bootloader program when it leaves the factory, and the SWD and JTAG debugging interfaces are dedicated. After reprogramming the program, you can change the BOOT mode to BOOT0=0, BOOT1=X and it can be used normally.


Principle of Power Circuit

Single-chip microcomputer level:
For any single-chip microcomputer, VCC and VSS are the core of the power supply. The C of VCC means Circuit, which refers to the voltage of the entire power supply circuit (there are 12V [supply voltage of punctual atomic board], 24V, 5V etc.); the S of VSS means Series, which generally refers to the common terminal. Usually, the common terminal in the circuit is grounded, which is the ground terminal voltage; the D of VDD means Device, which refers to the voltage on the device, that is, the working voltage of the chip. For example, the voltage value of the STM32 chip is generally 3.3V, which is VDD. (Visible VCC>VDD)

Usually, the level of the single-chip microcomputer is in the format of 3.3V/5V, also known as the CMOS/TTL level format. When you let a pin of the single-chip microcomputer output high level, its size is 3.3V/5V (STM32 is 3.3V V, 51 is 5V). Generally, we will use the external power supply VCC (>5V) to supply power to the single-chip microcomputer through step-down regulation, which will provide more stable power supply and provide higher voltage for peripheral circuits.

Now what we are talking about is the minimum system circuit of the single-chip microcomputer, which is developed around the chip, so what we need is how to convert VCC to VDD, and then form a loop with VSS. (Chips with relatively simple pins will directly write VDD as VCC)

How to build a power circuit?

Take STM32F407ZET6 as an example:
insert image description here

We connect all its VSS and VDD. The working voltage of the STM32 chip is 3.3V, so VDD is connected to 3.3V. So now is the question of how to convert VCC to 3.3V VDD.
Voltage conversion circuit:
insert image description here
insert image description here

Here I use a 9V power supply as an example for external power supply. First, the K7805-1000R3 chip is used to step down the voltage to 5V, and then the AMS1117-3.3 chip is used to step down the 5V to 3.3V as VDD.

The capacitors are used to stabilize the voltage. The specific values ​​are mainly related to the parameters of the chip used. The circuits of these two chips are very mature. If you are interested, you can go to the Internet to see the principle. This is the easiest way to step down and stabilize the voltage. Of course, you can also make the design more complicated, adding anti-reverse circuit, overvoltage protection, overcurrent protection, etc. to improve the safety of the circuit, but in general it is the same sentence. It is already very mature and can be used directly. The premise of innovation should also be to understand these mature things first.
The same is true for other chips:
insert image description here
insert image description here


special pin circuit

The so-called special pin circuits here are some pins that are directly related to the size of the power supply and ground. If these pins are not connected to the air, it is easy to cause a certain function of the microcontroller to work abnormally, and the level of them is also different. Determines some functions of the microcontroller. The more powerful the chip (the more pins), the more these special function pins will be, and the more we need to pay attention to.

How to build a special pin circuit?

Take STM32F407ZET6 as an example, the chip has many functions, so there are many corresponding special pins, and the following will introduce them one by one:

insert image description here

  • VBAT : VBAT is the power-down power supply of the system. It is actually a backup power supply. When the microcontroller is powered off, it provides power to the RTC and backup registers. (Do you still remember that there is a dispensable 32.768KHZ crystal source in the crystal oscillator? At that time, it was said that the crystal oscillator is to provide oscillation for the RTC, that is, the real-time clock, that is, the area that requires precise timing. For example, I If you want to display the date, time, etc., if you want the MCU to display a real-time world clock, then you must ensure that the RTC still has the ability to work after the MCU is powered off. After all, we cannot always supply power to the MCU.)
  • VCAP : VCAP is used to power digital circuits outside the backup domain and standby circuits (they already have a VBAT to power them), which is essentially a voltage regulator with an output voltage of 1.2V, that is to say, VDD is used as a chip After the input voltage of the chip enters the chip, in order to supply power to the digital circuit inside the chip, it is necessary to adjust the voltage to 1.2V through VCAP, and the function of the capacitor is to filter and stabilize the voltage.
  • PDR_ON : The power-down reset pin derived from the 144-pin series of STM32. Connecting to a high level means turning on the power-down reset, and connecting to a low level means turning off the power-down reset. (The absence of this pin in the 100-pin series does not mean that there is no such function, but ST Company does not give you the right to choose this function)
  • VDDA, VSSA, VREF : These three are the things that the single-chip microcomputer with AD conversion function needs. VDDA is the power supply for AD conversion, VSSA is the corresponding common terminal (equivalent to VDD and VSS), VREF is the reference voltage for AD conversion, the value is between 2.4V-VDDA, which determines the accuracy of AD conversion. It can be seen from this that the AD power supply VDDA and the reference voltage VREF must be stable to ensure conversion accuracy, so capacitors need to be added for filtering and voltage stabilization.

The same is true for other microcontrollers:
insert image description here

Above, we have successfully built a minimum schematic diagram of an MCU:

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/ROS_homes/article/details/122723748