In microcomputer measurement and control systems, A/D conversion is often used. A common method is to expand one or more A/D acquisition cards. When there are few analog quantities or slowly changing signals such as temperature and pressure, using a bus-type A/D card is not the most appropriate and economical solution. Here we introduce a sampling module with GNS97C2051 microcontroller as the core and a TLC2543 12-bit serial A/D converter. The sampled data of this module is level converted from the serial port of the microcontroller and sent to the host computer (IBM PC compatible). The serial port COM1 or COM2 forms a method of serial data acquisition and serial data transmission. It has been confirmed by practical debugging that this module has low power consumption, high sampling accuracy, good reliability, simple interface, and has certain practical value.
1 Introduction to main components
1.1 TLC2543 serial A/D converter
The module uses TI's TLC2543 12-bit serial A/D converter and uses switched capacitor successive approximation technology to complete the A/D conversion process. Because it is a serial input structure, it can save 51 series microcontroller I/O resources and is affordable. Its characteristics are:
|
The pinout of TLC2543 is shown in Figure 1. In Figure 1, AIN0~AIN10 are the analog input terminals; they are the chip select terminals; DIN is the serial data input terminal; DOUT is the three-state serial output terminal of the A/D conversion result; EOC is the conversion end terminal; CLK is the I/O Clock; REF+ is the positive reference voltage terminal; REF- is the negative reference voltage terminal; V CC is the power supply; GND is the ground.
1.2 GMS97C2051 microcontroller
GMS97C2051 is an 8-bit microcontroller with extremely high performance and price ratio jointly launched by Wuhan Liyuan Company and South Korea's LG Company. Its instruction system is fully compatible with the MCS-51 series. GMS97C2051 is compatible with AT89C2051 (can be directly replaced), but its performance-price ratio is better than AT89C2051. The pinout is shown in Figure 2.
1.3 Level converter MAX3232 MAX3232 is an RS-232 transceiver. It is simple and easy to use. It is powered by a single +5V power supply. It only needs a few external capacitors to complete the conversion from TTL level to RS-232 level. The pin arrangement is shown in Figure 3. 2 Hardware design The hardware circuit is shown in Figure 4. |
The single-chip computer GMS97C2051 is the core of the entire system. The TLC2543 collects the input analog signals. The conversion results are received by the single-chip computer through P3.5 (pin 9). The channel selection and mode data of the AD chip are input to it through P3.4 (pin 8). There is an internal 8-bit address and control register, and the data collected by the microcontroller is converted into RS232 levels by the MAX3232 through the serial port (pins 3 and 2) and transmitted to the host computer. The serial LCD display circuit in the figure is only used for debugging and monitoring the collected/transmitted data.
3 Microcontroller software design
The microcontroller program mainly includes the serial data acquisition module "DATA_SAM" and the serial data transmission module "RS232". The display subroutine used for debugging is omitted here.
The channel selection and mode data of TLC2543 is 8 bits, and its functions are: D7, D6, D5 and D4 are used to select the channel required for conversion. When D7D6D5D4=0000, channel 0 is selected, when D7D6D5D4=0001, channel 1 is selected, and so on; D3 and D2 are used to select the output data length. This program selects the output data length to be 12 bits, that is, D3D2=00 or D3D2=10; D1 and D0 select the leading bit of the input data, and D1D0=00 selects the high-order leading bit.
The data read by TLC2543 in each I/O cycle is the result of the last conversion, and the current conversion result is serially shifted out in the next I/O cycle. The conversion result of the first reading may not be accurate due to internal adjustments and should be discarded.
The data collection procedure is as follows:
DATA_SAM: | ||
MOV R0,#30H |
;Data buffer first address 30H→R0 | |
MOV R1,#00000000B | ;0 channel mode/channel data | |
ACALL RD_AD | ;The conversion result read for the first time may be inaccurate and discarded. | |
MOV R1,#00010000B | ;1 channel mode/channel data | |
ACALL RD_AD | ;Send 1 channel mode/channel data and read the 0th channel conversion result | |
MOV @R0,R2 | ;The conversion result is stored in the data buffer, the same below | |
INC R0 | ||
MOV @R0,R3 | ||
INC R0 | ||
MOV R1,#00100000B | ;2-channel mode/channel data | |
ACALL RD_AD | ;Send 2-channel mode/channel data and read the 1st channel conversion result | |
MOV @R0,R2 | ||
INC R0 | ||
MOV @RO,R3 | ||
INC R0 | ||
………… | ;Other channel operation methods can be deduced by analogy. | |
RET |
The microcontroller generates a serial clock through programming, sends and receives data bits in time sequence, completes the writing of channel mode/channel data and the reading of conversion results. The program is as follows, which is called by the data acquisition module "DATA_SAM".
CLKEQU P3.3 | ||
DINEQU P3.4 | ||
DOUTEQU P3.5 | ||
CSEQU P3.7 | ||
RD_AD: | ||
CLR CLK | ;Clear I/O clock | |
SETB CS | ; Set film select to high | |
CLR CS | ; Set film select to low | |
MOV R4,#08 | ;Read the upper 8 bits first | |
MOV A, R1 | ;Put the mode/channel control word to A | |
LOP1: | ||
MOV C,DOUT | ;Read conversion result | |
RLC A | ;Shift the A register left, shift in the result data bit, shift out the mode/channel control bit | |
MOV DIN,C | ;Output mode/channel bit | |
SETB CLK | ;Set the I/O clock to high | |
CLR CLK | ;Clear I/O clock | |
DJNZ R4,LOP1 | ;R4 is not 0, then LOP1 is returned | |
MOV R2,A | ;Put the high 8 bits of the conversion result into R2 | |
MOV A,#00H | ;Reset A register | |
MOV R4,#04 | ;Read the lower 4 bits again | |
LOP2: | ||
MOV C,DOUT | ;Read conversion result | |
RLC A | ;Shift the A register left and shift in the result data bits | |
SETB CLK | ;Set the I/O clock to high | |
CLR CLK | ;Clear I/O clock | |
DJNZ R4,LOP2 | ;R4 is not 0, then LOP2 is returned | |
MOV R3,A | ;The lower 4 bits of the conversion result are placed in R3 | |
SETB CS | ; Set film select to high | |
RET |
The serial data transmission module includes a serial port initialization subroutine and a data transmission subroutine. Each subroutine is as follows. The data transmission adopts query mode, which can also be easily changed to interrupt mode.
INIT_COM: | ||
MOV SCON,#50H | ;Serial port mode 1 operation, 8 data bits, 1 stop bit, no parity check | |
MOV PCON,#80H | ; SMOD=1, the baud rate is doubled | |
MOVTMOD,#20H | ;Baud rate setting, f OSC =12MHz, baud rate =2*2400, N=0F3H | |
MOV TH1,#0F3H | ||
MOV TL1,#0F3H | ||
SETB TR1 | ;Start timer T1 | |
RET | ||
RS232: | ||
MOV R0,#30H | ;Buffer first address 30H→R0 | |
MOV R5,#22 | ;Send data length→R5, 11* 2=22 | |
LOOP: | ||
MOV A,@R0 | ;Get data→A | |
MOV SBUF,A | ;data→SBUF | |
WAIT: | ||
JBCTI,CONT | ; Determine the sending interrupt flag. If it is 1, go to CONT and clear TI. | |
SJMP WAIT | ||
CONT: | ||
INC R0 | ||
DJNZ R5,LOOP | ||
RET |
4 PC serial port receiving program design
The C language program used by the host computer to receive data includes initialization subroutine and receiving subroutine. Each subroutine is as follows:
void init_com1(void) /*Initialization subroutine*/ | |
{ | |
outportb(0x3fb,0x80); /*The high bit of the line control register is set to 1, making the baud rate setting valid*/ | |
outportb(0x3f8,0x18); /*Baud rate setting, consistent with the microcontroller baud rate of 4800bps*/ | |
outportb(0x3f9,0x00); | |
outportb(0x3fb,0x03); /*Line control register setting, 8 data bits, 1 stop bit, no parity*/ | |
outportb(0x3fc,0x03); /*Modem control register settings to enable DTR and RTS outputs*/ | |
outportb(0x3f9,0x00); /*Set the interrupt enable register and disable all interrupts*/ | |
} | |
void receive_data(void) /*Query mode receiving data subroutine*/ | |
{ | |
while(!kbhit()) | |
{ | |
while(!(inportb(0x3fd)&0x01));/*If the receiving register is empty, wait*/ | |
printf("%x ",inportb(0x3f8)); /*Read the results and display*/ | |
} | |
getch(); | |
} |
5 Conclusion
The hardware and software given in this article have been tested in practice, and have been made into data acquisition cards based on the PC/104 bus. They are very easy to use and can meet applications where the data sampling frequency is not particularly high.
Previous article:Design of a single-chip microcomputer serial data acquisition/transmission module
Next article:How to use microcontroller to implement caller ID decoding
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
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- New breakthrough! Ultra-fast memory accelerates Intel Xeon 6-core processors
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- Consolidating vRAN sites onto a single server helps operators reduce total cost of ownership
- 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!
- Safety Y1 & Y2 capacitors
- Protel 99 SE and AD have copper holes and copper grooves
- It was such an accident that I bought a NUCLEO-G474
- Are the saturation of light and the brightness of light the same concept? If they are different, what property of light does saturation refer to?
- Finally, TMS320F28379D is dead
- Implementing HDMI with FPGA
- Help, how to find LVDS7:1 IP in Gaoyun Cloud Source Software
- Product Show + Years of Evaluation and Use of Development Board
- New: TI's code-free, sensorless FOC 70W BLDC motor drive solution
- How can the ST BlueNRG-LP, as a slave, prohibit pairing requests initiated by the Bluetooth host and only allow the slave to initiate pairing requests?