Sie sind auf Seite 1von 4

978-1-4244-3986-7/09/$25.

00 2009 IEEE
Design and Implementation of a Control System
Using AVR Microcontroller
Wang Weihong
1
, Xia Liegang
2

College of Software, Zhejiang University of Technology
Hangzhou, China
1
wwh@zjut.edu.cn
2
xialiegang@gmail.com

Abstract Nowadays, the intelligent appliance is becoming an
integral part of the smart home. In this paper, we adopt AVR
microcontroller atmega64 and relevant signal process circuitry to
design a control system, which is used to control the intelligent
toilet. After an overview of the hardware and software design of
this control system we analyze some detailed design. A series of
conflicts encountered in the course of implementation are listed
in the paper. With the resolution of these issues, this system has
been implemented to control an intelligent toilet with high
reliability and practicality.

Keywords intelligent toilet; AVR microcontroller; peripheral
equipment; stepper motor; polling scheme
I. INTRODUCTION
With the improvement of living standards, peoples demand
for intelligent electric appliances is growing fast. Also, the
widespread application of embedded systems allows us to
meet this demand. In this paper, we design a control system
based on ATmega64, which is used to control an intelligent
toilet. Judging from the performance of our control system, it
is better than most products on sale.
There are two main sections in this paper. First we will
introduce the control system, including hardware, software,
and some function of this intelligent toilet. Then we will
analyze the coordination of the system when designing the
details, mainly introducing some important parts.
II. CONTROL SYSTEM
We always judge an embedded system by its reaction
speed, function, cost and reliability. The performance of a
system mainly depends on the microcontroller. The
ATmega64 is a low-power CMOS 8-bit microcontroller based
on the AVR enhanced RISC architecture. Some of its useful
and important peripheral features are:
Four Timer/Counters, two of them are 8-bit, and the
others are 16-bit.
Two 8-bit PWM channels and six PWM channels
with programmable resolution from 1 to 16 bits.
8-channel, 10-bit ADC.
Programmable watchdog timer with on-chip
oscillator.
With these features, we can greatly reduce the complexity
of relevant signal process circuitry. Accordingly, the control
system is more reliable and performs better.
A. Function Introduction
Embedded Systems are being integrated into toilets with
more functions. By the datasheet of ATmega64, we can find
some of these features are:
Automatic-flushing, typically flushing a toilet when the
user stands up, or flushing a urinal when the user steps
away.
Water jets, as an alternative to toilet paper.
Blow dryer, to dry the body after using water jets, and
the temperature of the wind is adjustable.
Automatic lid operation, to open and close the lid or
seat automatically.
Heated seats.
Deodorizing fans.
It is worth mentioning that the temperature of the water or
seat is adjustable, and the exact nozzle position can also often
be adjusted forward or aft manually.
Since we have to realize these functions, there should be
corresponding equipment. In our control system, we use a
bipolar stepper motor to operate the lid, and DC motors to
operate the drying or deodorizing fan, even the pump, and an
electrothermal tube to heat the water or the seat, and so on.
Then, how to control and coordinate this equipment well
becomes our most important question.
B. Hardware Introduction
The hardware system is the basis of the whole system.
Next, we will try to summarize some key parts.
1) Overall Structure: As shown in Figure 1, we divide all
the peripheral equipment into two parts. The microcontroller
always plays the role of computing device, memory and
controller. Next, we will describe these parts one by one.
Sensors and Keys
ATmega64
Motors Leds
Electrothermal
Tube
INPUT
OUTPUT

