ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING ADC operation with COM port, simple data acquisition system. Encyclopedia of radio electronics and electrical engineering Encyclopedia of radio electronics and electrical engineering / Computers This article is aimed mainly at beginners. For those who have decided to try their hand at creating a data acquisition system, inputting analog signals to a computer, processing them, etc. This will be discussed in this article, and we will try to do everything ourselves. In general, there is little information on this topic on the Internet and in the literature ... Especially if you use the Visual Basic language. Therefore, I will try to fill, at least in part, this gap. So, let's begin… Whatever your goal, you first need to purchase the actual analog-to-digital converter (ADC). And also, install the Visual Basic 6.0 development environment on your computer. You also need to be able to navigate in this development environment in an elementary way ... because. The article is designed to ensure that the reader has at least basic knowledge of programming in Visual Basic. I also recommend reading the literature [1], [3]. As an ADC, I recommend purchasing the TLC549IP. This is an 8-bit, serial ADC with a simple communication protocol. It will be discussed in the article. Of course, you can use other ADCs with appropriate changes in circuit and code. You can read more about it in [1]. After you have wandered through the ADC, you need to assemble the hardware of our data acquisition system, namely the circuit shown in Fig. 1. The scheme was borrowed from [1] with minor changes. Diodes VD1, VD2, VD6 - KD521, any zener diodes for a stabilization voltage of 3 ... 5 V. Instead of 78L05, you can use KREN5A. Resistors R1, R2 with a tolerance of 1%, or a selection from several with the closest possible resistance value. The accuracy of the measurements will depend on them. Resistor R3 is preferably multi-turn. Setting: after supplying power to the board, we measure the voltage at the Out terminal of the stabilizer DA1. We write down the obtained voltage value with 3 decimal places, we will need it in the future. At pin 1 of the DD1 microcircuit, using the resistor R3, we set the voltage equal to exactly half of the stabilizer measured at the Out pin. Now let's deal with the actual software part. Generally speaking, at first use communication interfaces such as RS-232, I2C, Micro Ware, etc. I consider it inappropriate, because with a slight complication of the program code, the hardware part can become seriously complicated. Therefore, we will use the simplest exchange protocol taken from the "datasheet" on the ADC. Namely, its simple implementation. Of course, high speed cannot be achieved with such a protocol, in this case Visual Basic itself imposes restrictions, but it is quite suitable for obtaining the first results with a minimum of time and effort, as well as measuring relatively slowly changing processes. The communication protocol of the TLC549IP ADC is shown in Fig. 2. During a single state, the actual conversion occurs at the CS (chip select) pin of the analog-to-digital converter. Data output begins at low CS with the advent of the clock pulse, one bit for each pulse. To issue an 8-bit code, you need 8 clock pulses, respectively. After that, CS can be transferred to a single state and the next transformation can be performed. More details about the operation of the ADC can be found in [1]. From all this we can conclude that it is necessary to write a driver program that would generate the necessary sequences of pulses at the right time, after which we can only receive data. Start the Visual Basic development environment and create a standard EXE project. Add an MSComm Control. You can add it to the components panel like this Project-->Components-->select from the listMicrosoft Comms Control 6.0. Place it on the form, as well as 2 labels and 2 Timers. Leave the names as default. Now you can start writing the code for a simple voltmeter. Let's set variables: Dim b1, b2, b3, b4, b5, b6, b7, b8, sum, Ud As Single Place the following code in the form load procedure: Private Sub Form_Load () MSComm1.DTREnable = True 'initial value - high CS Timer1.Interval = 100 ' 1ms timer interval Timer2.Interval = 1 ' 100ms timer interval MSComm1.Settings = "1200,N,8,1" ' communication settings MSComm1.CommPort = 1 ' COM port number MSComm1.PortOpen = True ' open com port End Sub Into the procedure Timer1 put the code: Private Sub Timer1_Timer () MSComm1.DTREnable = False 'Create low CS Label2.Caption = "" 'garbage for initial delay MSComm1.RTSEnable = True '1st clock pulse clock high If MSComm1.CDHolding = True Then b1 = 1 Else b1 = 0 'Poll for one or zero value at CD input (ADC output) MSComm1.RTSEnable = False '1st clock pulse clock low MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b2 = 1 Else b2 = 0 MSComm1.RTSEnable = False MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b3 = 1 Else b3 = 0 MSComm1.RTSEnable = False MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b4 = 1 Else b4 = 0 MSComm1.RTSEnable = False MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b5 = 1 Else b5 = 0 MSComm1.RTSEnable = False MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b6 = 1 Else b6 = 0 MSComm1.RTSEnable = False MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b7 = 1 Else b7 = 0 MSComm1.RTSEnable = False MSComm1.RTSEnable = True If MSComm1.CDHolding = True Then b8 = 1 Else b8 = 0 MSComm1.DTREnable = True 'Create high CS MSComm1.RTSEnable = False '8st clock pulse clock low 'translate bits into decimal format using the decomposition formula sum = (b1 * 2^7) + (b2 * 2^6) + (b3 * 2^5) + (b4 * 2^4) + (b5 * 2^3) + (b6 * 2^2) + (b7*2^1) + (b8*2^0) Ud = Format(sum * 5.083 / 255, "##0.000") 'calculate proportional value Label1.Caption = CStr(Ud) & "Volt" 'display the received value End Sub The code in Timer1 is the driver itself. Which periodically repeating, generates clock pulses and receives data bits. Ud - voltage at the input of the ADC, if you apply 10, 12 bit ADCs, the number 225 will be replaced by 1024, 4096, respectively. For 10, 12 bit ADCs, you need to add the missing bits to the code, guided by their "datasheets". The value 5.083 is the voltage value that I got at the Out output of the stabilizer. Enter your value here. To power the board, you can use either a separate source or power it directly from the COM port. To do this, we place the following code in the Timer2 procedure: Private Sub Timer2_Timer () MSComm1.Output = Chr(0) & Chr(0) 'we create pulses on the TX pin (3) to power the ADC board End Sub It must be remembered that the COM port cannot be heavily loaded ... the maximum that you can count on is 20 mA. In operating mode, the circuit consumes a current of no more than 5 mA. Now connect the board to the COM port and run the project. Measure the voltage at the IN terminal of the DA1 stabilizer, it must be at least 6.5 V. If this is not the case, a separate power supply should be used. By changing the voltage at the input of the ADC, make sure that the program works and shows the voltage on the screen. The voltage reading accuracy when using an 8-bit ADC is 20mV, with a 10-bit ADC - 5mV, 12-1.2 mV A little about working in Visual Basic and the created application with a com port As you probably already understood, to work with the com port, you need a componentMicrosoft Comms Control namely the MSCOMM32.ocx file which, after installing Visual Basic, is located in the C:\Windows\system32 directory. Why am I doing this, but to the fact that if you copy your program, without creating an installer, to another computer that does not have Visual Basic, it will not work. You must also copy this file to the same directory as on your computer, i.e. in system32. Or create an installer. Now for some commands: The command that sets the data exchange rate: MSComm1.Settings = "1200,N,8,1" Command specifying the com port number MSComm1.CommPort = 1 Commands to open and close a com port MSComm1.PortOpen = True MSComm1.PortOpen = False Commands outputting + 12V to the corresponding leg of the com connector: MSComm1.RTSEnable = True RTS (7) - pin name and pin number MSComm1.DTREnable = True DTR(4) Commands outputting -12V MSComm1.RTSEnable = False MSComm1.DTREnable = False You can poll for the presence of a single or zero state outputs CD (1), CTS (8), DSR (6). If MSComm1.CDHolding = True Then (if one then…) If MSComm1.CDHolding = False Then (if zero then…) Sending the Tx (3) ASCII code of a character or string to the output: MSComm1.Output = "A" Numbers MSComm1.Output = Chr(10) number can vary from 0…255 By writing such a command in a timer and changing the number or symbol, you can create PWM modulation. More details about the commands can be found by downloading the description of the control Microsoft Comms Control. Now, having this code, you can write a number of programs for collecting data. For example: voltmeter, ammeter, temperature meter, simple oscilloscope, save data to a file. Measurements can be carried out just in 1 ms, and once an hour and a day, thereby monitoring long-term processes. To work with alternating voltages (passing through 0), as well as to expand the measurement limits, an input amplifier is required, the circuit of which can be taken from [1]. To work with mains voltage or with devices that are not galvanically isolated from the network, it is imperative to make an optical isolation of the circuit from the computer. Download source codes of sample programs (8 kB) Literature
Author: =ShooRooP=, evei [dog] mail.ru; Publication: cxem.net See other articles Section Computers. Read and write useful comments on this article. Latest news of science and technology, new electronics: Artificial leather for touch emulation
15.04.2024 Petgugu Global cat litter
15.04.2024 The attractiveness of caring men
14.04.2024
Other interesting news: ▪ Texas Instruments DRV5055 and DRV5056 Hall Sensors ▪ HGST Ultrastar He 6TB Helium Hard Drives ▪ Sunlight increases the sexual activity of men ▪ Prehistoric man was not a tramp ▪ Poor sleep increases atherosclerosis News feed of science and technology, new electronics
Interesting materials of the Free Technical Library: ▪ section of the site Dosimeters. Selection of articles ▪ article All are equal, but some are more equal than others. Popular expression ▪ article Which people used complex lenses a thousand years ago? Detailed answer ▪ article Swivel clamp. home workshop ▪ article Blue for linen. Simple recipes and tips
Leave your comment on this article: All languages of this page Home page | Library | Articles | Website map | Site Reviews www.diagram.com.ua |