Sie sind auf Seite 1von 37

1.

INTRODUCTION

1.1 What is Data acquisition?


Data acquisition (DAQ) is the process of measuring an electrical or physical phenomenon such as voltage, current, temperature, pressure, or sound with a computer. A DAQ system consists of sensors, DAQ measurement hardware, and a computer with programmable software. Compared to traditional measurement systems, PC-based DAQ systems exploit the processing power, productivity, display, and connectivity capabilities of industry-standard computers providing a more powerful, flexible, and cost-effective measurement solution. 1.2 Parts of a DAQ System

Figure 1.1: DAQ System

1.2.1 Sensor
The measurement of a physical phenomenon, such as the temperature of a room, the intensity of a light source, or the force applied to an object, begins with a sensor. A sensor, also called a transducer, converts a physical phenomenon into a measurable electrical signal. Depending on the type of sensor, its electrical output can be a voltage, current, resistance, or another electrical attribute that varies over time. Some sensors may require additional components and circuitry to properly produce a signal that can accurately and safely be read by a DAQ device.

1.2.2 DAQ Hardware


DAQ hardware acts as the interface between a computer and signals from the outside world. It primarily functions as a device that digitizes incoming analog signals so that a computer can interpret them. The three key components of a DAQ device used for measuring a signal are the signal conditioning circuitry, analog-to-digital converter (ADC), and computer bus. Many DAQ devices include other functions for automating measurement systems and processes. For example, digital-toanalog converters (DACs) output analog signals, digital I/O lines input and output digital signals and counter/timers count and generate digital pulses.

1.3 Key Measurement Components of a DAQ Device 1.3.1 Signal Conditioning


Signals from sensors or the outside world can be noisy or too dangerous to measure directly. Signal conditioning circuitry manipulates a signal into a form that is suitable for input into an ADC. This circuitry can include amplification, attenuation, filtering, and isolation. Some DAQ devices include built-in signal conditioning designed for measuring specific types of sensors.

1.3.2 Analog-to-Digital Converter (ADC):


Analog signals from sensors must be converted into digital before they are manipulated by digital equipment such as a computer. An ADC is a chip that provides a digital representation of an analog signal at an instant in time. In practice, analog signals continuously vary over time and an ADC takes periodic samples of the signal at a predefined rate. These samples are transferred to a computer over a computer bus where the original signal is reconstructed from the samples in software.

1.3.3 Computer Bus:


DAQ devices connect to a computer through a slot or port. The computer bus serves as the communication interface between the DAQ device and computer for passing instructions and measured data. DAQ devices are offered on the
2

most common computer buses including RS-232, USB, PCI, PCI Express, and Ethernet. More recently, DAQ devices have become available for 802.11 Wi-Fi for wireless communication. There are many types of buses, and each offers different advantages for different types of applications.

1.3.4 Computers Role in a DAQ System


A computer with programmable software controls the operation of the DAQ device and is used for processing, visualizing, and storing measurement data. Different types of computers are used in different types of applications. A desktop may be used in a lab for its processing power, a laptop may be used in the field for its portability, or an industrial computer may be used in a manufacturing plant for its ruggedness.

1.4 Different Software Components in a DAQ System 1.4.1 Driver Software


Driver software provides application software the ability to interact with a DAQ device. It simplifies communication with the DAQ device by abstracting low-level hardware commands and register-level programming. Typically, DAQ driver software exposes an application programming interface (API) that is used within a programming environment to build application software.

1.4.2 Application Software


Application software facilitates the interaction between the computer and user for acquiring, analyzing, and presenting measurement data. It is either a prebuilt application with predefined functionality, or a programming environment for building applications with custom functionality. Custom applications are often used to automate multiple functions of a DAQ device, perform signal-processing algorithms, and display custom user interfaces.

2.1 EMBEDDED MICROCONTROLLER


An embedded microcontroller is a microcomputer that contains most of its peripherals and required memory inside a single integrated circuit along with the CPU. It is in actuality a micro controller on a chip.

Embedded microcontrollers have been in use for more than three decades. The Intel 8051 series was one of the first microcontrollers to integrate the memory, I/O, arithmetic logic unit(ALU), program ROM, as well as some other peripherals, all into one very neat little package. These processors are still being designed into new products. Other companies that followed Intels lead into the embedded microcontroller arena were General Instruments, National Semiconductors, Motorola,

Philips/Signetics, Zilog, AMD, Hitachi, Toshiba, and Microchip, among others.

In recent years , Atmel has become a world leader in development of FLASH memory technology. FLASH technology is a non-volatile yet reprogrammable memory often used in products such as digital cameras, portable audio devices, and PC motherboards. This memory technology really pushed Atmel ahead in the microcontroller architecture, provides for very low-cost yet amazing solutions.

