Introduction to some hardware-related concepts in embedded development

To do embedded system development, often need to touch the hardware, you need to have a certain understanding of digital circuits and analog circuits, so that you can continue to study. Those who have just touched the embedded system always find it difficult. In fact, they must take the most basic knowledge firmly in order to finally embark on the path of the Great God. Below we briefly introduce some of the hardware-related concepts in embedded development.

Level

In the digital circuit, it is divided into high level and low level, which are represented by 1 and 0 respectively. The pin of a digital circuit always has a level, either high or low, or either 1 is going to 0 (in fact, there is another state, which will be mentioned later).

Bus

There must be a processor chip in the embedded system. In addition, there are other chips as external devices (hereinafter referred to as peripherals), which cooperate with the processor to realize the functions of the product. Complex products are often made up of a large number of chips. The inevitable is that we need to connect all the peripherals to the processor. The simplest is to connect all peripherals to the processor with separate (note separate) signal lines.

The benefits are easy to understand, but the problem is: not feasible. Because the processor chip needs to draw too many lines, it is not practical from the point of view of chip production and product production. In addition, the processor (here we assume that the processor is single-core, not multi-core) processing transactions are microscopically serial, that is, if the peripheral is to be read or written at a certain time, it is only possible It is done for one of a large number of peripherals, that is, multiple peripherals cannot be simultaneously accessed by the processor at the microscopic level. It should be noted that the concept of micro is proposed here, which is to distinguish it from the macro.

Macroscopically, there can be multiple tasks running simultaneously in a single processor, but these tasks are run one at a time microscopically (the serial will be used to describe the "one by one" here), multitasking The serial operation implementation is implemented by the operating system playing an important role. Back to our topic, it is not feasible to connect each peripheral with a separate signal line to the processor, and the processor will only access one peripheral in a single time, then we can use a shared signal line. Connect all the chips together? This is the origin of the bus concept.

In layman's terms, if there are ten families around us, in order to allow each of the ten families to travel between each other, we do not need to build a separate (note separate) path for each of the two families (if so, Instead of repairing 45 roads, you can build a road, and then each home is connected to the main road.

For the bus, we often say that the bus is a processor, while other peripherals are attached to the bus. There is a problem. We can only access one peripheral connected to the bus every time. How do we distinguish these peripherals? Like our way, we need to use an address to distinguish each family. On the bus, we also use addresses to distinguish them. In this way, the bus is divided into two categories according to its function. One type is the address bus. The data on this bus will only be "streamed" from the processor to the peripheral and is unidirectional.

