An Overview of ATmega AVR Microcontrollers Used in Scientific Research and Industrial Applications

Wojciech Kunikowski, Ernest Czerwiński, Paweł Olejnik, Jan Awrejcewicz

Department of Automation, Biomechanics and Mechatronics, Lodz University of Technology, 90–924 Łódź, 1/15 Stefanowski str.

Abstract: Nowadays, microcontrollers are commonly used in many fields of industrial applications previously dominated by other devices. Their strengths such as: processing power, low cost, and small sizes enable them to become substitutes for industrial PLC controllers, analog electronic circuits, and many more. In first part of this article an overview of the Atmel AVR microprocessor family can be found, alongside with many scientific and industrial applications. Second part of this article contains a detailed description of two implementations of ATmega644PA microprocessor. First one is a controller with PID regulation that supports a DC motor driver. Second one is a differential equation solver with 4-th order Runge-Kutta method implemented. It is used for solving a torsion pendulum dynamics. Finally, some general conclusions regarding the two presented implementations are made.

Keywords: Atmel, AVR, ATmega, microcontroller, torsion pendulum, PID control, DC motor, PWM control

1. Introduction

1.1. Overview of some Atmel microcontrollers

AVR ATmega is a family of 8-bit microprocessors from Atmel. Their features vary across models, but mostly, the following ones are present: 4‒256 kB Flash memory, from 28 to 100 pins (SMD or DIP packaging), a watchdog timer and up to 20 MHz clock speed (depending on external clock). In addition, the family of microprocessors offers on-chip Flash, SRAM and internal EEPROM memories. AVR ATmega family also supports SPI, TWI (I2C), UART, USB, CAN, and LIN communication protocols. Analog capabilities such as ADC and DAC are available, a built-in temperature sensor and internal voltage reference, brown out detector, a fast analog comparator and a programmable analog gain amplifier [1]. Worth mentioning are other types of AVR microprocessors. The ATtiny is also an 8-bit device. It can be viewed as a more compact version of ATmega. ATtiny works best in implementations where the performance and compact dimensions of control units are the most important requirements. The described microprocessor characterizes also with very low power consumption. It is the only processor in AVR family that works with 0.7 V power supply.

Two AVR groups dedicated for application where the high performance is required are XMEGA and UC3. The XMEGA is a member of family of 8/16-bit microprocessors with maximum clock frequency of 32 MHz. The UC3 states a group of 32-bit microprocessors with maximum clock frequency up to 66 MHz. Both groups are rich with peripheral devices.

Very popular among hobbyists and students are the Arduino boards. They are produced as a single printed circuit boards with a selected ATmega microprocessor installed. All the necessary circuits are built-in, leaving the end user just with the task of connecting the board to the power supply and connecting any desired peripheries. The dedicated Arduino Integrated Development Environment (IDE) is used for the programming purposes. The IDE is based on C/C++ programming language. The great advantage of Arduino board is that it is a relatively cheap and easy installable even on robots or control devices that interact with surrounding world [2].

1.2. Exemplary implementations

Repetitively, programmable microprocessors are used in applications previously dominated by other devices or complex electronic circuits. Small low-cost microprocessors are often used instead of simple analog electronic circuits. In some applications, even PLC controllers are pushed out by microcontrollers. Examples of scientific and industrial applications are described below.

In paper [3], ATmega161 was used as a controller with embedded system for an Uninterruptable Power Supply (UPS) system. This system was capable of receiving commands via internet and send back information regarding UPS status. Microcontroller also managed data communication with auxiliary memory unit via the I2C communication protocol. In certain determined cases the embedded system sends email messages to a list of defined addresses through SMTP protocol. Proposed solution allows for long distance monitoring and control of the UPS. Low cost and high reliability enables the use of mentioned microcontroller in serial produced UPS systems.

An application of the microcontroller as a data gathering device was presented in [4]. Here the ATmega328 acts as a real-time health vital signs monitoring system. Measurements are transmitted using an XBee communication system. The system is designed to collect the body temperature and heart rate. The described device has a memory card installed in the case of loss of communication through the XBee radio. Data can be transmitted in real-time and it is simultaneously stored on a removable memory card. This solution increases the reliability of data collection. It also enables a complete history of the data to be stored and read separately without using the XBee radio. The whole device is compact enough to be installed in a wrist mounted chassis.