The next great step in this high-tech evolution was the implementation of high level language compilers that are targeted specifically for use with these new microprocessors. The code generation and optimization of the compilers is quite impressive. The C programming language with its make your own rules structure lends itself to this application by its ability to be tailored to a particular targeted system, while still allowing for code to be portable to other systems. The key benefit of a language like this is that it creates pools of intellectual property that can be drawn from again and again. This lower development costs on an on-going basis by shortening the development cycle with each subsequent design.

WHY AVR?
The motivation that has led to development of this system using this special kind of microcontroller is the growing popularity of the AVR and other RISC microcontrollers, the ever increasing level of integration (more on a chip and fewer chips on circuit board), and the need for tuned thinking when it comes to develop products utilizing this type of technology. We may have experience writing C for an embedded microcontroller, the approach must be modified to get final results: small, efficient, reliable, reusable code.

2.2 ATMEGA32 Architectural overview


The AtmelAVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The ATmega32 provides the following features: 32Kbytes of In-System Programmable Flash Program memory with Read-While-Write capabilities, 1024bytes EEPROM, 2Kbyte SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG interface for Boundary scan, On-chip Debugging support and programming, three flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional differential input stage with programmable gain (TQFP package only), a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable power saving modes. The Idle mode stops the CPU while allowing the USART, Two-wire interface, A/D Converter, SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning.

Figure 2.1: Block Diagram

The Power-down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next External Interrupt or Hardware Reset. In Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except Asynchronous Timer

and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping.

The On chip ISP Flash allows the program memory to be reprogrammed in-system through an SPI serial interface, by a conventional nonvolatile memory programmer, or by an On chip Boot program running on the AVR core. The boot program can use any interface to download the application program in the Application Flash memory. Software in the Boot Flash section will continue to run while the Application Flash section is updated, providing true Read-While-Write operation. By combining an 8-bit RISC CPU with In-System Self-Programmable Flash on a monolithic chip, the Atmel ATmega32 is a powerful microcontroller that provides a highly-flexible and cost-effective solution to many embedded control application. Special Microcontroller Features Power-on Reset and Programmable Brown-out Detection Internal Calibrated RC Oscillator External and Internal Interrupt Sources Six Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, Standby and Extended Standby I/O and Packages 32 Programmable I/O Lines 40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF Operating Voltages 4.5V - 5.5V for ATmega32 Speed Grades 0 - 8MHz for ATmega32L 0 - 16MHz for ATmega32 Power Consumption at 1MHz, 3V, 25C Active: 1.1mA Idle Mode: 0.35mA

Figure 2.2: Atmega32 PDIP Pin Out

2.2.2 PIN DESCRIPTION


VCC: Digital supply voltage. Ground. Port A serves as the analog inputs to the A/D Converter.

GND: Port A (PA7...PA0):

Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal pull-up resistors (selected for each bit). When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port B (PB7...PB0):

Port B is an 8-bit bi-directional I/O port with internal pull-

up resistors (selected for each bit).. As inputs, Port B pins that are externally pulled low

will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port C (PC7...PC0):

Port C is an 8-bit bi-directional I/O port with internal pull-

up resistors (selected for each bit).. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port D (PD7...PD0):
RESET:

Port D is an 8-bit bi-directional I/O port with internal pull-

up resistors (selected for each bit). Reset Input. A low level on this pin for longer than the

minimum pulse length will generate a reset, even if the clock is not running. XTAL1: Input to the inverting Oscillator amplifier and input to the

internal clock operating circuit. XTAL2: AVCC: Output from the inverting Oscillator amplifier. AVCC is the supply voltage pin for Port A and the A/D

Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. AREF: AREF is the analog reference pin for the A/D Converter.

The microcontroller being considered is the Atmel VR RISC microcontrollers. This one sentence says the volumes about the architecture of the devices. First, they are RISC devices. RISC stands for reduced instruction set computing and means that the devices are designed to run very fast through the use of reduced number of machine level instructions. This reduced number of instructions contributes to the speed due to the fact that, with a limited number of machine instructions, most can run in a single cycle of processor clock. In terms of MIPS (millions of instructions per second), this means that an AVR processor using an 16 MHZ clock can execute nearly 16 million instruction per second, a speed of nearly 16 MIPS.

Secondly, the devices are microcontrollers. A microcontroller is a complete computer system optimized for hardware control that encapsulates the entire processor, memory, and all of the I/O peripherals on a single piece of silicon. Being on the same piece of silicon means that speed is once again enhanced, because internal I/O peripherals takes less time to read or write than external devices also.

