In traditional control systems, people often use single-chip microcomputers as the control core. However, this method has complex hardware connections and poor reliability. In addition, the number of ports, internal timers and interrupt sources of single-chip microcomputers are limited, and in practical applications, external expansion chips are often required. This undoubtedly brings many inconveniences to the design of the system.
Now many systems use programmable logic devices (CPLD) as the control core. Compared with traditional designs, it not only simplifies the interface and control, improves the overall performance and reliability of the system, but also creates conditions for system integration. However, the D flip-flop resources of programmable logic devices are very limited, and programmable logic devices are not as convenient as single-chip microcomputers in controlling timing. Many unfamiliar users often find it very difficult to use. The two-way communication controller composed of programmable logic devices and single-chip microcomputers overcomes the shortcomings of both and maximizes the advantages of both.
1 Principle of bidirectional serial communication between CPLD and MCU AT89C51
1.1 Serial communication from MCU to PLD
The serial communication interface circuit from the microcontroller to the CPLD is designed in the CPLD using the VHDL language to design an eight-bit shift register with serial input and parallel output, and its port is connected to P1.4~P1.7 of the microcontroller, as shown in Figure 1. CS is the microcontroller selection signal, and when it is low, the eight-bit register is enabled; when the rising edge of the DCLOCK signal reaches the clk port, the eight-bit shift register will shift in one bit of data output by the microcontroller to cxin; when the eight-bit data in the microcontroller A register is to be transmitted to the CPLD, eight consecutive rising edges are generated at P1.6, and the microcontroller will sequentially shift the data in A to cxin, and after eight times, the data segment in A will appear in cxout of the CPLD.
The VHDL source program is as follows:
entity cuanxing is
port (clk,cxin,cs:in std_logic;
cxout:out std_logic_vector(7 downto 0));
end;
architecture rtl of cuanxing is
signal shift:std_logic_vector(7 downto 0); parallel output of eight-bit temporary variables
begin
process(clk)
begin
if(cs=\'0\')then
shift<=(others=>\'0\'); if not selected, output all zeros
elsif(clk\'event and clk=\'1\')then;If the rising edge reaches clk, it is selected.
shift(7 downto 1)<=shift(6 downto 0); eight bits of data are shifted forward one bit
shift(0)<=cxin; the lowest bit is input by cxin
end if;
end process;
cxout<=shift; send eight-bit variable to port
end rtl;
The corresponding single-chip microcomputer control subroutine is as follows (the data to be sent is stored in A):
CS EQU P1.4
EN EQU P1.5
DCLOCK EQU P1.6
DOUT EQU P1.7
CONV: PUSH 07H
MOV R7,#8 ; store the shift number 8 into R7
CLR DCLOCK
SETB CS ; Select shift register
CLR EN
CLR C
JXL: RLC A; shift left one bit and send the data to be sent to CY
MOV DOUT, C ; send to port
ACALL YS1MS
SETB DCLOCK; Give a rising edge to shift data into the shift register
ACALL YS1MS
CLR DCLOCK
DJNZ R7, JXL; if it is less than 8 times, send the next one
SETB EN; All eight bits of command words are shifted in, giving EN a rising edge to make the CPLD perform the corresponding operation
ACALL YS1MS
POP 07H
RET[page]
1.3 Serial communication from PLD to MCU
The serial communication from PLD to MCU is similar to the serial communication from MCU to PLD, except that the eight-bit register is changed to parallel input and serial output, and its port is shown in Figure 2. When the MCU's cs=1, the register is selected; when load=1, the data to be sent is loaded to bxin; when the clk rising edge arrives, the data is shifted out to bxout one bit at a time, and at the same time, the MCU receives the data from bxout one bit at a time. After eight rising edges of clk, the data loaded into bxin is transmitted to the A register of the MCU (the VHDL and MCU source program are not given due to space limitations).
2 Implementation principle of dual control system
Since the microcontroller has limited ports, most of the peripheral device connections are completed by CPLD, while those peripheral devices with higher requirements for timing control are indirectly controlled by the microcontroller. The so-called indirect control means that the user can customize many command words, and each command word corresponds to one or a series of operations of CPLD. When the microcontroller wants an external device to implement a certain function, it can transmit the command word to the programmable logic device CPLD through serial communication. After the CPLD receives the command word and judges the command word, it will perform the corresponding operation after the rising edge of EN arrives. It is worth mentioning here that after the command word is transmitted to the CPLD, the CPLD can only perform the corresponding operation after the rising edge of EN arrives. This is to prevent the command word from causing the CPLD to malfunction during the word transmission.
When an external device has an interrupt signal fed back to the controller, a specific command word can also be sent from CPLD to AT89C51, causing AT89C51 to generate an interrupt for processing. However, no matter how many peripheral devices need to generate interrupt control. In the AT89CF51 interrupt subroutine, the serial communication program from CPLD to the microcontroller is run, and the specific command word is read into the A register, so that it can be known whether it is an interrupt generated by a peripheral device (defined by the user), and then what kind of external operation is required.
This dual control system is very flexible and convenient to use in project design. Here, an eight-bit command word is used, and up to 256 command words can be customized. Since both a single-chip microcomputer and a CPLD are used, programming is very flexible and convenient, and engineers can choose accordingly according to their own characteristics. For example, some people's single-chip microcomputer programming ability is slightly better than CPLD language programming, so he can define the operation corresponding to the command word in VHDL language programming to be simpler (the simplest is to make a certain pin high or low); if you want to simplify the programming of the single-chip microcomputer, you can make the operation corresponding to the specific command word in VHDL language programming more complicated.
The programming process of the microcontroller is to write different command words to the A register and then call the serial communication subroutine. If it is a VHDL command word, then call the serial communication subroutine. If the VHDL command word corresponds to a simpler program, then more command word calls will be required to complete the operation of a specific peripheral device. Vice versa, that's all.
In short, it is much easier to develop projects using a dual controller consisting of a single-chip microcomputer and a CPLD than to use them separately.
Previous article:Garbage weighing and charging control system based on single chip microcomputer AT89S51
Next article:MCU drives ds18b20 four-way temperature patrol detection program
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
- Meet the Electrocardiogram (ECG) Si1172 ECG Evaluation Kit
- TI C6678 Multi-core DSP Architecture
- [TI mmWave Radar Review] + Belated AWR1443 EVM Board Unboxing
- Watch Shuige's video for a reward | MIPI D-PHY transmitter physical layer consistency test
- Summary of Problems and Solutions in CCS6 Compilation
- [STM32WB55 review] +thread trial 1
- Guess the question about the list of materials for the undergraduate group of the electronic competition: Sound source localization system
- 【ST NUCLEO-G071RB Review】_01_First impression
- Why use discrete components for preamplification?
- MSP430IO Driver