The other type is the data bus, which is used to transfer data from the processor to the peripheral (write from the processor's perspective) or to transfer data from the peripheral to the processor (from a processor perspective) Is a read operation), obviously, the data bus is bidirectional. That is to say, in our embedded system, both the address bus and the data bus are connected to all the chips that need to communicate with the processor.

The bus is wide, just as our road is divided into "three lanes" or "four lanes". We say that 32-bit processors mean that the data bus width is 32 bits, that is, "32 cars can run at the same time. "Obviously, the wider the width, the faster the processor speed, because we can access data from peripheral chips faster, which is why our computer is moving to 64-bit." Similarly, the address bus is also wide, and for 32-bit processors its maximum width is 32 bits.

The concept of the bus has, then the next problem is, even if each peripheral has an address, then where is this address recorded? Is it on the peripheral chip? If this is the case, then there is a problem. The address of each type of peripheral must not overlap. When two identical chips are needed in a product, the addresses of the two chips cannot be distinguished. It seems that this operation There is a problem. Also, if so, each peripheral must be fully connected to (for example, 32) data buses, and listen to the data lines to see if the processor is "calling" itself, which is very complicated. In addition, the address may also be used up because of the variety of peripherals. In general, the address cannot be stored in the peripheral chip. How do you let the peripheral know that it is being replaced by the processor and needs to be read and written? The answer is the chip select (CS, chip select) signal, or the EN enable signal.

Chip selection (CS or EN)

For the peripheral chip, the chip select signal is a (also a) notification signal, telling the chip "Hey, please open the door, I want to put something in, or take something to go", the only thing here is the data. It can't be a corn cob or something. There is a question, where does this signal come from? Obviously, it can only come from the processor. Is that also like a bus, each chip shares a line together? If so, it is possible that the processor "opens the door" and all the chips open the "door".

If the processor is writing data, then all chips may be written with the same data. When fetching data, each peripheral chip "throws" the data outward, which will cause the data bus to conflict, because some chips "throw" 1 to the bus, and some "throw" 0. In this case, The processor must be "mad" because it doesn't know if it should get 1 or 0.

In this case, obviously it is impossible to connect all the chip select signals together, only the chip select signals of each chip are independent. As mentioned above, the address bus, we use an address line to connect a peripheral chip? Still use other methods. If you use an address line to connect a peripheral chip, you may only be able to mount up to 32 chips, which is obviously not possible. In fact, in reality, a 32-bit number is used to represent the address of a peripheral chip. For example, 1 can represent chip A, and 6534 can represent another chip B, and so on.

From this point of view, in theory we can represent 2 32 power (4294967296) devices, the reason is theoretical, because some devices take up a large number of addresses. That being the case, there is still a problem, if the 32-bit address bus is converted into a chip select signal of the chip? This requires the introduction of the concept of a decoder.

Decoder

The decoder converts a data into a signal on a signal line. For example, a 3/8 decoder can convert a data with a bit width of 3 bits into 8 (2 to 3 powers) completely independent signal lines. When the binary 011 is written to the data side, it corresponds to the third root of the eight lines, and when the binary 111 is input, it corresponds to the last one of the eight lines. With the decoder, the processor's address line is simplified. As long as 32 address lines are added to the external decoder, a large number of peripheral chips can be accessed. We have already solved the problem of selecting external devices. Now we have to look back at the data bus.

Figure 1 3/8 decoder

In an embedded system, the data bus of all chips can be understood to be directly connected. The reason why the word "understandable" is used is because the bus driver is added to increase the load capacity of the bus. To understand, let's take a look at the tap water in our lives. For example, in Beijing, all the water pipes may be connected together, but in the middle, in order to increase the water pressure, there are many small water stations to increase the water supply pressure. It is impossible for all the tap water in Beijing to come from a water plant.

Since all the data buses are connected together, there may be problems. When writing data to an external device, the processor first transfers the address of the target peripheral to the address bus, and the address decoder converts the chip select signal into a signal to the target peripheral, and the target peripheral receives the signal. , open the "door". Next, the processor will transfer the data to be transmitted to the peripheral device to the data bus. Since only the target peripheral chip opens the "gate", the data will only enter the target peripheral, and other peripherals will not receive anything. To.

Next, take a look and read. Read, because the data is sent from the peripheral to the processor, although we use the same method as the write to open the "gate" of the target peripheral, but at this time, other peripherals are also on the data bus, they may be in 1 may also be at 0, does it affect the processor to read the data of the target peripheral? The result is certainly not, but we have to introduce another concept: high resistance.

High resistance state

Obviously, when the processor reads data from the target peripheral, we hope that the data bus of other unselected chips will not affect the data to be transmitted by the target peripheral. What should we do? In fact, when the chip is not selected, its data bus is in a high-impedance state. The so-called high-impedance state, we can understand that this pin is disconnected inside the peripheral chip, so obviously does not have any impact on the processor reading data from the target peripheral. We say that when a chip is not selected or not enabled, its data bus must be in a high-impedance state. In the front, I used the opening and closing of the "door" to make an analogy. What does the "door" mean? Refers to the data bus of the peripheral. The role of the chip select signal is to control whether the data bus of the peripheral is connected or disconnected from the data bus of the processor.

drive

Whoever puts the data on the bus, we say who is the driver of that moment. That is, when the processor writes data to the peripheral, it is driving the data bus, and when the processor reads data from the target peripheral, the target peripheral is driving the data bus. For the address bus, the address bus is always driven by the processor because it is only possible to write from the processor to the target peripheral. When a chip is not selected, we say that it does not drive the data bus.

Tri-state gate

Earlier we said that the data bus of the peripheral chip is in a high-impedance state when it is not selected. When it is selected, its level may be high (1) or low (0). As a result, we say that the peripheral data bus has its chip pins belonging to the three-state gate, that is, there are three states of high level, low level and high resistance state.

Level validity

Earlier we learned what a chip select signal is, and also talk about the three-state gate. It should be pointed out that the chip select signal is usually not a tri-state gate. It only has two states, high level or low level. As we said before, the chip select signal is used to "open the door", and the chip select signal has high and low levels. In the end, is the high level indicating "opening the door"? Still low? For this problem, we say that if a level indicates "opening" for a chip select signal then it is the active level of this signal. For example, for a chip select signal, if the low level means "open the door", then we say that the chip select signal is active low. Although we use the chip select signal to explain the validity of the level here, many signals have validity problems. For example, the read signal and the write signal that we will talk about later have validity problems.

Timing

Earlier we said that when the processor wants to write data to the peripheral chip, the address of the peripheral to be accessed needs to be placed on the address bus, and then the decoder converts the data on the address bus into a chip select. The signal, chip select signal enables the target peripheral chip, and then the processor writes the data onto the data bus to complete a write operation. Obviously, the data on the address line must remain for a period of time before the processor writes the data to the data bus. Otherwise, the decoder cannot validate the chip select signal for a long time.

When the data write operation is completed, the processor does not need to ensure that the address on the address bus is valid. We can see that this series of operations has a strict chronological order, which is called timing. The timing describes the "procedure" of the interaction signal between the processor and the external device. Only by following this "procedure" can the normal communication between the processor and the external device be guaranteed. This is like a traffic light on our road. If our pedestrians and vehicles do not follow their instructions, an accident will occur. Typically, timing diagrams are used to describe the signal "procedures" for communication between chips.

Figure 2 read timing diagram

Figure 3 read timing diagram

From the figure we can see that ADDRESS is the address bus, DQ is the data bus, CE is the chip select signal, and it is active low, its width must be guaranteed to be valid during the read operation. Learning to look at the timing diagram is very helpful for doing embedded system development, because we inevitably have to deal with the chip. In the timing diagram, a lot of time requirement information is usually identified.

When writing the startup code, it is necessary to initialize the chip select address register and read and write timing of each address space. The timing configuration is based on the time requirement of the peripheral chip, which is a very important part of the chip manual. When there are multiple peripheral chips in an address space, we need to consider the time requirements of the slowest peripheral chip. Otherwise, some chips will not work properly.

Read/write signal

When the processor needs to read signals from the peripheral chip, in addition to generating a chip select signal, it is also necessary to tell the peripheral chip that this is a read operation, which is realized by reading the signal; or this signal is used to tell the peripheral chip. This is an operation to write data to a peripheral chip.

I/O port

The peripherals (chips) mentioned earlier are now the time to classify peripherals. In general, peripherals fall into two categories, one is memory peripherals, and the other is non-memory peripherals, which are often referred to as I/O devices. The I/O here is short for Input/Output, ie input Output. As you can see, I/O peripherals are a very broad concept. For a memory peripheral, it is characterized by a continuous space.

For example, SDRAM memory is a memory peripheral. If its capacity is 8 Mbytes, its occupied address space will be 8M. Unlike memory peripherals, the addresses used by I/O peripherals are generally small. For example, an I/O peripheral may have multiple control registers. These control registers are multiple I/O ports (addresses) from the processor. Writing data to this address is to write data to the corresponding register of the peripheral. It can also be read.

For example, a serial port chip may have multiple registers, one for querying the state of the chip, one for setting the function of the chip, the other for reading the data received by the chip from the serial line, and finally, one for Write data to the chip to send data to the serial line. The registers of this serial chip are independent I/O ports from the perspective of the processor.

I/O ports have read and write problems. Some ports are read-only. Some ports are write-only. Other ports can be read or written. The read/write performance is the register of the peripheral chip. The decision is found in the chip's data sheet. It should be noted that some memory peripherals also have I/O ports for certain control. From the name of the I/O port, for the processor, it is a general term for an interface that reads data from the outside or outputs data to the outside.

Interrupt

An interrupt is a signal line that produces high and low levels from a hardware perspective, but understanding it requires a processor perspective. We have said that the processor microscopically, the work done is in order, and the processing of the program can only be the execution of one instruction. If there is a need to access the peripheral chip, and it is possible to issue read and write commands from the processor, since the peripheral is usually much slower than the processor, the peripheral chip needs some time to prepare the required data. In this case, if the processor waits for the return data of the peripheral chip to execute the subsequent instructions, it will take precious time, and these times can be used for other work.

Don't forget, from a macro perspective, processors are often multitasking, and tasks are the scheduling units provided by the operating system. When a task is blocked by waiting for data from the peripheral chip, we can switch to another task to improve processing efficiency. This has a problem. When the processor is processing another task, if the data of the peripheral chip is good, what if the processor is told? correct! It is through the interrupt signal. The high and low levels of the interrupt signal can be used to indicate if an interrupt requires processor attention to handle a particular event (eg, an event with peripheral data ready).

From this point of view, the introduction of interrupts can greatly improve the efficiency of the processor. In order to use the interrupt on the processor, we need to initialize the interrupt controller of the processor at first, such as installing the required interrupt service routine or ISR (Interrupt Service RouTIne), and then opening the interrupt mask bit. The following operations are required in the interrupt service routine:

Read in or write data to the peripheral. Reading or writing usually requires reading the interrupt status register of the peripheral to determine.

Clear the interrupt signal of the peripheral. We know that the interrupt signal is driven by the peripheral chip. In order to tell the peripheral chip that the processor has processed the required work, the processor needs to notify the peripheral chip in a certain way. This method is to write a data to a bit in the register of the peripheral chip. For example, it may be written 1 to clear the interrupt, or 0 to clear the interrupt, which is usually in the peripheral data sheet. Checked. When the peripheral receives a clear interrupt request from the processor, it drives the interrupt line to disable it. For example, if a peripheral's interrupt line is low, it indicates that there is an interrupt, and changing it from low to high means that the drive is invalid.

Clear the interrupt signal identifier of the processor. The processor also often saves the external interrupt signal. When we have processed the interrupt of the peripheral chip, we also need to clear the identifier on the processor to prepare for the next interrupt. It should be noted that the interrupt of the clear peripheral must occur before the interrupt identifier of the processor!

There is also a trigger mode issue for interrupts. There are two trigger modes, one is level trigger and the other is edge trigger. Level triggering means that the level of the level indicates whether the peripheral has an interrupt, and the edge trigger is indicated by the level rise or fall of the interrupt line. Obviously, there are two kinds of edge trigger modes. One is that the interrupt line changes from low to high, which we call the rising edge trigger, and the other is that the interrupt line transitions from high to low, which we call the falling edge trigger. In general, the trigger modes of the interrupt are level trigger, rising edge trigger and falling edge trigger. The process of interrupt setting in the level trigger mode is an important step.

multimeter

A multimeter is usually used to check the level of the level, the size of the resistor, etc., and is one of the commonly used and indispensable tools. In embedded system development, we often use digital multimeters.

Oscilloscope

In the development of embedded systems, we inevitably have to deal with peripheral chips. When debugging the driver, in addition to fully understanding the chip's data sheet, and in the process of software height, we also need to see if the signal level we expect is on the chip. For example, when we write the driver, we need to write the I/O port to operate the peripheral chip. When writing the corresponding I/O port, we know that the chip select signal of the corresponding chip should be valid. Sometimes, we need to verify It happens as expected, which requires an oscilloscope. A general oscilloscope can observe the signal state of two signal lines at the same time.

The oscilloscope provides certain functions, such as setting the way the signal is captured. One of the most important parameters of an oscilloscope is its acquisition frequency. According to the Nyquist acquisition theorem, if we want to use an oscilloscope to look at a signal with a frequency of 100 MHz, then the sampling frequency must be at least twice, or 200 MHz. Some people may ask: Why not use a multimeter to see it? Because the multimeter's acquisition frequency is very low, it is impossible to collect very fast signal changes.

logic analyzer

Simply put, a logic analyzer is an oscilloscope with many signal channels. Through the logic analyzer, we can see the data on the address bus and data bus. Logic analyzers provide programming capabilities for programming when to start collecting data on the bus.

Beam Light

1).Excellent pattern,mute,the best effect of the light is 5 to 30 meters.

2).Competitive price and high quality.

3).LCD Chinese and English bilingual menu,brightness.

4).Suitable for performances,bars,banquet hall,multi-purpose conference room,theater,studio,etc.


Our company have 13 years experience of LED Display and Stage Lights , our company mainly produce Indoor Rental LED Display, Outdoor Rental LED Display, Transparent LED Display,Indoor Fixed Indoor LED Display, Outdoor Fixed LED Display, Poster LED Display , Dance LED Display ... In additional, we also produce stage lights, such as beam lights Series, moving head lights Series, LED Par Light Series and son on...

Beam Light Series,Sharpy Beam Light,Led Moving Beam Head Light,Led Beam Light

Guangzhou Chengwen Photoelectric Technology co.,ltd , https://www.cwstagelight.com