Being optimized for hardware means that the machine-level instruction set provides convenient instructions to allow easy control of I/O devices- there will be instructions to allow setting, clearing, or interrogating a single bit of parallel I/O port or a register. The ability to set or clear a bit is typically used to turn a hardware device off or on. In a processor not optimized for hardware control, the setting, clearing, or reading of individual bits of an I/O port (or any register) would require additional AND, OR, XOR, or any other instructions to effect a single bit of the port.

As an example, consider the following code fragment thats sets the third bit of Port A high:

//set bit 2 high While this code is correct for use with either standard microprocessor or a micro controller, the actual results are different for the two devices.

The fallowing snippet shows assembly code generated for standard microcomputer and for microcontroller to execute the line shown above:

Standard microcomputer:

IN MOV LDI OR

R30, 0x1B R26, R30 R30, LOW (4) R30, R26


10

OUT 0x1B, R30 Microcontroller: SBI 0x1B, 2

As these examples demonstrate, the standard microprocessor shown takes five instructions to set the bit high while the microcontroller takes only one. This equates to a five times speed increase for port operations in the microcontroller and a five times decrease in code size for these operations. Microcontrollers allow reduced code size and increased execution speed by providing instructions that directly applicable to hardware control.

Overall, the architecture of the Atmel AVR devices is that of a microcomputer. It is organized into a CPU (central processing unit), a memory, and an I/O section. The CPU is masked from our vision, but the memory and I/O sections are very visible and need to be understood by applications designer.

2.2.3 MEMORY
The memory section of the Atmel RISC AVR processors is based on the Harvard model, in which various portions of the memory are separated to allow faster access and increased capacity The CPU has a separate interface for the FLASH code memory section, the data memory section, and the EEPROM memory section, if one is present.

2.2.3.1 FLASH MEMORY


The FI-ASH code memory section is a block of FI-ASH memory that starts at location 0x000 and is of a size that is dependent on the particular Atmel AVR microcontroller in use. The FLASH code memory is non-volatile memory (retains its data even when power isremoved) ,and is used to store the executable code and constants, because they must remain in the memory even when the power is removed from device. The code memory space is16 bits wide at each location to hold the ma11

chine-level instructions that are typically single 16-bit word. Figure shows the memory map for the FLASH section of memory.

Although the FLASH memory can be programmed and reprogrammed with executable code, there is no provision to write to the FI-ASH by means of an executable program; it must be programmed by external means. Consequently, it is viewed as read-only memory from the programmer's perspective and is therefore used only to store constant type variables, along with the executable code. Constants are automatically promoted to int size variables when they are stored in FLASH code memory space because of the memory width.

2.2.3.2 DATA MEMORY


The data memory of the Atmel AVR processor typically contains three separate areas of read write (R/W) memory. The lowest sections contain thirty-two general purpose working registers, followed by the sixty-four registers, which are the internal SRAM.

The general-purpose working register are just that: they are used for the storage of local variables and other temporary data used by the program while it is executing, and they can even be used for the storage of global variables. The sixty-four I/O registers are used as the interface to the I/O devices and peripherals on board the microcontroller. And the internal SRAM is used as general variables storage area and also for processor stack

2.2.3.3 REGISTERS
The general-purpose working registers occupy the lowest thirtytwo cells in the data memory. These registers are used much like the storage locations in a calculator, in that they store temporary or intermediate results. Sometimes they are used to store local variables, sometimes global variables, an sometimes the pointers into memory that are used by the processor. In short, the processor uses these thirty-two work12

ing registers as it executes the program. The use of the thirty-two working registers is controlled by C compiler and is typically out of the programmers control unless assembly language is being used.

I/O REGISTERS
In an ATMega32, the I/O working registers occupy the next highest sixty four bytes in the data memory space. Each of these registers provide access to the control registers or the data registers of the registers of the I/O peripherals contained within the microcontroller.

The programmer uses the I/O registers extensively to provide interface to the I/O peripherals of the microcontroller. Other Atmel devices such as the ATMega128 have more I/O registers then will fit in 64-byte space.

Each I/O register has a name, a I/O address, and an SRAM address. A C language programmer will most commonly use the I/O register name. The two different numeric addresses are important when writing in assembly language because some of the instructions relate to the SRAM address and some relate to I/O address. The I/O register names are much more convenient for the C language programmer to use than the address. However, the C language compiler does not inherently know what does these names are or know what addresses to associate with the names. Each program contains #include header file that defines the names and the associated addresses for the C language compiler.

In summary, the C language programmer uses the I/O registers as the interface to the I/O hardware devices within the microcontroller.

2.2.3.4 SRAM
The SRAM section of memory is used to store variables that do not fit into registers and to store the processor stack. Figure shows the SRAM section of data memory.Data is usually stored starting at the bottom of the SRAM, and the
13