An industrial application of an ATmega128 working as a microcontroller was presented in work [5]. The microprocessor acts as a central controller of DXDF40 automated powder packaging machine. During the bag forming the microcontroller is responsible for packaging film feeding speed (measured by number of impulses from a rotary encoder) and packaging material tension control (basing on analog measurement from a potentiometer). Length of material can be set to a constant value or can be controlled by an input from a color tag sensor. Speed of filling and volume of powder in the package is also controlled. Sealing temperature (in the horizontal and vertical seals) is controlled by a PID algorithm by means of an analog measurement from K-type thermocouple. Furthermore, there are incorporated: master motor control, production counting, system status display, system failure alarm etc. Described controller fulfils all requirements concerning speed and precision.

An ATmega16 based wireless home appliance control system was presented in [6]. User can turn on and off up to 15 different devices using a set of relays. PWM regulation was applied for changing fan’s DC motor speed or to regulate intensity of connected lights. The system is controlled by a Radio Frequency (RF) remote controller. The controller is compatible with a Sim300 GSM modem. This solution enables the system to send notifications concerning status of powered devices through the mobile phone network to a defined telephone number. Same information can be shown on a LCD screen.

Another useful implementation of an ATmega type microcontroller in industrial manufacturing is presented in [7]. ATmega8535 is used as a process controller of Pulse Electric Field (PEF) pasteurization. The pasteurized apple juice is subjected to a high voltage in range from 20 kV to 100 kV. This process is conducted in room temperature, contrary to classical pasteurization process which is conducted in temperatures ranging from 76 °C to 88 °C. Consequently, more vitamins and micro elements do not decay during the process, which gives better nutrition values to the pasteurized juice. The electronic circuit responsible for generating appropriate voltage is controlled by the PWM signal from the microcontroller. ATmega8535 is also responsible for regulating the duration of the process. The process parameters are displayed on a LCD screen and could be changed by the user via the attached keypad.

A comparative analysis of efficiency in generating PWM signals by three different microcontrollers (8-bit ATmega328P, 16-bit SAB80C167 and 32-bit PIC32MX320F128H) is presented in [8]. Test was carried out for two duty cycle values and four different frequencies. Length of code needed to generate a PWM signal was compared as well as the time needed to reestablish the signal generation after reboot was measured. ATmega328P achieved shortest reboot time and required the least amount of code for the assigned task. It can be concluded that for simple PWM control, the 8-bit microcontroller has the advantage of easier programming and fast response.

Another usage example of the ATmega microprocessor working as an electric motor controller is shown in [9]. The paper describes a spherical robot capable of moving under water. The propulsion is realized by three water jet thrusters. Each thruster consists of one DC motor for generating propulsive force and two servomotors for changing its direction. In this application ATmega2560 is used via the RS-232 communication protocol as a unit controlling rotation of six separated DC electric motors.

Another device based on ATmega microcontroller used for underwater exploration is described in [10]. Quoted article describes a Poseidon MK6 Rebreather. Classical open-loop underwater breathing system disposes once used air into water. On the other hand, the Rebreather collects the exhaled air in a flexible bag (counter-lung). Carbon dioxide is chemically filtered in the so-called scrubber, and metabolized oxygen is substituted with fresh oxygen from a small tank. Whole control system for the Rebreather is based on four ATmega 8-bit microcontrollers connected into a network. The control system is responsible for the breathing gas composition, validation of the multiple sensor signals and performing automatic predive checks. In the case of a failure, several warning systems like flashing LEDs and vibration motor are included. System parameters can be displayed on a custom LCD display. Rebreather can communicate with a PC via the IrDA data transmission. It enables easy firmware upgrades and diving data exchange.

