Академический Документы
Профессиональный Документы
Культура Документы
INTRODUCTION
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.
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.
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,
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.
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
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):
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):
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:
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
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.
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.
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.
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
X= PINA;
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
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.
18
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.
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.
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.
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.
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
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.
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.
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
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.
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:
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.
27
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
29
30
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
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.
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.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.
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.
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