processor stack or stacks starts at the top of memory and utilize memory from the top down. The processor use the stack area of memory as the temporary storage for the function return addresses, intermediate results from calculations, and any other short-term temporary data storage. While the use of SRAM memory for data storage is fairly straightforward, its use for the stack is not. The stack may be thought of as an area of memory set aside for the storage of papers. New data is pushed onto the stack, and old data is popped off the stack in a LIFO manner. The stack pointer (SP) holds the address of the memory cell that is currently available for use. The major concept relative to the stack is that as data is pushed onto stack, the stack uses progressively more memory in the SRAM area, starting at the top of SRAM and working downward. As data is popped off the stack, the memory that has been previously used is released, and the available stack location moves up in memory. Likewise, the data stack is located in the SRAM below the system stack. The exact location is set by the programmer in the compiler configuration settings. The data stack works very much like the system stack, using a data pointer just like the system stack pointer, growing downward through memory as it is used and back upward as it is released. Global variables may also be stored in SRAM memory area starting above the I/O register area. The SRAM is used in an upward direction until space is made available for the global variables. It is the programmers responsibility to ensure that the system stack does not come down low enough in SRAM to overwrite the data stack and that the data stack does not come down low enough in memory to overwrite the global variables area.

2.2.3.5 EEPROM MEMORY


The EEPROM section of memory is an area of read/write memory that is non-volatile. It is typically used to store data that must not be lost when the power is removed and then reapplied to the microcontroller. The EEPROM space

14

starts at 0x000 and goes up to a maximum value that is dependent on the specific microcontroller in use. Although the EEPROM section of memory may be both read and written, it is seldom used for general variable storage. The reason is that the EEPROM memory is very slow to write: it can take up to one millisecond to complete a write operation on one byte of memory. The extensive use of this memory for variable storage would slow the processor down appreciably. Also, EEPROM memory can with stand only limited number of write cycles. So, for these reasons, EEPROM memory is usually reserved for those variables that must maintain their value in the event of power loss.

2.2.4 RESET
Reset is the lowest numbered interrupt. It is also a special interrupt in that it always takes precedence over all executing interrupts and any code that may be running. Three sources can cause reset to occur: a logic low applied to the external reset pin greater than 50 ns, as a part of the power on sequence of the micro controller, and by a timeout of the watch dog timer. Reset is used to preset the micro controller to a known state so that it can start executing the program located at location 0x0000 in code memory.

The microcontroller state following a reset will vary slightly depending on the processor being used, but it is essentially the following: All peripherals are disabled. All parallel ports are set to input. All interrupts are disabled.

By disabling all the peripherals and interrupts, the micro controller can begin executing the program without unexpected jumps due to interrupts that might cause unexpected or erratic behavior. Setting the parallel ports to input mode ensure that the port and an external device will not be trying to drive a port pin to opposite levels ,which could damage the port pin.
15

2.2.5 PARALLEL I/O PORTS


The parallel I/O ports are the most general purpose I/O devices. Each of the parallel I/O ports has three associated I/O registers: data direction register, DDRx (where x is A, B, C, and so on depending on the specific processor and parallel port being used), the port driver register, typically called PORTx, and port pins register, PINx. The data direction registers purpose is to determine which bits of the port are used for input and which bits are used for output. The input and output bits can be mixed as desired by the programmer. A processor reset clears all of the data direction register bits to logic0, setting all of the ports bit for input. Setting any bit of the data direction register to logic 0, setting all ports bit for output mode. For instance, setting least significant two bits of DDRA to logic 1 and other bits to logic 0 sets the lest significant two bits of port A for output and the balance of the bits for input. Port= 0x2; /*sets the second bit of port A */ /*and clear the other seven bits*/

Reading from the input bits of port A is accomplished as follows:

X= PINA;

/*reads all pins of port A*/

Input port pins are floating, that is, there is not necessarily a pull up resistor associated with the port pin. The processor can supply the pull up resistor, if desired, by writing logic 1 to the corresponding bit of the port driver register as shown below:

DDRA= 0xc0; //upper 2 bits as output, lower 6 as input PORTA=0x3; //enable internal pull-ups on lowest 2 bits

16

