Design of a single-chip microcomputer serial data acquisition/transmission module

Publisher:BeaLaity0170Latest update time:2006-04-12 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    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:

(1) 12-bit resolution A/D converter;
(2) 10μs conversion time within the operating temperature range;
(3) 11 analog input channels;
(4) 3-channel built-in self-test mode;
(5) Sampling rate 66kbps;
(6) Linear error +1LSB (max)
(7) End of conversion (EOC) output;
(8) Unipolar and bipolar output;
(9) Programmable MSB or LSB preamble;
(10) Programmable The output data length.

    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.

Reference address:Design of a single-chip microcomputer serial data acquisition/transmission module

Previous article:Design of a single-chip microcomputer serial data acquisition/transmission module
Next article:How to use microcontroller to implement caller ID decoding

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号