Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

ADC operation with COM port, simple data acquisition system. Encyclopedia of radio electronics and electrical engineering

Free technical library

Encyclopedia of radio electronics and electrical engineering / Computers

Comments on the article Comments on the article

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.

ADC operation with COM port, simple data acquisition system. Hardware
(click to enlarge)

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.

ADC operation with COM port, simple data acquisition system. ADC communication protocol TLC549IP
(click to enlarge)

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.

ADC operation with COM port, simple data acquisition system

ADC operation with COM port, simple data acquisition system

Download source codes of sample programs (8 kB)

Literature

  1. Gell P. How to turn a personal computer into a measuring complex: Per. from fr. - 2nd ed., corrected. - M.: DMK Press, 2001. - 144 p.: ill.
  2. An P. Pairing a PC with external devices: Per. from English. - M.: DMK Press, 2001 - 320 p.: ill.
  3. Visual Basic 6.0: Per. from English. - St. Petersburg: BHV - St. Petersburg, 2000. - 992 p.: ill.

Author: =ShooRooP=, evei [dog] mail.ru; Publication: cxem.net

See other articles Section Computers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Artificial leather for touch emulation 15.04.2024

In a modern technology world where distance is becoming increasingly commonplace, maintaining connection and a sense of closeness is important. Recent developments in artificial skin by German scientists from Saarland University represent a new era in virtual interactions. German researchers from Saarland University have developed ultra-thin films that can transmit the sensation of touch over a distance. This cutting-edge technology provides new opportunities for virtual communication, especially for those who find themselves far from their loved ones. The ultra-thin films developed by the researchers, just 50 micrometers thick, can be integrated into textiles and worn like a second skin. These films act as sensors that recognize tactile signals from mom or dad, and as actuators that transmit these movements to the baby. Parents' touch to the fabric activates sensors that react to pressure and deform the ultra-thin film. This ... >>

Petgugu Global cat litter 15.04.2024

Taking care of pets can often be a challenge, especially when it comes to keeping your home clean. A new interesting solution from the Petgugu Global startup has been presented, which will make life easier for cat owners and help them keep their home perfectly clean and tidy. Startup Petgugu Global has unveiled a unique cat toilet that can automatically flush feces, keeping your home clean and fresh. This innovative device is equipped with various smart sensors that monitor your pet's toilet activity and activate to automatically clean after use. The device connects to the sewer system and ensures efficient waste removal without the need for intervention from the owner. Additionally, the toilet has a large flushable storage capacity, making it ideal for multi-cat households. The Petgugu cat litter bowl is designed for use with water-soluble litters and offers a range of additional ... >>

The attractiveness of caring men 14.04.2024

The stereotype that women prefer "bad boys" has long been widespread. However, recent research conducted by British scientists from Monash University offers a new perspective on this issue. They looked at how women responded to men's emotional responsibility and willingness to help others. The study's findings could change our understanding of what makes men attractive to women. A study conducted by scientists from Monash University leads to new findings about men's attractiveness to women. In the experiment, women were shown photographs of men with brief stories about their behavior in various situations, including their reaction to an encounter with a homeless person. Some of the men ignored the homeless man, while others helped him, such as buying him food. A study found that men who showed empathy and kindness were more attractive to women compared to men who showed empathy and kindness. ... >>

Random news from the Archive

Economical climate control system 26.06.2013

The technology, developed at Northwest National Laboratory (USA), will allow a large office building to save up to 18% of annual energy consumption, and this will not only save tens of thousands of dollars, but also make people's work more comfortable.

Such significant energy savings can be achieved thanks to just one factor: automatic registration of the number of people in the room. The engineers came up with the concept of using a simple device that adjusts the power of the ventilation/heating system depending on how many people are in the room.

This idea may seem banal, but so far such devices have not been widely used, and usually ventilation / heating systems operate with the same power, regardless of whether the room is full or empty. As a result, for example, often in large halls designed for thousands of people, several hundred people are often cold. Climate systems in large buildings, offices, train stations, hospitals, etc., almost always operate at full capacity and almost always do not coincide with the "comfort zone" of people.

To solve this problem, a team of engineers conducted a series of experiments in a large office building measuring 48x73 m with 12 floors and a basement - in total, the building area was about 46 square meters. The scientists conducted a simulation: they programmed a virtual model of the building's climate system to heat when the air temperature is below 000 degrees Celsius and cool when the temperature is above 21 degrees Celsius. In the evenings and weekends, the temperature could fluctuate in a wider corridor.

Calculations have shown that in 13 out of 15 regions of the United States, a "smart" system that estimates the number of people in the room will save at least $40 per year for each building similar to that which was modeled. At the same time, in two cities, Duluth and Fairbanks, savings exceeded $000 per year, mainly due to the reduction in the need to heat the air pumped in from the street. Even in very hot cities, El Paso and Miami, where the savings were supposed to be small, they managed to save $100 and $000, respectively.

The new technology is very promising. The fact is that trying to save on lighting is, of course, laudable and correct, but lighting consumes a tiny amount of energy compared to heating and ventilation. For example, adding a "smart" sensor that measures the number of people in a room can save up to 40% of a building's energy even with HVAC (heating, ventilation and air conditioning) systems, which are considered very advanced.

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

▪ article Automatic discharge-charger (ARZU) Ni-Cd batteries. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024