With the development of electronic technology, printers have been widely used in various fields and have become an important means of data output for various intelligent digital instruments. Among them, thermal printers are becoming more and more popular due to their unique features such as small size, light weight, high reliability, clear printing characters, no noise, and even paper feeding. They have become the first choice for small medical instruments such as electrocardiographs.
The following takes the 12-lead synchronous electrocardiograph developed by the author's research group as an example to introduce the use of an ordinary 52 microcontroller as the main control chip and the application of a serial thermal printer to realize various ways of ECG pattern printing, and focuses on describing the 12-lead synchronous printing method. Program implementation plan.
1 System hardware design
The system is equipped with a built-in digital printer, which is mainly composed of a thermal print head (W216-QS) and a stepper motor. The W126-QS dot matrix thermal print head prints data using serial input. It not only contains a 1728-bit shift register composed of a C-MOS integrated chip, but also a heating element made by high-density thick film technology. These heating elements are driven by latching and switching transistors and can produce 1728 dots on thermal printing paper, corresponding to a printing width of 216mm and a resolution of 8dot/mm. The printing data required by the thermal print head is serial data, and the data transmission follows the communication protocol of the SPI port. The system uses a port line to simulate the working mode of SPI to communicate with the print head. The circuit is shown in Figure 1.
Considering that the 52 microcontroller has 256 bytes of internal RAM, the system also expands an HM628128 to store 12-lead ECG data and intermediate conversion results.
2 System software preparation
There are two key issues in the implementation of digital printing: ① How to convert ECG data into printing data; ② How to output the data to a digital printer. The usual method is to convert the data and output it to a printer for printing. This saves memory space; the disadvantages are that the program is complex to implement, has poor versatility (different printing methods have different data output programs), and the system functions are not easy to expand. The printing point position must be considered for data conversion and output, and each point of data output must be called A one-time program increases system overhead. This method is not adopted in the system software. Instead, a 216-byte printing buffer is opened in the memory, and the 1728 points of the thermal print head are corresponding to the 216×8-bit data. Each time the one-line data to be printed is converted. Then output. In this way, you only need to consider the printing position and method when converting data. The output program only needs to output 216 bytes of data bit by bit, and the output subroutine only needs to be called once for each line of data printed, reducing system overhead. The disadvantage is that it takes up system resources, which is particularly obvious in 12-channel synchronous printing.
The system program implements three printing methods: printing 12-lead data in two times, printing 6 leads each time, 12-lead simultaneous printing, and vertical printing (the printing effect is shown in Figure 2). In each printing program, the subroutine for sending the printing data to the digital printer through the analog SPI port is shared. The difference lies in how to convert the ECG data into printing data.
2.1 I/O port line simulates SPI port
The SPI (Serial Peripheral Interface) bus serial port is a synchronous serial peripheral interface proposed by Motorola. It communicates through four lines: clock line (SPKCLK), data output line (SPIMISO), data output line (SPIMOSI), Chip select line (CS), internal serial-parallel/parallel-serial conversion is completed through the SPIDAT register. It mainly works in a master-slave system. One master device can bring multiple slave devices. The master device controls bus conflicts through the chip select line, so that only one slave device exchanges data with the slave device at the same time.
The serial thermal array printer data transmission used in the system uses SPI timing, but ordinary 52 microcontrollers do not have an SPI port, so I/O port lines are used to simulate SPI timing. Considering that the MCU as the master device in the system always sends data, and the digital printer as the only slave device always receives data, you only need to use the port line to simulate the clock line (SPIKCLK) and data output line (SPIMOSI) of the SPI port. The program Just simulate SPIDAT to complete parallel-to-serial conversion. As mentioned before, the number of data points printed by the print head is 1728 points, the resolution is 8mm/mV, corresponding to 216 bytes of data. For this purpose, a 216-byte space is allocated from the internal RAM as a print buffer, and the program reads from the buffer The area reads the data in sequence, and under the control of the analog clock line, the parallel data is converted into serial data and sent to the printer's shift register bit by bit. After the end, the LATCH latch signal and the print head heating pulse STROBE are sent, so that the thermal Use sensitive printing paper to print out a line of ECG patterns, and drive the stepper motor to move the paper forward to print continuously. The SPI port simulation program is as follows:
OUTPUT:
Site protection
LCALL INTRAM; initialize the internal print buffer
MOV R0, #Dat_Buff; initialize R0 to the last address of the buffer
DAT_OUT:
MOV A,@R0 ;Read data from buffer
MOV R7, #08H; initialize R7 to control parallel/serial data conversion
CONT_CHG:
RRC A; implement parallel-to-serial conversion for ACC circular right shift
MOV P1.3,C sends serial data to printer
SETB P1.1; Analog SPI clock
NOP
CLR P1.1
DJNZ R7,CONT_CHG; Determine whether the 1-byte data has been converted
DEC R0; addressing the next byte
CJNE R0, #15H, DAT_OUT; determine whether all data has been converted
CLR P1.2; Generate data latch signal
NOP
SETB P1.2
NOP
CLR P1.0; generates heating pulses
LCALL HEATDLY; call heating delay program
SETB P1.1
LCALL MOTOR_RUN; stepper motor paper feeding
restore scene
RET
2.2 Printing algorithm
The digital printer essentially realizes the correspondence between data and printing points. That is to say, the value range of 8-bit ECG data is 0 to 255, which corresponds to 256 points on the thermal printing paper. A certain point on the paper is changed by the thermal unit. Black shows the size of the data. This requires converting the data that represents the actual ECG size (hereinafter referred to as original data) into data that can indicate the location of the heating point (hereinafter referred to as position data). The points corresponding to the ECG data are printed out in sequence through the control of the position data. , an electrocardiogram can be obtained. However, since the ECG data obtained by the system's analog-to-digital converter are discrete, if only their corresponding points are printed out, only some discrete points will be obtained. To obtain a continuous ECG pattern, adjacent discrete points need to be sorted according to a certain The algorithm connects them. The discrete point connection algorithm is different for vertical printing mode and horizontal printing mode. Due to space limitations, in the following introduction to the implementation of the printing method, only horizontal 12-lead simultaneous printing and vertical printing will be elaborated in detail, while only the implementation ideas for 6-lead printing will be introduced.
2.2.1 Horizontal 6-lead printing
The length of the ECG chart is 216mm, and 32mm is allocated for each lead ECG signal, which corresponds to the continuous 32 bytes in the print buffer. The position data after conversion of the print data is stored in these 32 bytes. The 12-lead ECG data is divided into two groups. When one group is printed, the remaining 6-lead data is printed. For the specific implementation process, please refer to the horizontal 12-lead printing method.
2.2.2 Horizontal 12-lead simultaneous printing
During the implementation of the 6-lead printing method, it was noticed that in most cases, in a complete ECG waveform, only the main peak of the QRS wave is high enough to fill the entire space, and the other bands have smaller amplitudes and occupy less space, and these bands It can provide more information. In addition, printing the 12 leads separately is not conducive for doctors to compare the ECG waveforms of different leads at the same time. With 12-lead synchronous printing, although there will be partial overlap of waveforms, it has little impact on the diagnosis of some heart diseases and can achieve more intuitive results.
The basic idea of implementing the 12-lead synchronous printing program is the same as that of 6-lead synchronous printing. The difference is that when the 12-lead data is printed on 216mm wide printing paper at the same time, the phenomenon of overlapping ECG patterns of different leads will inevitably occur. Corresponding memory units will also be reused. If you simply apply the 6-lead printing program, the data of the previous lead will be washed out by the data of the adjacent leads, so that the graphics cannot be displayed correctly. Figure 3 lists the thermal paper space and buffer memory units allocated for each lead (assuming the cache address is 0x1DH~0xEDH). It can be seen from Figure 3 that except for the 16mm space in front of lead I and the 16mm space in the back of lead V6 that are not reused, the other spaces on the printing paper are shared by the two leads. Internal RAM usage is similar. For this purpose, open an image area of the internal print buffer in the external RAM (the size is 216 bytes, the lower 8 bits of the unit address are the same as the corresponding unit of the memory, such as the internal RAM 0x1DH unit corresponds to the external RAM 0xXX1DH), and connect the 12-lead Divided into two groups: one group (I, III, aVL, V1, V3, V5) is still stored in the internal memory, while the other group (II, aVF, V2, V4, V6) is stored in the external image area, in the 12-channel When the connected line data is converted and needs to be printed, just AND the two parts according to the corresponding units. This can not only solve the above problems, but also save internal resources and reduce the difficulty of programming.
As mentioned before, different leads occupy different printing spaces. Therefore, for a certain lead's ECG signal, the printing interval must be determined first, and then the relative position of the printed data in this interval must be determined.
Assume that the starting byte of the printing space occupied by a certain lead is the n-th byte, and the ECG data to be printed is m. Divide m by 8 to get the quotient k, and the remainder is 1. Then the ECG data corresponds to Bit 1 of the logarithm (nk) byte. That is, the position data corresponding to the ECG data is the (nk)th byte (bit 1 of this byte is set to 1, and other bits are cleared to zero). Therefore, when printing this ECG data, only the first bit of the (nk)th byte in the 32-byte print data to be transmitted by this lead is 1, and the others are all 0.
Similar to the LCD display, for the ECG signal of one lead, to realize ECG printing, the two ECG data must be connected with a line. That is, for an ECG curve, the initial display data point only displays 1 point in the starting column; starting from the second data point, the line segment between the previous data point and this data point is displayed in the next column. On thermal printing paper, it means heating all the points between the two data points, and corresponding to the memory, it means setting all the data between the two points to 1.
For the -lead ECG signal, first read the first ECG data, convert it into 32-byte position data and print it directly. Starting from the second ECG data, in addition to converting it into position data, it also needs to be compared with the previous data. The position data corresponding to the large number is subtracted from the position data corresponding to the decimal number, and then the result is added to the position data of the large number. The result is the 32-byte data that should be sent for this ECG data, that is, the connection operation with the previous ECG data is completed. The analysis found that the connection algorithm only affects the data between non-zero bytes in the connected two position data. In order to simplify the calculation, it is only necessary to subtract these bytes instead of calculating all 32 bytes. For addition, you only need to add the non-zero bytes in the position data corresponding to the large number, that is, single-byte addition.
For example, for the ECG signal of lead V6, the previous data is 37H and the next data is 55H. The printing interval assigned to lead V6 is 1DH~3DH. According to the position data conversion algorithm, the position data of 37H is the 37H byte. The content of this byte is 80H, and other bytes are 00H; the position data of 55H is the 33H byte, the content of this byte is 20H, and other bytes are 00H. Since 37H<55H, it should be the position data of 55H in the ECG data minus the position data of 33H. The calculation is shown in Figure 4.
2.3 Portrait printing procedure
Vertical printing enables simultaneous display of 12-lead data without overlap. In this way, doctors can refer to and compare the changing trends of various waveforms at the same time to facilitate the diagnosis of diseases.
The width of the thermal printing paper is 216mm and the resolution is 8dot/mm. This way, it can print up to 1728 points, which correspond to the 1728 consecutive ECG data of a certain lead, that is to say, the nth data in the lead sequence. Corresponds to the nth point in the one-line graph. Compared with die-direction printing, longitudinal printing still has to solve the problem of connecting discrete points; but compared with horizontal sequential printing, that is, printing points in time sequence, the difficulty lies in the need to connect multiple points of the same value at different times. The points are printed simultaneously, that is, the printing points are printed in spatial order.
First define a memory unit to store the scan value so that it changes from the maximum value of the current channel data to 0, and compares it with each data of the channel in turn: if they are the same, the corresponding point will be traced; if it is small, it will not be traced; if it is large, the current center value needs to be Two adjacent points of electrical data are compared with the scan value. As long as one of them is larger than the scan value, the corresponding point is traced, and the corresponding data location in the memory of the device to be traced is set to 1.
For example, if the first byte of the print memory buffer is n and the size is 216 bytes, and the current mth ECG data in a certain lead sequence is v, and the scan value at this time is w: ①v>w, Then continue to compare the m+1th data; ②v=w, then the corresponding point needs to be traced; ③v
Previous article:Application of single chip microcomputer in micro printer
Next article:Application of EM78 series microcontroller in infrared remote control system
- 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
- I need help from a great God to look at this circuit diagram, thank you very much
- FPGA Global Clock Constraints (Xilinx)
- The 2020-2021 ON Semiconductor and Avnet IoT Innovation Design Competition awards have been announced!
- How to implement this email sending program? How to write program analysis? Please help me answer
- How to measure BLE power consumption (one of the most viewed app reports)
- 1. [Learning LPC1768 library functions] LED experiment
- [Synopsys IP Resources] How many steps are required for a successful RDC sign-off?
- Use Burn in software to test and vibration test the hard disk and a temperature alarm appears
- [Bing Dwen Dwen Award List] 2022 Digi-Key Innovation Design Competition
- Have you ever done this kind of impedance marking that makes people collapse and go to the hospital?