2.2.6 ADC
The ADC peripheral in the AVR microcontrollers is capable of 10-bit resolution and can operate at speeds as high as 15 ksps (kilo-samples per second). It can read the voltage on one of eight different input pins of the microcontroller. Two registers control the analog to-digital convener: The ADC control and status register(ADCSRA), controls the functioning of the ADC, and the ADC multiplexer register (ADMUX), controls which of the eight possible inputs are being measured. The ADC requires a dock frequency in the range of50 kHz to 200 khz to operate at maximum resolution. Higher clock frequencies are allowed but at decreased resolution. The ADC clock is derived from the s,-stem dock by means of a prescaler in a manner similar to the timers. The least significant three bits of ADCSRA control the prescaler division ratio. These bits must be set so that the system clock, when divided by the selected division ratio, provides an ADC clock between 50 kHz and 200 kHz. The selection bits and division ratios are shown as

Fig 2.3: ADC Control & Status Register

The most direct method for choosing the ADC pre selector factor is to divide the system dock by 200 kHz and then choose the next higher division factor This will ensure an ADC do& that is as fast as possible but under 200 kHz.
17

The ADC, like the serial USART, is somewhat slower than the processor. If the processor were to wait for each analog conversion to be complete, it would be wasting valuable time. As a result, the ADC is usually used in an interrupt-driven mode. Although the discussion that follows uses the more common interrupt driven mode, it is also possible for the ADC to operate in free-running mode, in which it continuously does conversions as fast as possible. when reading the ADC output in free running mode, it is necessary to disable the interrupts or stop the free running conversions, read the result, and then re-enable the interrupts and free-running mode. The ADC is usually initialized as follows: 1. Set the three lowest bits of ADCSR for the correct division factor. 2. Set ADIE high to enable interrupt mode. 3. Set ADEN high to enable ADC. 4. Set ADSC to immediately start conversion The selection of ADC pre scalar bits is as follows.

Fig 2.4: Pre Scalar Bits of ADC

18

3.1 Serial communication using USART:


Serial communication is the process of sending multiple bits of data over a single wire. The bits of a serial byte are separated by time so that the receiving device can determine the logic levels of each bit. The USART is used to communicate from the microcontroller to various other devices. Examples of such devices include the terminal tool in Code Vision AVR. (Used for troubleshooting and program debugging), other microcontrollers that need to communicate to control a system, or a PC that is communicating with the microcontroller to complete a task. The usual form of serial communication, and the form being discussed here, is asynchronous serial communication. It is asynchronous in the sense that a common clock signal is not required at both the transmitter and the receiver in order to synchronize the data detection. Asynchronous serial communication uses a start bit and a stop bit added to the data byte to allow the receiver to determine the timing of each bit. Figure below shows the elements of a standard asynchronous serial communication byte. This figure shows both the waveform and a definition for each bit of the serial word. The serial transmit line idles at a logic 1 and drops to zero to indicate the beginning of the start bit. The start bit takes one full bit time and is followed by the eight bits of the data byte that appear on the serial line in inverse order, that is, the least significant bit appears first and the most significant bit appears last. The stop bit follows the most significant data bit and is a logic 1, the same level as the idle state.

The falling edge of the start bit begins the timing sequence in the serial receiver beginning from the falling edge of the start bit the receiver waits 1.5 bit times before sampling the receiving line to get the first data bit- After that, the receiver waits 1 bit time per bit, thereby sampling each successive data bit in the center of its time period or maximum reliability.

The UART interface consists of three registers- Those are UART control and status register, the UART baud rate register, and the UART data register. These registers may be ei19

ther 8 or 16 bits in length depending on the complexity of the USART contained in the processor being used.

Fig 2.5: Serial Byte Format

In the ATMega16 for example, for normal asynchronous operation the USART control and status register is a 16 bit register consisting of two 8bit registers, UCSRA and UCSRB, and the USART baud rate register is a 16-bit register consisting of UBRRH and UBRRL, which are the high and low bytes, respectively, of UBRR. For other modes of operation an additional USART control and status register, UCSRC is also available.

Fig 2.6: Status Register


20

Regardless of the processor type, the UDR is actually two registers sharing a single I/O address. One is a read-only register and one is a write only register. The read-only register contains any serial byte received, and the write-only register contains any serial bye to be transmitted. So, when a program reads the UDR, it is reading the receiver UDR to get data that has been received serially. When the program writes to the transmitter UDR, it is writing data to be serially transmitted. Figure shows the bit definitions for the USART control and status registers part B, from an ATMega16. UCSRB is used to initialize and set the function of the USART in the ATMega16.

Fig 2.7: UCRB

UCSRA reflects the current status of the USART. The UCSRA contains the interrupt flag bits (most significant 3 bits) and other bits that indicate the results of USART activity. Figure shows the bit definitions for the USR. The USART status is important due to the fact that serial communication is always slower than parallel communication. During the 1.04 milliseconds that it takes to transmit a single serial byte
21

at 9600 baud, a microcontroller using a system clock of 8MHz can execute as many as 8000 instructions. So, in order for the microcontroller not to be waiting around for the serial port, it is important for the program to be able to tell the state of the serial port.

