Implementation of A Fuzzy Logic Based Se
Implementation of A Fuzzy Logic Based Se
A Thesis
Submitted to the Faculty of Graduate Saidies
in Partial Fulfilment of the Requirements
for the D e p of
MASTER OF SCIENCE
Permission bas been granted to the U b a r y of The University of Manitoba to knd or sell
copies of thb thesidpmcticum, to the National Library of Canada to microfilm this thesis
and to kad or sell copies of the fdm, aod «,Dtscrtatioas Abshnco Internatioaai to piblish
an absîract of this thesWpracticum.
The aothor reserva other publication iigbts, and neitbet this tbesidpracticum nor
esteosive extracts fmm it may be printed or otherivise reprodueed without the author's
w-ritten permission.
Imprecise seeding depth can lead to lower crop yields and increased power requirements.
For example, a variation of 2.56 cm (1 inch) b m optimum depth resdts in 45%, 2546, and 15%
reduction in the emergence of soybeans, sorghum, and wheat, respectively. Problems encountered
with traditionai linear seediag depth control systems inciude oscillation, instability, and
inaccurate depth control in undulating terrain. Variations of 1.27 cm to 4.45 cm (0.5 to 1.75
inches) are not uncornmon.
The control system in this ~searchutilws a rnicmprocessor-based fPzzy logic control
process in combination with a novel seeding depth gauge system. This system combines the
human coatrol reasoning of fùzzy logic with an electro-hydraulic seeding depth controiler. The
fuzzy algorithm is modelled upon expert human control by means of linguistic variables that
describe the error between the measured seeding depth and the desired depth set point. The inputs
of the fuzzy conml rules are the e m r between the measured seeding depth and the desired
seeding depth, and the rate of change in e r r a (the dinerence between the present and a past
sarnpliag instance). These variables descrik the direction of the e m r (positive, P or negative, N)
as weli as the magnitude (smali, S, medium, M or big B). The change in e m r is rnonitored in
order to provide dinerential control. Stability of the control system is ensured by monitoring these
proportional and differeatial input signals. The microprocessor unit used in the controller is the
Motorola MC68HC16Zl.
Three scenarios were examined: a 3-membership function, a 5-mernbership function, and
a 7-membership function fuzzy control algorithm. In each idgorithm simulation, the variation in
output gain, complexity, and number of MPU cycles to execute was observed. The 5-membership
function aigorithm ushg trianguiar memkrship functions was found to provide the best
combination of control and complexity for this application.
Two controller units were consmicted, for testing in laboratory simulations and under field
Data was
conditions. The 5-membership fuaction algorithm was tested under field conditio~~~.
logged fiom the field trials, with error mean fiom the set point king 2 mm, with variation and
standard deviation king 17.1 cm and 2.8 cm, respectively, based on converted A/D nadhgs.
I wish to acknowledge the guiding efforts of my advisor, Dr. W~toldKinsner, for providing
the topic of this research and for takllig the photos of the contmUer modules. His encouragement
and faith in what bis students can achieve serves as testament to bis dedication to the
advancement of knowledge.
I also wish to express my heardelt th& to George Oamby, President of hofile Resource
Management. George and 1 spent many days and eveaings at the workshop and in the fields of
Gamby Farms Ltd. during both static tests throughout 1994, 1995 and 1996, and field testing in
fall'96.1 also wish to acknowledge the support of Gamby Fanns Ltd. for the use of the workshop,
tractor and discer throughout tbis research, as weil as Joseph Gamby for his assistance with the
sensors.
In pursuhg a cross-disciplinary approach to research, I had the help and support of many
graduate students in the Department that were always willing to take the time to explain a new
concept or approach to a problem, and always to share their enthusiasm for leaming. Special
thanks goes to Dr. Ken Ferens, Dr. Armein Langi, Geoff Stacey, Warren Greider, Eric Jang, and
Aiex McIlraith.
1 wish to express thanks to my colleagues at ALjuit Aerospace Incorporated. Their
encouragement and support are very much appreciated Th- also goes to Vlad Kowalyk of
New Hoiland Canada, who supplied the sensors and the proportional valve, as well as advice on
suppression of noise in electricd devices on agricultural tractors.
This work was financially supported in part by Profile Resource Management, Iac. of
Winnipeg and the Natural Sciences and Engineering Research Council of Canada Technical and
software support was also received h m the Department of Electrical and Computer Engineering
of the University of Manitoba
This thesis is dedicated to my supportive parents, Gaii and ClBord Tessier, and my loving
wife Angela, who worked with me every step of the way to the conclusion of this work. It is also
dedicated to our daughter Adrienne, who always keeps life in perspective for her parents!
A b ~ t r o e t ~ ~ ~ ~ m a ~ . m ~ ~ . ~ ~ ~ ~ . ~ . m . ~ ~ ~ ~ ~ m . ~ . ~ ~ ~ ~ ~ ~ ~ m ~ ~ ~
0 . 0 ~ ~ ~ ~ ~ ~ ~ a ~ ~ a m m ~ ~ a
Acknowledgements ......................................................iv
Table of Contents ........................................................ v
ListofFigures ...........................................................ix
ListofEquatioas ............................xi
ListofAbbreviations ..................................................... xü
Chapter 1:
Introduction .........................................................m.gl
1.1 Background and Motivation .......................................... 1
1.2 Thesis Objectives ................................................... 2
1.3 Overview of Thesis Chapter Contributions ............................... 3
Chapter 2:
Control of Seeding Depth .................................................7
2.1 Effects of Seeding Depth on Crop Emergence ............................ 7
2.2 Types and Accuracy of Seeding hplements .............................. 9
2.3 Advantages to using discer seedea in the Red River Valley .................. 13
2.4 MethodsofDepthControl ............................................ 14
2.5 Chapter Overview .................................................. 16
Chapter 3:
Chapter 5:
.
Detailed Hardware Design of the Fuzzy WCB a d Depth Controlkr ..........53
5.1 The Controuer Module .............................................. 55
5.2 TheDepthSensorModule ............................................ 61
5.3 The Hydraulic Control Module ....................................... - 6 3
5.4 Electrical Noise and EMI Suppression .................................. 65
5.5 Power Supply Module ............................................... 65
5.6 Chapter O v e ~ e w................................................. - 6 7
Chapter 6:
Software Design of the Fuuy logic-Based Seediiig Depth Contn,Uer .............69
6.1 Initiakation and Data Preparation Routines ............................. -70
Initiaikation .................................................70
CHECK-KEYSRoutine ....................................... 72
SAMPLERoutine ............................................77
ERROR-CONVERT Routine .................................. - 7 8
ERROR-BUFFERRoutine .....................................78
6.2 The F u z y Control Subroutine: ....................................... - 7 8
FUZZYTEST Routine ........................................ - 8 0
6.3 Hydraulic, LCD Display and Data Logging Routines ....................... 84
HYD-CONTRoutine ......................................... 84
Display-Depth Routine ........................................85
Send-DataRoutine ........................................... 86
6.4 Chapter Overview .................................................. 88
Chapter 7:
System Implementation ...................................................89
7.1 Field Test and Data Logging Mode ..................................... 89
Operational Issues ........................................... -90
Field Operation .............................................. 91
7.2 CalibrationMode ................................................... 96
KeypadFmctions ............................................ 97
7.3 Chapter Overview ................................................. -101
Chapter 8:
Discussion and AnalysSs of F o a y Logk B d Seeding Depth ContmUer .........103
8.1 F u u y C o n ~......................................................
l 103
8.2 SimuIation ........................................................107
8.3 Lab Testing .......................................................114
8.4 Field Testing ...................................................... 115
8.5 Chapter Summary .................................................. 123
Chapter 9:
Conclusions And Recommendations ........................................125
9.1 Performance of the Sensors ........................................... 125
9.2 Hardware Observations and Recommendations ........................... 126
9.3 Aigorithm Development Recommended Impmvements .....................127
9.4 Production of a Fuuy CASE Tool ..................................... 129
9.5 FutureWork ....................................................... 129
9.6 Chapter Overview .................................................. 131
References.............................................................. 133
Appendur A: Fwzy Depth Controiier Schemtic Diagrams ..................... A-1
Appendix B: !hftware Flowchart .F u a y ControUer ..........................B-1
B .1 Controuer Initiaiization........................................................................................ ...B 4
8.2 Main Program Execution 2
CHECK-KEYS Flowchart ............................. ....J3-8
RATSED-POSKION-SET ............................................................................B-10
Setting Disk Raised Position............................................................ B-1
Sening Disk Raised Position............................................................ .B -12
Choosing Imperia1 or Metric Units ..................... . . ................*.......B-13
MOVETO-UP ............................................................................................. B. 14
SET-OPERATING-DEPTH ................................ d l 5
FIELD-0-POSlTION-SET ....................................................................... J-16
CALIBRATE ... .........................B.17
.............e.*.r.........*.....*.....*.e..o.*.............*.....
Fig.3.1. Membenhip functions. uich a reference fuzzy set of the term set for error........24
Fig.3.2. Fuzzification of the crisp input XO into the memkrship fiinctions of error.......25
Fig.3.3. Fuzzi£ication of the cnsp input X1 into the membership fcns of chg in error.....25
Fig.3.4. Fuzzy conmil d e summary ........................
............ .d
Fig. 3.5. Alpha cuts for the output Du@) when N = 0.0. Z = 0.3. P = 0.25. ................... -32
Fig.3.6. The rwultiag mean of maxima (MOM) output for change in output..................33
Fig.3.7. Geometric representation of fuzzy sets A aod B............................................... ..35
Fig.3.8. A fuuy contrd output s d a c e............................................................................. 36
Fig.3.9. The Fuzzy Logic Controiler (FLC)in the framework of a control system.........38
Min of inputs.................
........... ........................................................ 106
Mernbership of the min of the input variables (x. y) ........................ .
.
......107
Max of ail fuuy phrases............................................................................... 107
A ampetes
AC altemathg current
A/D analog to digital converter
CAL caiiirate
CNT control
COA center of area defindication method
CONT control
COP microprocessorunit w atchdog mer
cm centimetre
CPU central processing unit
DC direct current
DEG degrees
DOS disk operathg system
DSP digital signal processing, digital signal processor
EPROM erasable, programmable read-oniy memory
ERR errot
FCN fiinction
FFI' fast Fourier transfonn
FLC fuuy Iogic controllet
GPT general purpose tirnet of the MC68HC16
HYD hydraulic
Hz hertz, cycles per second
IBM International Business Machines
in inch
UO inlout Iiaes andlor referrhg to a microcoatroller UO subsystem
Wiz kilohertz, 1,000 cycles pet second
KHz kilohertz, binary designation, 1,024 cycles per second
km kilometre
LCD liquid crystal display
LED light emitting diode
ma milliamperes, 111,000 of an amp
MAX maximum function
MC68HCI 1 Motorola &bit micmprocessor unit29
MC68HC16 Motorola 16-bit micmprocessor unit
MEMB membership
MHz megahertz, million cycles per second
MIN minimum function
mm millimetre
MOM mean of maxima defimification method
MOV metal oxide varistor
MPU microprocessorunit
MS Microsoft
OM organic matter
PC IBM-compatible personal computer
PD proportional-differentialcontroller
PI proportional-integral controuer
PID propoaional-integrai-differentialcontroller
PWM pulse-width modulation
QSM queued serial module of the MC68HC16
RAM random access memory
ROM read-only memory
RS232 serial interface port, adhering to RS232 standard
S M system integration modde of the MC68HC16 MPU
SRAM standby, battezy-backed RAM in the MC68HC16 MPU
STD DEV standard deviation
SYS system
v volts
VAR variance
VLSI very large scale integntion
1.1 Background and Motivation
The depth of seeding of field crops is a cntical crop production factor. Of al crop
management parameters that must be coatrolled, this is one of the few that requires ao
additional cash outlay, yet can have a profound effect on the final yield and grade of a cmp
Each type of seeding implement has unique characteristics that affect how weli it
maintains accurate depth while seeding. Among the types which pose the greatest control
accuracy challenge is the one-way discer seeder. This type of implement has been replaced
by other types on many Western Canadian farms for various reasons, not the lest of
which is the difnculty in maintainhg consistent seeding rate and depth under conditions of
varying terrain and soi1 conditions. However, one-way discer seeders are still predominant
in many parts of the Red River Valley of Manitoba, as it has the advantages of both low
capital cost combined with high efficiency in penetrating the characteristic heavy clay-
based soi1 textures predominant in the region. Seeding with discer seeders cm often
commence without the need of s p ~ pretillage
g of the field. By eliminathg this spring
pretiiiage, fuel costs are lower, wbüe the threat of soi1 erosion is also reduced. Additional
advantages are a lower labour nquirement due to fewer tiiiage passes over the field, thus
resulting in food producers complethg seeduig earlier in our short growing season. This,
in tum, reduces the risk of laie season fiost damage to the crop.
Fig. 1.1. w i c a i discer seeâer.
W~ththe problems discer seeders have in maintaining consistent seeding depth,
agricuitural crops may suffer in both yield and quaIity when discer seeders are used and
due care is not taken to m ü h k excessive emrs in seeding depth. Th- negative effects
manuaily controiied discer seeders, Dyck, at the University of Saskatchewan. found that
depth variations of plus or minus 1.27 to 4.45cm (0.5 to 1-75 inches) were not uncornmon
IDyck751. This fauity depth regulation may also lead to signikant increases in p w e r
requirement for heavy mil, particuiarly for large equipment [GKWD8 lb].
of fuzzy Logic contxol. The seeding depth controuer described in this thesis combines the
Chaptcr 1: Introduction
human control rrasoauig of fuPy logic with a traditional electrobydraulic seeding depth
controiler to provide optimal depth control with minimalinput fiom the operator.
presentation of the basic concepts of hiay logic control and why this approach was
chosen in m i s study. Thus, the problems to be addressed by this research are defined.
These chapters are then followed by three chapters which present the system organization,
hardware details, and software design. Finaily, the 1 s t two chapters present the results and
recommendations fkom this research. The appendices contain iDformation related to the
Chapter 2
The problem of maintaining correct seeding depth and current methods used to
control seed depth are outlined in this chapter. The approach taken is from the viewpoint
research and on prairie cereal famis. This aiiows for an intuitive definition of the problem
that is consistent with the reason funy control is king investigated for this application:
lirerature that can define how such a system should respond to a wide variety of field
conditions.
Chapter 1: Inuoduction
Chapter 3
The theory of fuzzy logic controiiers is presented in Chapter 3 of this thesis. This
will be compared to the basic theories of conventional control law, and how tbis relates to
some of the problems encountered in conventional seeding depth control methods. The
reader is stepped through the profess of d e m g a control problem, generating niles, and
how the fuuy inference process works. A simple example is used to illustrate the major
points. The final portion of this chapter dso provides background information on the topic
Chapter 4
Once the problems with using conventional control law in designing seedhg depth
controllen has been presented. the system definition section wili explain how the theones
of hiuy control can be applied to solve the problem. By d e m g the problem and the
approach to a solution, the required hardware and software specincations are developed.
Vitrious choices in hardware and types of software algorithms wiil be explored. Finally,
the chosen design will be outiined, with an explanation of why this route was chosen.
Chapter 5
A more detailed blodc diagram wilî be presented in the Detailed Hardware Design
of the Fuzzy Seeding Depth Controller, with an explanation of the system architecture and
organîzation. The implementation wiii aIso be described, with speciai focus on how the
Chapter 6
In this chapter, the objectives and functions of the software design are presented.
This section wiU also outline how this relates to the nst of the system architecture. The
Chapter 7
The integration of the hardware and software to produce a working fuay seeding
depth control system is explained in the System Implementation section. This includes the
process of putting the different parts of the system together and vewing that the systern
Chapter 8
In the Discussion and Andysis of the Fuay Seeding Depth ControlIer section,
theoretical and field experirmntal results are presented. The design of the experirnents is
explained, with emphasis on the test methods and what parameters were king tested. The
final results will also be discussed, with an explanation of why the best results meet the
test criteria.
Chapter 9
Findy, the Coaclusions and Recommendations summarizes the proven points and
work in thïs area wiU aiso be presented based on what howledge was gained fiom this
research.
The approach of this research is to combine the theoretical aspects of hizzy logic
connol with the practical aspects of controliet implemntation and testing. The f h t sfep
Chapter 1: huoduction
of this process, the definition of the problem of accurate seeding depth control, will be
defined in Chapter 2.
Cbaptcr 2: Control of Seeding Depth
In this Chapter, the problem of maintaining consistent and accurate seeding depth
control is prrsented. The crop emergence and crop health coasequences of poor seeding
depth control are pnsented in Section 2.1. In Section 2.2, the most common methods of
seeding depth control with discer seeding ùnplements are described and compared.
negative effects of improper seeding depth have k e n observed by many researchea. For
found that depth variations of plus or minus 1.27 to 4.45 cm (0.5 to 1.75 inches) were not
power requirement in heavy soüs, particulariy with large equipment [GKWD8 lb],
[BBKR83].
fundamental problem bas k e n studied for many years, and the effects n quite well
have even k e n developed that predict emergence based on seeding depth m 1 7 4 1 . The
effect can be quite severe, given the nonlinearity of crop emergence fuoctions.
Chapter 2: Conml ofS 4 n g Depth
O 2 4 6 8 10
Depth of Pfanting [un]
Fig. 2.1. Crop emergence as a function of seeding depth. (Mer woGe8Sa], [KGFT93]).
(0.39 inches) fÎom this peak results in a reduction in emergence of 5%. In cornparison,
(0.39 inches) in depth above and below this set point wiil resdt in reduced emergence by
Results such as those presented in Fig. 1 are genedy true for crops in which the
main independent variable, that is to Say, the ody major limiting factor, is the depth of
seeding. Other, less optimai situations typicaiiy arise on prairie fields that can f d e r
magnify the effects of improper seeding depth. Such extra limitations are chanicterized by
Chapter 2: Controi of Seeding Depth
adding additional stnss on the emerging crop, in addition to the stress induced by
Stress factors due to the enects of nature include conditions that may slow crop
emergence, such as extreme environmental conditioas. Soils which are extremely hot.
cold, wet or dry all produce suboptimal conditions for growth. Other natwal factors that
can have a magnifying effcct on poor depth control include intense weed cornpetition,
cmsted soil surface, and the presence of soilborne diseases and insect pests [ H a D m .
Manmade stress factors have also been documented to magnify the negative
effects of poor seed depth control. These iaclude the presence of excessive herbicide
residues such as triailate and trifluralin, especidy in soils low in organic matter (under
2.5%) WSSA83J. This problem c m be very severe in areas such as central Saskatchewan,
where rolling soil with low organic matter eroded knolls are ofien seeded deeper than
surroundhg areas. This deeper seeding is due to depth control system of the seeder king
There are many dinerent types of implernents used in western Canada for seeding
cereal and oilseed crops. In tenns of the types of tillage or soil disturbance methods most
commonly by these implernent types in both cenals and oilseed crops, three are in most
common use today: the double disc press drill, the airflow or airseeder cultivator system,
The double disc press drill is the most accurate seeding implement used on the
prairies, with two flat discs peuetrathg the soil at an angle of o d y a few degrees h m the
direction of travel.
I
Seed Spout
The discs open the soil in such a way that a h o w is produced at the desired
depth. Seed is then dropped iato the hurow, and soil is placed over the seed. Soil covers
the seed by two processes: soil falling back into the funow once the discs have passed by,
and by the compression action of a flat wheel or tire, about twice the width of the furrow,
pushing soil down over the seed and packing i t Depth control with these implements is
generaily by means of mechanical conml, by a stop bolted to the ram shaft of the
hydraulic disc lift cylinder. Most double disc press drills also have s p ~ g which
s act upon
the double disc soil penetrating assemblies, thus keeping fairly consistent depths even in
undulating tenain. The packing discs are mounted ngidy to the seeder fiame, and provide
a large surface area for the seeder to ride on (as wide as the entire implement). Although
they are very accurate, these systems are weil suited only for loose soils that have been
Chapter 2: Control of Seeding Depîb
preworked by cuitivatiag and barrowiagor on very light textureci soils. Some zero tillage
seeders use this system, but o k n need considerable weight and tractor hoisepower to
penetrate the soil to an ndequate deph without field prewodring. 2ero tillage double disc
press drills are excellent for soil and moisture conservation, and in fact have been
designed to preclude the need for any pretillage priot to seeding, thus eiiminating vimially
ail soil erosion. Unfortunately, they also tend to require a relatively high labour, draft. and
Fig. 2.3. Airseeder system with high capacity seed hopper, air blower and cultivator.
a very low lift cultivator shovel as the means of soil penetration. Depth control with these
systems is a challenge, with many companies using different configurationsof depth guide
wheels, dual tires for Boatation over soft soil, elecnic over hydrauLic conventional conml
systems, and various mechanical meam [GKWD8la]. Each rigid cultivator shank may
Chapter 2: Conml of Seedig Depth
have one or two springs holding it in place. The design is a compromise between accuracy
of seed placement and seedbed quaiity to time savings and low labour requirement.
By v h e of it's design, the discer seeder does not use the kind of precise seed
placement techniques used by otber systems. One of the major drawbacks of using one-
way discer seeders is the lack of precise seeding depth controi. Tn fact, depending on how
weii the seed outiet spouts are placed in relation to the discs, the seed could be placed
nonuniform distribution. Seeding rate also varies as the discs gang swings fkom side to
side over dinerent soil conditions, thus widening or narrowing the area seeded per disc
unit.
The discs can be describeci as the concave circular steel tools with a sharpened
edge making up the working part of a discer seeder Wen93J.Discer seeders use gangs of
single concave discs that penetrate the soil at an angle a few degrees fiom the direction of
travel. This angle ope= the concave side of the disc to the soil, where the edge of the disc
Chapter 2: ControI of Seeding Depth
cuts into the soil. The larger the angk of the disc to the soil,the Iarger the cross-section of
soil the disc is exposed to in the direction of travel. As a dtas the mgle of the disc to
,
the soil increases, so too does the draft, increasing the power nquirement h m the tractor
to maintain the same speed. Likewk, with the seed m g the hoppen above the discs,
this added weight can cornpress the tires holding up the discer unit This compression acts
to push the discer deeper into the soii, addiag to the seedhg depth. Lïkewise, with more
depth, draft increases, which adds a traverse force on the discer against the wheels,
causing the discer to swing perpendicular to the direction of travel, thus wideaing the
width of cut across the whole discer. Now, with a seed depth that is deeper than that set by
the operator, there is also an decrease in seeding rate proportionai to the decreased width
covered by the discer in each p a s at this depth. An expert operator is able to weigh the
different factors that affect these problems when choosing the best compromises for depth
sening, includiag such parameters as wheel positioning, speed, and tire pressure.
These include local soil texture(s), local experience, types of crops grown, costs, pre-
seeding preparation methods and labour requirements. In the Red River Valley, producers
on heavy soils such as Osborne Clay have two major problems: incorporating straw left on
the soii surface fiom the previous year's harvest, and penetrating the heavy soii deep
enough while seeding without producing too many soii lumps. One-way discer seeders are
well suited for these conditions. As an additional benefit of using discer seeders, many
producers fhd that they can seed straight into the soi1 in the spring without pretiiîage
Cbapter 2: Controi of Seeding Depth
preparation. This eliminates the tirne, expense, soi1 moisture l o s and increased ri& of soi1
erosion associated with pre-seeding tülage. Seecling with these implemnts has been
popuiar for many years in this region, and is still common, although other seeding
implements are being improved and are slowly being adopted over discer seeding-
"feei" for the sound and vibration of increased engine load when the seeder digs into the
grwnd. Many other schemes have been introduced to improve on this method Froe921.
With the use of a cornputer controlled electromechanical depth monitor for the
hydrauiic depth control mechaaism of a Seeder, average seeding depths varied within a 2
cm range IDyck751.
Fig. 2.5. Discer seeder, (typical of the types used in the Red River Valley of Manitoba),
used in this research.
Fig. 2.6. Illustration of the distance h m the cab to the disk gangs.
control. These methods do not aiways provide consistent accwacy of seedhg depth over
varying terrain conditions, especiaiiy on one-way discer seeders. Commoa methods for
controlling the depth of discer seed implements in uneven terrain are tiring for the
operator, and are inaccurate, leading to increased power requirements and reduced crop
yields. The seeder, which is used for seeduig and on occasion tillage, is raised aad lowered
flow valves. As fuel and machinery costs rise, efforts to maximizc efficiency lead to the
use of larger implements such as 58-foot wide cultivators/air seeders and the practice of
effecriveness of even an expert human operator who must estimate the depth of the rear
furrow as far as 20 m away. Coupled with this, the operators' vision is often obscured by
dust, and they must mentally average out tbe depth for varying soi1 conditions. Errors in
the estimates increase with large variances in soii moistue, topography, soil texture, and
draf't load as the seed emptics out of the hoppers. In discer seed implements, this is M e r
compounded by the fact that the width of the ana seeded also changes with large
operator's experience are used to produce control algorithms that have k e n effective in
controlling nonllliear. dynarnic plants that proved to be extremely difficult or too complex
The problems encountered with one-way discer depth control, with its combinations of
varying dr& loads, soil types, soi1 conditions and topography certainly make this seeding
problem a good candidate for determining the results of applying a hizzy logic control
algorithm mOTN87].
provide the main motivation for the investigations in this research. Characteristics and
limitations inherent in different seeding methods and depth controiler srpes were given.
The prevalence of one-way discer &ers and thek advantages and disadvantages for use
depth control under varying soi1 and topographie conditions, problems have been
expenenced with these control methods. A more suitable control regime was investigated,
with an eye to providing more consistent coatrol by accurate sensing of the seeder depth,
in combination with the ability to vary hydraulic control signal gain based on the depth
position at the current instant in t h e and the position in the past. Fwzy logic control is
welI suited for this type of nonlinear application, and is evaluated in this research.
Chapter 3: Fuzzy Logic Control
nonünear inputs characterue the system [KiMa77]. Examples Uiclude a wide variety of
industrial and domestic uses, fiom controllhg the braking of high-speed commuter trains
The concept of fuuy logic, and specificalIy, funy set theory, can be directly
attributed to Lotn A. Zadeh, of the University of Caiifomia at Berkeley. In the first paper
published on this topic, Zadeh d d b e d fuzy sets and the underlying theory behind them
[ZadedS].
"conventional control law" in Section 3.1. In 3.2, then is a step by step explanation and
example of how one would formulate a hizzy control algorithm. Once the basic principles
of huzy logic control have been presented, Section 3.3 deals with the issue of how to
order to synthesize the algorithm mamd93]. Fuzy control algorithms. on the other band,
Chapter 3: Fuzy Logic Control
are constructeci using logical mies. Each d e defines what the output of the controlier
must be, based on the specific value(s) of input state(s). Rather than behg derived pmly
as the result of creating a mathematical model, the d e s are ofkn fonnulated under the
direction of an expert human operator. Linguistic contml algorithms are used, which are
constructed from a nile base that in nim is fomulated fkom human experience and
intuition. The theoretical and practical aspects of the dynamics of the controlled system
integral, PD, P D )can aü be denved fiom the generai form of the control law for different
w here
e is the error between the setpoint and the output of the controller,
The fuzy logic controllet (FXC),on the other band can ofken be repnsented in a
sirnilar fonn
Cbapter 3: Fwzy Logic Control
control logic. In fact, the representation above is only limited to situations wbere it is not
ciifficuit to describe it verbaliy. This is especially tnie when it is considered that a FLC
uses a knowledge base, so past higher-order values of both the control action u and the
error e are not always needed in order to complete the fuuy algorithm. Since the FLC is
are relevant to the mal-world operation of the plant in ways not possible with conventional
control law WaFi94J.For example, the various operations can be easiiy incorporated into
error change
error sum
control change
Au(k) = ~ ( k- u
) (k-1) (3 -5)
to be controlled. This knowledge can originate as the control actions of an expert human
operator for each set of input variables. It can also originate as a set of &ta containhg
Through the aext several sections of this Chapter, an example funy controuer
with nine d e s , two input variables and one output variable will be used to illustrate the
fuzy control d e s . The control d e s constitute the fuuy control algorithm. These d e s
are consmicted using logical (Boolean) "&then" d e s . The d e s are based on the
base of experience, but in reality they have a very specific syntax. The foilowing is an
ALSO
where
- The "IF'portion of the d e contains the antecedents. This part of the nile
-21 -
contains the conditions that a e c t the plant.
- AND is one of the ailowable fuuy logic Bookan operators, (such as AND,OR.
Non
- the antecedents are in the fom of an input variable equal to some value. For
example, "temperature is HOT",where temperature is the input variable, and hot
- the "THEN" portion of the rule contains the consequent This gives the output or
conclusions, should the conditions in the antecedent part of the d e be satisfied.
- the consequents are in the fonn of an output variable equal to some value. For
example, "fan speed is HIGH", where fan speed is the output variable, and high
Linguistic labels.
In the application described in this thesis, the FLC describes the relationship
action, such as the error, change in enor, and output. The linguistic labels within the d e s
each constinite a fbzzy set, or a referencefuuy set. When a number of refennce fuzzy sets
Chapter 3: Frtay Logic Conuol
are grouped for a specinc variable. this is a tenn set. The variable king measured or
cdculated exists within a finite range of values, or the unberse of discoure. In mmmary,
this means that for one variable, for example, emr; e(k), the t e m set contaias a number of
reference fupy sets (wgative, appmximately zero, and positive), ail defiwd over the
same universe of discourse. Each reference fuzzy set represents the associated linguistic
variable.
Fig. 3.1. Membership functions, each a reference hiuy set of the tem set for erroi; e(k).
Generaily, the scaliog of variables and reference fuzzy sets within a universe of
discourse ranges over the input variable values. The shape of membenhip functions can
Vary; trianguiar membership h c t i o n s are quite easy to code in software, but other shapes
caa include Gaussian, rectangular (non-fuzy or crisp control), and variations of merent
3.2.3 Fuu~jïcatiun
The process of converthg crisp input values of the FLC variable(s) into a level of
evaluated, membership values in each reference fuuy set (for each membership function)
are determined.
Input X* = -O. 1
membership in Positive = 0.
membeahip in Appdmately Zkro = 0.75
membersbip in Negative = 0.25
Fig. 3.2. Fuzzification of the crisp input Xointo the membership fiinctions of erra>; e(k).
Fig. 3.3. Fuzzification of the crisp input Xlinto the membership functions of change in
error; Ae(k).
The degree of membership of an input in a membecship fwction is determined by
cornparhg the value of the input to the values defmed for each membersbip hinction. The
resulr, thetefore, is the level of memkrship that the input value has in each rnembership
funftion, described as a number between O and 1. For example, the crisp input for error
may be a value of -0.1 uni&. In Fig. 3.2, this value of 4.1 cinits gives a degree of
zero,
3.2.4 F u m Inference
The degne of membership in each fuay set is then determined for a i i other input
variables. Once complete, the membership values for each membership function are
substinited into the mies goveming the process of the fuuy controlles. This process,
calied rule evaluation, or fuuy inference, appLies the fuuy input values from the
fimification process to the d e s that govern the controller. Each mie is then evaiuated to
1. IF the error is positive AND the change in error is positive TEEN the change
of the control is negative;
ALSO
ALSO
3. IF the enor is positive AND the change in error is negative THEN the change
of the control is approximately zero;
ALSO
4. LF the error is approximateIy zero AND the change in emr is positive TEiEN
ALSO
ALSO
6. IF the error is approximately zero AND the change in emr is negative TEiEN
ALSO
7. IF the error is negative AND the change in error is positive THEN the change
of the control is approximately zero;
ALSO
8. IF the error is negative AND the change in error is approximately zero THEN
the change of the control is positive;
ALSO
9. IF the error is negative AND the change in error is negative THEN the change
The complete d e base that describes the control actions of the FU3 in this
N - Negative 2- Approximately
P - Positive Zero
Fuzzy Decision Rule Chart for the example rules
model.
The value of each antecedent of each mie is determioed, and substituted into each
antecedents. In this case, the Boolean operator linking the antecedents is AND. This
means that the nile takes on the lowest value of each antecedent for the d e . Using the
e(k) and change in ezror Ae(k) into the d e s of the sample d e base to obtain the degree of
based on the vaiues of the antecedent input values. Each of these values were cietermined
using an AND-type (or intersection) conjective connection, the Min A operator, between
Where Ti is the DOF for the i' ruie with respect to the input values within the
universes of discourse (LI,). U I= xl and CI2 = x2. Bil and Bn denote the membership
Now that we have the d e strengths for each nile, we can proceed with the
aggregation of these values using the OR-type (or union) disjunctive conneciive ALSO.
The result of the fuzzy ORing operation yields degrees of membenhips of the
consequents in each membership fiiaction of the change in output Au(k):
defuuicicotion.
Chapter 3: Fuay Logic Control
3.2.5 Deficmcation
Now that we have the values of the consequents. we move on to the h a 1 step,
defuwcation. In this pnicess. a singie crisp output value is caicuiated by any one of a
number of defuuification techniques. Three common defuaification methods are the
Center of Area (CO& or centroid method), the Singleton methoci, and the Mean of
Maxima (MOM).
In the centroid method, each output membership function is truncated above the
indicated level of its degree of membership. This is c d e d an alpha cut. AU the @ha cuts
for each membership functions of the term set output are determined, with the center of
This results in the output king the ~ s doft a weighted average taken as the center
of mass of an area comprishg the combined areas under the alpha cuts. In the example
given above for the nine membership functions, the output is represented graphicaiiy Fig.
3.5.
Chapter 3: Fuzy Logic Control
output Y= 0.3
resultiug alpha cuts and output for change in output, &(k)
Fig. 3.5. Alpha cuts for the output h ( k ) when N = 0.0, Z = 0.3, P = 0.25.
In the MOM methoci, the defuzzified value is determined as the meaa of al1 values
of the universe of discourse having the maximum membership values:
Where J is the set of aU elements of the universe of discourse of Y that have the
results are based on a lookup table for vaiues withh a given range, rather than using extra
clock cycles to compute a summation. This does not result in values that are as precise or
of this method.
Fig. 3.6. The resuiting mean of maxima (MOM)output for change in ourput, &(k).
In the singleton method, the mie consequent values are ploned on the Universe of
Discourse of the output range. The average value between the points is then calculated.
determined by the level of matching the input values with the respective fuuy
2. In the next step, findication (or huy implication), the degree of membership
3. Rule aggregation takes place when the maximum (OR) function is performed
output variables, FLC's can be represented geometrically. The antecedents of each d e can
be mapped over a 2 dimensional m a , with one antecedent on each side. In Fig. 3.7, the
universe of discourse for each antecedent is represented by two dimensions XIand X2,
(the fwzy input space) while the memkrship fiinctions are represented by Bi 1 and Bi2.
Chapter 3: Fuzy Logic Conml
The inputs fiom the universes of discoune (Ul. Ud are mapped to what is
essentidy a state space for the input variables (antecedents) in the dimensions Xi and X2.
output, (for example, the control action) Di, is within the universe of discourse It is
shown in Fig. 3.7 as the Y axis. The DOF of this output is a resuit of the huy inference
process. Therefore, this representation is similar to a control surface with the overlapping
regions of the control d e s analogous to areas of gradua1 slope on the surface (Fig. 3.8).
If,
controller. The relationship to conventional contml can be made by describing the actions
Cbapter 3: Fuzzy Logic Control
o m
state space, for example, regions A and B in Fig. 3.7, are important in the measurement of
the fuzziness of the FLC. Should these regions not overlap at all, the result would be a
disjoint collection of d e s which operate as a variable gain relay. Only one d e could 6re
at a time.
consüucted there are several approaches that can be taken to do this. The traditional
method is to put together a d e base in a simüar way that an expert system would be buiit.
An expert operator is asked to describe their actions when the system is in various States.
As this may not produce optimal control actions, the operation and characteristics of the
plant to be controlied are M e r studied, much in the same way as for conventional
Chapter 3: Fuzzy Logic Control
conaol. The d e s are then fomulated and the h t membenhip functions are put in place.
The controller results arr then found by simulation or testing- Suitable changes are made
to the membeahip fimctions an& niles untiI the resuits are satisfactory.
wacV77]- This method uses a standard d e base that is modified to fit the particular
controlier. It is a more formal approach to producing fuay control mies than the
The basis of the template method is that mies are produced based on three
metaniles:
CONTROL h ( k ) is O.
fW)-
These metaniles are then expanded to cover the input States and the corresponduig
With having defîned the niles and membership fùnctions of a fuzy logic control
algorithm. the next step is to implement this into a workable controller. The example we
have been describing as the example in this Section is similar in hinftion to a conventionai
Chaptcr 3: Fwzy Logic Control
Fig. 3.8 shows a basic block diagram of a Mamdani-type FLC. The input error
signal, e(k), a direct input to the FLC, is ais0 stored in memory for the next sampling
instance, and compared to the previous sampling instance to determine the change in emr.
The defuuined output is also cornparrd to the previous output value, which provides a
feedback mechanisrn to prevent control oscillation when output varies around the set
point.
Fig. 3.9. The Fuuy Logic Controller (FLC) in the fhmework of a control system (fiom
YaFi94).
Appropriate sensory and control devices are chosen to meet the original criteria for
the fuay controller inputs and outputs. Appropriate controller cornputer design
Chapter 3: Fuzzy Logic Control
specifications are also worked out, given the fuay code to be implemented, the speed of
actuation needed, and other considerations in the design such as cost, powet availability,
size requirements. and operathg environment Once the controk has been built, the
control actions are tested agakst the expected results from the theoretical and simulated
predictions. Appropriate changes in fuay control algorithm and hardware are then made
if necessary-
thesis was presented here. Of course, there is a growing body of research found in the
iiterature about fuuy set theory and b z q aritùmetic methods as they pertain to funy
controllers, so there are other interesthg approaches that can be taken in any further
niles and definition of the limits of fuuy sets that govem its operation. The number of
membership functions depends on how smooth the controlier output must be for proper
considerations wiil also affect the number and shape of d e s . An example of this is the
degree of accuracy of AID converters (for example. 8-bit vs. Idbit), hearity of sensors,
and the amount of precision needed for the output actions.
In considering the criteria for the system definition in the next Chapter, the
covered in this Chapter included COA, MOM and the singleton mcthod. The dinerences
Chapter 3: Fuzzy Logic Control
between these methods have a significant impact when considering an efficient MPU
implementation.
Cbapter 4: System Definition
CHAPTER
4
SYSTEMDEFINITION
OF THE ~ Z Z SEEDING
Y DEPTH
CONTROLLER
In this Chapter, the basis for the hypothesis that a hizzy logic controller is suitable
for use in controlîing the depth of seeding of a one-way discer seeder is developed. As
discussed in Chapter 2, the main methods of controlling seed depth are manual,
using conventional control laws. In Section 4.1, the results of cesearchers that have
investigated these methods are presented. This is foiiowed by a discussion of the main
attributes of each method that has been investigated, as well as the attributes of funy logic
control. The criteria for a system to investigate the suitability of hizty logic control for the
control of the seeding depth of a one-way discer seeder is developed in Section 4.2. A
discussion of the spexifications of the hardware and software to conduct the research, is
given in Section 4.3. A discussion of the choices for hardware and software
the surface (and on the surface, in the case of seeding with granular appücators and
aircraft) of prairie fields has been a topic of study for decades NuAr391.
Chapter 4: System Definition
mechanical, and electrowchanical systems and techniques. These methods do not always
provide consistent depth accuracy, which may lead to seed placement at less than optimal
depths for vigorous crop emergence. This is especiaily mie for variable terrain conditions
V i r d i y aIi one-way discer type seeding irnplements corne equipped from the
factory with a mechanical stop that is bolted at the desired position on the shaft of the
hydraulic ram that controls the depth of the implement. As this ooly provides a very rough
control of seed depth, most operaton h d that they s a m u t manuaUy adjushg depth by
actuating a hydraulic control lever. This can lead to great variation in depth, as the
operator must estimate the depth of seeding visually, someiimes obscured through dust
and at distances of up to 20 m. This can be very tiring for an operator when conditions are
such that constant adjusanent is necessary. Errors increase under conditions of varying
soi1 moisture, texhue, and varying draft loads due to changes in the weight of the
elecuomechanicai PI, PD, and Pm type control. Even with these systems, however,
problems have been encountered with lack of accuracy, as weii as oscillations about the
depth set point. Seeding depth variations of 1.27 cm to 4.45 cm (0.5 to 1.75 inches) have
k e n observed [MoGegSa]. This is due to the noniinear nature of controllhg seed depth-in
a PD-type controller, for example, the transfer fùnction must take into account each
Chapter 4: System Definition
necessary chaage in the error s u m scaiing and control change as field conditions vary. This
It has also beea shown that it is possible to maintain average seeding depths to
[Dyck75]. However, as these methods of depth monitoring and control have increased
seeding accuracy, so too have problems with complexity of operation for the operator and
persistent problems with overshooting the control set point. They also do not incorporate
the human operator's ability to adjust to changing field conditions [Dyck75]. New
digitaily-controueduni& have eliminated Som of the overshoot problems mtt911 but still
require the operator to adjust gain and daxnping factors (for example, 15 dinerent settings
was found in the literature. As funy logic control has been effective in contrd problems
determine how well it solves the problems encountered with cunent conventional manual
and electronic systems, since seeding depth control is a nonlinear coatrol problem.
conventionai controiler, the error aione would be enough to formulate a control aigorithm,
while more complicated cornputer-controlled depth control units would use change ia
between the change in control (output) and the error and change in enor (inputs). For the
purposes of this research, the procedures to be used here include an overview of the
for simulation, simulation in FIDE, Manifold Editor and Mathcad, testing on a lab bench,
and testing in the field. A labolatory test fixture with a microcontrolier evaluation board
was used for software and hardware development. For field testing, a proof of concept
control system was built for testing the conml algorithms in the field.
Chapter 4: System Definition
requirements had to be met In order that the system provide reliable data, a number of
variation in accuracy.
The conuolier MPU operate fast enough to ailow for a l l necessary calculations
and operations to occur and still have a seasor sampling rate fast enough to
prevent aliasing.
The hydrauiic valve have sufticient bandwidth to raise and lower a disc type
seeding implement as steps as small or large as necessary, with sufficient speed
The rate of oil flow of the hydrauiic valve must k variable to diow NIuse of
10. The system must have a means of 1ogg.gdata in order that algorithm
11. The tractor mounted controlier m m not impede the safe operation of the
Therefore, it must easily fit in the cab, with an interface that is easily viewed
and operated.
control (or simply controller) module, depth sensing module, soleaoid valve module, and
power supply module. For the field data collection unit, al1 the electronics of these
modules are protected in a single shielded aluminum box that is operated in the cab of the
tractor. Information about the depth in the f o m of variable DC signals are sampled fiom
depth senson, through the sensor module. An analog conaol signal is generated which
The controuer module includes all controller memory, interfaces to other modules,
operator user interfaces, and the CPU which conducts the computation functions. The
controller has been designed so <hat it c m display information for the operator while
aiiowing the operator to control normal operating and calibration huictions. The controller
dso cornes equipped with suitable interfaces for gathering sensor input information,
transmitting control signal information to the hybuiic control module and to an extemal
The computational role of the controiler is to compare the input signais from the
depth sensors to a set point, and calculate an appropriate contml signal to correct any
ciifference in an optimal way. The decision about the type of microcontroller used was
- sufficient speed to d o w for at least one samplhg every 6 inches in the field, at a
speed of 6 miles per hour;
debugg*g);
- adequate monitors and compilers to be able to write, compile and debug assembly
code effectively;and
MPUs (micropmcessor units) are VLSI chips that include not ody a CPU core for
computations, but also have on-chip modules for such fuactions as y0,RAM, ROM,
EPROM or static RAM memory, pulse wide modulation module(s). A D converten. There
are a very large number of chips available fiom a number of vendors with variations of
these features, with the major mes considered for this work. Some of these include
- Texas l n s m e n t s TMS320 DSP series, with very fast operation for DSP
fiuictions, with II0 and extemal ND'S. Evaluation board version not readily
available, and not as weil suited to controiler functions with less Il0 ports.
In order that it meet a i l these cequirements, the controiier is based upon the
16.78 MHz, which has proven to be adequate to conduct a i l computations and hinctions
The depth sensor unit used is a simple novel design, produchg a DC voltage signai
proportional to the height of the seeder fiame above the ground. A second sensor monitors
Highiy linear potentiometen convert the angle variations of the two sensor
assemblies hto voltage signals. As it is difficult to miiintain high accuracy with one-way
discer seeders, the sensors were selected to meet this worst-case scenario.
A gauge wheel used in the sensor uses a wide, low-pressure tire designed to ride
on the soil regardiess of the soil consistency. This method should also be unaected by the
varying actual height profile of a zero-tillage stubble field surface and to moderate field
trash (straw), both of which are read by ultrasonic sensors [GKWDl 1a1.
The hydraulic control module is the interface and buffer between the 5 V control
module and the duai 12 V hydrauiic solenoid valves. This module also serves to convert
the output PWM signal nom the controlier to two opposite signals, one for each solenoid
valve. A proportional hydraulic valve is the best choice for this application, as it is capable
of both variable rates of oil flow through the main spool and fast enough actuation in
The electrohydrauiic solenoid valves control the height of the seeding implement.
They are driven by opposing signals fiom the hydraulic control module: one which forces
the main hydraulic spool to produce a positive hydrauüc flow in order to move the
hydraulic ram piston in one direction, and the other to d o w oil to drain fiom the opposite
side of the piston of the hydraulic ram,thus allowing the piston to move. The signals can
be reversed to move the hydraulic ram piston in the opposite direction, or equalized to
Chapter 4: System Definition
keep the piston in place. A small, constant cüther signal was imparted on the main spool at
128 Iiz. This is required in these types of proportionai valves, as it maintaias an oii füm on
aii moving parts, reducing spool Wear aud improving reaction tirne.
1. The operator must be able to calibrate and control the fuuy logic controiler,
4. The fuzzy logic algorithm must provide for a target accuracy of 1cm.
The software flow is given in Fig. 4.4. Once the controller has k e n initialized it
then checks for any operator input. This is an intempt-driven routine, in that if a keypress
has been detected. the seed depth control operations in the main flow of the code is
are controiied by the operator include the cdibration routines. raising and iowering of the
Once past the keypress detection stage. the controuer proceeds to the sampling
routine. On the discer seeder, there are two sensors, one on the disc a m and one on the
depth sensor in the fkont. Both sensors are sampled, and the emr calculated based on the
In the emr conversion stage, the nsdt is convened to a form suitable for use in
the fiiw logic control algorithm and the depth display algorithm. The units used in these
calcuiations are in thousandths of an inch, as this provides the best combination of
Once the error has been caiculated, converted and store& the fuzzy control
algorithm reads the error h m the c m n t sensor readings and the reading from the 7th
previous sampling instance to put through the fuuy inference engine. A decision value is
The hydraulic control routine cakes the value form the fuzzy decision, and scales it
appropnately based on the type of hydraulic valve king controiied. It is then converted to
a pulse width modulated (PWM) signal, h m the PWMA port on the MPU.
The value of the current depth is read nom the registers storing the converted
depth sensor values and displayed in the LCD screen for the operator. The uni& can be
either imperid or metrïc, depending on which choice is made by the operator.
Finally, data fiom the sensors, error, change in error and hizzy decision is
convexted to ao RS232 signal and transmïtted to a PC laptop sewing as a logger. The data
can then be analyzed to determine how well the process is working. Once this operation is
completed, the program loops back to the keypress detection routine to begin the entire
The o p e r a ~ and
g construction requirements for the fuzzy seeding depth controuer
were given in this Chapter. These requirements are the result of the necessity for a certain
Chapter 4: System Definition
experiments explained in the literature showed the strengths and limitations of different
seeding systems and control methods. Roblems with cumnt systems were considered,
with an eye to setting system specitications that meet or exceed the accuracy which can be
gained using colluaercialiy availabie equipment and control philosophies. The primary
hardware and software was the next step. The choice of the MC68HC16Zl MPU was
justified by its capabilitiesto meet a l l the necessary I/O. memory, availability and processor
speed requirements. The choice of a proportional hydraulic valve offers the system a robust
control actuator that is compatible with the variable output gain needed in this
implementation of hizzy control. The depth sensors met the cnteria for accuracy, with noise
suppression maintained by shielded cable and differential inputs. FinaiIy, the flow of the
software code actions to tie ali these hardware components and the fuay control algorithm
together was defined. Most of the code is used in measuring the sensor positions,
calibration, processing the input signals and displaying the depth on the LCD.
With al1 of the major hardwan criteria defmed, and hardware types chosen ia order
to meet or exceed these criteria, the hiuy depth conml system can now be described in
detaii. In Chapter 5, the controiler modular hardware design is described, based on the
The systern descriid here has been constructed and is being testai on a one-way
discer type seeding implement There were two versions of this system built: a
and a field test unit for operathg h m a tractor to log pertinent controiler state data in the
the previous Chapter. Section 5.1 wiii cover details relevant to the controiier module, 5.2
module. The power supply and conditionhg module wili be explained in Section 5.4.
-52-
Cbapter 5: Detalled EIardware Design
The hatdwm descriptions in sections 5.1 to 5.3 will be bised upon the basic
operations and components of the controiler, with Section 5.4 also covering noise and
Connecter for -
Sensors
Solenoid
,/'
1,'
SA Fuse Holde
to produce the desired output contml signal. This includes analog to digitai ( A D )
conversion of the input signal, cornparison of tbis signal to preset parameters in software,
and the fuuy Iogic decision process that controls a pulse width moddated output signal.
This module also serves as the openitor interface, so is located in the tractor cab next to
the operator. It has a numeric keypad for input of calibratioa and control point information
fiom the operator, and an LCD digital display that serves as a visual inte~ace(see Fig.
5.3).
Cbapter 5: Detaiied Hardware Design
Features utilized in the fuzzy seeding depth contmlier include the A/D converters.
on-chip generai purpose tumr (GPT), queued serial module (QSM), and 1 KB of battery-
+=
backed static RAM.
Port GP
Queued
Port QS Seriai
J-
Control
Fig. 5.5. Block Diagram of the MC68HCl6Zl showing main mobiles and ports.
The A/D converters are selectable between 8 or 10 bit, with &bit conversions
king used in this application. This is because it provides adequate accuracy in monitoring
the depth sensors, while enabiing the 8-bit A and B registers to be used in the CPU16. This
results in a reduction in complexity in pmgramming and aliows two bytes to be used for
Cbapter 5: Detaiied Hardware Design
data, not 3. They are successive approximation (SA) type ND converters, with a sample
and hold ( S m unit to increase the effective aperture time -911. As the N D module
c a . nia at up to 2.1 MHz,an 8-bit conversion only requhs 9 rnicmseconds (ms)to
cornplete a conversion.
EPROMs:
Even Byte
Clock
Circuitry
ûdd Byte
The QSM is used to communicate between the HC16 and a PC in order to log test
results. The QSM is configureci for 9600 baud fidi duplex asyncbFonous coinmunication in
this mode. Serial communications signais fiom the QSM are converted to RS-232 levels
by a Motorola 145450 serial interface. This chip was chosen over the more common 1488
and 1489 chip combination in order to reduce the part count, and eliminate the necessity
for plus and minus 13 V supplies. The 145450 uses four 10 uF electrolytic capacitors in a
Chaptet 5: Dttailed Hardware Design
charge pump circuit to produce its own plus and minus 10 V supplies. This is usehil for
the field test unit, as this reduces the size of the boards and box needed to do the control
and data logging. Likewise, whenever the necessary fiinctions can be implemented with
fewer parts, there are less chances for failures in initial &bugag and in operation.
On-chip static RAM is used to store program variables, such as the caiibration
values. These variables are maiataiwd by a lithium 3 V battery while the unit is in a
battery backup standby mode when the main power is switched off. As a i l the registers in
the HC 16 are memory-mapped, there are no other special addressing procedures needed to
access this memory other than to ensure the correct base address of the 64 KB page is in
In order that there wouid be enough room around the HC16 chip to use wire
wrapping in the construction of the field unit, a single sided PC board was made. This
enabled the HC16 to be securely ddered in place using surface mount technology, while
allowing the cntical clock circWtry to be assembled on the same board. There are several
advantages to having the clock crystal and capacitors mounted directly to the PC board:
the distance to the HC16 pins is minimized; problems due to stray capacitance of wire
wrap pins affecthg the clock waveform are eliminated; and puttir~gthe crysial on the PC
board ailows for a foii ground plane to be extended under the crystai, thus M e r ensuring
The HC16 is also capable of addnssing up to 1MB of program and data space, of
which 32 KB of program space are used in this application. Two fast (70 os) 256K
controller. There is a jumper block that sets the correct addressing, chip select and chip
enable pins for the appropriate type of memory configuration in use. The ability to use
battery-backed R A .is very advaatageous for 6eld use. The two RAM chips are each
in the lab bench controller setup, which is co~ectedto a PC running the HC 16 assembler
(MASMl6) and control program (EVB16). Once the chips are programed, the whole
system is powered dom, and the chips cm then be removed and placed into the memory
sockets of the tractor unit for in-field testing. This way, it is not necessary to have an
EPROM burner and a large collection of EPROMs and an EPROM eraser on hand, so
W
lth
in the GPT are two pulse width modulation units. One of these
(PWMA) is used to produce the output signai for controliing the hydraulic valve. The
output from PWMA is a periodic square wavefonn set to 128 Hz,which is optimal for the
Rexroth proportional valve king used in this research. The duty cycle of the waveform is
The keyboard and LCD display are both mounted on the top of the controller box
for easy access by the operator. Both are socketed in order that they cm be easiiy removed
software that is controiled by the GPT. This software subrouthe will then intermittently
resample the lioe for 10 milliseconcis. This enables the microcontrolier to determine
whether a detecwl key press was due to electncai intecference (noise) or whether the
event was a reai keypress by the operator. This serves as a software-based key debounce
function. W u p resistors on each line maintain a steady 5 V Ievel on the port pins until
Port F
A ldsegment LCD display serves as the visual display interface for the operator.
The LCD has an adjusmient for contrast, and is set for maximum visibility by a
potentiometcr inside the controiier unit. Instructions are supplied to the operator via the
LCD in naturai language to facilitate caiibration and operation. Resent depth is displayed
while in normal seed depth control operation. The unit used is the single h e , 16 character
Optrex DMC40401 which bas its own built-in control logic and osciilator, thus requiring
no extemal parts. Custom charactea could be programmed and stored into display
(see Fig. 5.5). the shieldeâ cabks running h m the discet to the tractor cab. and the two
differential sensor intefiaces that produce the controller A D input signals, The h n t depth
sensor used here is a simple, novel design that produces a varying DC signal based on the
angle of a gauge arm h m the soil surf" to the d i s a r h u e , A second sensor signai
bdicates the angle of the d i s gang to the implement fiame. Highly iinear, cahirated
the use of a differential input buffer, and shielâed cabhg gmm&d to the controiler box.
The novel ground-sensing unit used in the design is key to obtaining diable depth
readings. A gauge wheel used in the sensor uses a low pressure tire designed to ride on the
soii surface, regardless of the implement weight or soi1 consistency. The adjustable weight
of the gauge wheel allows the operator to prevent excessive sinking in soft soil. Simiiarly,
the use of a low-pressure tire to sense ground level serves to dampen out insigniscant
topographicai features, such as s d fuwws, whiie stül giviag diable readings in fields
with standing stubble. In modehg this system, the sensor assembly itself serves to act as
an integrator and a low pass filter. This is particularly important foc minimum and zero
Chpter 5: Detailed Hardware Design
mage fields, where straw and stubble are not left intact in order to minimize soi1 erosion.
This dampening feanin, combiDed with analysis of the rate of change in depth by the
fuay logic aigorithm. nIters out the effects of sudden changes in depth reading caused by
large soi1 clods or b o w s . These features provide this sensor design with a distinct
accuracy advantage over ultrasonic sensors and other types of mechanical sensors
presently in common use, although it could be argued that low-pass filtering of the signals
The sensors themselves are highly linear (< 0.5% variation across 85 degrees of
travel) units that are sealed from moisture and dia. They employ robust rnounting flanges,
and employ spring pressure to ensure that they always are in contact with the rnachined
sensor linkage. Cabling is with dconductor, 100% shielded cable. The shielding is
grounded at the tractor, and is not comected to the gound wire on the sensoa, in order to
prevent a ground loop. Cables are mounted on the seeding implement in an elevated ring,
used to securely fasten the cable to the controller box and provide grounded shielding at
Each of the senson are buf5ered by TMS4066 operational amplifiers. This serves
to protect the HC16 A/D converter inputs fiom any high voltage spikes that may be
induced in the sensor cabling. The operational ampMers aiso serve a noise eiïmination
function, as they employ differential inputs. This technique of noise suppression has k e n
shown to eliminate noise to about 60 dB. These op amps are aiso unique in that they
extra negative power supply is needed to run the op amps. The rail-to-rail feahire also
means that the op amp inputs are sensitive right acnws the m e r voltage level, so can
detect signas h m O to 5 This eliminates the need for additional analog scaling
components, thus reducing part comt and eliminating the extra variables of temperature
and age effects on the input scaling io the op amp differential inputs.
(see Fig. 5.7). It is dnven by a 12 V pulse width moduiated signal in order to contml both
diodes, logic circuitry to divide the puise modulated signal h m the PWM uni& on the
HC7414 CMOS inverting b e e r protect the control module circuitry h m any elecaical
shorts or power spikes in the 12 volt section of the hydraulic conml module. Protection
Chapier 5: Detailed Hardware Design
diodes ailow back EMF in the inductors of the hydrauiic valve solenoids to bypass the
The hydraulic solenoid valves operate at a fiequency of 128 Hz. This produces a
dither on the main valve control spool that significantly increases its response speed over a
valve that must operate h m a state of rest At a duty cycle of M%,an equal force is
imparted on the main spool in both directions. This results in no net oii flow to the discer's
iifi cylinder through either of the main spool's ports. However, as that duty cycle changes,
there is a proportional change in the flow of oil fiom the valve to the hydrauiic cylinder
controlling the implement depth. Therefore, by adjusting the control signal duty cycle
above or below 50%.the speed and direction of oil flow to the cylinder is controlled.
The cable to the solonoid valves is a 4-stranded, 100%shielded cable with the
shielding grounded to the controiler box. In order to prevent ground Ioops, the grounded
Chapter 5: Detailed Hardware Design
shielding is not comected to the ground of the solonoid control wires. The cables are
grounded to shield the solonoid control wiring where is meets the connector. The solonoid
end of the cable is comected to a plastic plug which is provided by Rexroth and custom
designed to fit over thme solenoid lugs and bolt into place.
hazard to electroaic devices, as EMI sources as varied as the uactor electncal system,
wireless communication devices and high power overhead liaes may a i l be present at the
same time in worst-case situations. This is especidy tme for systems such as that used in
this resewh, where cables to senson also act as very good antennas!
Precautioas wen also implemeated to protect the controiler unit from power
fluctuations within the tractor electricai system. For example, in a load dump, in which the
comection between the batteries and the charging system is suddenly severed while the
motor is running and the electrical system is othemise functioning normaily, voltage
rninimize the amount of cable withia the contro11er box that may cany noise fiom the
tractor electrical system, shielded h e s to the power supply module only pass beside the
Chapter 5: Decailed Hardware Design
hydrauüc control module, aad do aot pass through the control module. The power supp1y
hise, then to a 24 V metal oxide varistor (MOV) that is designed to take any voltage spikes
above 24 V to ground Likewise, a 500 mH ferrite COR choke and a 300 mi?electrolytic
ground.
Voltage Regulator
In the voltage reguiator circuit there are two 10 mF capaciton, which also act as
filters. A 0.01 mF capacitor also acts to take even higher fiequency signals to grouud.
Finally, regulated SV power to the controiier module is supplkd via shielded cables which
pass over the aluminum shielding to supply the module. 12 V power to the hydraulic
connol module is via a shielded cable which passes over the shielding between the power
controiler module keep voltage variations to a minimum. Special attention is paid to the
memoty supply pins and the N D contmller power and reference pins. Decoupling
capacitors are especially important considering that the rnajority of parts in the controiler
MHz, this is just below the generally accepted Mt of 20 MHz for wire-wrapped circuits.
There is aiso an alurninurn shield between the hydraulic control module and the controIler
module to nduce noise effects that may occur due to the back EMF in the solonoid cables
generated by the collapsing fields around the coils in the valve solenoids. Ali of the
modules were built as small as possible to minimize the length of connecting wires.
apparent that the hardware choices used in this study are the result of extensive searches
for the appropriate components. For example, there are hundreds of types of
potentiometers in a wide array of packages available, but very few have the combined
capabilities of king dustproof, able to be securely mounted, and a high degree of liaearity.
Once all the suitable testing hardware was found, the software was designed and
Mtten. Hardware characteristics were taken into account in this process, including the
speed and zero position of the proportional valve main spool, and the linearity of the
Software design in this Chapter describes the fuzzy logic controuer and how the
most important software twls associated with this research were used. The fuzzy logic
controiier itself is written in the &bit MC68HC16 assembler code, with portions of the
fuzzy logic routine written in &bit MC68HCll assembler code. This format is M y
compatible with the MC68HC16Zl. Other programs written for the purpose of this
research. but not directly used in the formation of the hizzy logic controller code, are
before, during, and after fuuy decision routines. These sections are detailed descriptions
of the block diagram components and pNnary system functions given in Chapter 4. Each
subsection describes a major subroutine, in the order they are executed in the
-
3. SAMPLE Sample the sensors.
-
5. ERROR-BUFFER Store c u m n t enor. read emr 7 samples previously.
-
6. FUZZYrrST Fiazy contml decision mutine.
and data preparation for the funy logic decision routines. Section 6.2 presents the fuzsr
routines, while 6.3 covers the hydraulic control, data logging and LCD display functioas.
6.1.1 Initiulizution
Each of the modules of the HC16 are controlied by memory-mapped registen that
must have initial values written to them in order to perfomi in the appropriate marner
Mot092b].
The nrSt module initiaüzed is the SIM (system integration module), controlling
bus and software watchdogs, configuration parameters for the HC16,system clock, system
address and data buses, chip selects and a system test block.
The systern dock provides timing signals to all operations in the MPU. In the
MPU configuration used for this rcsearch, the clock is driven by an external32.768 kHz
watch crystal. This in turn controis the speed of an intemal oscillator (PLL,or phase lock
Ioop). The high fiequencyoutput fiom the P U is divided down by a dividerlprescaler and
the output cornpared to the phase of the input crystal frequency. Once the PLL locks on
Cbapter 6: Software Design
this signal. the HC16 boots up. The speed of the HC16 is determined by the value passed
to a divide by two prescaler bit, a 3-bit pfescaler in the PLL feedback divider. and a &bit
moduio 64 down cornter. System speed with a 32.768 ItHz crystal can be set h m as low
as 4 Hz, to vaiws in excess ofthe maximum rated operating fkequency of 16.78 MHz.The
The modules are mapped to a 4 Kilobyte block in the MPU. The location of this
block is set by the module mapping bit ia the S M module configuration register. This bit
is set at initiaikation so that the addresses are spread w i t h the range fiom SFFFOOO to
SFFFFFF.
The the SWE (software watchdog enable) is also turned off to prevent immediate
software interruption by the watchdog. This is a timing circuit that, if not disabled would
continuaiiy interrupt the operation of the CPU if the software watchdog timer location was
Initial values for the CPU (centrai processing unit) also are set. The memory page
registen are set so that the code wiil start at the correct memory page base location. Each
The SRAM (stmdby RAM module) consists of 1 Kilobyte of fast static RAM and
a control register block. This memory is where calibration and scahg values are stored, as
they can be maintained by a backup battery when the MPU powers dom. This memory
can also be mapped anywhere within the entire HC16 memory space (as long as it does
not overlap any module régisters or the bootup and intempt locations nom $00 - $200). It
The QSM (queued serial modnle) is initialized to be able to send and receive data
at 9600 baud. This module sen& and receives signals at 'Ml. levels. It is comected to the
or depth gauge wheel sensor, and ADCL is the input for the rear, or disc sensor.
GPT (general purpose timer) initiaibation values are written to the appropriate
control registers, setting the fiequency of PWMA to a rate of 128 Eh.The duty cycle of
this signal carries the information to the hydraulic solenoid valves, while the fiequency
Initial values for controiler operation variables are set once all the modules are
enabled. These include calculation constants for the theta correction in the sensors, rough
sensor zero positions, sensor mode setthgs, and rough calibration factors such as seeding
depth setpoint and raised height for lifting out of the ground. Initialization subroutines that
enable the appropriate I/0 ports for the LCD display and keypad are also m.
Once the HC16 modules and calculation values have completed initialization, the
huzy logic controller code enters the main software operation hop.
Scan
Direction
of Rows
Scan
DiW * o n
of Columns
The keypad is scanned in this routine, on every loop of the main program. If a low
signal is detected on one of the lines of the keypad port (Pon F), the code immediately
keypress (iow) signal is stili present If so, it is assumed that a key was pressed, (that the
first low signal detected was not caused by noise). The program then branches to a routine
to identify the key pressed. If the identification produces a jump to a subroutine, the HC16
then executes the appropriate function. These functions include calibration and control
Real
ldeal
,
Fig. 6.2. Actuaï and ideal signals fkom a switch, iiiustrating the need for a key debounce
routine.
Chapter 6: Software Design
Once the routine has finished, the program exits the CHECK-KEYS routine and
There are k e e major types of caliiration subroutines. The fim, and most simple
to implement in code, an operator set point value settings. These are the values for desired
display units (metric or imperid), sensor modes (both sensors or fiont only are used),
seeding depth and raised height. Setthg these are a simple matter of entering the numeric
The second type of calibration setting includes values that are read from sensoa,
then directly stored to their respective locations in memory. This includes the setting for
the field "zero depth" position. No calculations occur in this setring; it is a straight "read -
-
and storet' operation.
The third type of calibration setting includes values that are detennined by reading
sensor positions, and using these in calculations to detennine the appropriate scaling and
conversion factors. These calibration subroutines include the sensor scaling factor and the
and seeding implement combination. Once it is set, it does not have to be updated unless
there is a change in the position (such as the location or rotational pitch) of sensors relative
to the implement they are mounted on. Therefore, this calibration should be repeated
Chapter 6: Software Design
anytime sensor mechanical mountings are remounted or any changes are made to the
The scaling faftor is obtained by calculating the difference between the 6" height
position of the disks and the 0" (gromd level) position of the disks, and then dividing this
Merence into 6 to obtain sensor units per inch of mvel. These measurements are made
on a soiid, level sudace, such as on a concrete pad. It is critical that the suface be level
and ail measurements be as accurate as possible. as any error in this caiibration will results
correct for this enor due to the rate of change of seasor angle per change in depth
becoming srnalier as the angle increases. The disc gang is raised so that the sensor M a g e
for the rear sensor is positioned in such a way that the connecting arm from the sensor and
the connecting ann to the discs are precisely 90 nom one another. The front sensor wheel
is also positioned so that the sensor connechg ann is precisely positioned 90 from the
sensor arm connecting the ground sensor. The positions of both senson are now stored as
By using %bit ADC conversion rather than 10bit, each degree of movement of the
sensors used here translate to a change in ADC reading of precisely $3. This is due to the
fact that in an 8-bit ADC,the range is fkom decimal O to 255. The total degrees of rotation
of the sensor type used in this research is 85. Thus?decimal 25985 = 3. It has also k e n
found that a variation of 1 unit of ADC measurement with the discer and sensor
combination used in this research was the equivalent of 14 units per inch around the zero
Chapter 6: Software Design
point, to about 12 unîts at the 3 inch &pth point This is sufficient to give the 0.1 inch
sensor accuracy des- for this controller. Using the 10-bit settkg for the AM3 would
provide ôner readings, as there wouid be decimal 12 units rather than 3 per degree.
However, baving to use 10 bits of accuracy would coaiplicate propmmbg, as the &bit
operations).
rotation of the individual sensors nom this position is simply this dinerence divided by 3.
Therefore, the degrees of movement of the 6 inch positions fiom the 90 points of the
sensors is known. This gives the value of the opposite side of a right angle triangle (is
equal to 6 inches). Basic trigonometry gives the length of a hypotenuse equal to the length
of the opposite side divided by the sine of the opposite angle. Using this "opposite" value
(6 inches) and the angle fkom 90. the length of the hypotenuse is determined. This
Other depth values can then be determined by converting the sensor readings into
degrees, then converting the degrees rotation into sensor position above or below the
ground by applying the scaling factor obtained in the 6 inch calibration routine, and using
this to determine the length of the opposite side of a right angle triangle to get the depth
the sensor values are converted to thousands of an inch in a 16-bit format This process
normal operation mode,the signals are passed onto the next subroutine. If it is in a single
The sensors are highly linear nsistive elements operathg by indicating the
position of a contact on a circular track In order to preserve accuracy in reading the sensor
positions, the theta correction factor is employed for all nadings. This works by taking the
sine of the angle from the 90 position of the sensor iinkage, where it is precisely 90 £tom
the sensor. In order to ensure maximum calculation speed, an 8-bit sine lookup table is
used, rather than calculating each valw by division. In the HC16,the sine table technique
takes 6 clock cycles to load the value. If sine had to be caiculated. it would take 34 cycles
to clear, load and scale the ADC reading (in degrees) and the value 1 into another
accumulator, then 24 more cycles to divide these two, and another 10 cycles to sale them
again, for a total of 56 clock cycles. This would have to be conducted twice every tirne
through the program, resulting in an unnecessary loss of 124 clock cycles per main
program execution. The only downside of using the sine table is that it takes up extra
EPROM memory, but with only about 10 Kilobytes used out of a total of 32 Kilobytes
available, this is not an issue. In this design, opthkations have been made for speed
Initial conversion values for the theta correction subroutine are written to the
respective registers during controfler initiakation. This allows the operator to raise the
implemcnt for transport to the area of use. Once at the field, the operator then goes tbrough
Chapter 6: Software Design
a calibration routine that sets the ngisters with the correct conversion and setthg values
error is converted fiom thousands of an inch to tenths. This facilitates the calculations that
will include only addition, subtraction, and maximum and minimum comparisons.
reading and subtracting it fiom the error reading 7 samples previously. This equates to
about 112 a second, or the equivalent of one m e a of distance covered at 6 mph. This
value is written to the CHANGE-IN-ERROR variable for use in the next routine.
of industrial processes since it was introduces 20 years ago CKipe90, Mura841. This
control strategy is based upon the experience of a human operator, who iinguisticaüy
describes the control actions as a set of heuristic decision d e s in the fonn of "if this
occurs. then do that" [KiMa77]. The resuit is that the conml algorithm incorporates the
The inputs to the funy control d e s include the error from the desired depth set
point, and the change in the error between the present and last sampling instances. This
Chapter 6: Sofiware Design
error change leads to differential control KGFï931. These proportional and differential
Linguistic variables descriibe the direction (either positive, P or negative, N), while
the size of the change is descnkd as small, S. medium, M and big, B (see Table 1). Rules
ERROR, c
OUTPUT
, - Negative
N S - Small
1 - Positive
P M - Medium
B - Big
Fig. 6.3. Fuzzy d e s output table.
Wmdows graphics-based fuay logic simulation and analysis tool, FIDE (Fuz2y Merence
Development Engine) nom AptronUr. The different rnembership fuactions were set up and
FIDE speeds up development with increased accuracy by the use of several valuable
development tools. Each membership function can be viewed graphically, and quickiy
changed using the mouse. Likewise, FIDE instantiy generates the fwzy control surface for
any set of membenhip fûnctions and inputs. Once a given combination of membenhip
functions produce an acceptable gain level of monotonie control, a visual simulation can
be run with inputs nom either artincidy generated signals and actual recorded field data.
If, at this stage, the control looks like it will produce the appropriate results, FIDE can
be pasted into the controller code and compiled The code automaticaily takes into
account scaling factors for sensor inputs and the hydraulic control output signal. These
scaling factors are used to match the fuzzy output signal to the actuation speed
produced quickly and accurately that can be tested in the field. Some setting up of the code
is necessary, such as naming variables and memory location redefinition, but this is trivial
compared to having to rewrite all fuuy membership function tables manually. Of course,
Chapter 6: Software Design
rnembership hctions can be modined by editing the tables. but it is much more
productive to modify only small part of the code in the field rather than having to remn aU
In this routine, the fuay logic algorithm operates the four steps of determinhg a
control decision:
to the lookup tables generated nom the membership fûnctions in the FIDE
The fuuy values are evaluated according to the d e s . The DOF for each mie is
detennined.
The mies are aggregated, and the mies that apply are determined.
The hiuy decision fiom the mie analysis is defwzified. The algorithm uses
as the COA or MOM methods, it is much more efficient to code and execute in
assembler, and does provide sufficient 8-bit accuracy for this application.
Using the Mamdani max-min preposition is very conducive to the assembly code
For the MAX operation, the equivafent is a union operation. This operation is
Assembler Commriad
ldaa ht-nunber
dab second-number
cba
bmi b-is-larger
mva result,of,max
rts
rts 12
This is a total of 44 clock cycles per MAX operation, or 7 X 44 = 308 cycles for
ldaa first-nwnber 6
dab secondCnumber 6
cba 6
bpl a-is-larger 6
mua result-~f~xnin 8
rts 12
rts 12
This is a total of 44 clock cycles per MIN operation, or 7 x 44 = 308 cycles for the
At the end of this MIN operation, the resultîng fhzded value is then defuzzitied.
It is compared to the values for output, in this case, 4, and the two closest values are
averaged.
very computation intensive uniess done with the aid of lookup tables. Without lookup
tables, individuai dopes would have to be calculated for each membership function-
other hinctions can be quite complex. Of course, with look up tables, you trade accuracy
for speed. For the purpose of this nsearch, the accuracy using 8-bit lookup tables for the
f u z q inference engine is sufncient This matches the format of the data and the AID input
The output range for the controller is between decimal 120 to 135 (CHECK). This
is due to the characteristics of the proportional valve used and the hydtaulic system of the
tractor used. The tractor used in testing was a Case International 7210 Magnum with a
closed center hydrauiic system. This type of system maintains constant pressure at ail
on the system.
Chapter 6: SoftwareDesign
width modulation unit A (PWMA)of the MPU. This modulates the duty cycle of a 128 Hz
signal that controls two solenoid valves that control the position of the main spool on a
proportional hydraulic vaive. By having a constant 128 Hz pulse on the main spool, a flow
of oil keeps the main spool moving. The motion is not enough to significantly change the
position of the hydraulic ram on the seeder, but is essential to keep valve response t h e at
an optimum level. The duty cycle of the two smaU solenoids that contml the main spool
are equal when the main spool is in the proper position. When the seed depth (disk
position) has to be changes, the spool must be moved off center by changing the duty
cycle of the tow s m d solenoid. This is done by changing the duty cycle of the signal from
P W M A . The signal is split, with one signal controlling one solenoid, and the other.
inverted signal controlling the other. Therefore, when the duty cycle is changed, one
solenoid will open wider, with the other opening with an equal. opposite narrower
opening. The ciifference in pressure moves the main spool one way or the other, thus
acting as a hydraulic amplifier by aliowing a large volume of oil to move fkom one side of
the LCD depth display routine. The depth error value is compared to the soi1 surface
value, and the difference is displayed on the LCD.The routine includes a subrouthe that
Chapter 6: Sotbuare Design
Once all the numbers have been calculateci, the LCD display routines are cailed to put
each character on the screen. The unit preference can be clected by the operatoc
The Op- display used in the controller has its own intemal memory and display
osciliator circuitry. As a resuit, any characters wntten to the display will stay on the screen
until the "clear display" commaad is sent by the controlier. In order to reduce display
flicker due to unnecessary display writes. the code in this routine will check the contents
of the display registers before writing a character to the display. This way, if the desired
character is already diplayed on the screen, the write routine for this character is skipped.
communication data logging routine is utüized Data read h m registers in the controller
is sent to a laptop cornputer for saving in a log file and later analysis.
order that these calculations can be céecked during program debugging to ensure that they
are correct. These data ailow crossthecking the controller huy decision with the
expected output Born previous simulations. Also, if any changes are made in the field, the
and 1 readings over the time of the trial, the entire process of calcuiating ERROR,
CHANGE-IN-EERROR, the fuuy decision and final hydrauiic valve output value can be
evaluated. Parts of these data can be used as input values to the simulator in FIDE and the
values fiom the field unit c m be tested against the results of FIDE and Mathcad simuiator
calculations to ensure that this part of the program is giving the expected results.
The ADC O aad 1 readings can be used in other Mathcad routines to test how weli
the controller calibration and operation subroutines work. These readings also can be used
The sister PC routine operates by checking for valid data being in the serial bufXer,
reading the data, and sending an acknowledge signai. Once received, the controlier
Chapter 6: Sofiware Design
increments an index, and sen& the next data byte. Both the contn,Uer and the PC are
synchronized to prevent data skew.In total, 10 bytes are sent per sampling instance. The
PC logging program automatically formats the data for saving into an ASCII file for easy
importing into a spreadsheet, mathematics or signal analysis pmgram. As data are being
collected, a bar graph display on the PC aliows the operator to monitor the progress of the
When the controUer has nnished the SEND-DATA routine, main program
execution loops back to the CHECKJCEYS routine, to begin the next loop through the
The present system m s fast enough to log data 23 times a second. This is
equivalent to one sample king taken every 7 cm (2 1/2 inches) at a speed of 10 kmmt (6
mph)-
Several versions of the control software are used in different parts of the research.
The program described here referred to the fmt version, where the operationai purpose is
to log data pertinent to controiier operation, as weli as control seeding depth. The second
program version is intended for use when logging is not needed, such as when debugging
controller code with the tractor and discer in a stationary position. in this version, the
routine for the MC68HC11 was adapted to the 16-bit MC68HCl6Z 1, for deteminhg the
routines as it does to write the core control algorithm, Calibration was especiaiiy
to e n s w that the readuigs were consistent and accurate. It was also discovered at this
point in code development that a single seasor on the front of the implement would not be
accurate, as it would not be able to give the position of the discs as they chmged. A single
sensor also would not be able to discern sinking of the discer into the soi1 nom discer
rocking motion over the axis of the discs and implement tires.
The hardware has been designated, as well as the software design defined. This
now takes us to Chapter 7, Fuzzy Depth Control System Implementation, where these two
The emphasis in this Chapter is to explain how hardware. software and the process
of simulation and verification combine in the formation of a system suitable for e v a l u a ~ g
the suitability of f k z y logic for the application of seed depth monitoring and control. In
Section 7.1, the field test and &ta logging functions are discussed. Section 7.2 presents
how the calibration routines work. Finaiiy, Section 7.3 deals with how data is verified and
new funy routines simulated and tested. AU HC16 software was written directly in
assembly language to maximize execution speed. Software written for the PC was in
of fuzzy logic for the application of seeding depth control, it is imponant to have a means
of couecting field data to use in software simulation. evduation and design. The field test
and data logging mode is useâ to control seeding depth and record observations and
contml parameters, thus, measuring actual field conditions and ncording them for
analysis.
This mode is used when operathg as a depth conuoiler and data logger. The
sampling rate can be set to up to 24 samples per second, which translates to one sample
lighter through a power cord constmcted for this purpose. A power switch on the case
operates in series with the power connecbon to the power supply module. A 5 ampere
fast-blow fuse is also installed, to protect the board and tractor circuits fiom short circuits.
Cables to the sensors and the hydrauiic valve solenoids are c o ~ e c t e dto the controller on
the side of the box facing the rear of the tractor. Cables were nui through the rear of the
tractor cab.
Some ergonomie issues were taken into consideration in the design of the conuol
box even though it was constructed for research purposes, and would not have many hours
of use in the field. The interface for the controL1er was made to be simple. in order that the
design met the cntena for making operation as safe and non-distracting to the operator as
possible. One reason the controller box was constructed as small as possible was to enable
it to be easily placed beside the operator without impeding operator movements. The
operator is able to see the display while tumed panially backwards when watching the
discs. Likewise, the box couid be fitted over the dashboard above the steering whed,
allowing the operator to see the display without Ruaing or looking to the side, away from
the direction of travel. If the controiler box was cwibersome to use and obstnicted the
operator's movements in the cab. this would pose a senous distraction for the tractor
operator and pose a safety hazard to anyone wodting behind the tractor while it was
Chapter 7: System Implementation
goes through the module and memory initialization steps, and enters the main program
loop. Upon entering the SEND-DATA routine, the HC16 copies the parameters to be
logged to temporary locations. These include the values for the Mit format sensor
position rcadings fkom ADC O and 1, the 16-bit quantities for enor and change in error,
passing handshaking characters between the PC logger and the HC16.The HC16 enters a
loop where the Receive Data Register is checked for new data If the Start signal ($F) is
received from the PC logger, the routine continues. If then is noise on the h e or the PC
logger is out of synchronization. $F will not be received and the HC16 goes back to the
wait loop for the correct character. Therefore, in order for the HC16 to work. it must be
comected by a null modem cable to the PC logger computer. The contmller must be
started kt,then the PC logger program. Using a specinc stm character e l M a t e s the
possibiiity of data king written to the log 6le that is out of the correct sequence. Of
course, as the log fiie is formatted in a certain way,if information was out of sequence it
Once the Start commaad is received by the HC16,it then sen& the k t data in
byte format. After each byte, the HC16 checks the Receive Data Register for the character
logger when it is ready to receive the next character. Once this pmcess has been repeated 6
iimes, the HC16 r e m s to the top of the main pro- loop of the controiier code. and
continues und execution again reaches the SEND-DmA routine, where the Receive Data
Whüe the HC16 is executing code for the other routines in the main program loop,
the PC logger program reformats the data received for storage, stores it to the log file, and
writes a bar graph line for each data item to the PC screen. The bar graphs are a graphical
representation of the processes occumhg in the hury logic controller. Extreme conditions
can be spotted immediately, and the controller stopped for code modification and
checking. The data logger can be stopped by pressing the Escape key on the PC. The
HC 16 wilI continue execution until it reaches the Receive Data Register test loop, where it
wiii continue looping until the logger is restarted. This way, the controller can be stopped
There is also a version of the HC16 controller code that has the data logging
routine commented out. This is used for initial installation and check-out of the system
when it is king installed in the tractor and hooked up to the sensors md the hydrauiic
valve.
DEPTH
Fig. 7.1. LCD interface display in operation.
Chapter 7: System Implementation
The LCD interface is very simple. W e the controiier is operating, the LCD
displays the depth in the units that are chosen by the operator. It is bolted to the top iid of
the connol box above the keypad A 20 cm niboa cable coanects the pc board bolted to
the box lid to the coatroiier module main board. The controuer box can be tilted toward
the operator if the angle of the LCD is too high to see it properiy.
The alpha keys on the keypad are used for initiating calibration and control of the
depth control operatioos. The "A" key starts the set raised height and modes subroutines.
The "B" key is for raising the discs, while the "(2" key is used to start the subroutine for
sening the seed depth. The " D key is used for starting the process of setting the ground
position. The "E" key is used for initiating calibration, while the "F" key is used to lower
the discs.
By hitting any key except the "F'key, the controuer stops operating as a seed
r enters the chosen subroutine. The key fuactions were chosen based
depth c o n ~ l l e and
Chapter 7: System hplemeotation
on how an operator would intuitively remember the functions. For example. the "Raise
Discs" command key is located above the "Lower Discs" command key.
The keypad type chosen is a membrane keypod with raised keys. This keypad
requins some effort on the part of the operator to activate individual keys, thus reducing
The most cornmon hinctions were located on the edges of the keypad. For
exampie, the taise discs command was located on the right side of the keypad. so the
operator c m operate it with their thumb with the rest of the hand steadying the thumb by
resting on the right side of the box. Steadying the thumb is important, since this button
would be pressed while the tractor is in motion over the field. The position also reduces
the lïkelihood that the operation of the controller would be intenupted by hitting the
wrong key, as the number "7" key above the 'B" will have no effect. and the "F" key
below it will not intempt controller operation, either. If the "A" key is hit accidently, the
controller wiii stop operation, but quickly hitting the "B" key will cause the controller to
recover and raise the disks. This enor would not be iikely to occur ofien, as the operator
must stretch the thumb fanher away fkom the nght edge of the box. The "F" key is located
on the right hand lower side, so that it is easüy found and operated when the operator
While seeding. the operator need only use two keys: the UP position key for
raising the seeder, and the DOWN position key for lowering the discs to operating
position. Sethg the disc raised position provides the üP key subroutine with the desired
height for the discs to be raised above the ground when actuated. The DOWN position key
Chapter %: System implementation
releases the conml software fiom a W m loop (initiated with an UP key press) that
r e m s the program to normal seed depth operation. When the dûcs arr in the lified
position, it displays "DISCS RAISED" and wili lower hem by hitting the "F' key on the
keypad. This command directs the fuuy controller to remme normal operation, so the
Two main parameters to meanire are the shape of the topography of the field (S),
and the characteristic rates of change as one moves across the field (dS/dt). A data
sampling function in this mode samples both the discer sensoa at a relatively high speed
(24 Hz) in order to provide accurate promes of the soi1 surface for use in simulation of the
control system in the lab. The sample data are collected by the control module, and
simulation and for analysis of how the controiler responds to different inputs.
The rate of change in field topography is important to know to ensure that the
sampling rate used in the depth control operating mode (normal operation mode) satisfied
the Nyquist sampling theorem. This States that in order to prevent errors due to aiiasing,
the sample rate must be at least double the rate of change of the signal. In actual use, this
sample rate is set to about 1.6 times the rate of change of the signal. An HCl6-native. 16
bit fast Fourier transform (FFD was written for this purpose, based on the l3T produced
by Ron WiUiam of Ohio University for the MC68HC11, which in tum is based on the
witten by Richard Lord [Lord79]. Output is sent to a portable computer, which logs the
data and provides a real-tirne graphical display of the resdts. The FIT' used takes
Chapter 7: System implementation
advantage of the Idbit operathg capabilities and digital signal processing cotnmands of
the HC16.
characters wide. where messages encompass more than 16 characters, each iine of the
/
/
I
/' l
height increase is
I reduced
Sensor
Axis
- - -
Disc ComectioD
Point I
Fig. 7.3. Calibration hctions - 90 degree setting and theta correction.
calibration operation. This ensures that a i l subsequent sensor readings are interpreted
correctly. The h e e control parameters described here include setting the raised position
of the disks. setting the operating depth (the depth set point), and the field surface level.
Raised level and operating depth are programmed by pressing numeric keys when
prompted to do so. These parameters can be set in either metric or impenal uuits. The
units are chosen as a sub-menuof the raïsed &CS level setting. Field surface level is found
g disks to the ground, thea pressing a key to store the A/D value directly to
by l o w e ~ the
static RAM as a variable. Once these three values are set after calibration, the depth
for setting pararneters, and the two previously mentioned used in controlling the height of
the discet.
The "A" key starts the subrouthe for setting the height of the discs when lifted,
When the "A" is pressed. the controller displays the message "Choose
raised position, 2 to set units".Ressing the "0" key causes the controller
single sensor". Pressing "û" at his point causes the controller to determuie disc
position by sampling both the front and rear sensors (this is also the default mode, and is
part of the controller initiation settings on initial start-up). Pressing "1" sets the controiler
to use sensor data fkom the front depth wheel sensor oniy. This mode is used in studies
where the ftame height above the ground is the oniy parameter desired, as in determinhg
the amount of wheel sinkage on a given field. Once either the "0"or "1" keys are pressed,
Chapter 7: System fmplementation
and the controiier Wshes writing to the respective register, the controiler resumes depth
control operation.
Pressing "1" ta set seeder raised position, the message ''ENTER INCHES: '5s
displayed. The operator aow presses a numeric key to represent the inches raised. The
controlier then displays the message "ENTER TENTH INCH". Once the operator has
pressed a numeric key for tenths, the controller resumes depth control operation.
Pressing "2" for setthg units results in the display 'Y) for imperial, hit 1 for
METRIC". Choosing "O" sets the units to imperial, and the displayed depth is shown in
inches and tenths with the word "INCHES" on the K D display. Choosing "1" sets units
to metric, and the uni& are displayed in centimetres and millimetres, with "(34" on the
LCD.
The "C" key triggea the subroutine for setting the seeding depth. The LCD
displays the message "SET SEED DEPTH", then "HIT ANY KEY'. Once the operator
has pressed a numeric key, the LCD shouts, "ENTER INCHES:". When the operator
presses a numeric key, the value is stored as the inch setthg. The LCD then displays,
"ENTER TENTH INCH".Again, when the operator presses on a numeric key, this value
is saved as the tenth of an inch setthg. Once this has been done, the controiler resumes
The " D key initiates the "set ground level" subroutine. The LCD displays "SET
S O L SURFACE" message, followed by "HIT ANY KEY' several seconds later. Once
the operator has pressed a nwmric key, the message 'ZOWER TO G R O U N D appean,
foliowed by "HIT KEY TO STORE".The operator manually lowes the discs to the
ground on the field, using the hydraulic levers. Once on the gromd, the operator presses a
numenc key to store the value as the "Zero" depth position, or ground surface. Once this is
The '2" key starts the calibration subroutines. For calibrating both the front and
rear sensors. the implement is moved to a hn, level surfacc where the disks do aot sink
into the ground when lowered The b t variable to be set is the point in which seasor
linkage arms are 90 degrees to the depth linkage amis.Fiialy. the ground positions of the
senson, and their positions with the disks at 6 inches above the gromd are recorded. This
results in a characteristic calibration factor king calculated for the specinc sensor setup,
When the "E"key is pressed, the controiler prints "Choose Funcfion: Press O to set
sensors 90 deg to Linkages, 1 to cal disk sensor. 2-cal front sens" to the LCD display. If the
operator presses 'Y)", the message "PRûCEDTJRE TO STORE THE SENSOR POSITION
90 DEG TO DISK LINKAGE' is displayed, foilowed by "HIT ANY KEY". Once the
operator has pressed a numeric key, the message bbPositi~n
disk so sensor arm is 90 deg to
disk arm" is displayed. This is foliowed by the "HI. KEY TO STORE message. The
positions of the rear and front sensor anns are then set 90' fiom the respective connecting
a m to the discs and fiont sensor. When the operator presses a numeric key, the values in
the sensors are stored as the position where the sensor arms are perpendicular to the
connection amis to the disc gangs and front depth sensor assembly. Once the values are
controiier displays the 'mISC SENSOR CAL" message on the LCD. This is followed by
"ON LEVEL SURFACE"' then "HiT ANY KEY". The operator presses a numenc key,
The operator then lowers the dixs to the ground manuaüy ushg the hydraulic levers, and
then presses a numeric key to Save the value. The message "RAISE DISKS UP SM
INCHES" is displayed foiiowed by 'HIT' ANY KEY'. The discs are lifted manuaiiy, and
the distance from the ground to the bottom edge of the disc is measured. The discs are then
raised or lowered untA they are 6 inches above the &round. To ensure that the height
reading is not in error due to sagging of the disc gang when above the ground. make the
Once the discs have k e n set to 6 inches, the operator presses a numenc key, and
then the "HïïKEY TO STORE"display is written to the LCD. Once the value is written
to memory and the respective calculations have been made, the controller r e m s to seed
Pressing the "2" key WUstart the subroutine for calibrahg the front sensor. The
controiler displays the ''FRONT SENSOR CAL" message on the LCD.This is followed
by the "ON LEVEL SURFACE" and "HIT ANY KEY' LCD messages. The operator
presses a nuwric key, and the "LOWER TO SURFACE'' message is displayed, foliowed
by "HïïANY KEY". If the front sensor is on the ground a numeric key is pressed to Save
the value. The message "RAISE DISKS UP SIX INCHES" is displayed, followed by
Once the sensor wheel has k e n biocked up 6 iaches, the operator presses a
numeric key, and then "Kïï KEY TO STORE" is displayed on the LCD.Once the value is
Wnnen to memory and the respective caicuiations have k e n made, the controiier rehuns
to seed depth control operation. Once sensor calibration is complete, the parameters for
display. Each of the six alphabetical keys on the keypad contml a separate depth controiier
set of functions.
Cbapter 8: Dixussion and Analysis
CHAPTER
8
DISCUSSION
AND ANALYSIS LOGICBASED
OF NZZY
DEPTHCONTROLLER
SEEDING
retums without additional input costs or t h e . The limitations of cornmon seeding depth
control methods and the suitability of fuay control for this application have k e n
preseoted in previous Chapters. A proof of concept controlier design was built using the
composition. The Mamdani type of hiuy coatroller, first inuoduced 20 yean ago
[KiMa77]. has been appüed to a variety of industrial processes. For example, it has been
used in heat exchangers. cars, and w a s h g machines iKipe90, Mua84J. Thus, fuuv
control is gaining in popularity in control applications that use nonlinear, tune varying
In utiiizing fuuy logic in the decision process of the seeding depth controlier, the
state of the seeder position is described using linguistic labels. The fuuy membenhip
fuoction mA(x) describes the extent to which the adjusted value x of the two sensor inputs
belong to a specific Linguistic input classification describing the error Born the set point.
Similarly, mB(y) describes the degree to which the Merence between the depth reading
Cbapter 8: Discussion and Analysis
seven samples previously and the present reading belongs to a specinc linguistic
classification for the change in e m (seven samples rrpesents about 113 second for the
data Iogging controller. and about 1/7 second for the non-data logging contder-ushg
adjacent sarnples provided very littie difference in enor). For instance. the rneasured
error from the depth contdier set point input may k classified by its degree of
membership in the linguistic classincation, Negative Medium, and the error change from
the previous depth reading classioed by its degree of membership in Positive SmaU (see
Fig. 8.1).
NM
NS
ZE
PS
PM
NS
2 . CHG
IPS IPS JPM IPM IPB JPB
Fig. 8.1. Fuuy control mies for 7 memkrship fvnction algorithm, fiom FIDE
simulation.
A list of linguistic conaol d e s were formed based on the fuuy relation. Each nile
is based on the advice fÏom an expert human operator. Linguistic variables are set up in
where
In the f h t example for this research, seven Linguistic variables for &or, and seven
iinguistic variables for Change in Error were constructed in the fouowing form.
ELSE
form usable by the fuzzy logic coatroiier. The hiuy depth conml algorithm is therefore
defined by these d e s . The control action is determinecl by the max-min product of the
Cbapter 8: Discussion and Analysis
depth reading input x with the h z y depth control algorithm, D,denoted by xOD.The
fuzzy depth control algorithm D consists of fuuy relationships ktween the inputs x and y,
and the control signal output, r Additional tests with 25 d e s and 9 d e s were nui with 5
membership fimctions for error and change in enor. and 3 membenhip huictions for enor
The discrete numkrs representing the e m r and change in error are fuzzified. This
means that the discrete input values are classifîed as king mcmben of given fuuy
number between [O,L]. This is also said to represent the degree of membership in the
respective fuuy set. The algorithm is based on the max-min composition of theses values,
represented by the fuuy control d e s . For example, when X is the degree of membership
of a given depth input in negative medium, and Y is the degree of membenhip of the
corresponding change in error in positive srnail, the hiuy phrase P describes the min of
the inputs. or X X Y
membership of the min of the input variables (x,y) in the output variable negative srnail.
fuuy phrase Q
Chapter 8: Discussion and Analysis
controuer
The value, mS(x,y,z), is then dehiuined using the center of gravity (COG)
approach. This approach determines the output using the weighted average of singleton
output functions. The resuitant output signal voltage is then appiied to an electrohydrauiic
proponional valve.
8.2 Simulation
In preparing for simulations, the objective was to approximate the decisions of an
expert operator as closely as possible. The k t step was to form the f k z y control d e s .
These provided the reasoning for the actions, and serve as the implementation of an
operator's actions. A combination of the "conventional" and the "template" method was
used. The next step was to determine the control parameters based on the mechanical
characteristics of the plant to be controiied. The maximum height and depth the discs
could obtain are the iimits of movement and the Limits the membership hinction Enor
(about half this total distance negative, and half the total distance positive) could obtain. in
a simüar fashion, the working depths of different seed types were considered and
compared to the maximum rnovement of the discs in order that the best membership
fuaction shapes couid be determined Fmaiiy, the maximum speed of movement of the
front sensor and disks was considered, in order that the sampling rate was fast enough to
Chapter 8: Discussion and Analysis
satisfy the Nyquist sampling theorem. By observing the motion of the d i x s and fiont
sensor, this was àeemed to be about 75 cmlsecond This provided the information needed
to put together the membership functiom for Rate of Change. Thenfore, it was possible to
assess the performance of fuzy logic control aigorithms by comparing results to the
desired output.
The values for the fiuzy controller were then simulated, using Manifold Editor
(Version 1.8.01- 100049, Fuay Systems Engineering, San Diego, California, USA),
Mathcad (Version 6.0 - MsthSofi, 101 Main Street, Cambridge, Massachusetts, USA
02142) and FIDE (Fuzzy Inferroce Development Engine, nom Aptronk, CA, USA).
Manifold Editor enables the user to graphically edit membership functions, set input
values, and view output values given different input values. Mathcad is designed to
operate like a clean sheet of paper, where the user enters equations and variables just as
they would with pen and papec Data nles can dso be imported, so once field readings
were available, these were imported and processed. FIDE is meant to be a complete fuuy
logic development tool, with graphic membership function editing. simulation functions.
viewing of control surfaces and generation of &bit code for several microcontrollers.
In using Manifold Editor. initial input parameters for membership funftions were
entered, then analyzed using the Manifold Walker. As each input was changed, the
resulting output value was noted and recorded. Output values were compared to the
desired values.
Output values for this application must be monotonic, in order to preserve the
stability of the controller. Output values of the Manifold Walker were graphed to ensure
Cbapter 8: Discussion and Analysis
rnonotonicity. Minor adjustments weE ma& to the input and output membership
functions to epsure this. The fuzzy membership functions and their mal values are
Fig. 8.2. Manifold Editor input membeahip fhction exampie - 7 membership function
algorithm. Error on Ieft, Change in Error on nght.
Fig. 8.3. Manifold Editor - output membership function for 7 membership funftion
algorithm.
Chapter 8: Discussion and Analysis
Fig. 8.4. FIDE simulation screen example: input and output membership functions for the
7-membership fûnction aigorithm.
The membership functions in "Error" (Fig. 8.2) refer to the degree of error
between the acnüil depth of the Unplement to the desked target depth (the set point = O).
The fuil scale readings Vary kom -15 cm (15 cm below the set point) to +15 (15 cm above
the set point). In the "Change in Enor" membership fuactions (Fig. 8.2) are the rate of
1.a
B.5
B.B
-1s 125
Fig. 8.5. Input membership fuactioos for change in emr fkom prpviobus depth reading.
The output memberrhip hiactions, in "Depth Adjust" (Fig. S), refer to the distance
the irnplement must move in order to approach the set point. This is expressed in terms of
Once the vaiues of the output were recorded from the Manifold Walker, a surface
plot was produced to give a graphical representation of the fuzzy controiler output (Fig. 8-
8)-
lis
Fig. 8.7. Fuuy control surface (fiom a FIDE simulation). The X axis represents positive
64 mm to negative 64 mm change in emr, the Y axis representing positive 125 mm to
negative 125 mm error from the set point, and the Z axis the change in output of -15 cm/
second to 15cm/second.
The control surface shows the monotonie control characteristics of the fwzy
controiier. The surface near the zero error and zero change in depth point shows a gradua1
positive slope, where control signais need to correct the depth a small amount. Areas
closer to the extremes of the control surface have a higher rate of change in the slope. By
monotonicity is ensured.
aUows the user to use programmulg hinctions, including loops, iterations and if-then
statements. The variety of graphing functions also made it possible to instantiy see the
effect small algorithm changes had on huzy contml, as a two dimensional output result
and as a three dimensional surface plot. As it was possible to produce a variety of output
Chapter 8: Discussion and Analysis
results quickly while knowing exactly what calcdations were taLing place to prduce
them, this was the tool in which most simulation was done. It was more tiw consuming
than other tools but had the important advantage of having the flexibility to modify the
parameters. One comparison made was the granulanty of data. The fineness of control was
compared in the three regimes. Obviously, the minimum control achievable on output is
one unit in 256, or 8-bit control. The minimum amount of each membership function
Another criteria for comparison was how weU each regime fit into the
requirements for the fuzzy depth controiler. For example, in the 3membership function,
was necessary to reduce the slopes of the Zero fiinction to the point it was no longer
possible to achieve fast response tirne on extreme Error readings, whiie rnaintaining fine
(slow rnoving) control when there is very Little error. A weli-designed fuzzy controlier
should be able to quickiy move the discs to the set depth, without overshooting the target.
In conventional seeding depth controllers, lack of overshoot is often attainable only at the
expense of speed andlor accuracy by the use of a "dead band". It is worthy to note here
that as the slopes of the membership fiinctions of a fuuy controlier becomes steeper, the
controiier cornes closer and closer to approximating the actions of a conventional, non-
fuuy controiier. The 5- and 7-membership function algorithm both provided sufncient
Work with FD)E dealt mainly with the assembly code producing capabilities of
this program. Membetship fuactions were set up and verifi.ed, then the assembly code
produced. The version of FIDE king used here produced assembly code for the
MC68HCll. Although this is 8-bit code, the MC68HC16 compiler MASMl6.EXE will
properly compile this code for use in the HC16. The code to be tested in the controller
hardware is placed in the fuzzy controiler assembly code, and the respective variable
names adjusted and memory space ailocated to aliow it to work with the rest of the code.
FIDE version 1.0 uses only singleton output functions. This is appropriate, given the
characteristics of the hydraulic valve. Although the valve is proportional, the speed of
operation does not vary considerably once the P W M A output exceeds 25 hex uni& fkom
center, or about one nfth of the total PWMA output possibility is usable in this way.
8.3 LabTesthg
Once a new algorithm wodd be produced in FIDE, it was compiied with the HC16
controller code and tested in the MC68HC16EVB evaluation board laboratory test unit.
The sensors were taken through their entire range to observe the depth reading results on
the LCD display. An osciiloscope was also used to examine the PWMA output waveform
as the inputs wen varkd to the controiler. Once it was detennined that code produced a
monotonie control action and approximated what was needed to work in the field, the lab
unit would then be comected to the actud disk sensors and hydraulic proportionai valve.
A tractor comected to the discer supplied hydrauiic pressure for the testhg. In order to
simulate a "fieldtzeroTTcondition, the discer was operated in one spot, but the "zero"
Chapter 8: Discussion and Analysis
position wouid be set severai inches above the ground in order that control on both sides
W~thoutthe damphg effect of the soil, it was found that the discs would oscillate
when ushg the 7-membership and 5-membership fiinction algorithms. Oscillation was
stopped by scaling the membership algorithm outputs d o m 50% in speed. It was found
that once oscillation began, the resonant frequency of the discer would be obtained quite
easily, as it rodred back and for& on two baiioon tires. The tires are located about 10 feet
from the other, so the resuit of this distance was a lever action using the implement frame
that tended to ma- the rockkg motion of the discer. Thus, with a combiaation of large
rubber tkes ~spendingseveml tons of steel discs and associated hardware, oscillation was
very easily achieved by several quick movements of the &ont sensor. If this work was to
the oscillation problem would only be defeated by using a valve that would be too smali to
move the discs quickly when the error or rate of error change was high. Cascading several
valves wouid also work, but would add complexity in the hydraulic valve plumbing and
lead to increased possibility of leais, complexity for servicing. cost and increased nsk of
failure due to a higher number of electric solenoid valves and associated wiring.
med under field conditions. The lab MC68HC16EVB control unit was suitable for use on
a table in the laboratory and stationary testing, but would serve to be impractical for use in
the field when the tractor was in motion. An umbilical setup could have been set up for use
Chapter 8: Discussion and Analysis
with a vehicle following the movhg disc, but a mch simpler tractor cab mountcd unit
was constmcted in a s m d aluminum box for testing and logging of tesuits. Shielded
! ~ the sensors and the hydraulic proportionai valve were nin into
control wûes C O M ~ C ~ € to
the cab. and securely cornecteci by amphenol-type shiekkd screw connectors. A shielded
aluminum box enclosed the controller electronics. with sbïelded compartments for the
power supply and hydraulic signal switching. Power was suppiied to the unit via the
screen display was produced that graphically indicatedthe cunent ~adingsbeing received
from the controlier (Fig 7.9). In order that it would function on any PC,and not just a
Chaprer 8: Discussion and Analysis
Wmdows-3.1 or above capable machine, the software was written in Turbo C. with
The m e n was set up with a simple interface for easy interpmation of the state of
the controller. The text across the bottom is as follows: Error, Ermr Chg (change in error),
Fuzzy Decision and the sensor position readings Fnt Sensor (front sensor, on the gauge
wheel) and Dsk Sensor (the rear seasor, on the disk gang). Shon lines on the vertical
access of each screen parameter represent the median positions of enor, change in error.
and hzzy decision when error and change in e m r are zero. For the disk sensor positions,
the median line represents a hexadecimal reading of $7F or 127 decixnai, the center of the
sensor range. The h e at the top represents SW,or 255, with the bottom axis of the graph
representing 0.
the tests, an incorrectly wired sensor was causing a pronounced darnping effect on the
level of error. producing values that were much below the expectation. The deficiency was
spotted immediately with the display values, and the changes made. In another example, a
sensor was not clamped in the center of its total operating throw. This meant that the
sensor would rcad zero nom the to time, resulting in incomplete data and erroneous
conaol action. Sensor connections were loose in one experiment, resuiting in wildly
changing output values. Steps were then taken to eliminate this effect. If the logger had
not had the display, it would have led to fuaher delays in development of an operating
controller, since problems would not have been apparent until the logged data was
graphed.
Cbapter 8: Discussion and Analysis
A numbu of different trials were nui with the 7 membership function algorithm.
on unworked stubble. soil disced once and soil disced twice. Tractor speed was a constant
6.8 miles per hour, typicd for seedïng. It was found that the low-pressure tire of the front
sensor foilowed the soi1 contours very weU, but wouid be easily lifted up by piles of straw
larger than 1" thick Also, if there were intermittent piles of straw within severai feet of
each other, the resonant vertical motion fkequency of the sensor would sometimes be
obtained, leading to steady bouncing of the sensor up to 4" off the ground In this case, the
aigorithm with the speed of the discs dampened by 50%was unable to move the discs fast
enough to follow the bauncing, so the discs actually remained quite stable as the front
Data was collected giviag the enor, change in error, decision and the sensor
position readings fiom the A/D converters. This way, the sensor readings could be
converted to inches, and the action of the hizy control algorithm checked against what
was expected.
Fuzzy Decision
Value
Change in Error Front Sensor Reading
Fig. 8.9. Portion of data output fiie showing data format for PC logger.
-ter 8: Discussion and Analysis
A sample of the data coUected is given in Fig. 8.9. A time domain plot of the
sensor position over time is also given in Fig. 8.10. Emr, change in error, and fuay
Sample Number
The FFI' of the data is given in Fig. 8.13 and Fig. 8.14. This shows that there was a
considerably higher amount of movement in the front sensor, with most motion to about
5 Hz, with a smaller amount to the fiill measwable bandwidth of 9 Hz. The disc sensor
reading shows a much different scenario, with the majority of action to about 2 Hz. The
In an excerpt fiom Trial 1 Fig. 8.14, the error over tirne show that the discs had
peaks up to 5 inches h m either side of the set point, with the grratest variation due
mainly to sensor bouncing on lumps of siubble in the unworked stubbie field portion of the
Chaptet 8: Discussion and Analysis
test However, emr peaks of several inches are expected in the field trial. since the soii
topography will change rapidly as the dixer moves acmss the field.
O 20 40 60 80 IO0
Sarnple Number
Fig. 8.11. Example plot of error and sensor position for 100 samples from the PC logger
data fiie for the 5 membetship fuaction algorithm.
w
FFT d front Sensor
Fig. 8.12. FFT plot nom PC logger, h t sensor, for field test 5.
Chapter 8: Discussion and Analysis
w
Fft of Rear Sensor
Fig. 8.13. plot fiom PC logger, disc sensor, for field test 5.
Fig. 8.14. Error plot fiom the 5 membership fuaction algorithm. field test 5. with mean,
standard deviation and variance measurements.
Chapter 8: Discussion and Analysis
Fig. 8.15. Field trial 5 emr from set point, over 1400 samples (78 seconds), with
statisticai measwernents for these data.
Figure 8.15 shows the results of the field aiai. The units for emr, FL,DOERR, are
in decimal, and are the ciifference fiom the set point to the curent depth position as read
by the two N D converters. Each decimal unit corresponds to one hexadecimal unit for the
A/D readings, thus the range of the graph is from 60 to -60,representing the hexadecimal
values 7C to -7C actually recorded by the PC logging program. The approximate number
sampling t h e over both unworked stubble, stubble disced once and stubble disced two
Chaptet 8: Discussion and Aodysis
times. These areas are repnsenting différent soil topographies and discer sink rates into
varying degrees of support fiom the soilThe unworked snibble represents very solid soil,
in which the tractor and discer sink o d y about 1 inch, with level soi1 and 1-2 inches of
intermittent straw cover. The area disceci once represents an area with soi1 ndges 4-6
inches deep, with tractor and discer sinking about 3 inches. The area disced twice has a
more even topography, with soil ridges about 2-3 inches deep, but with a higher discer and
The mean of the e m r over these different regions was 0.954 of a hexadecimal A/D
unit, or about 1.0 units considering two signincant digits due to samphg accuracy. This
represents an error overail of approximately 0.10 inches (2 mm), based on the calibration
value of (decimal) 14 hexadecimal units per inch in the calibration sequence. The standard
deviation for these readings was 15.451 units, or 1.1 inches (28 mm). Vkriance was
The significance of these results is that although the sensor was moving across the
set point a significant amount, with peaks as many as 4 inches (10.2 cm) fkom either side
of the set point, the seeder was able to maintain a mean e m r within the 1 cm goal set in
the cnteria for the controller to operate with adequate accuracy for seeding depth control.
field, minor code revisions were made with the aid of the battery-backed RAM module.
However, after each day in the field testing a major variation in an algorithm or controller
Chaptcr 8: Discussion and Analysis
code procedure, major rewrites had to be conducted off-site. Extra testing of different
fuzzy control algorithms. and possibly an impmved PC logger routine for faster operation
could have been conducted if it was not for the onset of winter 1996. Field results obtained
are only for the 5-membership fuaction algonthm, and although it appeared to work quite
weil for this operation, additional testing of variations to fine-tune this code and compare
it to other membership £bnctions would have added fiutber interestkg results for
cornparison in this research. In all, however, the objective of this work was to test the
suitability of hiuy control for the application of seeding depth control with one-way
work. and present thoughts on fuhue work based on the research in this thesis.
Chaptcr 9: Conclusions and Recoinmendations
CHAPTER
9
CONCLUSIONS AND RECOMMENDATIONS
Improving seed depth conml can improve crop performance. The most common
seed depth control methods and the limitations of their accuracy were described. Fuvy
logic controllers are well suïted for control applications B e seeder depth control, where
the inputs are nonlinear and tirne-Maut. A model of a seeding depth controller
utilizhg fuay logic has also been described. Simulation results of the model were
presented in the fiom of the final structures of the mernbership functions and the resulting
control surface.
found that compacted straw on the field h m the previous harvest was m e r packed by
the action on the wheel, but that the reading would be for the disc depth was shown to be
deeper than it actually was. As a resdt, the disc would be lifted by the erroneous amount.
The fuvy algorithm did tend to low-pass nIter s d impedections in depth, such as that
caused by wheel tracks in the field. However, the "very large" membeahip functions did
cause the discs to move quickly when there were large changes in depth, such as in
drainage ditches and wide nits. The integration actions of the depth gauge tire. mass of the
sensor and time for the hydtaulics to move the disc depth control cylinder also add enough
t h e lag that the discs can adjust to changes in depth 2 m ahead, at the wheel sensor.
Cbapter9: Conclusionsand Recommendations
The front wheel sensor essentidy gave a reading of the amount of main wheel
siakage and discer swivel as it crossed various soil conditions - soil that is previously
cultivated and loose, soil compacted by large agricuiturai vehicles, and soi1 with varying
moisture contents. In soil with straw cover less than 70% [reference on measuring straw
cover] the effect of straw on the depth reading was not significant. DBerent weights of the
sensor, as weil as different tire pressures and even the use of a Buid-nlled or solid rubber
tire codd also be tested for immunity fiom straw aad soil clamp "noise".
depth controiier, it was found that the construction of the device was critical. Any wires
within the unit that were tw shon or under excessive pressure soon came Ioose or became
disconnected in the vibration of the tractor cab. It is necessary to ensure all connectors
lock into place, and are securely soldered to prevent separation in the connecton.
Likewise, the original sensors had contacts that easiiy corrodeci if not completely covered
in storage. It was necessary to clean the corrosion fiom both the contact ends to prevent
periodic signal interruptions due to vibration and shock as the discer moved across the
field. It was also necessary to ensure al1 wires to the discer were properly secured to
The proportionai valve has a variable speed setting that varied the rate of oil flow
through the main spool. It was found that at the high rate, the discs would respond much
more crisply to controller commands. However, if the discs were raised out of the ground,
thus eliminating soil resistance to movement, the discs would osciïiate across the set point
Cbapter 9: Conclusions and Recommendations
until they contacted the grouod This was noticed using the 5-membersbip hinction
algorithm and the 7-membership fiinction aigorithm, without 50% gain reduction. At that
point, the gnwid would slow the disc gang movement, and stop the osciilation.
development: the use of an anaiog simulator. use of a hydraulic vaive and ram driven by a
operationai amplifiers, each element of which would mode1 a different part of the
controiler and discer system. Sensor inputs wouid be the combined voltages nom
simulator feedback and an added perturbame, to simulate the changing soil contours. The
action of the wheel sensor assembly can be simuiated as a low-pass filter, with only
changes above the minimum characteristic fkquency of the sensor passing to the
controller. Likewise, the integration action of the hydraulic hoses, hydraulic proportionai
vaive. hydrauiic ram and the soil itself can be modelled with op amps. Thus, an output
voltage would feed tbrough the simulator. with the output (representhg the changing disc
position) feeding back to the senson as a slowly changing signal, at the characteristic rate
unit with a w w controller code revision to M e r test the characteristics of the hydraulic
proportionai valve/tractor/ram and hose combination, returning to the lab the next day to
Chapter 9: Conclusions and Recommendations
recode a set of control actions. retuniirig again to the tarm to test the code several days or
weeks later. Having access to a hydrauiic valve and ram powered by an electric hydraulic
pump at the University wouid have enabled development of the output parameters of the
fuzzy control algorithm to take place much more rapidiy. Controk code changes couid
take whatever time is necessary to snidy the characteristics of the system and produce the
desired output. A hydraulic bench apparatus at the University would also have enabled
more detailed measurements to be made of the control action. such as iitres of oil moving
per second, oil pressure, optimization of hose configurations and comections for
minimum oil flow resistance and heating. A more detailed evaluation of different valve
spool combinations, oil flow rates and throitle positions in investigating the optimal
ailowed algorithm and controiler development to continue throughout the winter months
and without the necessity of travelling to a remote location. More extensive testing of both
conventionai and fuuy control algorithms would then be possible, as different soii
The simulations done in Mathcad were facilitated by the Version 6.0 capabilities to
program in if-then loops and other iterations Wath96J. Otherwise, the only other option in
such as C or C++ - this would have required mon tirne spent on the implementation of the
test code and interface, and less time on evaluation of results. Of course, if the time was
Chapter 9: Conclusions and Recommeadations
avaiiable to p m e this option, a u s e N CASE tool couid have been produced, as outlined
two dimensions, it becomes obvious how to produce a CASE tool that would provide a
fast method of simularing the results of varying membership fiuiction and d e variables.
Such a tool could also be set up so that assembly code could be produced based on the
shape of the membership functions and the des.The assembler code generation
capabïiity could also be set up for a number of rnicrocontroUers, with a menu for the user
to choose the appropriate program path. The code generation portion of the program codd
use several branches for dinerent defuuification h c t i o n types that can be chosen by the
operator. A general fuuy inference engine can be used for determining rule suengths. The
number and shape of membership functions could be varied by the operator, using not
only point-and-click modifications with the mouse, but also have the option of choosing
be advantageous to extend this into testing of more variations of the huzy control
algorithms. For example, a Gaussian membership huiction s h a p for the Zero membership
Chaprcr9: Conclusions and Recommendations
graduai control c m be achieved than was found in the lhratory simulations. The 3- and
defimification, for example. the mean of maximum, could also be tested to see how well
In this system, it should be noted that although the control algorithm is based on
fuzzy control, it operates entirely using discrete data. The sensors are imprecise to a smail
degree (although within tolerances for this application). Therefore. the controller
algorithm interprets the analog signals and classifies them by degree of membership of
different membership functions. Rather than undergohg this process in such a discrete
way, fuuy sensors codd be utilited that would sent the controller signals giving the
This research, concerned with the depth of seeding, is only a smail part of what c m
be investigated for the use of artificial intelligence techniques such as furzy control.
Pesticide and fertiiizer application takes on many forms, with grandar, low and high
volume liquid, mist, gas. and emulsion methods used commonly on the prairies, each with
their own unique challenges. The combination of accurate positioning and a better
explored in these areas. Increased efficiency in the harvesting and handiing of crops can
take the form of reduced combining losses tbrough more accurate machine controls, better
sensors in stored grain and reduced shrinkage whea handliag large volumes. Neural
networks and genetic algorithms are king applied to market data in order to reduce the
risk individual growers and agribusiness enterprises face when planning fùture crop pnces
In the area of optimization of ruies, it was found that the controiler performance
could be changed considerably with minor changes in d e s . The use of a neural network
nonsupe~sedieaming selfsrganizing map to quantize the input vectors into groups, and
through E contain the controller schematic diagrams, software flow charts, source code for
the controller, source code for the PC logging program, and an example of Mathcad
Brian Armstrong, ' R C design for ûoboded separable fimctions with hear
inputsutput relations as a special case," IEEE Trans. on Fulzy Systems,
Vol. 3, NO.1,72-79,1995.
The Amencan Radio Relay League, Ihe ARRL H'dbook for Radio
Amateurs 1992, Newingtoa Cornecticut: The Amencan Radio Relay
League, 1991.
[GKWD8la] D.G.Gunderson, TG.Kkk, I.N. Wdson and J.N. Dyck, "A cornparison of
ultrasonic, ski, and ski-wheel systems for mage depth measurement,"
Papers of the American Society of Agricultural Engineers Microfiche
Collection, fiche no. 81-1602, 1981,
D.G. Gunderson, TG. Kkk, J.N. Wilson and IN. Dyck, "Drift-speed-
depth characteristics of cultivators and discers and their effect on fuel
consumption," Paprs of the Arnerican Sociev of Agricultural Engineers
Microfiche Collection, fiche no 81-1603, 1981.
P.J. King and E.& Marndani. "The application of fuzzy control systems to
industrial processes" in Fuuy Automata und Decision Processes. New
York, NY: North Hoiland, pp. 321-330, 1977.
Frank Klawonn. Jorg Gebhardt and Rudolf &se, bbFuzzy control on the
basis of equaüty relations with an example fiom idle speed control," IEEE
Tram on Fuuy Systerns, Vol. 3, No. 3,336350, 1995.
References
Seong-Gon Kong and Bart Kosko, "Adaptive fuuy systems for backup up
a truck-and-trailer," IEEE Trans. on Neural Netwonks; Vol. 13, No. 2,
Match 1992.
Richard Lord, 'FFT for the 6800," Byte; pp. 108-119, Febmary 1379.
Raaier Palrn, "A huzy logic controller for an ABS braking system." IEEE
Trans. on Funy Systems, Vol. 3, No. 4,38 1388. 1995.
Mark McQuilken and James P. LeBlanc. Digital Signal Processing und the
Microcontroller, Phoenix, Arizona: Motorola Literatuce Distribution, 1992.
J.E. Momson, Ir. and T.J. Gerik, "Planter depth control: Empincal testing
and plant responses, Part II," Trans. ASAETvol. 28, no. 6, pp. 1744-1748,
NovJDec, 1985-
Moto9 la] Motorola, GPT General Pwpose îïmer Rcference Manual, Ph~enÿc.
Arizona= Motorola Literature Distribution, 1991.
Moto9 1b] Motorola, Parts List and Schematic Diagram for REVision E
M68HC16EVB printed cincuit board REWsiion 5 M68HC16EVB schematic
diagrams, Phoenix, Arizona: Motorola Literature Distribution, 1991.
G.S. Pask, J.N. Wdson and G.C. Zoerb, "An automatic height-of-cut
conaol system for windrowers," 1973 Annual Meeting, m e Anterican
Society of Agricultural Engineers, Paper No. 73-155, 1973.
Bradley L. Richards, ' m e n facts get ruYy," BYTE, pp. 285-289. April
1988.
[Schu89] John K. Schueiier. "'Digitalsimulation of combine ceel and forward speed
controllers," Cornputers and Electmnics bt Agncuftute, 459-7 1. 1989.
[Sche891 Francis J. Scheid, Nmerical Analysis 21ed. New York, New York
McGraw-HiIl Book Company,1989.
[ShDH9 11 Bumsoo Shin. Roy B. Dodd and Young I. Han, '%round d a c e detection
using dual-fiequency continuous-wave radar," 1991 Intemutional Mnter
meeting, m e Americm Society of Agricultural Engineers, Paper No. 91-
3540.1991.
Tom Williams. "Fwq logic is anything but rUny," Cornpufer Design, pp.
113-127, A@, 1992.
R.R. Yager, S. Ovchinnikov, RM. Tong, H.T. Nguyen, Fuuy Sets and
Applications: Selected Papers by LA. M e h , New York, New York: John
Wiley & Sons hc., 1987.
The schematic diagrams were fint produced in PADS, then edited for size as a
postscrîpt nle in Adobe Illustrator. Several parts were not found in the libraries, and had
to be made. Tbis included the MC68HCMZl MPU, the MC145450 serial interface, and
the inductors.
wrnr; TOM f ESSlER
R
DRL.I).
WI e, im
DWD;
ul a, itn
UTICITZINC FU2ZY COGIC
CKCNID; DA IlD.
CWi WC W. MVi
FDC 10 11.0
Appendix B: Software Fiowchart
biUTXRE ND PORT
SET FOR 8-BIT OPERATION
INITIALIZE LCD
INlTiALIZE REGISTERS, SET UP CHARACïER DISPLAY MODULE
DISPLAY WELCOME MESSAGE
8.2 MainPmgrsmExecution
The main program consists of eight main parts. Each part is a subroutine that is
executed in sequence:
to see if a keypress (iow) signal is still present. If so, it then identifies the key pressed and
2. SAMPLE - Each of the two sensors are sampled in this subroutine. If the
controller is in normal operation mode, the signals are passed onto the next subroutine. If
positions, a theta correction factor is employed. This works by taking the sine of the angle
from the "zero" position of the sensor Liakage, where it is precisely 90 fiom the sensor. In
order to ensure calculaiion speed and accuracy, at l6-bit sine look-up table is used, rather
Initial conversion values for the theta correction subroutine are written to the
respective registea during controller initialization. This allows the operator to raise the
implernent for transport to the area of use. Once at the field, the operator then goes through
a calibration routine that sets the registers with the correct conversion and setting values
the sensor values are converted to thousands of an inch in a 16-bit format. This process
facilitates the calculations that WUinclude only addition, subtraction, and maximum and
minimum comparisons.
Windows graphics-based fuuy logic simulation and anaiysis tool. FIDE (Fuuy Merence
Development Engine) ftom Aptronix. The different of the membership functions were set
FIDE speeds up development with increased accuracy by the use of several valuable
development tools. Each rnembenhip bction can be viewed graphicdy, and quickly
changed using the mouse. Likewise. FIDE instantly generates the fuzzy control surface for
any set of membersbip fimctions and inputs. Once a given combination of membeahip
huictions produce an acceptable gain level of monotonie contml, a visual simuiation can
be nui with inputs h m both artSciaUy generated signals and acnial recorded field data.
immediately generate 8-bit (MC68HCll compatible) assembler code. This code can then
be pasted into the controller code and compiled The code automaticaliy takes into
account scaling factors for sensor inputs and the hydraulic conml output signal.
Therefore, code is produced quickly and accurately that can be tested in the field.
In this routine, the fuuy Iogic algorithm operates the four steps of determinhg a
control decision:
degree of membership for each membership fuoction is then passed on the fuzzy inference
engine.
- The fuzzy values are evaiuated according to the des. The DOF for each d e is
determined.
- The rules are aggregateà, and the d e s that apply are determined.
- The fuzzy decision fiom the nik d y s i s is defuruned. The algorithm uses the
singleton method of defuuincation. Aithough this methd is not as elegant as the COA or
MOM methods, it is much more efficient to code and execute in assembler, md does
The output range for the controiler is between decimal 120 ta 135 (CHECK).This
is due to the characteristics of the proportional valve used and the hydraulic system of the
Appcndix B: Software Flowchan
tractor used. The tractor used in testing was a Case International 5240 (CHECK)with a
closed center hydraulic system. This type of system maintains constant pressure at all
times, so will provide a consistent hydraulic conûol respow regardless of the demands
on the system.
6. HYD-CONT - Now that a fury decision has been produced, the control signal
is sent to the pulse width modulation unit A (PWMA) of the MPU. This modulates the
duty cycle of a 128 Hz signai that controls two solenoid valves that control the position of
the main spool on a proportional hydraulic valve. By having a constant, opposing 128 Hz
pulse on the main spool, a constant tiow of oil keeps the main s p l in constant motion.
The motion is not enough to significantly change the position of the hydraulic ram on the
seeder, but is essential to keep vaive response t h e at an optimum level. The duty cycle of
the two srnail solenoids that control the main spool are equal when the main spool is in the
proper position. When the seed depth (disk position) has to be changes, the spool must be
moved off center by changiag the duty cycle of the tow small solenoid. This is done by
changing the duty cycle of the signal h m PWMA. The signal is split, with one signai
controlling one solenoid and the other. inverted signal controlling the other. M e f o r e .
when the duty cycle is changed, one soleuoid wiU open wider, with the other opening with
an equal, opposite n m w e r opening. The Merence in pressure moves the main spool one
way or the other, thus acting as a hydraulic amphfier by ailowing a large volume of oil to
move from one side of the seeâer hydtaulic cylinder to the other.
-
7. DISPLAY-DEPTH Now that the control signal has been sent to the discer, the
controiier moves into the LCD depth display mutine. The depth error value is compared to
AppendIx 8: SoftwareRowchart
the soi1 suffice value, and the Merence is displayed on the LCD. The routine indudes a
subroutine that converts the depth number to inches or centimetres and tcnths of an inch or
millimetres. Once ail the numbm have k e n calculated, the LCD display routines are
c d e d to put each character on the screen. The unit preference c m be selected by the
operator.
-
8. SEND-DATA In order to subjectively test the performance of the controiler, a
serial communication data logging routine is utilized. Data read h m registen in the
controiler is sent to a laptop computer for saving in a log nle and later aaalysis.
order that these calculations cm be checked. This data allows cross-checking the
controiler fuzzy decision with the expected output fiom previous simulations. Also, if any
changes are made in the field, the results of these changes can be recorded and monitored.
The sister PC routine operated by checking for valid (new)data king in the serial
buffer, reading the data, and sending an achowledge signal. Once received, the controIler
increments an index, and sends the next data byte. Both the coatroller and the PC are
synchronized to prevent data skew. In total, 10 bytes are sent per sampling instance. The
PC logging program automaticaiiy formats the data for saving into an ASCII file for easy
coilected, a bar graph display on the PC alIows the operator to monitor the pmgrrss of the
The present system nuis fast enough to log data 23 times a second. This is
mph).
The SEND-DATA routine is commented out before compiling for normal. non-
logging operation. When the controiier has hished this routine, it loops back to
sensor only, rear ody, or both), "1" for setting the seeder raised position for hirris and
transporting, and "2'' for setthg the units to either impaial or meûic values.
s KEY PRESSED?
8.2.2 .a Settr'ng Disk Ruised Position
r -
DISPLAY PJSfRUCnONS CHOOSEMODES 1
Appendix B: Software Flowchart
b
KEY PRESSED?
Appendix B: Software Fiowchart
B.2.3 Mo ~ & u P Appendu B: Software Flowchart
This key comrnand is for raising the disks out of the ground for hims and
transporting. The discs are lowered when the "Fkey is hit, which resumes normal
controlier operation.
[3)i
KEY PRCSSED?
r7
MECK KEYS
b PRESSED?
Appendix B: Software Fiowchart
In this routine, the calculation, scahg and conversion factors are set for the
particular sensor/discer implement configuration in use. Once stmed by pressing the "E"
key, the operator is given thme calibration choices: 'Y)" for setting the position where the
sensor linkage is exady 90 between each a m , "1" for calibrating the disk sensor height,
v
1DISPLAY INSïRUCiiONS - POSITION SENSORS 90 SENSOR ARMS 1
-H~+KEYTOSTORE]
I
C
I
* ACfOR FOR D m
BY FINDiNG THE LENGï€fOFTHE
Appendix B: Software Flowchart
8.2.7 MOVETO-DOW
This routine is used to Iower the disc to the fieId for use in no& controUer
hit on the keyboard. the discs retum to their set seeding depth.
+ '
F KEY RESSW
w
1 C O N T R O RESUMES
~
1
NORMAL OPE RATIO^
Appendix B: Software Ftowchart
B.2.9 ERROR-CONVERT
Routine to convea the error Born 1000's of an inch to tenths in hexadecirnal-This
converts it to a form compatible with the fuzzy inference engine and for display on the
LCD.
Appendix B: Software Flowchan
B.2.10 ERROR-BUFFER
Routine to calculate the change in enor fkom the 10th previous sample.
w
CAUlLltATECHANGE M ERROR -
ClfRRENT ERROR COMPARED 'ID
'I
IO SAMPLES eREVIOUS
B.2.11 FUZYïEST
NZZYTEST produces the fuPy decision, based on the inputs, ERROR and
B.Z.12 HYD-CONT
Routine to scale the hiuy output decision and send it to the hydrauiic valve
solenoids.
8.2.13 DISPLAY-DEPTH
Routine to convert f3om 1000's of an inch to tens and inches, or centimetres and
B.2.14 S m - D A T A
Raw AM3 serwr nadings. error, change in emr and the output fiizzy sigal are
Appendix C: Controuer Source Code
This appendix contains the code usedin the Fuzzy Logic Seeding Depth Controuer
to sample bth sensors, determine the fiinv output and control the hydraulic valve
controllhg the seeder. The order in which they appear is (1) the make file for compiling.
(2) the fuay controiier code, (3) the table of equates for the register locations in the
MC68HC16, (4) the initialization routine for the reset vectors. and haUy (4) the
initialization routine for the intemipt vectors. Oaly one intempt is utilued in the
*O -
FELD2ASM Fit field operational version, "
*O Version 2 logs data, and does not iniualize tbe"
*O calibration values-the SRAM is battery-backed. The "
*O values alteady exist in RAM before this version is "
O
*O NU.
Appendix C: Conaoller Source Code
*
*O iacluding emr, change in enor, and fiiny control '
*O signai, once lhis fiinction is uncommented in MAIN.
*O O
LDAB #$O0
STAB ADCMCR *for stoP/fieezelsupeNisormodes-setto normal
*LDE #!KM83 *10-bit resoluaon
LDE #$O003 *%-bitresolution and 8 AiD clock penods (fastest)
STE A D C I Z O *NDcoatrol register O-set up for &bit conversion
*STE ADCTLI *EXP-1. CONTROL REGISTER I
*
*Set up GPT PWMA for 128 HZ
*
**********************************************************
LDE #$O008 *256 hz
STE PWMC *n$0018=128hz, #$0028--64 hz, #$0038=32 hz
LDAB #$O1
TBEK * point EK to bank O for i€AM access
LDAA a 0 9
S?AA CXRC-ERROR-BUFFER ;load $A into circdar cbg in error buffer
LDE #!§FFFF
STE m s
LDE #SIOFF %ex for 2.56 cmfinch, times 100
STE CM,COEN-FACTOR
CLRE
STE INPUTS
STE DEPïH-IOINCHES
STE OP,DISPLAYYON
STE SEEDDEPTEI-ERROR
STE PREVIOUS-ERROR
STE ERRORCHANGE
STE SIGN-FLAG
STE KEYCHECK
STE ADC-CHANNEL
LDE #ERROR,LABLE
XGEZ
Appendix C: Controller Source Code
LDE fi9999
STE HYDRAUL-TIMERI
LDE #$O004
STE HYDRAUt-TlhdER2
LDE
STE HALFEC-INlT
LDAB #!§ûF
TBEK * point EK to bank F for registeraccess
**********************************************************
* Initialize Calibration Factors
*
**********************************************************
* LDAB 4601
* TBEK point EK to bank O for RGM access
* LDE
* S E
* LDE
* STE
* STE
* LDE
* S E
* LDE
* STE
* LDE
* STE
* LDE
* STE
* CLRl
* STE CALIB DEPTH
* LDE #$1~00-
* STE EM'OTENEUSE,DISC
* STE HYPOTENEUSEJRONT
* LDE #$OODE
* STE FRONT-GROUNDUNDZERO
- -
* LDAB #%OF
* TBEK point EK to bank O for RAM access
*
*NTKALIZE THE LCD L C D - m configure font, cursor
*
**********************************************************
LCD-INIT LDAA #$38
STAA GPTPDR *CONFIGURE LCD AS &BIT D m LENGTH, 1 DISPLAY
*LINE, FONT 5 X 10 DOTS
JSR LCD-NST
LDAA 4601 *clear the display, pu& cursor at position O
STAA GPTPDR
JSR LCD-WST
LDAA #$OC *turns on display, cursor on and blinking
STAA GPTPDR
JSR LCD-INST
LDAA S80 *SETDDRAM ADDRESS
STAA GPTPDR
JSR LCD-INST
*Display initial LCD message
LDX MEETINGS *point to the appropriate ASCII string
JSR SEND-STRING *print string to Icd
Appendix C: Controiler Source Code
JSR ONESEC-DELAY
LDX UGREETINGS2 *point to the appropriate ASCII string
JSR SEND-STlUNG * p ~string
t to Icd
JSR ONESEC-DUY
LBRA MAIN
LCD-iNST
LDAA MO0 ~ ~ IN GPrPDR
*WRITE INSTRUCTIONSTO L C D - INST.
JSR LCD-DELAY *****EXPERIMENTAL-DUE
TO OC NOT WORKING ON DUT
LDAB #SM
STAB CSPDR *SETENABLE HIGH
JSR LCD-DELAY
STAA CSPDR *SET ENABLE LOW
RTS *GETO ü ï T A HERE
LCD-DELAY:
LDAB #$O1
TBEK
NOP
NOP
NOP
NOP
STE TEMP-DELAY2 *put previous data in here so you don? lose it
LDE #$OOFF
STE TEMP-DELAY
LCD DELAY-DEC:
-DECW --DELAY
BGT LCD-DELAY-DEC
LDE TEMP DELAY2
LDAB #$OF-
TBEK
RTS
CLEAR-DISPLAY: *resets display to prevent pmblems
LDAB #$OF
TBEK
LDAA #$O1 *caiiedjust before info is dsiplayed
STAA GPTPDR
JSR LCDJNST
LDAB 4601
TBEK
RTS
Appcndix C: Controller Source Code
* *
*KEY CHECKING ROUTINE: CHECK-KEYS read port F to see ifany keys hit *
* RETORN-DEBOUNCE program rems here fier debounce intemprs then *
* checks key fiinction e
* DEBOUNCE intempt 22 times thea recheck key for signal
* KEY-IRQ actions taken on each intempt-int disabled afier 22 times *
* READ-K.'Scheck key id. with READ-COLUMN,KEY-ID 1,KEYKEYID2, KEY-IDED, *
* HEXCONV (which retunis the key's id in KEY *
* *
CHECK-KEYS:
LDAB #$OF
TBEK
LDAA WbFO *Set al1 column lines low
STAA PORTFO
LDAB PORTEQ *Lod PO-
CBA *See if any keys are pressed-any high nibble bit is set
BNE DEBOüNCE *Sets up the GPT to intempt the CPU 6 times
*to allow for at least 20 ms for tbe key pressed
*to stop bouncing. On the 6th intemipt, the keypad
*is read to determine whicb. if any, key was actually
*pressed.
RTS
RETURNRETURNDEBOUNCE:
NOP *HAVING TROUBLE WfTH #SOL NOT GûING INTO acc B
NOP *WHEN RETURNING FROM INTERRUPT-SO ADDED NOPS
NOP
NOP
LDAB #O1
TBEK
TSTW KEYCHECK
BNE FINISHED KEYS *if you don? want to id the key yet, RTS
JSR HEXCONV-
LDAB a 0 1
TBEK
TSTW HEXKEYYrn
BEQ FINISHED-KNS
JSR CHECK-FUNCîïON
FINISHED-KEYS :
Appendix C: Conuoller Source Code
RTS
DEBOUNCE:
LDAB #$O1
TBEK * point EK to banEr O for RAM acccss
LDAA 6 1 6
STAA IRQICOUNT *Put the countdown amount for 22 IRQ's in standby ram
CLIU)
STD iR&DONE *initialite to prevent repeatkg IRQ in endiess loop
CLRW OP,DISPLAYYON
LDAB #$OF
TBEK
LDAA 6 7 3 *Enable the pulse accumulator counter to work, gated
STAA PACTL %de, so that it will count & intemupt cn demaod
CLRA
STAA PACNT *Set pulse açcwnulator counter to O
TPD * T d e r CCR to Acc. D
LDD #SûOAO *Set up D for clearing CCR and setting IRQ mask to 5
TDP *Tramfer D to CCR DDR is now ready to accept iat 5
*fiom the GPT timer overflow interrupt.
NOP *NOPS to add t h e for the 286 debugger to catch up
NOP
NOP
LDD HO086 *MCR DOESN'T EXST IN THE EQU-S TABLE!! ït's caiIed
*GPTMCR
STD GPïMCR *Store lRQ 6 for IMB to module configuration register
LDD #$4004 *Enable OC4 intempt in the QSM,and set timer
*rimer prescaler to 64-intempt every 64*$FF clocks
*equal to 0.98 ms-20ms delay, read on 22nd in^
STD TMSKI
LDD #$7660 *Set GPT intemipt pnority to OC4 (number 7),
STD ICR *intemipt level to IRQ 6, vector base address to 6
*6X, so 6* l6=% in decimal.
*so, IRQ vectot will be 67.
*The CPO decodes as 67*2 by
*lefi shifting the iRQ vector, using IRQ seMce routine
*label at location $134. Changed label BDM at '36"
*to KEYJRQ
BRA RE'ïüRN-DEBOUNCE *Now tbat the intempt is set,return
*and let the keyboard be read by the intempt routine
KEY-IRQ:
NOP
NOP
LDAB 4601
TBEK * point EK to bank O for RAM access
TSTW IRQ-DONE * set in HEXCONV
LBGT RETURN-DEBOUNCE * get out if keys akeady read afier RQ's
DEC IRQ-COUNT *Decrement the counter for each intempt request
LDAB #$OF
TBEK point EK to bank F for cegister access
LDD #$0000
STD TFLG1 *Clcar the GPT intcrrupt Bag so the CPU isn't
*internipteâ again immediately following Rn
LDAB #$O1
TBEK * point EK to bank O for RAM access
TST IRQ-COUNT *rtsetting
LBEQ READ-KEXS *Btaacb after 22 ints, to keyboard reading mutine.
LDAB #$OF +restoring of k registeroccurs afker br to READ-KEYS
TBEK
RTI
Appeodlx C: ControUer Source Code
READ-KEYS :
LDAB #$OF
TBEK
LDD na0000 *Disable OC4 intempt in the QSM, and Ieave timer
*prescaler at 64.
STD TMSKl *New, the intempt fiom the GPTis completely
*disabled-
LDD mOOOO *Set GPT uitemipt prbrity to OC4 (number 7).
STD ICR *intemiplevel to iRQ 6, vector base address to 6
LDAA MF0 *Set aii column lines low
STAA PORTFO
LDAB PORTFO *LoadPORTF
CBA *See if any keys are pressed-any bigh nibble bit is set
LBEQ NO-KEY-PRESSE.*leave if no indication of keypcess afta delay
LDAB S O L
TBEK
LDE #$FFFF
STE IRQIDûNE *set flag so program r e m to mutine pmperIy
STE KEYPRESSED *set KEYPRESSED Bag so other functions can use it
LDAB #$OF
TBEK
TPD Urransfer C a to Acc. D
LDD #$OOEO *Set up D for clearing CCR and setting IRQ mask to 7
TDP *Trader D to CCR DDR now wiU refuse int 6 & l e s
LDAA #$El
READ-COLUMN:
STAA PORTFO *Write to column 1
LDAB PORTFO
CBA *Sec if this column was pressed
BNE KEY-ID 1 *If this column was pressed, see which row it is
TDE
TPD
ORD
TDP
TED
RORA *ShB nght to check next colwnn (enters 1 on MS bit)
LBCC NO-KEY-PRESSED *Wkn carry is clear, leave mutine
LBRA READ-COLUMN *If it wasn't this column, go and check the next one
KEY-ID 1:
LDAA #$O 1
XGAB * TBEK onlv works with Acc B-so rcbange - BA
TBEK * point EK t6 badt O for RAMxccs
CLRW KEY * start key hex identity cegister at O
LDE #$O011
STE KEY-ERR-COUNTER * load $10 to count down each time a different
* key identity is tested-just in case the key
* byte in acc B doesa't match any in the
* table KEY-TABLE-this prevents an endless loop
KEY-ID2:
DECW KEY-ERR-COUNTER
LBEQ NO-KEYJRESSED
LDAB KEY+l
CLRW INDEX
STAB INDEX+l
LDE #KEY-TABLE
ADDE INDEX
STE INDEX
LDX iNDEX
Appendix C: ControUer Source Code
LDAB X
CBA
LBEQ KEYIS-iDED *if quai, btmch to HEXCOW and compare
NCW KEY *check to see ifit's the next nwnber higher
BNE KEY-ID2
KEYIS-IDED:
mAB HOF
TBEK
m
HEXCONV:
LDAB #$O1 %cc B is the number presseci-KEYis hex
TBEK
LDE #$O0
STE HlXEY-Hïi'
LDAB KEY+l
SUBB HOA *subuact A; if acc B is 9 or less, will be neg
LBGE HEICNUMHEICNUMCONV
*branch to HEXMTMHEXMTMC0NV below if A to F
LDAB KEY+l *at tbis point* so reload number and
ADDB #$30 * then add 4630 to make an ASCII
STAB KEYASCII code. Save to KEY for later use.
LDAB #%OF *reset to bank F so MPU wiU cal1 peripherals
TBEK *point EK to bank F for register access
RTS
HEXMiMHEXMiMCOMr: *convert numbers A to F to ASCII and implirnent
LDAB KEY+I * I d the number pressed to B
ADDB -0 *maice it an ASCII letter value
STAB KEYASCII *store it to KEY for later use
LDAA #$OA %ad acc A COsee if B is SOA
CBA *compare acc 0 to acc A (B-A=x)
LDE #$O001
STE HEXKEY-KiT
RTS
LDX #MODES
JSR SEM)-STRING
JSR TWOSEC-DELAY
JSR WNTFERKEY'PRESS
JSR HEXCOW
LDAB H O 1
TBEK
LDAB KEY+l *load key number
SUBB HO2 *subtract A; if acc B is I or less, will be neg
LBGE ERROR-PRESS *emr $2-F
CLRW ADC-CHANNEt Wear location of raiseci vaiue
LDAB EY+l *Io& key number
STAB ADC-CHANNEL
LDAB #WF
TBEK
RTS
CHECKFERKFERl,0R,2:
LDAB KEY+l
DECB
LBNE SET-UMTS
SET-RAISED-ms:
LDX #SEI-RAISE-MSG *point to Icd message for setting raised pos
-
D-wm
IR SAMPLE *sec what the height of the discs are
t**SUBTRACTACIUAL HEiGEîT FROM THE SET HEIGmAS LONG AS ITIS BELOW
*=T
[EE SET HEIGHT 1T WIU KEEP RAISING TEE IMPLIMENT
3AB #O1
BEK
3 A B RAISED+l *LOAD HEIGHT YOU WANT TO M S E TO
JBB DISC-READING+l *SUBTRACCTHE ACTUAL EIEIGHT
PL RAISED-Wm *BRANCESIF OVERnOW CLEAR-IE., STILL BIG NUMBER
*MIlWS SMALLER NLTMBER-V BiT SET WHEN HIGEER
*THAN THE RAISED SET POINT
M A #$7F *discs are up to the required height-stopdisc moment
>AB #OF
3EK
CAA PWMA *by Ioading neutral movement (7F) and store to PWMA
iR Wm-KEYPRESS
HEXCO~
3 A B 601
3EK
>AB -1
JBB #$OF
UE RAISED-wm
>AB #$OF
3EK
rs
SET,OPER,DEITH:
JSR CLEAR-DISPLAY
LDX #SR-OPER-MSG v i n t to Icd message for setting raised pos
JSR SEND-STRING *print it to the lcd çcreen
JSR TWOSEC-DELAY
JSR CLEGR-DISPLAY
LDX #HIT-KEY-MSG
JSR SEND-STmG
JSR WAITFER-KEYPRESS
JSR CLEAR-DISPCAY
LDX #ENTER-DEPTH
JSR SEND-STRING *pnnt it to the lcd screen
ISR TIKOSEC-DELAY
JSR W-R-KEYPRESS *first-inchesentry
JSR HEXCONV
LDAB #%O1
TBEK
LDAB KEY+1 *load key number
SUBB nâOA *subtract A; if acc B is 9 or Iess, will be neg
LBGE ERROR-PRESS *emr if A-F
LDAB 4601
TBEK
CLRW M I S E D L *clear location of r a i d value
LDAB KEY+l *load key nurnber
LDAA #$OA
MUL *inches times decimal 10
CLRW OPJZWUIIUGGDEPTEI
STAB OPEWWINGDEPTH+l
LDX #ENTER-IOTH-Dm
JSR SEND-STRiNG +print it to the lcd sacen
JSR TWOSEC-DELAY
JSR WAITFERKEY'PRFCS *second- tenth inch or mm entry
JSR HEXCONV
LDAB #Wl
Appendix C: Conmller Source Code
TBEK
LDAB ICEY+l *load key nurnber
SUBB #0A subaact A; if acc B is 9 or les, wül be neg
LBGE ERROR-PRESS *enor $A-F
LDAB KEY+1 *load icey numûer
ADDB OPERATINGDEPTH+I *add in or cm to tenths or mm
STAB O P ~ G G D E V I n +*store l as raiscd nurnber
LDE OPEMMNGGDWTH
LDD #$O64
EMUt
STD O P E R A T N G - D m *store as 1000's of an inch
LDAA UMTS *see if inches or cm
TSrn
BPL O P E R A T I N G - m C
JSR CLEAEt-DISPLAY
* LDX iN-CONVJACIOR2 *divide inches & tenths by total possible (60)
* LDAB RAISED2 *load actual in and tentbs
* IDN *remahder(in D-acc A is MSB of remainder)
* STAA OPERATING-DEPTH *store remainder (in D-acc A is MSB of remainder)
LDAB #$OF
TBEK
RTS
OPEMTINGGMETRIC:
NOP
NOP
NOP
NOP
Krs
FIELD-O-EWS-SET: *set the zero depth position in the field
JSR CLEAR-DISPLAY
LDX #FIELDO-SET-MSG *point to the appropriate ASCII smng
JSR SEND-STRING *print string to lcd
JSR TWOSEC-DELAY
JSR CLEAR-DISPLAY
LDX #HIT-KEY-MSG
JSR Sm-STRING
JSR WAITFERKEYPRESS
JSR ClEAR-DISPLAY
LDX #LOWER,GRND-LEVEL
JSR SEM)-STRING *print it to the lcd screen
JSR TWOSEC-DUY
JSR CLEAR-DISPLAY
LDX #HIT-'0-STORE
JSR SEM)-STRING
JSR W-R-KEYPRESS
JSR SAMPLE *sarnple the sensors again
LDAB #$O1 *set page-SAMPE leaves it as $OF
TBEK
LDE DISC-READING
JSR ANGLELECORRECïiON*correct for angle of sensor to linkage
*input to aigorithm is in acc E, with answer put in E
STE CORRECTEDCIW)FlELD,2ER0
LDE FRONT-READING
JSR ANGLE-CORRECTION *correct for angle of sensor to linkage
*input to aigorithm is in acc E, with answer put in E
STE FRONT-GROUND,ZERO
LDAB #!Hl1
TBEK
RTS
Appendix C: Controlier Source Code
-C-1s -
Appadix C: Controllet Source Code
JSR TWOSEC-DELA..
JSR CLEAR-DISPUY
LDX #SETETTOT09û-MSG2
JSR SEND-STRING *@nt it to the lcd screen
JSR TWOSEC-DELAY
JSR CLEARCLEARDISPtGY
LDX #SETETTOT090,MSG3
ISR SEND-STRING *@nt it to the lcd screen
JSR TWOSEC-DELAY
JSR CLEAR-DISPLAY
LDX 4tHI.T'-TOTOSTORE
JSR SEND-STRING
JSR WAITFER,KEYPRESS
JSR SAMPLE
LDAB Mi01
TBEK
LDE DISC-READING
STE DISC-MNETY-DEG-POS
LDE FRONT-READING
STE FRONT-90-READING
RTS
CHECKFER,l~OR,2~FORCHECKFER,i,oR,2,FoR,CAtrie:CALtB:
ïDAB KEY+1
DECB
LBNE CALIB-FRONT-SENSOR
CU-BACK-SENSOR:
fSR CLEAR-DISPUY
LDX #LEYEïO-SET,MSG *point to the appmpriate ASCII string
JSR Sm-STRING *print string to lcd
ISR TWOSEC-DELAY
SSR CLEARLEARDISPLAY
LDX #LEVELtFvEf.SURFURFCALIB
JSR SEND-STRING
JSR TWOSEC-DELAY
JSR CLEARLEARDISPLAY
LDX #KiT-KEY-MSG
JSR S m - S m G
$SR WAITFER-KEYPRESS
JSR CLEAR-DISPUY
LDX #DISC-tr;Vm,tr;vm,ZERO,MSG
JSR SEPIJD-STRING *print it to the lcd screen
ISR TWOSEC-DELAY
JSR CLEAR-DISPLAY
LDX #HIT-TO-STORE
JSR SEPID-STRING
JSR TWOSEC-DELAY
JSR W-KEYPRESS
$SR SAMPLE
LDAB #$O1
TBEK
LDE DISC-READING *use disk readinn onlv for this
JSR SEND-STRING
JSR TWOSEC-DELAY
JSR UEAR-DISPUY
LDX #HIT"KEYMSG
JSR SEND-STRING
JSR TIKOSEC-DELAY
JSR W m - m
JSR UEAR-DISPLAY
LDX #HIT-TOTOSTORE
JSR SEND-STRING
JSR W O S E C - D U Y
JSR WAITFER-KEYPRESS
JSR SAMPLE
CLRD
LDAB #$O1
TBEK
LDE DISC-READING
SUBE DISC~MNETY-DEG-POS
BPL LOAD-DISC-SINE
NEGE
LOAD,DISC,Sm
XGEX
LDY #SINE-T'LE *now we have the sine of the sensor angle at 6"
XGEY
CLRA
CLRW C A L I B - D m
LDAB E X *sine of sensor position at 6"
STAB CALIB-DEPTH+L EX^^'-CHANGE THIS VARIABLE NAME
LDE DISC-LEVEL-ZERO
SüBE DISC-NINETY-DEG-POS *now, get the sine of the angle between ground and 90 deg pos
TSTE
BMI NEGATIVEATIVECALIB
XGEX
LDY #SINEINETABLE *now we bave the sine of the sewor angle at 6
XGEY
CLRA
LDAB E X *sine of sensor position at 6'
CLRW TRUE-O-DEPTH
STAB T R U E - O - D m
LDD C A L I B - D m
SUBD TRUEUEOODEPTH *subuact the sine of the difference between
*DISCJEVELLnrELZERO and DISCONINETYNiNETYDEG,POS from the difference
*between the 6" point and DISC-NINETY-DEG-PûS
FINISH-CALIB :
XGDX
CLRE
LDD #SI770 *asis 6000 thousandths of an inch in hex
EDIV *divide the sine into the length of the opposite
*side-this gives the hypoteaeuse in thousandths of an inch
XGDX fmultiply by 256-you had DIVIDED by a whole number
ASLD *(muitipiied by sine 256)
ASLD *(ah-179 for vertical bar!)
ASLD * \
ASLD * 6'depth is \ hypotencuse
ASLD * equal to the \
ASLD * opposite side-> \
ASLD * ( \ <-sine of this angle
XGDE
STE HYPOTENmJSE-DISC *sine of angie * opposite = HYPOTENEUSE,DISC
LDAB #$OF *INTHOUSANDSTHOF AN INCH
TBEK
Appendix C: Controller Source Code
NEGATïVE-CALIB :
NEGE
XGEX
*now we have the sine of the sensor angle at 6"
LDY #SINEINETABLE
XGEY
CLRA
LDAB EX *sine of sensor position at 6"
ADDD CALIB-DEPTH *subtract the sine of the merence betwecn
DISCJEVEL-ZERO and DISCLFvET_NiNETY'DEGJûS h m the difference
*between the 6" point and DISC-NlNETY-DEG-POS
BRA FINISH-WIB
CALIB-FRONT-SENSOR.
JSR CLEAR-DISPLAY
LDX nLEVEtF-SET,MSG *point to the appropripriate
ASCIf smog
JSR SEM)-STIUNG *print string to lcd
JSR TWOSEC-DELAY
JSR CtEAR-DISPLAY
LDX RLEVEL-SURFURFCALfB
JSR SEND-STRING
JSR IWOSEC-DELAY
JSR CLEARCLcEARDISPLAY
LDX #HIT-KEY-MSG
JSR SEM)-STRING
JSR W m - K E Y P R E S S
JSR CLEAR-DISPLAY
LDX #DISCLEvmZERO-MSG
JSR SEND-STRING ?rint it to the Icd screen
JSR TWOSEC-DELAY
JSR CLEAR-DISPLAY
LDX RIiIcr-TO-STORE
JSR SEM)-STRING
JSR TWOSEC-DELAY
JSR W m - K E Y P R E S S
JSR SAMPLE
LDAB #$O1
TBEK
LDE FRONT-READING *use disk reading oaly for this
STE FRONT-LEW3.-ZERO
****now, calibrate for 6"deep8***
JSR CLEAR-DISPLAY
LDX #SIX-IN-CALIBO
JSR SEMI-STRING
JSR TWOSEC-DELAY
ISR CLEAR-DISPLAY
LDX #SiXTXiNINCALIB 1
ISR SEND-STRING
JSR TWOSEC-DELAY
JSR CLEAR-DSPLAY
LDX Rrn-KEYMSG
JSR SENDSEND,STRINGSTRING
JSR TWOSEC-DEtAY
JSR w--KEYPRESS
JSR CLEAFt-DISPLAY
LDX #m-TOdsTORE
JSR SEMI-STRING
JSR TWOSEC,DJ?LAY
JSR w--KEYPRESS
$SR SAMPLE
Appendix C: Controller Source Code
CLRD
LDAB 6 û L
TBEK
LDE FRONT,-READING
SUBE FRONT'-READING
BPL LOAD-FRONT-SINE
NEGE
LOADLOAD,FRONT,SINE:FRONTM:sINE:
XGEX
LDY #SINECTABLE *now we have the sine o f the sensor angle at 6"
XGN
CLRA
CLRW CALIS-DEPTH
LDAB EX *sine of sensor position at 6"
STAB CALIB-DEPTH+l
LDE FRONT---ZERO
SUBE FRONT-9û-READING *now, get the sine of the angle between ground and 90 deg pos
TSTE
LBMI NEGAïnE-CALJB
XGEX
LDY #SINEINETABLE*now we have the sine o f the sensor angle at 6"
XGEY
CLRA
LDAB E s *sine of sensor position at 6"
CLRW TRWEUEOODEPTH
STAB TRUEUEOODEP'ï'H
LDD Cm-DEPCH
SUBD TRUEEOODEPXX*subtract the sine of the difference between
*FRONT,LEVEL-ZERO and FRONT-MNETY-DEG-POS fiom the difference
*between the 6" point and FRONT-NINETY-DEG-WS
FINISH-CALIBB:
XGDX
CLRE
LDD #SI770 *this is 6000 thousandths of an inch in hex
EDIV *divide the sine into the Iength of the opposite
*side-this @es the HYPOTENEUSE in thousandths of an inch
XGDX *multiply by 256-you had DMDED by a whole number
ASLD *(multiplied by sine * 256)
ASLD *(ait- 179 for vertical bar!)
ASLD * \ *
ASLD 6" depth is \ hypoteneuse
ASLD *equal to the \
ASLD opposite side-> \
ASLD ( \ <-sine of thïs aogle
XGDE
STE HYPOTENEUSEJRONT *sine of angle opposite = hypoteneuse
LDAB n%oF *IN THOUSANDSTH OF AN INCH
TBEK
ms
NEGAïMZJXLIBB:
NEGE
XGEX
LDY #SINEINETABLE*now we have the sine of the sensor angle at 6"
XGEY
CLRA
LDAB EX *sine of sensor position at 6"
ADDD CALIB-DEPTH * s u b a t the sine of the ciifference between
*DISC---ZERO and DISC-NINETY-DEG-PûS h m the Merence
*between the 6" point and DISC~NINETY-DEGJOS
BRA FtMSH-CALIBB
Appendix C: ControllerSource Code
MOVETOODOWN--
JSR CLEAR-DISPLAY
LDX nL0WER-MESSAGE *point to the appropriate ASCII string
JSR SEND-STRING *pcint string to lui
JSR TWOSEC-DELAY
LDAB S O I
TBEK
LDE UOPERATING-DEPTH
sTË OUTPUT *&nd the value to the hydraulic conîrol mutine
LDE UHM)RAULULTIMERl*loiid the nmber to count down
STE c0UNTDOWN1
LDE HYDRALJL-TIMERL *load the number of times the number will be
STE COONTDOWN2 * counted dowu
JSR HYD-CONT *niove the hydraulics
LDAB #$OF
TBEK
RTS
********************************************************************
* *
* KEYPRESS AND DELAY UTIUTY ROUTINES: W m - K E Y P R E S S loop for waiting for
* a key to be pressed for calibrationand setting routines *
* ERROR-PRESS kicks in when the m n g key is pressecl *
* HAtFSEC-COWNT a timing loop for putting messages on the LCD screen *
* ONESEC-DELAY and TWOSEC-DELAY cails HALFSEC-COUNT several rimes. *
* NOKEYPRESSED clears key jpressed flag if noue pressed.
* *
*
*********************************************************************
WAITFERAITFERKEYPRESS:
LDAB #$O1
TBEK
LDE #$O001
STE KEYCHECK *set Bag-no key id, only check for press
LDAB #$OF
TBEK
JSR CHECK-KEYS
LDAB #$O1
TBEK
T S W KEYPRESSED *see if a key had been pressed
LBEQ W-R-EYETtESS
LDE # S m
STE KEYPRESSED
LDE #$O000
STE KEYCHECK
RTS
ERROR-PRESS:
JSR CLJ5A.R-DISPLAY
LDX IERR-PRESS-MSGO
JSR SEND-STRING *print string to lcd
JSR TWOSEC-DELAY
JSR CLEGR,DISPLAY
LDX #ERR-PRESS-MSGL *enor if A-F
JSR SEN'-STRING*print stnng to lcd
JSR TWOSEC-DELAY
LDAB #$O1
TBEK
RTS
Appcadix C: Coatroller Source Code
LDAB MOI
TBEK
MOVW HALFSEC-INlT.COUNTDOWN2
HALFSEC,LOOP
LDAB m1
TBEK
DECW COUNTDOWN2 *decrement the main countdown
LDAB #$OF
TBEK
LDAB a 0 1
TBEK
TSTW COUNTDOWN2 *when done dcount, test "largev*main count
BNE HALFSEC-LûûP *bop back until done
LDAB #$OF
TBEK
RTS *say, "Bye Bye" "(mailwave)
ONESEC-DELAY:
JSR HALFSEC-COUNT
JSR HALFSEC-COUNT
RTS
TWOSEC-DELAY:
JSR HALFSEC-COUNT
JSR HALFSEC-COUNT
*JSR HAtFSEC,COWNî *cou( out these since it TAKES SO LONG!!!
*BR HALFSEC-COUNT
RTS
NOKEYPRESSED:
LDD #!$O000
TBEK
STD KEYPRESSED *clex kerpressed flag, since noue hit
LDAB #$OF
TBEK
RTS *return-this should be oniy RTS besides one in CHECK-KEYS
SAMPLE:
LDAB
TBEK
LDE Mo0
STE ADCMCR *for stop/fieeze/supe~sormodes-set to normal
LDE Mo003
STE ADCTU) *8-bit, 8 ADC clock cycles
LDE #Sm0*&bit rcsolution (mode 2) (mode2:4 inputs-0020)
*this does conversions on 4 inputs, starting wiih
*the one specified in bits CA-CD. So, ADû in RlURRO,
*and AD1 supposai to be in FüüRRl.
STE ADCTL 1 *Set port F data registers. niis starts conversion.
NOP *süght dclay to allow conversion to complete
Appendix C: Connoller Source Code
XGEY
CLRA
LDA0 EX
LDE HYPOTENEUSEJXSC *multiply by the hypoteneuse
EMUL
TEDM
ASRM *divide by 256, since sine is a 6action
ASRM
ASRM
ASRM
ASRM
ASRM
ASRM
ASLM *now, shift AM left 16 places for transfemng to E
ASLM *The TME.=Tand TMER commands only uansfet the
ASLM *upper 16 bits of AM to E,so tfre answer has to be
ASLM *thece.
ASLM
ASLM
AStM
ASLM
ASLM
AStM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
T'MET
TSW
BEQ
CLRW
RTS
BELOW-GRNDRM)ADJUST:
NEGE - -
*2's comp E (0000 E,not FFFF E as in COME)
îLRW SIGN-FLAG
RTS *later.
POS-ANGLE:
LDD #!§FFFF
STD SIGN-FLAG
BRA RESUME-ANGLELECORRECTION
ANGLE,CORRECïiONOFROm ****SETUP FOR THE FRONT-READING FOR MORE
ACCuRACY***
*the origionai ADC d n g s remain in DISC-READING and
*FRONT-READING. The comted readings are for displayhg
*on the LCD and for the fiiay mutine, to enswc corrections
*are made based on the depth, not just the sensor position
*(as are the routines for calibration).
CLRW SIGN-FLAG
SUBE FRONT-90-READING *subtract zen, position fimm reading
TSTE ce if answer was negative
BPL POS-ANGLE1 *branch bere if answer is positive
NEGE '2's complement E
~UMEUMEANGLE,CO~ONNFRONT:
XGEX
LDY #SINEINETABLE*now we have the sine of the sensor mgïe at 6"
XGEY
CLRA
Appendix C: ControUer Source Code
LDAB EX
LDE KYPOTENEUSETENEUFRONT
%nultiplyby the hypotcneuse
EMUL
TEDM
ASRM *divide by 256,since sine is a fraction
ASRM
ASRM
ASRM
ASRM
ASRM
ASRM
ASLM *now, shift AM lefi 16 places for traosfemng to E
ASLM Q e TMET and TMER commands only transfer the
ASLM *upper 16 bits of A M to E, so the a m e r has to be
ASLM *there.
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
ASLM
TMET
TSTW
BEQ
CLRW
RTS
B EL0W-GW-ADJUST 1:
NEGE *2's comp E (0000 - E, not FFFF - E as in COME)
CLRW SIGN-FLAG
RTS *later.
POS-ANGLE 1:
LDD 6FFFF
STD SIGN-FLAG
BRA RESm-GNGLE-CORREmON-FRONT
ABOVE-GROUND:
NEGE
STE SEED-DEITH-ERROR *save this negative number
LDD #$FFFF
STD SIGN-FLAG *set the sign flag to indicate a negative number
RTS ***(ABOVE GROUND)
DISPLAY-DEPTH:
***convert to decimal output***
LDAB 4601
Appendix C: Controllet Source Code
TBEK
LDD SEED-DEPTH-ERROR *l& D with divisor
TSTW UNITS *determine whetber i n c h or centimetres
LBEQ CENTIMETRES
DECIMAL-CONVO: *convert the MSB to decimal
LDX #$000A
IDIV
STD DEPTH-1000TH *reminder fiom moduio division is 1/1ûûû
XGDX
LDX nâmA
IDIV
STD DEPTH-l(NYïH *remahder h m modulo division is 11100
XGDX
LDX #sOOOA
DIV
STD DEPTH-1OTH *temainder h m rnodulo division is 1/10
XGDX
LDX W%mA
IDIV
STD DEPTH-INCHES *says inches, but shouId read "integers"
XGDX
LDX ~OOoA
IDIV
STD * 10's position integer
DEPTHPTHIOiNCHES
ISR DECIMALCIMALCONVl
LBRA WRlTE-DEPTH
DECIMAL-CONV 1: *convert the second digit of the hex frac to decimai
LDE DEPTH lOOOTH
SUBE n%0005-
B PL ADD-TO-DEPTHIOOTH
LDE DEPTH-100TH
SUBE #$O5
BPL ADD-TO-DEPTHlOTH
RTS
ADD,TO_DEPTHlOOTH:
mcw D m - 1 0 0 T H
LDE DEPTH 1-
SUBE 60005-
BPL ADD-TO-DEPTH1ûTH
RTS
ADD-TO-DEPTHlOTH:
INCW D m - L O T H
LDE Dm-IûTH
SUBE WâOOOA
BPL ADD-TO-INCHES
RTS
ADDADD,TO,INCHES:TOOINcHES:
am
STE DEPTH-1OTH
INCW D m - I N C H E S
LDE DEPTH-INCHES
SUBE 6ûûûA
BPL ADD-TO-1OUNITS
RTS
Appendix C: ControllerSource Code
JSR LCDJNST
LDAA H2E *write a periodto the scrcen
LDAB GPTE'DR
CBA
BEQ CHECK-TENTfL
STAA GPrPDR
JSR LCD-DATA
CHECKCHECK,TENTH:TENTH:
LDAA #$C2 *Location for the 10th lcd display position
STAA GPrPDR
JSR LCDJNST
LDAB #sol
TBEK
LDAA DEPTHEPTHIOïH+l *write 1/10 inches to LCD
ADDA 6 3 0 *convert to ascii
LDAB #$OF
TBEK
LDAB GPTPDR
CBA
BEQ CHECLSIGN
STAA GPTPDR
JSR LCD-DATA
CHECK-SIGN:
LDAB 6 0 1
TBEK
*determine whether the numbers are negative or positive
LDAB SIGN-FL,AG+l *check sign flag for negative
TSTB
BEQ BELOW-GRND fif positive (not afmve ground) branch here
TSlW DEETH-IOINCHES
LBNE S E V E N T H E V E N T H P L U S ~ P O S ~ ~
LDAA #$87 *Location for the 7th Icd display position
LDAB USOF
TBEK
STAA GPTPDR
JSR LCD-INST
LDAA #SB *load a plus sign
LDAB GPTPDR
CBA
BEQ PLUS,IS_THERE
STAA GPTPDR
JSR LCD DATA *put it on the screen
PLUS-IS-THEIRE:
LDAB #SOL
TBEK
TSW DEPTHEPTHIOINCHES
LBEQ SEVENTH-PLUS-PûS-CLR
CLRW SIGN-FLAG
RTS *go back to the M A N submutine
SEVENTHVENTHPLUS,POSpWRITE:
LDAA #$86 *Location for the 7th lai display position
LDAB #$OF
TBEK
STAA GVrPDR
JSR LCDJNST
LDAA # S a *loiad a ~ l u sim
s"
LDAB GPTPDR
CBA
BEQ PLUS-1s-THERE2
STAA GPTPDR
Appendu C: Controller Source Code
* *
*ERROR CONVERSION ROUTWE convert SEEDDEPTH-ERROR (in 1000's of an iach for LCD *
* to a fom compatible with the fuzsr routine (8 bit format). *
* display)
OPERATING-DEPTH (in 1000's inch) is also converteci by the sarne factor.*
* niese are thea added or subtracted to rcfiect the error h m the operating*
* deph
* Convert so $OA = 1 inch in difference. This can *
cbanged (ie, to
* $14 = 1 in) in order to provide scaling down for thebe32 gallon pcr *
* minute hydraulic valve spool. Tbis requitts dividing ihe error in
* 1000's of an inch into e m r in l/lM inch or so- This is thtn added*
* or subtracted fiom the O error value to provide the appropriate FRONT.*
* The answer is put into INPUTS and the RAISE-DEFïH-FLAG is set or cleared*
* to reflect whether the discs have to be taised or lowered (this is for *
* the correction factor for the PWMA signal to reflcct the transfer *
* function of the hydraulic valve.
*
*
******************************************************************************
ERROR-CONVERT: *change e m r in 1000's inch to IO'S ia hex-
LDAB #!§O 1 *add or subtract h m 3F (O e m r position) to
Appendix Cr Controller Source Code
-C-30-
Appendix C: Conttoller Source Code
ORG l
lMFPTR
FDB h
FDB n
FDB h
FDB h
FDB h
FDB h
FDB 11
FDB b
FDB h
Appenâii C: Coanoller S o m Code
rnB MF10
FDB MF11
FDB MF12
FDB MF13
FDB MF14
FDB MF15
MF1
FCB $02
FCB $OF
FCB $00
FCB $00
FCB $FF
FCB S2F
FCB 57c
FCB $FF
FCB $50
FCB $00
FCB $00
FCB $FA
FCB $00
FCB $00
FCB $Fi?
MF2
FCB $04
FCB $IF
FCB $00
FCB $00
FCB $00
FCB $2F
FCB $45
FCB $00
FCB $6A
FCB $BI
FCB $Fi?
FCB $81
FCB $00
F a 3 $00
FCB $FA
FCB $00
FCB $00
FCB $FF
MF3
FCB $04
FCB $1F
FCB $00
FCB $00
FCB $00
FCB $41
FCB 542
FCB $00
FCB $7F
FCB $44
FCB $FF
FCB SBB
FCB $00
FCB $00
FCB SFA
FCB $00
FCB $00
FCB $FF
MF4
Appendix C: Controiier Source Code
FCB $04
FCB $IF
FCB $00
FCB $00
FCB $00
FCB S7E
FCB SA1
FCB $55
FCB SFF
FCB $Dl
FCB $00
FCB $00
FCB $FA
FCB $00
FCB $00
FCB EFF
MF5
FCB $08
FCB $17
FCB $00
FCB $00
FCB S00
FCB $AF
FCB $SD
FCB $00
FCB $DB
FCB $00
FCB $FF
FCB $F9
FCB $FF
FCB $FF
FCB $FA
FCB $ 0
FCB $00
FCB $FF
MF6
FCB $02
FCB $OF
FCB $00
FCB $00
FCB $FF
FCB 51A
FCB SB1
FCB SFF
FCB $31
FCB $ûû
FCB 600
FCB $80
FCB $00
FCB $00
FCB fFF
MF7
FCB $04
FCB $IF
FCB $00
FCB $00
FCB $00
FCB SlA
FCB $CC
Appendix C: Contrder Source Code
FCB $00
FCB S2E
FCB Sm
FCB $FF
FCB S3F
FCB $00
F a $00
F a $80
F a $00
FCB $00
FCE $FF
MF8
FCB $04
FCB $ID
FCB $00
FCB $00
FCB $00
FCB S2E
FCB $11
FCB $00
FCB $3D
FCB $89
FCB SFF
F a $53
FCB $00
FCB $00
FCB $80
FCB $00
FCB $00
FCB $FF
MF9
FCB $04
FCB $IF
FCB $00
FCB $00
FCB $00
FCB $3F
FCB $CC
FCB $00
FCB $53
FCE $D7
FCE $FF
FCB $66
FCB %O0
FCB $00
FCB $80
FCB $00
FCB $00
FCB SFF
MF10
FCB $00
FCB $OF
FCB $00
FCB $00
FCB $00
F a $51
FCI3 SC2
FCB $00
FCB $66
FCB $00
FCB $FF
Appendix C: Conuoller Source Code
FCB $80
FCB Soo
FCB $FF
FCB SFF
MF1 1
FCB Soo
FCB Sot
FCB $38
FCB $00
FCB SFF
FCB $FF
MF12
FCB $00
FCB $01
FCB Sm
FCB $00
FCB SFF
FCB $FF
MF13
FCB $00
FCB $01
FCB $7F
FCB $00
FCB $FF
FCB $FF
MF14
FCB $00
FCB $01
FCB %Al
FCB $00
FCB %FF
FCB $FF
MF15
FCB $00
FCB $01
FCB SC3
FCB $00
FCB $Fi?
FCB $FF
EVEN
FUZZYTEST:
JSR INlT
LDAA ïNPüTS+$ûû
STAA iN-BUF
LDAB #$O1
JSR MF,SUB
STAA TVLST+$OO
LDAB #$O2
JSR MF,SUB
STAA TVLST+$Ol
LDAB MO3
JSR MF,SUB
STAA TVLST+$02
LDAB #$W
JSR MF-SUB
S'CAA TVLST+$03
LDAB n$05
JSR MF,SUB
S m TVLST+$OQ
LDAA ERROR CHANGE *Lod emr change
S T U IN-BUF-
Appendix C: ControUer Source Code
LDAB n$06
JSR MF-SUB
STAA TVLST+SOS
LDAB -7
JSR MF-SUB
STAA TVLST+â06
LDAB 6 0 8
JSR MF-SUB
STAA TVtST+$07
LDABm9
JSR MF,SUB
STAA TVLST+$OS
LDAB W A
JSR MF-SUB
STAA TVLST+$û9
LDAA TVLST+$04
STAA AND-REG
LDAA TVLST+$O!3
JSR MINI-OP
LDAA ANDANDREG
STAA OR-RJ2G
LDAA TVLST+$04
STAA AND-REG
LDAA TVtST+$OS
JSR MiNl-OP
JSR MAXZ-OP
LDAA TVLST+$W
STAA ANDANDREG
LDAA TVLST+$07
JSR MINI-OP
JSR MAX2-0P
LDAA TVLST+W3
STAA ANDANDREG
LDAA TVLST+$û9
JSR MIN1,OP
JSR MAX2-OP
LDAA TVLST+$û2
STAA AND-REG
LDAA TVLST+$O9
JSR MIN1,OP
JSR MAX2-OP
LDAB #$3B
JSR DF2-C
LDAA TVLST+$04
STAA ANDANDREG
LDAA TVLST+âOo
JSR MIN1,OP
LDAA AM)-REG
STAA OR-REG
LDAA TVLST+â03
STAA AND-REG
LDAA 'iVLST+$OS
JSR MIN1,OP
JSR MAX2-OP
LDAA TVLST+$03
STAA AND-REG
LDAA TVLST+$û7
JSR MIN1,OP
JSR MAX2-OP
LDAA TVLST+$02
STAA AND-REG
Appendix C: Controuer Source Code
LDAA TVLST+WS
JSR MINI-OP
JSR MAXî-OP
LDAB #Sm
JSR DF2-C
LDAA TVLST+W
STAA AND-REG
LDAA WLST+WS
JSR MINI-OP
LDAA ANDANDREG
SïXAORJEG
LDAA TVCST+$û3
STAA AND-REG
LDAA TvLST+W
JSR MINI-OP
JSR NAX2-0P
LDAA TVLST+$03
STAA AND-REG
LDAA TVLST+$OS
JSR MIN1,OP
JSR MAX2-OP
LDAA TM,ST+$OZ
STAA AM)-REG
LDAA TVLST+$07
JSR MIN1,OP
JSR MAX2-OP
LDAA TVLST+%O1
STAA AND-REG
LDAA TVLST+$OS
JSR MINI-OP
JSR MAX2-OP
LDAA TVLST+$O
STAA AND-REG
LDAA TVLST+$OS
JSR MIN1,OP
JSR MAX2-OP
LDAB #$7l?
JSR DE-C
LDAA *ST+$O~
STAA AND-REG
LDAA TVLST+$Oo
JSR MINI-OP
LDAA AND-REG
STAA OR-REG
LDAA ïVLST+$ûl
STAA ANDANDREG
LDAA TVLST+$û8
JSR MINI-OP
JSR NAX2-0P
LDAA TVLST+$ûl
STAA AND-REG
LDAA TVLST+â07
JSR MINI-OP
JSR MAX2-OP
LDAA TVtST+$ûl
STAA AND-REG
LDAA TVtST+$û6
JSR MIPII-OP
JSR MAXî-OP
LDAA TVLST+W
STAA AM,-REG
Appendix C: Conmller Source Code
LDAA TVLST+âOS
JSR MIN1,OP
JSR MAXZ-OP
LDAB #$A1
JSR DFZ,C
WAA W T + â 0 2
S W AND-REG
LDAA TVIiST+âOS
JSR MINI-OP
LDAA AM)-REG
STAA OR-REG
LDAA TVLST+âO1
S U ANDJZEG
LDAA TVLST+âoS
JSR MIN1,OP
JSR MAX2-OP
LDAA TVLST+$OO
STAA AND-REG
LDAA TVLST+$O7
JSR MINl-OP
JSR MAX2-OP
LDAA TVLST+$OO
STAA ANDANDREG
LDAA TVLST+$06
JSR MIN1,OP
JSR MAX2,OP
LDAA TVLST+$OO
STAA AND-REG
LDAA TVLST+$OS
JSR MIN1,OP
ISR MAX2-OP
LDAB #$C3
JSR Dm-C
JSR DIV-SUB
LDX #$O0
LDAA OUTUTREG *load A
CLRW HYD-SIGNAL *clex E to ensure MSB is clear
STAA HYD,SIGNAL+l *store hydraulic sigoal value to LSB (=no change)
RTS
MIN1,OP CMPA AND-REG
BCC MINI-E
STGA AND-REG
MINI-E RTS
MAXî-OP LDAA AND-REG
CMPA OR-MG
BCS MAX2-E
S W OR REG
MAXZ-E RTS-
D u LDAAOR-REG
MUL
TAB
CLRA
ADDD TUH-EUX
S m TUH-REG
CLRA
LDAB OR-REG
ADDD SUH-REG
STD Sm-REG
RTS
DN-SUB LDD TUH REG
LDX sUH-REG-
Appcndix C: Controller Source Code
BCS DIV-1
XGDX
S'ïAA OUT'REG
RTS
DIv-1 CLROUT-REG
ms
INiT CLRTUL-REG
CLR TUH-REG
CLR SUL-REG
CLR Sm-REG
RTS
MF,SUE ASLB
SUBB #$2
CLRA
ADDD #MF-OFF
XGDX
LDX $OX
LDAA $ 0 3
STAA MF1,REG
LNX
LDAA $ 0 3
STAA MF2-REG
LSL MFt-REG
LSL MF2-REG
LNX
MFJ XGDX
GDDD 6 3
XGDX
LDAA $OX
LSR MF1,REG
LSR ME;2-REG
CMPA IN-BUF
BLO MFJ
LSR MF1,REG
BCS MF-2
JSR MF32
ADDB MFI-REG
BCC MF-4
LDAB #$FF
M E 4 TBA
RTS
M F 3 2 DEX
LDAA $OX
STAA MFl-REG
LSR MF2-REG
BCC MF-3
ISR MF,S 1
LSRD
LSRD
LSRD
LSRD
TSTA
BEQ MF-7
LDAB # S E
MF-7 RTS
MF-3 JSR MF,S I
TSTA
BEQ MF-5
LDAB #$FF
MF-5 RI'S
Appendix C: Controlkr Source Code
-1 DEX
LDAA m x
S U MF2-REG
LDAA IN-BUF
DEX
SUBA S O X
LDAB MF2-REG
MUL
RTS
MF-2 JSRMF-SZ
STAB MF2-REG
LDAA MFI-REG
SUBA MF2-REG
BCC MF-6
LDAA 460
MF-6 RTS
******************************************************************************
* *
* SEND OUT SIGNAL TO HYDRAULIC CONTROL signals are adjusted to compensate *
* for the nansfer fiinction of the hydraulic valve
* *
******************************************************************************
HYD-CONT:
LDAB #$O1
TBEK ****FIRST--inven the hyd signal to reflect valve action
* s u s lifting at $77-max at $68
* s u s lowering at S8F-max at S9B
LDAA HM)-SIGNAL+l *Io& output h m fuzzy engine
LDAB #$7F * b d midpoint between O and FE
SBA *get the dïerence h m tbe "mitidle"
BMI NEG-RESULT *beginning of control gain scaling-if negative, skip
****scaling for positive result of HYD-SIGNAL less than 7F
LSRA *scaling factor-divide by 2
NEGA *invert this difference
ABA *add it, to give equai magnitude in opposite direction
BRA SCALING-DONE *branch here when done the scaling
NEG-RESULT: *scaling for negative result of )IYD-SIGNAL less than 7F
NEGA *invert ihis difference
LSRA *scaling factor-divide by 2
ABA *add it, to give equal magnitude in opposite direction
SCALING-DONE:
STAA HYD,SIGNAL+l
T S W RAISE,DEPTHEPTHFLAG *if set, discs must be lowered
BMI SUBTRACT-2 *IF FLAG N E G N ï ï E (discs mut be lowered) BRANCH
****(disis need to be raised-below set point)****
LDE HYD-SIGNAL
SUBE #$OOOC *subnact 9 to b ~ O signalg h m 7F to 77
LDAB #$OF *since hyd valve won't move at less than 89
TBEK
TED
STAB PWMA
RTS
****(disks necd to be lowered-above set point)****
SUBTRACT,2:
LDE EiYD-SIGNAL
ADDE #S000D *add C to bring O signal from 7F to 8D
LDAB #$OF *since hyd valve won't move at more tbat 71
Appendix C: ControUer Source Code
TBEK
TED
STAB PWMA
rn
SEND-Dm:
LDAB 6 0 1
TBEK
LDX #DATA -END ;point to the beginning of data to send
LDE #$OOOA- ;load data uansmit index for 10data points
STE DAIA-INDEX ;Save locaaon index
CLRE
STE DMX-TOTOSEND ;put in temp array
STE DATAATOOSEND+2;cIearword
LDD INPUTS ;Io& error h m seeding set point
STAA DFiIAFiIATOTOSEMh1 ;put &bit data in proper order
LDD ERROR-CHANGE ;get change in e m r h m 10 readings previous
STAA DMX-TOTOSEND+3;put &bit data in proper order
LDE KYD-SIGNAL ;get fiuq decision output
STE DAïA TO,SEM)+4 ;put in temp amy
LDAB WSOF-
TBEK
LDE EUURRl ;get fiont sensor 8-bit a/d vdue
LDAB #$O1
TBEK
STE DATA TO,SEM)+6 ;put in temp array
LDAB WF-
TBEK
LDE RJURRO ;get &SC sensor &bit a/d value
LDAB #$O1
TBEK
STE DATA TO,SEND+8 ;put in temp array
LDAB #$OF-
TBEK
PC-READY 1:
LDAB SCSR+1 ;check "Receive Data Register Full" flag-should bave
BITB #$4û ;START signal h m PC in buffer
BEQ PC-READY 1 ;if not, go back aod check again
LDAB SCDR+l ; l d receive cegister into B
SUBB #$OF ;see if if has received an $F (this is the START sig)
BNE PC-READYl
SEMl,STRR?JG2: ;subroutine to send out tbe entire ASCa string
LDAB #$OF
TBEK
LDAB #$O1
TBXK
LDAB OX ;get next byte in string as pointed to by IX
TBA ;data byte now is transfened to acc A
LDAB
TBXK
JSR SEND-CH ;go send out the byte
AIX #$O1 ;increment IX to point to the next byte
LDAB #$O1
AppendU C: Controller Source Code
TBEK
DECW DMAJNDEX ;decrementtransmit counter
TSTW D H ' I N D E X if6 samples haci b e n taken
BNE SEND STRING2 ;loop back and do nea byte in soing
LDAB #$OF
TBEK
KI'S
SEND-CH: ;subroutine to send out one byte to SC1
LDAB SCSR ;check 'TcitllSmitData Rcgister Enable" bit, $0, means
AM)B #SOI ;register TDR sàll bas data to be sent to a seriai s W f
BEQ SEM)-CH S T D R is not empty, go back to check it again
TAB ;&ta byte ttansferred to B-had to do tbis since ody acc B &ers to K
LDAA #!§O0 ;cl= A to send a fiiil w o d to SCDR (SFFCOE)
STD SCDR ;transmit one ASCII character to the PC
TC-LOOP:
LDAB SCSR+l
ANDB #$80 ;test the TC bit (transfer complete)
BEQ TC-LûûP ;continue to wait until TC is set
LDAB SCSR ;test transmit buffet empty
ANDB #!SOL
BEQ TC-LOOP
LDAB #$OF
TBEK
ET-READYZ:
LDAB SCSR+1
BITB #$40 ;check for "CONTINUE" h m PC
BEQ PCPCREADY2 ;if not, go back and check again
LDAB SCDR+l ;load receive register into B
SUBB #$OE ;see if if has received an $E
BNE PC-READY2 ;if not, go back and check again
LDAB #$O1
TBEK
RTS ;finish sending out byte
* LCD MESSAGES *
* *
EVEN
RAiSE-MESSAGE 1 DC ' L m IMP- ',m
EVEN
RAISE-MESSAGE2 DC 'IMPL- RAISED',$OO
EVEN
LOWER-MESSAGE DC "TO SEED DEITH ',â00
E V ~
SET-RAISEJMSG DC 'SET RAISED POSN ',$W
EVEN
HIT-KEY-MSG DC 'IITT ANY KEY ',â00
EVEEl
ENTER-JiEIGHT DC 'ENTER INCHES: ',$O0
EVEN
ERR-PRESS-MSGO DC 'OH S m ,ERROR; ',$O0
EVEN
Appendùt C: Conttoiier Source Code
EVEN
PICK,CALIBSO,OR,oINS DC ' 2 4 b n t sew*,$ûû
EVEN
CALIB-9û DEGl DC 'PROCEDORE TO 'JXlû
EVEN-
CALIB-90 DEG2 DC 'STORE THE SENSOR'SHI
EVmi-
CALIB-90 DEG3 DC 'POSITION 90 DEG ',$(Ml
Evmi-
CALIB-90 DEG4 DC 'TODISK LINKAGE ',$Ml
EVEN-
SET~TO~~O-MSG1 DC 'Position disk so*,$ûû
EVEN
SETETTOT09û90MSG2DC 'sensor a m is W,$ûû
EVEN
SETETTOTO9O-MSG3 DC 'deg to disk arm ',$O0
EVEN
*
* TABLE FOR KEY IDENTIFlCATION
* *
KEY-TABLE:
DC,B $EE *O
DCB $DE *1
DC.B $BE *2
DCB $7E *3
DC.B SED *4
DCB $DD *5
DC.BSBD *6
DC.B$7D *7
DC.B$EB 8
DCB $DB *9
DC.B SBB *A
EVEN
SINE-TGBLE:
FCB %00,$01,$03,b05,$06,~8,W,$0~
FCB $OD,SOE,$OE,$11,$12,$14,$16$17
FCB $ 19.âl&$lC,$ IE,$IF,$20,$22.$23
FCB $Sv$
26,$28,$29,$2B,b2C,$ZE,S2F
FCB $30,$32.$33.$35.$36.$38.$39.$3A
Appendur C: Conmller SourceCode
DEPTHEPTHIûWSXRMB $02 * 10060 *X-on for 11100th inch decimal for lcd roundoff
OP-DISPLAY-ON IMB $02 * L W 2 *tlag showing that tbe operathg display is on
ADC-CHANNEL RMB $02 *Idon for telhg which A/D to rcad firnn
DISC-READING RMB !5û2 *location for @th readiagh m &CS
DEPTH-1OINCHES RMB a02 *location for 10 incbes numeral
HYD-SIGNAL RMB $02 *locationfor output
DISCJW%iYJEGJOS RMû $02 *location for output
CORRECFEn-FIELD-ZERO RMB $02 *10012 *zero position set by operator
CORRECIED-DISC-READING RMB $02 * I d o n for depch reading h m discs
CORPECFEnDEPTEI-READDG RMB $02 *location for depth reaàing b r n discs
FRONT-READING RMB $02 *locationfm AID 1 for second sensor
CORPE~JRONï'ZERO RMB $02 *location for FRONT zero reading
COREECïEDJRONT-READiNG RMB Sû2 *l-on for b n t seasor corrccted reading
FRONT-iEV'EL-ZERO RMB â02 *GROUND POSITION FOR CALIBRATIONOF FRONT SENSOR
FRONT-%-READING RMB $02 *90 DEG POSITION OF FRONT SENSOR
FRONT,GROUNDUNDZERORMB $02 *GROIMD READING FOR THE FIEW)
EIYPOTENEUSESFRONT RMB $02 *hypotenuese for front, is hypot * a factor
TRUE-O-DEITH RMB $02 *ternp Iocation for diffetence between zero and 90,deg
HYPOTENEUSE-DISC RMB Sû2 *constant value fm angle correction factor
ERROR-TNLE RMB S 14 *&ange in error circular buffer
Da-TO-SEM) RMB $OA
DATA-INDEX RMB $02
RAISE-DEPTH-FLAG RMB $02 *when set. means the discs are too deep-raise discs
ERROR-CONVNVFORMAI:RMB SM *errer fiom sutface in 1000's inch divided by 200
OPERATING-DEITH-CONVNVFOURMB $02 *operathg depth (in 1000's in) /factor
CIRCCERROR,BUFFER RMB $02 *cucutar error b a e r index
Titie :ORG00008
Description :Tbis Me inïtiaIUes the iatcmiptl
-
exception vectm ( $ 0 8 $01fe).
If an inrempt OCCUIS tequiring ihe use of
any of these vectors, program flow wiU
continue at the iabct "Wm" wbich must be
added by the programmer to bisiher code to
put tht program into backgrounddebug made
or some otber appropriate rouùnc.
This appendix contains the source code used for the PC logging program. This
MC68HC16EVB or the tractor cab controller that was built for this research. Data fiom
the controller was displayed on the screen as liws proportionai in length to the signal
received. This proved to be very helpful while field testing, where no representation of the
control actions was available using the LCD-only equipped controller. It was written in
Borland Turbo C, and nins under DOS using the DOS graphic commands available under
Turbo C. Although the logger program interface could have been improved and extra
features easily added if it was written in Visual C for Windows. the program was wrîtten
for DOS in order to maximize portability and minimize incompatibility problerns. It was
designed to nin on a laptop PC with or without a hard disk, many of which have
The controller data logged hcluded the enor from the set point, the change in
error, and the fuay decision output. ND hexadecimal values from the sensors was dso
logged. This data, fkom the front and rear sensors, came directly fkom the registers for the
A/D converters.
Appendix D: PC Logger Source Code
-- P locations */
to fonn 16 bit */
1
P combine 8-bit
.P put b p m filem into words */
fileout = (unsignai rn *)filein; I* in Gleout */
1
setcolor(0); /* set coIow to black */
F(i= 1)
bne0efk 0, left, bottom); /* draw black tine over old one */
The simulations done in mathcad were prduced inVersion 4.0 at the outset of this
research. With the release of Version 6.4 this work was expanded by using the
capabilities to program in if-then loops and other iterations. Otheraise, it would have
z vector with dimension 21 rows x 1 cotumn is the riumber of tirnes vector y is repeated:
if ERROR,, ,-P.
if @RRORm,,sZR
1[(ZL- @RROR)~,,]ZE!RO~MBMB~SLOPE~ if ERROR,, ,,<ZM
I
[[(ZR -
O oihcrwisc
ERROR),,~]*Z~RO-MEMB-SLOP@] othcrwisc
10 aihcrwisc
Section 6: CHANGEJN-ERROR Membership Function Parameter Definilions, similar to ERROR in
shape:
CNBM : - IOCNSL 10 CZL : 5 CPSL : O CPBL : 5
CNBR :=- 5 CNSM : = - 5 CZM :=O CPSM : = 5 CPBM := 10
CNSR:=O CZR:=5CPSR:=IO
The inputsfor CHANGE-IN-ERROR are rnatrix x, but are transpose& CHG-ERROR : = xT
othewise
if CHO-ERROR,, ,X N S L
if CHO-ERROR,,,SCNSR
1(CNSL - CHO-ERRoR,, ,. )~C-NEG-SMALL-SLOPEI
l
if CHO-ERROR,,,, $NSM
1(CHG-ERRoR~, ,- NSR) C-NE!O-SMALL-SLOPE~ ohemisc
O othewise
O othewise
if CHG-ERROR,, ,>CiIL
if CHO-ERROR,, , X Z R
( (CZL - CHO-ERROR,,, ,$ OC-ZERO-MEMB-SLOPE~ ,,
l
if CHO-ERROR,,, , SCZM