ATmega microprocessors can be applied as regulators in complex dynamical systems. In papers [11] and [12] the microprocessors can be found as main controllers for Unmanned Aerial Vehicles (UAV). ATmega168-20U controls the flight of a tri-rotor flying robot. Using signals from two MEMS gyroscopes (ADC voltage conversion) it determines the pitch, roll and yaw angles of rotation. Later calculations have led to proper regulation of the speed of three PWM regulated brushless DC motors. Thanks to that, the tri-copter can fly and hover stably.

Similar implementation is shown in work [12]. An ATmega644PA microprocessor is used there as a main regulator of the four-rotor flying machine’s hovering state. The quadrocopter aerial vehicle is controlled by a microprocessor located on the ATB 1.03 start-up board. Commands are sent by pressing the appropriate buttons on the remote control supplied with the board. The signals informing about the current quadrocopter’s state are retrieved from a KAmodMEMS2 3-axis accelerometer (LIS35DE MEMS Motion Sensor) and a KAmodGYRO 3-axis gyroscope (L3G4200D MEMS Motion Sensor). The control unit processes the data and then sends specific duty cycles that are transferred to the rotational velocities of four three-phase BLDC motors. The motors are sourced from the ESC Quattro-SQ20A4U driver. It combines four high performance 20 A ESCs and a 5 V/3 A UBEC, where the ESC is based on standard PWM control signal. The UART communication with a PC computer was applied for realization of real-time data acquisition.

2. ATmega644PA as a PID controller for a DC motor

In the two subsequent sections of the article the described algorithms were implemented on the Atnel Testing Board (ATB) 1.03 [13]. It is equipped with ATmega644PA – an 8-bit microprocessor with 64 kB of Flash memory, 2 kB EEPROM, 4 kB SRAM and three programmable timers (two 8-bit and one 16-bit). The system used in this study operates under the control of 16 MHz external timing source.

The controlled object consists of a conveyer belt with a block mass m oscillating on it and a bracket M attached to the block mass by means of two linear springs (see in Fig. 1). The source of the oscillations is the so-called “stick-slip” phenomenon caused by self-excited vibrations of mass m on the belt. Depending on the linear placement of the block m and the angular displacement of the bracket M, the friction force in a contact surface between the block and the belt changes rapidly. Moreover, the friction force characteristics switches itself between its kinetic and static form. The experimentally observed periodic changes of frictional force between the two cooperating solid bodies are responsible for significantly varying load transferred on the DC motor driving the mechanical system. Constantly changing amplitude of load affects the speed of the gear’s conveyer belt. A more detailed description of the model can be found in [14‒16].

Figure 1 presents the laboratory station on which the experiments have been carried out. Control of the angular velocity of the DC motor (part 1 in the figure) is made by a system composed of the ATB (test board) equipped with the ATmega644PA microcontroller (5) and the RN12 driver (2). To measure the speed of the transmission belt on which the oscillating body of mass was placed (the physical system (3) under control) an incremental encoder (4) was used. The ATB is powered by a 15 V power supply (6). The DC motor is controlled by a RN12 driver (2). Its power and logical electric circuits are sourced by MATRIX 60 V and 30 V power supply (7), respectively.

Fig. 1. Picture of the experimental station

Rys. 1. Zdjęcie stanowiska badawczego

For the purpose of GI333 encoder’s output noise cancelation, in the dedicated measuring circuit a M74HCT14N Schmitt Inverter has been used. It allowed to damp any voltage peaks causing appearance of incorrect (redundant) pulses to be counted by the microcontroller. To enable compatibility between the microcontroller and the RN12 driver, a L293D integrated circuit was implemented. It served as an amplifier for the PWM signal.

A control algorithm pictured by the closed-loop control system shown in Fig. 2 calculates the adequate duty cycle of the PWM signal based on the reference speed and the number of pulses produced by the encoder in some predefined time interval (30 ms). In consequence, 9.7 kHz frequency PWM signal having well-modulated pulse width is sent to the RN12 regulator, which generates appropriate voltage for the DC motor. The PWM signal’s resolution is 10-bit so the variable describing its duty cycle can be tuned from 0 to 1023.

Fig. 2. A diagram of the closed-loop control system