Fig. 1 Structure of the hardware system
2) Microcontroller: As the most important component of
the control system, ATmega 64 is a high-performance, low-
power AVR 8-bit microcontroller. It adopts advanced RISC
architecture which means up to 16 MIPS throughput at 16
MHz. The ATmega64 has 64KB of in-system
reprogrammable flash, 2KB EEPROM and 4KB internal
SRAM. These features make it a good choice for a control
system.
3) Output Devices: Based on the functions of this system,
there are many output devices that have to be controlled. We
have some motors that are used to lift the lid or seat, others are
used to control the position of the nozzle.
Some other important devices are:
LED(Light Emitting Diode), most of the LED lamps
are used to show the work status of the whole system.
Electrothermal tube, to heat the water, seat or air.
Pump, to increase the water pressure.
SL solenoid, a valve to control the water flowing into
the water tank.
4) Input Devices: Input devices are used to detect the
users action or the operation status of the important
components. For example, the ranging infrared sensor can
detect someone standing in front of the toilet, and a hall sensor
can detect the position of the motor shaft.
Some other input devices are:
Angle sensor, to determine the location of the lid or
seat when lifting them automatically.
Thermistor, to detect the temperature of the water or
seat.
Infrared receiver, to receive the information from a
remote control.
Water-level sensor, to detect if there is water to heat.
Pressure-sensitive sensor, to detect if there is
someone on the seat.
C. Software Introduction
In order to maintain and expand our software easily in the
future, the program is written in C language.
1) Polling Scheme: According to the characteristics of the
peripheral equipment, also considering the reliability of the
system, as shown in Figure 2, we adopt the polling scheme to
control all devices, which means the microcontroller will
check the flag and status of any device from time to time.
Once the flag is not the same as the status, an interrupt
program will be called to execute.
Since there are only four timer/counters offered by
ATmega64, and this is far from enough according to the
function of the system, we have to create a timerto count
the times of cycle interval. Considering all these aspects, we
set the cycle interval of the polling scheme at 5 milliseconds.
Now, if we want to set a time of 1 second, what we need to do
is only count 200 times in the polling program.
Tutut
ly:
Su:o:
Stutu:
lvy 5ms
unchange
unchange
unchange
Cluu_
tl
'u_
Main
l'u_:
change
\u`ou:
`utut
o_um:
Loop
change
change
change
unchange

Fig. 2 Flowchart of the polling scheme
In another loop of this software, the program will call the
interrupt programs to execute some task and change the status.
2) Auto-aging Procedures: To check the stability and
reliability of the control system, we design an auto-aging
program. Through moves of this procedure, we may
demonstrate all the function of this system.
Another function of the auto-aging procedures should be
continuous running of the system automatically. This is a kind
of approach to assess the performance of the entire system
not only the hardware, but also the software.
III. DETAILED DESIGN
The main difficulty in designing the control system may be
finding the method to solve the conflicts, which are existing
almost everywhere. Not only that, but we have to coordinate
all the parts so that they can run as a whole.
Next, we will list some detail of this system to illustrate
how we solve the conflicts.
A. Between Microcontroller and Peripheral Equipment
1) Pin Number: Although ATmega64 has 53 programmable
I/O lines, it is not enough for our control system. As shown in
Figure 3, we add 3 chips to expand the pins. Considering the
devices connected to these expanded pins, such as keys,
sensors, always check the transient signal, we can read these
signals through the chips one by one.

Fig. 3 Expansion of the pinout
2) ADC Channels: The ATmega64 features a 10-bit
successive approximation ADC. The ADC is connected to an
8-channel Analog Multiplexer which allows 8 single-ended
voltage inputs constructed from the pins of Port F. The single-
ended voltage inputs refer to 0V(GND). As shown in Figure 4,
PF4-7 are used to consist into a JTAG interface, so there are
only 4 channels left for us.

Fig. 4 The ADC channels of ATmega64
Here in Figure 5, we adopt a dual differential comparator
LM393 to check the signal from a ranging infrared sensor.