Fig 2.8: UCSRA

3.2 RS 232 STANDARD

Information being transferred between data processing equipment and peripherals is in the form of digital data which is transmitted in either a serial or parallel mode. Parallel communications are used mainly for connections between test instruments or computers and printers, while serial is often used between computers and other peripherals.

22

Fig 3.1: RS-232 Signal

Serial transmission involves the sending of data one bit at a time, over a single communications line. In contrast, parallel communications at least as many lines as there are bits in a word being transmitted (for an 8-bit word, a minimum of 8 lines are needed). Serial transmission is beneficial for long distance communications, whereas parallel is designed for short distances or when very high transmission rates are required.

Fig 3.2: DB9 connector pin out

23

One of the advantages of a serial system is that it lends itself to transmission over telephone lines. The serial digital data can be converted by modem, placed onto a standard voice-grade telephone line, and converted back to serial digital data at the receiving end of the line by another modem. Officially, RS-232 is defined as the Interface between data terminal equipment and data communications equipment using serial binary data exchange. This definition defines data terminal equipment (DTE) as the computer, while data communications equipment (DCE) is the modem. A modem cable has pin-to-pin connections, and is designed to connect a DTE device to a DCE device.

3.2.1 RS-232 SPECIFICATIONS: TRANSMITTED SIGNAL:


VOLTAGE LEVELS: Binary 0: +5 to +15 Vdc (called a space or on) Binary 1: -5 to -15 Vdc (called a mark or off)

RECEIVED SIGNAL :
VOLTAGE LEVELS: Binary 0: +3 to +13 Vdc Binary 1: -3 to -13 Vdc

DATA FORMAT:
Start bit: Binary 0 Data: 5, 6, 7 or 8 bits Parity: Odd, even, mark or space (not used with 8-bit data) Stop bit: Binary 1, one or two bits

Fig 3.3: RS-232 cable


24

RS-232 cables are commonly available with either 4, 9 or 25-pin wiring. The 25 pin cable connects every pin; the 9-pin cables do not include many of the uncommonly used connections; 4-pin cables provide the bare minimum connections, and have jumpers to provide handshaking for those devices that require it. These jumpers connect pins 4, 5 and 8, and also pins 6 and 20. The advent of the IBM PC AT has created a new wrinkle in RS-232communications. Rather than having the standard 25-pin connector, this computer and many new expansion boards for PCs feature a 9-pin serial port. To connect this port to a standard 25- pin port, a 9-to-25-pin adaptor cable can be utilized, or the user can create his own cable.

3.3 MAX 232


MAX232 is used as the signal-level converter. It coverts TTL signal to RS-232 level and vice versa .Four electrolytic capacitors (10F, 16V) are used with MAX232 for voltage-level conversion.The analogue input is converted into digital level by the AVR and transmitted to the PC through a 9-pin, D-type serial com port connector.

Fig 3.4: Max-232 Pin Out

25

Operates From a Single 5-V Power Supply with 1.0 F Charge-Pump Capacitors Operates Up To 120kbit/s Two drivers and two receivers 30-V Input Levels Low Supply Current . . . 8 mA Typical Applications:

Battery-Powered Systems, Terminals, Modems and Computers

3.4 LM-335 temperature sensor


Temperature sensor LM335 is from National Semiconductors. LM335 has a breakdown voltage directly proportional to absolute temperature at 10 mV/K with less than 1-ohm dynamic impedance. The device operates over a current range of 400 A to 5 mA with virtually no change in performance. LM335 can be used in any kind of temperature sensing application within the range of -55C to 150C. Low impedance and linear output make it easier to interface with the readout and control circuitry. It is not internally calibrated for degree Celsius (C), so you need some external circuitry in the form of a 10-kilo-ohm preset and a 1 - k i l o - o h m pull-up resistor.

Fig 3.5: Lm 335 pin out

3.5 VOLTAGE REGULATOR 7805 is a voltage regulator integrated circuit. It is a member of 78xx series of fixed linear voltage regulator ICs. The voltage source in a circuit may have fluctuations and would not give the fixed voltage output. The voltage regu26

lator IC maintains the output voltage at a constant value. The xx in 78xx indicates the fixed output voltage it is designed to provide. 7805 provides +5V regulated power supply. Capacitors of suitable values can be connected at input and output pins depending upon the respective voltage levels.

Fig 3.6: LM 7805 pin out

27

4.1 VISUAL BASIC


Visual Basic is a high level programming language which evolved from the earlier DOS version It called is a

BASIC. BASIC means Beginners' All-purpose

Symbolic Instruction Code.