Rys. 2. Schemat blokowy zamkniętego układu sterowania

The classical discrete PID controller takes the form:

, (1)

where: u(n) – controller output in current iteration, y(n) – plant output (measured value), e(n) – tracking error, Kp – gain of proportional action, Ki = Kp ×Ts/Ti gain of integral action, Kd = Kp ×Td/Ts – gain of derivative action, Ts – sampling time, Ti – time constant of integral action, Td – time constant of derivative action.

To eliminate any rapid responses of the derivative action when the reference speed changes in time (the so called “derivative kick”), the dependant variable was changed from error to difference between last acquired measurements of speed.

Output of the PID controller is limited by the PWM resolution in the range of integer values [0, 1023], and then treated as the new value of the PWM duty cycle.

Due to a complexity of the controller’s tuning, a black-box approach to the control problem was taken into the experimental considerations. Therefore, mathematical model of the multi-dimensional plant was omitted, and tuning of the controller was done manually basing on the acquisition of step responses.

In Fig. 3, the experimental results show a step response of the angular velocity of the mechanical system’s gear with respect to the reference input of 15 rpm. As can be observed, the belt pulley’s angular velocity oscillations have not been completely rejected. The value of standard deviation of the measured speed is about 0.56 rpm (calculated for 12 seconds after reaching a steady state).

Fig. 3. Time history of the angular velocity controlled by the tuned PID algorithm (Kp = 1, Ki = 1.75, Kd = 0.05)

Rys. 3. Wykres prędkości kątowej, sterowanej zgodnie z algorytmem PID

3. Solving the dynamic equation of a torsion pendulum model on ATmega644PA

The torsion pendulum is an angular equivalent of the linear harmonic oscillator. It consists of a twisted rod which is called string (1) and a suspended element (2) which rotates in the plane of oscillations. The oscillating element can have many shapes, for example, a cylindrical, spherical or can be a ring.

Dynamic equation of the physical model presented in Fig. 4 takes the form:

, (2)

where: I0 – moment of inertia of the cross section of the string (part 1 in Fig. 4), B – moment of inertia of the suspended element (part 2), G – modulus of rigidity of the string, l – length of the string.

Fig. 4. Physical model of the analyzed torsion pendulum

Rys. 4. Model fizyczny rozpatrywanego wahadła torsyjnego

Analytical solution of the dynamical problem of torsion vibrations is given by the angular harmonic oscillator’s equation with free vibrations:

, (3)

, (4)

where TC is the period of free vibrations of the system.

To prepare the model for numerical computation, it was converted into a set of ordinary differential equations of first order:

, (5)

where a = GI0/(Bl) is an auxiliary constant.

The Runge-Kutta method of 4-th order (RK4) is one of the most common methods for solving systems of ordinary first-order differential equations and will be used for solving equations (5) of the torsion pendulum. It possesses a relatively simple coding, simplicity of implementation and high accuracy.

According to RK4 algorithm given by equations (7) and (8), a subsequent point of the discrete trajectory of numerical solution is estimated by the formula:

(6)

where ki (for i =1 … 4) are the approximation coefficients of the derivative at different points on the trajectory within the time range [ti, ti+1], h – a time step of integration.

The approximation coefficients of the applied method are given by formulas:

(7)

Table 1 shows the comparison of data output from numerical and analytical solutions. The following parameters are assumed: time step of numerical integration h = 0.001, and the initial conditions:

The observed variable is the angular displacement of the pendulum. As can be observed both graphs are identical and overlap. The difference between obtained values in both methods can be observed on sixth decimal place. The data series used to build the graph was obtained from the microcontroller via the UART communication protocol.

Table 1. Numerical and analytical solution of the angular displacement (t)

Tabela 1. Analityczne i numeryczne rozwiązanie przemieszczenia kątowego ϕ (t)

t[s]

ATmega

644PA

Analytical

Solution

0

0

0

0.001

0.000944

0.000945

0.002

0.001579

0.001580

0.003

0.001697

0.001698

0.004

0.001261

0.001260

0.005

0.000412

0.000409

0.006

0.000570