Fig. 5 The circuit with LM393
We can modulate the voltage on port 6 by the variable
resistorW2. Accordingly, the voltage on the port 5 should
be changed. To the ranging infrared sensor, this change of
voltage is from the change of distance. So, we can use the
ranging infrared sensor without occupying any ADC channel.
B. Between Peripheral Equipments
1) Motor Control: The stepper motor is important to our
control system, and there are various methods to control the
bipolar stepper motor. Josh Zagorski introduced a method
with an Allegro A3977SED in Stepper Motor Controller.
The more typical control method is to adopt L297 + L298
configurations.
In this control system, L297 will occupy at least 3 pins
from the microcontroller. The L297 is intended for use with a
dual bridge driver, quad darlington array or discrete power
devices in step motor driving applications. It receives step
clock, direction and mode signals from the systems
controllerATmega64 and generates control signals for the
power stage. The principal functional components are a
translator, which generates the motor phase sequences, and a
dual PWM chopper circuit which regulates the current in the
motor windings. The translator generates three different
sequences, selected by the HALF/FULL input. These are
normal (two phases energized), wave drive (one phase
energized) and half-step (alternately one phase energized/two
phases energized). Two inhibit signals are also generated by
the L297 in half step and wave drive modes. These signals,
which connect directly to the L298s enable inputs, are
intended to speed current decay when a winding is de-
energized. When the L297 is used to drive a unipolar motor
the chopper acts on these lines.
An input called CONTROL determines whether the
chopper will act on the phase lines ABCD or the inhibit lines
INH1 and INH2. When the phase lines are chopped the non-
active phase line of each pair (AB or CD) is activated (rather
than interrupting the line then active). In L297 + L298
configurations this technique reduces dissipation in the load
current sense resistors.
As shown in Figure 6, we need two bipolar stepper motors.
Shall we really use two motor controllers? At last we just add
a relayHFD27 in the circuit. So we can choose a motor to
control by the relay. It is obvious that this controller is more
reliable and less costly.

Fig. 6 Control two motors
2) LED Control: There are two cases that we need to use the
LED. Normally, it is used to indicate the running status, like
the power is on, the water is heated, etc. When some part of
the system is abnormal, the LED is used to indicate which part
is unusual.
One idea is that we need two sets of LED lamps, but can we
realize all these features with only one set? Then we have
another idea. Actually these two cases wont happen at the
same time, so we can control one set of LED lamps with just
two programseach program for one case. The result shows
that this new idea is entirely feasible and much better than the
first one.



IV. DETAILED DESIGN
Embedded System has been widely used in industry in
recent years. It profoundly enhances the performance of the
product. In this paper, we designed a control system in which
ATmega64 was adopted as the microcontroller. Based on the
principle of reliable and reasonable we designed a variety of
peripheral circuits to control all the peripheral equipment. At
the same time benefiting from the flexibility of software, the
control system has already been used in an intelligent toilet
and proves to be successful.
Although we already adopted a lot of much more
appropriate technology to improve our system, there is still
something that is not perfectly implemented. A better way is
expected to improve the method of control for a stepper
motor, and more advanced features may be added into the
system.
ACKNOWLEDGMENTS
This research was supported by the National High
Technology Research and Development Program of China
(863 Program, 2006AA10Z235) and National Natural Science
Foundation of China under grant no.60873033.
REFERENCES
[1] Atmel Corporation, ATmega64(L) Preliminary Complete Datasheet,
2490G-AVR-03/04. 2001.
[2] Rolf Ernst, Codesign of Embedded Systems: Status and Trends,
IEEE Design & Test of Computers. IEEE Computer Society Press, vol.
15, Apr-Jun 1998, pp. 45 - 54. 1998.
[3] J. Zagorski, Stepper Motor Controller, Available: http://jszagorski.
googlepages.com/StepperMotorController.pdf. 2007.
[4] SHARP Corporation. GP2Y0A02YK Optoelectronic Device Datasheet,
SMA06009.Available:http://document. sharpsma.com/files/GP2Y0A02
YK-DATA-SHEET.PDF. 2006.
[5] Fairchild Semiconductor Corporation. LM393/ LM393A Datasheet.
2001.
[6] P. Arat, S. Juhsz, Z.A. Mann, A. Orbn and D. Papp,
Hardware/software partitioning in embedded system design,
Proceedings of the IEEE International Symposium on Intelligent Signal
Processing, pp. 197- 202, 2003.
[7] I. Panagopoulos, C. Pavlatos and G. Papakonstantinou, An Embedded
Microprocessor for Intelligent Control, Journal of Intelligent and
Robotic Systems. Springer Netherlands, vol. 42, pp. 179-211, 2005.

Das könnte Ihnen auch gefallen