“At present, in many application fields, there are many so-called “smart instruments” and “intelligent instruments”, and most of these systems are computer application systems with single-chip microcomputers as the core. Among the many single-chip computers, Intel’s 8XC196MC/MD is the best among them. It is one of the most powerful 16-bit microcontrollers, and can be used for almost all kinds of measurement and control work, especially in motor control.
“
Author: Liu Suli
At present, in many application fields, there are many so-called “smart instruments” and “intelligent instruments”, and most of these systems are computer application systems with single-chip microcomputers as the core. Among the many single-chip computers, Intel’s 8XC196MC/MD is the best among them. It is one of the most powerful 16-bit microcontrollers, and can be used for almost all kinds of measurement and control work, especially in motor control. However, because the 8X196MC/MD microcontroller does not provide a hardware universal asynchronous transceiver (UART), this brings some inconvenience to users who are used to UART. However, using the special PTS mode, not only can serial communication be realized, but also the operation is more flexible, more efficient, and the CPU overhead is smaller; both asynchronous (ASIO) and synchronous (SSIO) functions can be realized; The rate is established by EPA, including check digit and stop digit, and the data format for sending and receiving can reach 16 bits/character.
1 Overview of EPA and PTS
1.1 EPA and its working principle
EPA (Event Processor Array), similar to HSIO, handles time-dependent input and output events, but is more flexible and efficient. In EPA, there are mainly two types of modules – capture/compare module and independent comparison module, which are used to realize capture and compare functions. Each module is associated with a designated input/output pin, supports its high-speed input and output functions, and all modules can generate interrupts. “Capture” is used to capture the transition events generated on the pin, including positive transitions, negative transitions and positive and negative transitions, and record the moments when these events occur; “Compare” is to compare with a predetermined time, the time As soon as it arrives, the following selected output functions are performed: reset the timer, start an A/D conversion, generate a reload trigger signal for the waveform generator, change the output pin state, etc.
1.2 PTS and its working principle
PTS (Peripheral Transaction Server, peripheral transaction server), is a special interrupt response method. Compared with the normal interrupt response, the PTS response maps the same interrupt to the corresponding PTS channel. This channel generates a PTS cycle, which is inserted into the normal instruction stream just like a DMA cycle, without additional software overhead, so its CPU overhead is much less than the general interrupt response. PTS has a PTS vector table, its arrangement order and priority order are the same as normal interrupt vector, but remove NMI, illegal opcode and software trap 3 kinds of interrupts. Except for NMI, all PTS channels have higher priority than any normal interrupt. Each PTS vector points to a PTS control block (PTSCB), which specifies the microcode that should be executed. It must reside in the internal RAM space, each control block contains 8 bytes, and its first address should be divisible by 8.
8XC196MC/MD has 4 kinds of PTS work ways, need to use its SIO (serial input/output) way to realize serial communication. Among them, there are two ways of SIO: ASIO (asynchronous serial I/O) and SSIO (synchronous serial I/O). To work in a certain mode, the corresponding control block (PTSCB) must be established. There are two control blocks corresponding to the SIO mode, as shown in Figure 1. Only BAUD and SAMPTIME are explained here.
BAUD (LO and HI): Store 16-bit data that controls the baud rate of SIO operation. In asynchronous mode, it is calculated by the following formula: FXTAL/(4 × baud rate × EPA preset value). Among them: FXTAL is the input frequency of XTAL1 pin, the unit is Hz.
SAMPTIME: It is only used for asynchronous reception of most sampling methods, and is used to specify the sampling time interval, which is calculated by the following formula: FXTAL×Tsam/2-9. Among them, Tsam is the sampling interval time (μs); FXTAL is the same as above, but the unit is MHz.
2 Serial communication using EPA and PTS
2.1 Basic idea
The basic idea of using EPA and PTS to realize serial communication is: First, select an EPA capture/comparison module as the receiving module of serial communication, select an independent comparison module (or select a capture/compare module and only use its comparison mode) As the sending module of serial communication, it constitutes the hardware port of serial communication. Then, open up the corresponding PTS channel for the selected EPA module, and write the sending and receiving PTS module according to the communication requirements. Both EPA and PTS work together to realize serial communication.
2.2 Application examples and specific implementation
The following takes the commonly used asynchronous serial communication mode as an example to introduce the specific implementation principle and method. This example uses an EPA capture/compare module CAPCOMP0 to generate the shift clock, P2. O is used as the transmitting end (TXD), the baud rate is 9 600 bps, 8 data bits, no parity bit, 1 stop bit, timer 1 is used as the time base, 16MHz crystal oscillator. Due to space limitations, only asynchronous serial transmission is introduced.
2.2.1 Establish and locate the control block
To use PTS to realize serial communication, the corresponding control block must be defined first, and located at the first address that can be divisible by 8; the control block address must also be assigned to the PTS vector. The specific implementation code is as follows:
2.2.2 Send initialization and PTS interrupt subroutine
When sending, use a comparison module in the EPA, or use a capture/compare module to make it work in a comparison mode, which is mainly used to generate a shift clock when sending to ensure the specified bit period. The specific process is as follows: First, a falling edge is generated on the specified sending pin (to ensure that the falling edge is generated, the pin should be set to 1 first), and the time register of the EPA comparison module ( CAPCOMPx_TIME or COMPx_TIME) to specify the transmitted bit period. Then, turn on the interrupt and PTS function, and start the data transmission process; in the future, a PTS cycle will be generated every other bit cycle. In each PTS cycle, the data in the DATA register is shifted to the designated sending pin one by one until the After one bit is removed, an End_of_PTS interrupt is generated, and the frame data is sent. The number of bits of data per frame is specified in the ptscount of the control block. If you need to continue to send data, it is necessary to re-initialize the PTSCB, EPA time register and corresponding pins in the interrupt service routine, and start the sending process again. The transmitted data is stored in the transmit array, and the number of transmitted frames, that is, the number of data, is controlled by T_Count. The specific implementation code is as follows:
Epilogue
The method and example have been verified in practical applications. Practice has proved that it can fully meet the needs of serial communication, and is more efficient and flexible.
The Links: MD805TT00-C1 G190ETN013