0.000576

0.007

0.001366

0.001372

0.008

0.001715

0.001719

0.009

0.001503

0.001502

0.01

0.000799

0.000794

4. Conclusions

As it was presented on the basis of many examples, the ATmega family microcontrollers proved to found many practical applications, both in scientific research and industrial use. Atmel microprocessors are offered in a wide variety of package styles, they have low power consumption over a wide operation voltage range and allow excellent code density. Embedded AD/DA converters, better support for communication protocols and more flexible programming have proved to be more efficient in many cases of real applications comparing to even a small PLC controllers. The second part of the article has shown in details that the ATmega644PA is capable of controlling even complex multidimensional dynamical systems, and has enough processing power for conducting numerical calculations. In both tests of usability some satisfactory results have been achieved.

Acknowledgements

This work has been supported by the Polish National Science Centre, MAESTRO 2, No. 2012/04/A/ST8/00738.

References

1. http://www.atmel.com/products/microcontrollers/avr/default.aspx

2. http://www.arduino.cc

3. Zhang D.G., Dong D.C., Peng H.T.., Research on development of embedded uninterruptable power supply system for IOT-based mobile service, “Computers and Electrical Engineering”, Vol. 38, No. 6, 2012, 1377–1387. DOI: 10.1016/j.compeleceng.2012.04.001.

4. Kioumars A., Tang L., ATmega and XBee-Based Wireless Sensing, [in:] Proceedings of the 5th International Conference on Automation, Robotics and Applications, Dec 6‒8, 2011, Wellington, New Zealand. DOI: 10.1109/ICARA.2011.6144908.

5. Lu Y., Liu Y., Li G., Song G., Liu M., Liu W., Design and application of an automatic packaging machine controller based on ATmega 128, [in:] The 2nd International Conference on Computer and Automation Engineering (ICCAE), 2010, Singapore.

6. Shah J., Modi B., Singh R., Wireless Home Appliances Controlling System, 2014 International Conference on Electronics and Communication Systems (ICECS), Coimbatore, India. DOI: 10.1109/ECS.2014.6892520.

7. Syamsiana I.N., Putri R.I., High voltage pulse generator design with voltage control for pulse electric field (PEF) pasteurization, [in:] International Conference on Electrical Engineering and Informatics, 17–19 July 2011, Bandung, Indonesia. DOI: 10.1109/ICEEI.2011.6021712.

8. Croitoru B., Tulbure A., Abrudean M., Microcontroller-based multiple-platform PWM signal generation procedures for industrial use, [in:] IEEE International Conference on Automation, Quality and Testing, Robotics, Cluj-Napoca, Romania 2014. DOI: 10.1109/AQTR.2014.6857891.

9. Yue C., Guo S., Li M., Shi L., Electrical System Design of a Spherical Underwater Robot (SUR-II), [in:] Proceeding of the IEEE International Conference on Information and Automation, 2013, Yinchuan, China. DOI: 10.1109/ICInfA.2013.6720479.

10. Sieber A., Jones N., Stone B., Pyle R., Koss B., Sjoblom K., Embedded Systems in the Poseidon MK6 Rebreather, [in:] 7th Workshop on Intelligent solutions in Embedded Systems, Ancona, chapter 3, Italy 2009. DOI: 10.1007/978-94-007-0638-5_3.

11. Zou JT., Su KL., TsoH., The modeling and implementation of tri-rotor flying robot, Springer, “Artif Life Robotics”, Vol. 17, No. 1, 2012, 86–91. DOI: 10.1007/s10015-012-0028-2.

12. Czerwiński E., Szewc M., Wojtunik I., Awrejcewicz J., Olejnik P., Mathematical model, computer aided design and programming of a multifunctional flying object, Taylor & Francis, Aviation, Vol. 18, No. 1), 2014, 28–39. DOI: 10.3846/16487788.2014.865941.

13. [www.atnel.pl/download/elektronika/atb_instrukcja/Instrukcja-zestawu-ATB_v102.pdf] – Documentation for the ATB1.03 testing board.