very easy programming language to learn. The code looks a lot like English Language. Different software companies produced different versions of BASIC, such as Microsoft QBASIC, QUICKBASIC, GWBASIC, IBM BASICA and so on. However, people prefer to use Microsoft Visual Basic today, as it is a well-developed programming language and supporting resources are available everywhere. Now, there are many versions of VB exist in the market, the most popular one and still widely used by many VB programmers is none other than Visual Basic 6. We also have VB.net, VB2005, VB2008 and the latest VB2010. Both Vb2008 and VB2010 are fully object oriented programming (OOP) language. VISUAL BASIC is a VISUAL and events driven Programming Language. These are the main divergence from the old BASIC. In BASIC, programming is done in a text-only environment and the program is executed sequentially. In VB, programming is done in a graphical environment. In the old BASIC, you have to write program code for each graphical object you wish to display it on screen, including its position and its color. However, In VB , you just need to drag and drop any graphical object anywhere on the form, and you can change its color any time using the properties windows. On the other hand, because the user may click on a certain object randomly, so each object has to be programmed independently to be able to response to those actions (events). Therefore, a VB Program is made up of many subprograms, each has its ownprogram code, and each can be executed independently and at the same time each can be linked together in one way or another.

28

4.2 AVR STUDIO


Atmel Studio is the integrated development environment (IDE) for developing and debugging Atmel ARM Cortex-M processor-based and Atmel AVR microcontroller applications. The Atmel Studio 6 IDE gives you a seamless and easy-to-use environment to write, build and debug your applications written in C/C++ or assembly code. Atmel Studio 6 supports all 8- and 32-bit AVR, SAM3 and SAM4 microcontrollers, and connects seamlessly to Atmel debuggers and development kits. One of the finest C language tools developed to date is CodeVisionAVR. Written by PavelHaiduc of HP InfoTech S.R.L., this completely integrated development (IDE) allows editing, compiling, part programming, and debugging to be performed from one PC Windows application.

4.2.2 KEY FEATURES


Integrated C/C++ compiler. Integrated editor with visual assist. In-system programming and debugging. Full chip simulation.

Fig 4.1: AVR Studio Interface

29

4.3 PONY PROG


PonyProg is serial device programmer software with a user friendly GUI framework available for Windows95/98/ME/NT/2000/XP and Intel Linux. Its purpose is reading and writing every serial device. It is use to burn the Hex code compiled from a program on to the program memory. At the moment it supports IC Bus, Microwire, SPI eeprom, the Atmel AVR and Microchip PIC micro.

Fig 4.2: Ponyprog Interface

30

5.1 Block diagram

Fig 5.1: Block diagram of Data Acquisition and Logging System

5.2 Need of Data Acquisition and Logging


In environments like factories, power plants and transformers in electricity substations, controlling temperature to a safe value is important. Supervisory and control systems are used to monitor the temperature and other physical parameters on a centralized machine whereby one can monitor and control the remote devices. The AVR microcontroller-based system described here does the same job of acquiring the analogue data and sending it to a remote terminal for monitoring. Figure here shows the block diagram of the eight-channel data acquisition and logging system using AVR microcontroller.

5.3 Key Features:


The key features of this system are: User-friendly software written in VB 6.0 and Data is acquired through serial port of the PC and displayed on the screen of the PC monitor

31

Precise analogue signal conversion using AVR analogue-to-digital converter with 10-bit resolution All data acquired by the system is logged into a database for future reference with date and time of sampling

5.4 CIRCUIT DIAGRAM

Fig 5.2: Circuit Diagram

The internal analogue-to-digital conversion (ADC) channels of the AVR are used to acquire real-time data in the form of analogue signal. The data is sent to the PC via UART channel.

5.4.1 CIRCUIT DESCRIPTION


Figure shows the circuit of the eight-channel data acquisition and logging system using AVR. At the heart of the circuit is ATMega32 AVR microcontroller from Atmel. This data logger uses ADC channels of the AVR to acquire real-time data in the form of analogue signal and sends this data to the PC via UART

32

channel. Vcc (pin 10) and AVcc (pin 30) of the AVR are connected to +5V for its operation. By default, this AVR works with the internal RC oscillator at 1 MHz. Here, fuse bits of the AVR are set to operate an external oscillator. We have used an external stable crystal oscillator to run at a frequency of 16 MHz. The AVR has internal power-on reset facility. Resistor R2 (10-kilo-ohm), capacitor C5 (10F) and switch S1 make up the external reset circuitry. Switch S1 allows you to reset the system at run time. Analogue reference voltage pin VREF (pin 32) is connected to the variable terminal of the 10-kilo-ohm preset. Using this preset, you can adjust the ADC reference voltage. We have used all the eight channels of the 10-bit ADC for acquiring the analogue voltage proportional to the environmental temperature of temperature sensors. The in-built UART channel of ATMega32 is used to send the current data to the host PC. UART works on 9600 bauds per second. The length of RS-232 serial cable is tested for operation up to 10 meters but it should work.

