introduction
In today's industrial control systems, in order to improve the real-time performance and applicability of the system, DSP is generally used to complete the core algorithm and control, while MCU is used to implement human-computer dialogue to achieve real-time control functions. In this way, DSP and MCU need an efficient data bus to complete the large amount of data transmission between them. The SPI bus is an ideal design solution because it occupies fewer interface lines, has high communication efficiency, and is supported by most processor chips.
In view of the actual use requirements of AC servo systems, TI's high-performance DSP controller TMS320LF2407A (referred to as "2407A") is used as the control core; MSP430F149 from the MSP430 series microcontroller produced by TI is selected as the control chip of the human-machine interface to realize the functions of button, data acquisition and display; SPI serial port communication is used to realize data transmission between the microcontroller and DSP.
1 System Hardware Composition
1.1 MSP430
The MSP430 series of microcontrollers are a new generation of microcontrollers developed by TI in recent years. The design of this microcontroller breaks the convention and adopts a brand-new concept. Its outstanding advantages are low power supply voltage, ultra-low power consumption, and multiple functions. Because its functions far exceed those of other series of microcontrollers, it is also called a "hybrid microcontroller". MSP430 has a very high degree of integration. It integrates multi-channel 12-bit A/D conversion, on-chip precision comparator, multiple timers with PWM function, on-chip USART, watchdog timer, on-chip digital control oscillator, a large number of I/O ports and large-capacity on-chip memory. At the same time, MSP430F149 is a Flash memory type microcontroller with good simulation development technology. It is equipped with a JTAG simulation interface and a high-level language compiler. Under the system support software, hardware debugging and software development of the target system can be realized online, including assembly language, C language, connection and dynamic debugging, single-step, multiple breakpoints and tracing, and all memories and registers are open, which can conveniently and reliably carry out software and hardware development of the system [12].
Based on the above characteristics, this series of microcontrollers are widely used in portable instruments, intelligent sensors, practical testing instruments, motor control, home automation and other fields.
1.2 TMS320LF2407A
2407A is designed by TI to meet the needs of industrial control applications, especially motor control. It integrates a high-performance DSP core and many peripherals into a single chip. The processing speed of 2407A is 40 MIPS, which can meet the needs of quickly processing large amounts of data and algorithms.
The 2407A has a rich set of peripheral modules: 3K words of Flash program memory, 1.5K words of data/program RAM, 544 words of dual-port RAM (DARAM) and 2K words of single-port RAM (SARAM), 2 event managers EVA and EVB, 16-channel input A/D converter, watchdog timer module (WDT), serial communication interface (SCI), 16-bit serial peripheral interface module (SPI), controller area network (CAN) 2.0B module, phase-locked loop-based clock generator, up to 40 general-purpose input/output pins that can be individually programmed or reused, and 5 external interrupts. It can be seen from this that the 2407A does have a strong real-time processing capability and is one of the ideal devices for high-performance servo drive control [3].
1.3 Hardware interface design and implementation of SPI communication
The hardware connection of SPI communication equipment only needs to connect the host's transmission with the slave's reception, connect the host's reception with the slave's transmission, and output the clock signal generated by the host to the slave's clock pin. The hardware connection between the microcontroller and the peripheral is shown in Figure 1.
Figure 1 Interface connection circuit between MSP430F149 and DSP
The single-chip microcomputer MSP430F149 is used as the host of serial communication, and the DSP 2407A is used as the slave. Among them, SPICLK is the SPI clock pin, SPISIMO is the SPI slave input/active output, SPISOMI is the slave output/active input, and SPISTE is the slave transmit enable.
As shown in Figure 1, SPI synchronizes the host and the slave through a clock lead. Therefore, its serial data exchange does not need to add start bits, stop bits and other format bits for synchronization. The data to be transmitted is directly written into the host's SPI transmit data register. This writing process automatically starts the host's transmission process, that is, the content of SPITXBUF is moved one bit at a time to the pin SPISIMO under the beat of the synchronous clock SPICLK; for the slave, the data appearing on the pin SPISIMO is also moved one bit at a time to the slave's shift register under the beat of SPICLK. After receiving a complete data block, the interrupt flag is set to notify the slave that the data block has been received, and at the same time, the content received by the shift register is copied to the slave's SPI receive data register SPIRXBUF. It can be seen that the user programming only needs to write data to the SPI transmit data register when sending data, and read the SPI receive data register when receiving data. The rest of the work is automatically completed by the SPI module [4]. [page]
2 Software Design
Both MSP430F149 and DSP allow users to program in C language and assembly language. In the system, DSP realizes real-time control of the motor and has strict requirements on the running speed, so the program is implemented in assembly language. MSP430 realizes functions such as key display, data management and instruction transmission, and has low requirements on the running speed, so it is implemented in C language.
The main tasks of software design are: initializing the corresponding registers; the microcontroller sends data on the corresponding interface; the DSP receives the data arriving at the serial port in a timely manner, identifies and saves the data.
2.1 Communication protocol settings
In order for two devices to communicate with each other, the protocol for transmitting data must first be specified. Generally speaking, the host sends commands and configuration information to the slave, and the slave sends feedback information to the host. The system mainly implements the MCU sending data information to the DSP. The MCU first sends command data to indicate the start of the process of the host sending data. If 0 is sent, it marks the beginning of the process. In order to avoid erroneous operation, the command data is sent twice. When the two data received by the DSP are both 0, the corresponding operation is performed, otherwise the command data is retransmitted. Then the data that the MCU needs to transmit is stored in an array and transmitted in sequence. For example, if 3 data are to be transmitted, arrays a[0] and a[1] are defined to store the command data, and a[2] to a[4] are defined to store the arrays to be transmitted.
2.2 Serial port initialization
The SPI initialization of the microcontroller includes: configuring the corresponding I/O port as an interface with SPI special functions, selecting the clock mode, selecting the baud rate, selecting the length of the data to be sent and received, and enabling the corresponding internal clock. All settings are implemented by designing the corresponding SPI control registers [5].
The initialization procedure is as follows:
WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog
BCSCTL1 = RSEL0 + RSEL1 + RSEL2; // XT2on
BCSCTL2 = SELM1 + SELS; //Select high-speed crystal oscillator as clock source
UCTL1 = CHAR + SYNC + MM + SWRST; //SPIZ master mode 8-bit data, MCU as active mode
UTCTL1=STC+SSEL1+CKPL; //Data is output on the falling edge, system master clock, three-wire mode
UBR01=0x02;
UBR11=0x00; //Baud rate is set to fclk/2
UMCTL1=0x00;
ME2=USPIE1; //Module enable 2
P5SEL|=0x0F; //The lower 4 bits are the module port function
P5OUT|=0xf0;
UCTL1&= ~SWRST; //Reset ends
The SPI initialization of 2407A is similar to that of the microcontroller, but the DSP is a slave device, so its baud rate is determined by the master device and no further design is required.
2.3 MSP430 sends data
The system has membrane buttons and LCD display, which can easily send data when needed. For example, after designing the parameters, a selection interface will appear, allowing the operator to choose whether to save the parameters, back up the parameters, or transfer the parameters to the DSP. The operator can choose the corresponding function according to his or her different needs. If the parameter transfer function is selected, the microcontroller will jump to the corresponding program segment to perform the parameter transfer task. The data sending program is as follows:
P5OUT &= 0x1f; //Chip select DSP chip
while((U1IFG & UTXIFG1) != UTXIFG1);
for(k=0;k<6;k++) {//Number of data transmitted
P5OUT &= 0x1f;
while((U1IFG & UTXIFG1) != UTXIFG1);
TXBUF1=a[k]; //Send data
while((UTCTL1&0x01)==0);//Sending completed
delay(10);
P5OUT &= 0x2f;
}
2.4 DSP receives data
DSP receives data sent by the microcontroller through interrupts, and an interrupt occurs every time a data is transmitted. After the main program completes the initialization of the DSP, it enters the waiting state. Once the interrupt signal of the microcontroller is received, the DSP enters the interrupt service subroutine and stores the received data in the storage unit starting at 70H. When all data transmissions are completed, these data are assigned to the corresponding variables. It should be noted here that the SPIRXBUF of the DSP is 16 bits, and the data sent by the microcontroller is 8 bits, so after the DSP receives the data, it needs to process it and mask the upper 8 bits. This can be achieved by ANDing with 00FF. The interrupt program flow is shown in Figure 2.
Figure 2 DSP interrupt program flow[page]
The interrupt procedure is as follows:
LDP #6
LACC K;K=K+1
ADD #1
SACL K
MAR *,AR2; AR2 is the storage unit address pointer
LDP #DP_PF1
LACC SPIRXBUF
AND #00FFH; high bit is blocked
SACL *+
LDP #6
LACC K
SUB #1; Determine whether it is instruction data
BCND L1,NEQ
LDP #0
LACC #70H
SUB #0
BCND L3, NEQ; if not 0, jump to L3
BL2; if it is 0, jump to L2
L1: ...; Determine whether it is the second data
L4: LACCK; determine whether the data transmission is completed
SUB #05H
BCND L5,EQ
BL2
L5: LDP #0; All data sent
LACC 72H
LDP #6
SACL SPEED; assign value to corresponding variable
……
L3: SPLK K,0;K=0
LDP #0
LAR AR2,#70H; address pointer points back to 70H
L2: CLRC INTM; open interrupt
RET
3 Conclusion
Experiments have shown that the use of SPI communication for serial communication between the MSP430 microcontroller and the DSP fully meets the real-time requirements of the servo system. At the same time, due to the relatively complete functions of the SPI interface, clear communication protocols, and simple timing, serial communication of data between the DSP and the host can be easily realized without the addition of other components, which simplifies the system design and enhances the system's real-time processing capabilities and application scope. The structure is highly flexible and easy to expand, while reducing the burden on the main CPU and improving the reliability of the system.
References
[1] Hu Dake. Principles and Applications of MSP430 Series Ultra-Low Power 16-bit Microcontrollers[M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2000.
[2] Texas Instruments.MSP430x1xx Family Users Guide (SLAU049B.pdf), 2002.
[3] Liu Heping, Yan Liping, Zhang Xuefeng, et al. TMS320LF240X DSP structure, principle and application [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.
[4] Ren Zhibin, Che Changzheng. Application of Serial Peripheral Interface SPI[J]. Application of Electronic Technology, 2002, 29(10):2022.
[5] Wei Xiaolong. MSP430 series microcontroller interface technology and system design examples [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.
Previous article:Design and implementation of shortwave RF frequency source based on DDS
Next article:Working principle of IC card smart water meter based on MSP430F41
Recommended ReadingLatest update time:2024-11-16 17:48
- 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