14. Kunikowski W., Awrejcewicz J., Olejnik P., Efficiency of a PLC-based PI controller in stabilization of a rotational motion affected by the chaotic disturbances, [in:] Dynamical Systems – Applications, Eds. J. Awrejcewicz, M. Kaźmierczak, P. Olejnik, J. Mrozowski, Publishing House of Lodz University of Technology, 2013, 173‒184.

15. Awrejcewicz J., Olejnik P., Friction pair modeling by 2-dof system: numerical and experimental investigations, “International Journal of Bifurcation and Chaos, World Scientific”, Vol. 15, No. 6, 2005, 1931‒1944. DOI: 10.1142/S021812740501306X.

16. Awrejcewicz J., Olejnik P., Occurrence of stick-slip phenomenon, “Journal of Theoretical and Applied Mechanics”, Vol. 45, No. 1, 2007, 33–40.

Wojciech Kunikowski, M.Sc. Eng.

wojciech.kunikowski@gmail.com

Ph.D. student of Mechanics at the Faculty of Mechanical Engineering at the Lodz University of Technology. In July 2014, he defended his thesis in Mechatronics titled “Fuzzy logic in angular velocity control algorithms of DC motors”. Currently, under the leadership of Paweł Olejnik, Ph.D. D.Sc. His planned Ph.D. thesis is to be in the field of Applied Mechanics. His research interests cover: theory of control, mechatronics, system modeling, numerical simulations.

Ernest Czerwiński, M.Sc. Eng.

czerwinski.ernest@gmail.com

Ph.D. student of Mechanics at the Faculty of Mechanical Engineering at the Lodz University of Technology. In July 2014, he completed Master’s degree in Mechatronics by writing the thesis „Modeling and parameter identification of vibrations of a double torsional pendulum with friction”. Currently he is continuing research in the field of Applied Mechanics. Research interests: classical mechanics, theory of control, mechatronics, CAD design, system modeling, numerical simulations.

Paweł Olejnik, Ph.D. D.Sc. Eng.

pawel.olejnik@p.lodz.pl

In 2000 he completed Master’s degree in computer physics at the Faculty of Technical Physics, Computer Science and Applied Mathematics of Lodz University of Technology. Then, he took a research and teaching job in the Department of Automation, Biomechanics and Mechatronics at Lodz University of Technology. In 2002 he defended his doctoral thesis in Mechanics under the leadership of Professor Jan Awrejcewicz with a distinction of self-made experimental station exploring of a two degrees of freedom system with friction. He received D.Sc. degree in Applied Mechanics from Lodz University of Technology in 2013. He is an author of scientific publications concerned on the use of computational techniques for solving problems of dynamical analysis of discontinuous systems, experimental research on laboratory stations, control of dynamical systems, virtualization of mechatronic systems.

Prof. Jan Awrejcewicz, Ph.D. D.Sc. Eng.

jan.awrejcewicz@p.lodz.pl

He received the M.Sc. and Ph.D. degrees in the field of Mechanics from the Lodz University of Technology in 1977 and 1981, respectively. He received bachelor’s degree in Philosophy in 1978 from the University of Lodz, and D.Sc. degree in Mechanics from Lodz University of Technology in 1990. He is an author or co-author of 538 publications in scientific journals and conference proceedings, monographs, text books, edited volumes, conference proceedings, journal special issues, other books and short communications or unpublished reports. He is now the Head of Department of Automatics and Biomechanics, and the Head of Ph.D. School on ‘Mechanics’ associated with the Faculty of Mechanical Engineering of Lodz University of Technology. In 1994 he earned the title of Professor from the President of Poland, Lech Wałęsa. He is a contributor to research journals and to conferences. His papers and research cover various disciplines of mathematics, mechanics, biomechanics, automatics, physics and computer oriented sciences

Autor korespondujący:

Paweł Olejnik, pawel.olejnik@p.lodz.pl

Artykuł recenzowany

nadesłany 3.12.2014 r., przyjęty do druku 12.01.2015 r.

Zezwala się na korzystanie z artykułu na warunkach licencji Creative Commons Uznanie autorstwa 3.0