5.4.1.1 Temperature sensor


Temperature sensor LM335 from National Semiconductors has been used in this project. Its pin details are shown in Fig 5.3. LM335 has a breakdown voltage directly proportional to absolute temperature at 10 mV/K with less than 1-ohm dynamic impedance. The device operates over a current range of 400 A to 5 mA with virtually no change in performance. LM335 can be used in any kind of temperature sensing application within the range of -55C to 150C. Low impedance and linear output make it easier to interface with the readout and control circuitry. It is not internally calibrated for degree Celsius (C), so you need some external circuitry in the form of a 10-kilo-ohm preset and a 1 - k i l o - o h m pull-up resistor as shown

Fig 5.4: LM335


33

5.4.1.2 Calibration
Careful calibration is done to map voltage values exactly into temperature in degree Celsius.. Voltage values are measured for different temperature conditions and a constant multiplying factor is obtained. This constant is multiplied every time with the current ADC value. When calibrated at 25C, LM335 has typically less than 1C error over a range of 100C. Most of all, it has a linear output. The voltage across the output terminal of LM335 is 2.982V at 25C.

5.4.1.3 Signal-level conversion


This microcontroller works with TTL digital logic, while the RS-232 standard specifies different voltage levels of the digital logic. So you need a signal-level converter for communication between the microcontroller and the PC over RS-232 port. MAX232 is used as the signal-level converter. Four electrolytic capacitors (10F, 16V) are used with MAX232 for voltage-level conversion. There are eight input lines (IN0 through IN7) through which analogue inputs are fed into the circuit. The analogue input is converted into digital level by the AVR and transmitted to the PC through a 9-pin, D-type serial com port connector. Here, we have used only three pins of the connector(Rx, Tx and Gnd) for communication with the PC.

5.5 PC GUI software


The graphic user interface (GUI) displays the stored data on the dashboard with date and time of logging. This can be useful to analyze the trend of temperature change. The software dashboard has eight blocks for displaying data of eight different analogue channels. The GUI software is written in Visual Basic and has ActiveX controls for communication with the serial port of the PC. It is programmed to scan the real-time incoming data from external hardware. The entire working logic is asynchronous; it doesnt matter which channel has what data. The software can capture the data from a particular channel and put into an appropriate location in the database.. The software is calibrated such that it shows the temperature directly in degree Celsius by

34

multiplying a calibration constant to the incoming analogue voltage. The software is configured to work on fixed values such as com1 for the serial port and 9600 for the baud rate by default. But you can easily configure it to work with different serial ports (like com2, com3 or com4) and different baud rates. The software can save the data of different input channels into a daq. mdb database with time and date of each channel input data. Start/Stop buttons are provided to start or stop logging activity anytime by the user. The GUI program output is shown in Fig.

Fig 5.5: Dash Board

Fig 5.6: Data base

35

5.6 C PROGRAM
#include<avr/io.h> #include<util/delay.h> void UART_transmit(unsigned char data) { while(!(UCSRA & (1<<UDRE))); UDR=data; } void adc_getdata(void) { int temp; unsigned char ch=0; while(1) { for(ch=0;ch<8;ch++) { ADMUX=0x00+ch; // Selecting Channels ADCSRA=0xE7; // ADC free running mode, 128 prescaling division factor temp=(ADC)*(48); temp=temp/10; temp=temp-2280; temp=temp/10; _delay_us(1000); UART_transmit(ch+'0'); // Sending channel number for synchronization _delay_ms(10); UART_transmit(temp); // Sending temperature value _delay_ms(1000); } } } int main(void) { DDRA=0x00; PORTA=0x00; UCSRA=0; UCSRB=1<<TXEN; // UART transmit enable UCSRC=1<<URSEL | 1<<UCSZ1 | 1<<UCSZ0; // 8 data bit, a stop, none parity UBRRH=0; UBRRL=103; // for 9600 baud at 16MHz adc_getdata(); return 0; }
36

CONCLUSION

Human beings would suffer from fatigue and even some times the process environment can be hazardous, and in every supervisory control and process environment monitoring applications, a DAQ system plays a key role. This simple ATMEGA32 based data acquisition and logging system serves this purpose economically and provides results on display monitors remotely. It is not limited to only temperature measurements, but can be extended to wide variety of applications like pressure, humidity, flow, speed monitoring and control applications.

37

Das könnte Ihnen auch gefallen