47
Electronic Distance Counter Executive summary Peat bogs contain turf which can be used as a fuel to heat houses. Turf is dug out of the bog and spread on land to dry under the sun. When the turf is dry it will be stored in a shed and used during the winter to heat houses. A machine called a turf hopper is used to spread the turf. The turf is spread in rows, each 91 metres long. Three rows make up a plot, this is the unit turf is sold in. Problem Definition The turf hopper operator does not know when 91 metres of turf have been spread. The distance must be measured and then marked so the operator will know when to stop spreading. The distance can be measured by walking a distance of 91 metres and putting down a stick as the marker. The problem with this is that operators tend to have an inconsistent stride length which results in different length rows. A more accurate method is to use a metre wheel to measure the 91 metres. This solves the accuracy problem but it takes time for the operator to mark out the distance. The operator might have to do this a few times per day which wastes time and in a turf cutting season time is a precious resource. The solution then is a device on the machine itself that can calculate the distance of turf spread. This device should have good accuracy and be easy to read. The length of the row should not vary more than 2% from the desired length. The operator is concentrating hard on working the machine and needs to know the distance travelled with one glance at the device. Implementation The solution was an electronic distance counter that determines the distance travelled as the machine spreads the row of turf. A sensor is mounted opposite a gear in the machines gearbox. The gear speed is directly proportional to the forward speed of the machine and the sensor can detect each revolution of the gear. A microcontroller is used to convert the revolutions of the gear to the distance travelled in metres. This information is displayed on a liquid crystal display which can easily be viewed by the operator. When the device is installed on a machine it has to be calibrated before it is ready to use. The device is simple to use, once the machine starts moving the distance will increase on the LCD. Before spreading a row of turf the counter is set back to zero. A reset

Report - Distance Counter

Embed Size (px)

Citation preview

Page 1: Report - Distance Counter

Electronic Distance Counter

Executive summaryPeat bogs contain turf which can be used as a fuel to heat houses. Turf is dug out of the bog and spread on land to dry under the sun. When the turf is dry it will be stored in a shed and used during the winter to heat houses. A machine called a turf hopper is used to spread the turf. The turf is spread in rows, each 91 metres long. Three rows make up a plot, this is the unit turf is sold in.

Problem DefinitionThe turf hopper operator does not know when 91 metres of turf have been spread. The distance must be measured and then marked so the operator will know when to stop spreading.The distance can be measured by walking a distance of 91 metres and putting down a stick as the marker. The problem with this is that operators tend to have an inconsistent stride length which results in different length rows. A more accurate method is to use a metre wheel to measure the 91 metres. This solves the accuracy problem but it takes time for the operator to mark out the distance. The operator might have to do this a few times per day which wastes time and in a turf cutting season time is a precious resource.

The solution then is a device on the machine itself that can calculate the distance of turf spread. This device should have good accuracy and be easy to read. The length of the row should not vary more than 2% from the desired length. The operator is concentrating hard on working the machine and needs to know the distance travelled with one glance at the device.

ImplementationThe solution was an electronic distance counter that determines the distance travelled as the machine spreads the row of turf. A sensor is mounted opposite a gear in the machines gearbox. The gear speed is directly proportional to the forward speed of the machine and the sensor can detect each revolution of the gear. A microcontroller is used to convert the revolutions of the gear to the distance travelled in metres. This information is displayed on a liquid crystal display which can easily be viewed by the operator. When the device is installed on a machine it has to be calibrated before it is ready to use. The device is simple to use, once the machine starts moving the distance will increase on the LCD. Before spreading a row of turf the counter is set back to zero. A reset button on the device can be pressed to set the counter back to zero. The LCD will display the current distance travelled so when the LCD gets to 91m the operator knows a row of turf has been spread.

EvaluationEvaluation was by means of computer simulation and building a prototype. The computer simulation involved calculating the accuracy of the system at different distances. The prototype was used to validate the computer simulation and also to test how easy it was to use. The accuracy of the device at 100 metres was 0.05% while the largest error was 2% which occurred at 0.1m. The accuracy test was carried out on flat hard ground. A stick was used to mark the start and then a measuring tape was used to measure a straight line 100m long. The machine was driven from the starting point to the end and the distance on the LCD display was recorded. The error was calculated from the difference between the measuring tape reading and the reading on the LCD. The prototype was also tested at various distances and the results were similar to the simulation results. The LCD used on the device was tested at different distances and under different light

Page 2: Report - Distance Counter

conditions to demonstrate it meets the design requirements. The LCD demonstrated it could be viewed from up to 5 metres away and under direct sunlight which is a problem in many LCD displays.

This device is accurate and simply to use which makes it a perfect tool for turf hoppers. Before this device can be brought to market it needs some small improvements. The sensor installation needs to be quicker to reduce the cost of installation. The calibration process could be automated to simplify the device use. More functionality could be added to appeal to more customers. When these improvements have been made the design should be marketed to appeal to turf cutters.

Page 3: Report - Distance Counter

ContentsExecutive Summary...............................................................................................................................1

Problem Definition............................................................................................................................2

Implementation.................................................................................................................................2

Evaluation..........................................................................................................................................2

Problem Definition................................................................................................................................1

Problem.............................................................................................................................................1

Existing solutions...............................................................................................................................2

Design requirements.........................................................................................................................2

1. Have an accuracy of 1% at 100 metres..................................................................................3

2. Have an accuracy of 2% at all other distances.......................................................................3

3. Give the operator a distance update every 0.1 metres.........................................................3

4. The operator must be able to read the display from 2 metres..............................................3

5. The operator must be able to read the display under all light conditions.............................3

Implementation.....................................................................................................................................4

Proximity Sensor............................................................................................................................4

Microcontroller..............................................................................................................................5

Liquid Crystal Display.....................................................................................................................5

Detailed description..........................................................................................................................5

Proximity Sensor............................................................................................................................5

Microcontroller............................................................................................................................10

Liquid Crystal Display...................................................................................................................16

How the design is used....................................................................................................................17

Calibrating device........................................................................................................................17

Operation modes:........................................................................................................................17

Reset / Zero counter....................................................................................................................18

Evaluation............................................................................................................................................18

Overview.........................................................................................................................................18

Prototype.........................................................................................................................................19

Testing and Results..........................................................................................................................20

Design Requirement 1 – accuracy of 1% at 100m........................................................................20

Design Requirement 2 – accuracy of 2% overall..........................................................................20

Design requirement 3 – update display every 0.1 metres...........................................................21

Design requirement 4 – view display from 2 metres...................................................................22

Page 4: Report - Distance Counter

Design requirement 5 – view display in all light conditions.........................................................22

Assessment......................................................................................................................................23

Design positives...........................................................................................................................23

Design negatives..........................................................................................................................23

Next Steps........................................................................................................................................24

Appendices..........................................................................................................................................25

Appendix A – Circuit Diagram......................................................................................................25

Appendix B – Theoretical System Accuracy.................................................................................32

Appendix C – Software.................................................................................................................33

Page 5: Report - Distance Counter

Problem DefinitionPeat turf is cut from bogs and spread on land to be dried by the sun and then brought to people’s home to be burnt as a fuel for heating houses. Peat turf or turf is a poor quality coal and is made from layers of dead vegetation that has decomposed over millions of years. The turf is dug out of the bog using an evacuator and spread out on dry land using what is called a turf hopper. There are different types of turf hoppers; wheel hoppers, track hoppers and self-propelled hoppers. Wheel hoppers are similar to trailers and are pulled by tractors, tracked hoppers use tracks instead of wheels and self-propelled machines are on tracks and use their own engines to propel them. Turf is extruded from the hopper onto the ground in what are called sods of turf. Sods are square in shape and about 1 foot long. The sods come out of a spout which will spread ten sods at a time one beside the next. This is called a ten sod hopper since it spreads ten sods at a time. Below is a picture of turf in rows:

Figure 1Rows of turf spread on land

Most turf contractors will spread a row of turf 100 yards long, 3 of these rows make up a plot. A plot is the most common unit of sale of turf.

1 | P a g e

Page 6: Report - Distance Counter

ProblemTo determine the distance of a row of turf, without leaving the machines cab.A row of turf is 100 yards by 10 sods wide which is 1000 yards of a single sod of turf. 3 rows make up a plot and this is the unit turf is sold in. It is important then to get the length of a row right, if it is too long money is being lost, too short and customers are getting less turf than they paid for. The rows can be 1 or 2 yards longer or shorter without causing any problems, but large variations can be problematic. It is not easy for the operator to judge when 100 yards of turf has been spread. If the turf was all the same density the operator could take the same load every time and spread until the hopper was empty. However, the density of turf changes from bog to bog and some bogs can get 100 yards of turf with a significantly smaller load than other bogs.

Existing solutionsAs the problem outlines the distance of turf spread must be known, currently there are two solutions: 1. The operator will walk 100 strides with each stride length 1 yard long. 2. Use a metre wheel to mark out 91 metres which is equivalent to 100 yards. The first solution works well when the operator has a stride that is 1 yard long and has a consistent stride, but many operators either have a stride that is too short, too long or not consistent and this can leave a big error in the distance. The second solution is accurate but time consuming because the operator has to stop work, get out of the machine and walk along with a metre wheel to mark out the 91 metres.

In some cases the ground where the turf is being spread might not hold 91 metres of turf and the rows must be shortened. The shorter rows must be a multiply of a plot (91 x 3, 68 x 4, 55 x 5, or 45 x 6) and thus a new measurement is needed. This is again more time lost and reduces efficiency.

The solution to this problem is already on many tractor driven hoppers. Modern tractors have distance counters which can be used to determine the distance travelled. But self-propelled machines do not have this device and many turf cutting machines are self-propelled.The solution to the problem is a distance counter on the machine itself that does not require the operator to leave the cab.

Design requirementsThe overall design requirement will be to design a distance counter that can be fitted to a self-propelled turf hopper. The distance counter will allow the operator spread any distance of turf without the need to get out of the machine to measure the distance.

To achieve this overall requirement, more specific requirements must be used. The first will be the accuracy at the critical distance which is 91 metres. The overall accuracy of the system should also be satisfactory. Distance counters in tractors will usually update the distance after every metre travelled; this would adequate for the operator since a metre too short or too long will not be a problem. But if the system can be designed to be more accurate without much extra work this would be desirable. If the display was updated after every 0.1 metres it would mean the operator could be more accurate. The operator is concentrating hard on making sure the rows of turf are straight and

2 | P a g e

Page 7: Report - Distance Counter

the sods of turf are good quality. This does not leave much time for looking at the display so the display must be very easy to read.

The following are the design requirements that must be met:

1. Have an accuracy of 1% at 100 metres2. Have an accuracy of 2% at all other distances3. Give the operator a distance update every 0.1 metres4. The operator must be able to read the display from 2 metres5. The operator must be able to read the display in all light conditions

1. Have an accuracy of 1% at 100 metresThe allowable error distance will be 1 metre at 91 metres (90m – 92m) this is just over 1% error. To simplify explanations, calculations and testing 100 metres will be used in the design requirement. The percentage error will be a little lower than if 91m were used so it will not negatively affect the system accuracy.

2. Have an accuracy of 2% at all other distancesOther distances that the system needs to be accurate at are: 45m, 55m, 68m, 137m and 182m so instead of setting a requirement for each an overall system accuracy will be set at 2%. This value is being chosen because it will make it easier to design the system if there are distances where the accuracy is difficult to get under 1%. Once the critical distance (100m) is accurate to 1% and the other distances are accurate to 2% the design will be satisfactory.

3. Give the operator a distance update every 0.1 metresAn update every 1 metre would be adequate, every 0.1m would give the operator more accuracy. Another reason is if the accuracy of the system cannot meet the design requirements the operator might have to determine the inaccuracies at the different distances; having the ability to see values within a metre will allow the operator to get more accuracy out of the system. Consider if the operator knows that at 137m the distance counter was 0.5m too short and the value that should be stopped at is 137.5m. Having an update every 0.1m will allow the operator to do this, otherwise the stop value would be 138m, 0.5m too far. Of course this is still within the limits for this application but if it is possible to implement an update every 0.1m the overall accuracy can be improved.

4. The operator must be able to read the display from 2 metresThe display must be large enough to easily read it from a distance of 2 metres. This can be easily tested by placing the display two metres away from the operator and changing the values to see if the operator can determine what each one is. The operator must be able to quickly recognize each value. The LCD resolution will also play a role in the clarity and viewing distance of the display.

5. The operator must be able to read the display under all light conditionsThe sun is very bright and can make it very difficult to view the display. This often happens when the sun is low in the sky. The machine orientation cannot be changed in most cases so the display must account for this. This can be tested by facing the display towards the sun at different angles and asking the operator to recognize the values on the display. This should also be done at night to ensure the display is visible in the dark.

3 | P a g e

Page 8: Report - Distance Counter

ImplementationThis design displays the distance travelled by a machine in metres on a liquid crystal display that can be mounted anywhere on the machine. A sensor is mounted in the gearbox of the machine that tracks the revolutions of a gear in the gearbox. A microcontroller then converts the number of revolutions of the gear to a distance travelled by the machine. The distance is then displayed on an LCD screen so the operator can view the information.Below is a block diagram of the system:

Figure 2Block diagram of system overview

The distance counter is the name of the design; a distance counter is the function the design carries out. The distance counter is split into the three components that make up the design, a proximity sensor which monitors the revolutions of a gear in the gearbox. The microcontroller which carries out all the calculations and conversions and the liquid crystal display which displays the distance travelled in metres.

Proximity SensorA proximity sensor detects metal objects within its detection range, depending on the sensor it will be anywhere from 2 – 8mm. When a metal object is detected the sensor will change its output from 0 volts to 12 volts.The sensor is used to detect shaft rotation; the sensor is mounted opposite a gear in the gearbox which has teeth on it. The sensor detects the teeth on the gear and sends a signal for every tooth that is detected. The more teeth detected the further the distance the machine has travelled.The signal from the sensor will be a pulse signal that will go between 0v and 12v. The microcontroller will count each time the sensor outputs 12v.

4 | P a g e

Page 9: Report - Distance Counter

MicrocontrollerThe microcontroller is a small computer. The microcontroller is used with the Arduino platform which allows easy programming and communication with hardware. The microcontroller converts the sensors signal to metres and sends it to the LCD. The microcontroller will count each sensor pulse from the proximity sensor and store it in a pulse counter. Since each pulse represents a forward distance the pulse counter will hold the total distance travelled. The microcontroller converts the pulse counter to a distance travelled.This distance is then written to the LCD registers where it can be displayed by the LCD.

Liquid Crystal DisplayAlso called an LCD display, it is used to display meaningful data from the microcontroller. The LCD takes the data from the microcontroller and writes it to its display. It is controlled by the microcontroller using parallel communication which is fast and reliable.

Detailed descriptionThe block diagram of the system is shown in figure 3 below and breaks down each hardware device into their functions. For example the proximity sensor is split into “detect movement” and “send signal to microcontroller”. The first function is to detect when the machine is moving and the second part is to send the information to the microcontroller. Some of the functional parts need to be broken down further to help explain what is happening, this will be done with the use of headings. The explanation will start at the proximity sensor and finish at the LCD to help understand the system from start to finish.

Figure 3Block diagram of system

5 | P a g e

Page 10: Report - Distance Counter

Proximity SensorThe proximity sensor is used to detect the forward movement of a machine by detecting the number of revolutions of a gear in the transmission that is directly proportional to the forward speed of the machine.

A proximity sensor detects objects within a given range, there are different types of proximity sensors for sensing different materials; inductive for metal and capacitive for plastics are two common types. This design will use an inductive sensor since metal is the material being detected.An inductive proximity sensor detects metal objects within its range and closes a switch which can either set the output of the sensor high or low depending on the circuit configuration.Below is a diagram of the internal components of a proximity sensor:

Figure 4Inside an induction proximity sensor

How it worksThe oscillation circuit produces oscillations of fixed amplitude and frequency. The inductor (L) produces a magnetic field. When a metal object (or target in the diagram above) is brought within its detection range the magnetic field induces eddy currents (currents in a conductor due to a changing magnetic field applied to the conductor) which in turn increase the load on the oscillator circuit. With the increased load the oscillator cannot sustain the oscillations and they reduce in amplitude or stop completely. An amplitude detection circuit monitors the oscillations and when they decrease it will trigger the output circuit. The output circuit will output a high voltage (12v) when the sensor is triggered and a low voltage (0v) when the sensor is not triggered.

The block diagram below shows the main functions of the proximity sensor in this design.

6 | P a g e

Page 11: Report - Distance Counter

Figure 5Block diagram of proximity sensor functions

Detect gear rotationThe proximity sensor will be used to detect the speed of a gear in the transmission of the system. The sensor is placed opposite to a gear as shown in figure 6, each time a tooth of the gear passes the sensor the output of the sensor goes to 12 volts. The sensor output will return to 0 volts when the tooth has passed the sensor. As the next tooth passes, the sensor will output 12v again. When the sensor output goes from 0v to 12v it is called a pulse.

Figure 6Proximity sensor outputs a signal when a gear tooth passes it

7 | P a g e

Page 12: Report - Distance Counter

Shaft rotation to sensor signalThe distance travelled by the machine can be determined using a proximity sensor to count the number of revolutions of a gear in the transmission. The sensor outputs a pulse for every tooth that passes it. If the gear has 10 teeth, after 10 sensor pulses the gear will have completed 1 revolution. This revolution will have moved the machine forward by a distance X, this distance can be determined by using a measuring tape. Dividing this distance by the number of teeth on the gear (10 in this case) will give the distance travelled by the machine between each pulse. This is called the pulse distance. The pulse distance is divided into 1 metre to determine the number of pulses per metre. This is called the calibration value and must be set to provide an accurate system. This also determines the resolution of the system, the smaller the pulse distance the higher the resolution since the pulse distance is the smallest distance the system can detect.

CalibrationIn most cases the pulse distance will not be known because the number of teeth on the gear will not be known. If the number of teeth on the gear is known then the following steps will calibrate the device:

1. Calculate pulse distance2. Calibration value = 1 / pulse distance3. Test machine over 100 metres to verify accuracy4. Adjust calibration value if necessary

The calibration value is selected using a potentiometer connected to an input pin on the microcontroller, the input is between 0 – 5v and this maps to values between 0 – 200 pulses per metres. Values outside this can be selected but it is expected that these values will be suitable for most systems. If the pulse distance cannot be calculated the calibration distance must be set to 100.

Then the following steps will calibrate the system:1. Set calibration value to 1002. Measure a distance of 100m on flat dry ground with measuring tape3. Drive the machine the 100m distance4. Note the reading on the display5. This is the new calibration value6. Retest new value over 100 metres7. If the system is not accurate make a small change to the calibration value8. Retest and re-tweak until accuracy is acceptable.

Example: pulse distance is unknown so calibration value of 100 is chosen, the calibration value is selected using the potentiometer and the vehicle is driven the 100 metres marked out. After the 100 metres the display shows 110 metres.The new calibration value will be: 110The machine is tested again and this time the display shows 100m.

8 | P a g e

Page 13: Report - Distance Counter

Send pulses to microcontrollerEvery time a tooth passes the sensor a voltage pulse is produced. The schematic diagram for the sensor is shown below in figure7. L+ is the power into the sensor which is connected in parallel to the load. The L- wire is connected to ground. The switch in the diagram is closed when the sensor is triggered and current can flow through the load. In this design the load will be a pull down resistor and the output will be taken off the ‘BK’ wire. This will be connected to the input pin of a microcontroller which will detect whether the voltage is low (<2v) or high (>3v). When the sensor is not triggered the ‘BK’ wire will be connected to 12v through the pull up resistor and when the sensor is triggered the ‘BK’ wire will be connected to 0v through the sensor switch.

The microcontroller can only input voltages between 0 – 5v. The 12v must be converted to 5v; this is achieved using a voltage divider as shown in figure 8. Figure 8 shows that there is an 8 kilo ohm resistor between the sensor output and ground. This creates a voltage divider with the 10k pull down resistor. The voltage at the sensor output will then be 5.3v which is within the input limit for the microcontroller input. The voltage seen by the microcontroller will be 5v when the sensor is not triggered and 0v when it is triggered. The microcontroller registers a pulse when the voltage changes from 5v to 0v, to register another pulse the voltage must first return to 5v. In the previous sections it was explained that a pulse occurs when the sensor output goes from 0v to 12v, this was just for explanation purposes. It is easier to understand that a pulse occurs when the voltage goes from low to high. It does not matter which way a pulse is determined because the pulse signal repeats itself.

Figure 7Circuit schematic of output circuit for proximity sensor

9 | P a g e

Page 14: Report - Distance Counter

Figure 8Voltage divider circuit: 12v input -> 5v output

MicrocontrollerThe microcontroller unit (MCU) is the brain of the system and coordinates the sensor and the display to translate the sensor output to a distance in metres on a Liquid Crystal Display that can be read by an operator. The microcontroller also provides functionality in terms of two operating modes and the option to zero the distance travelled at any time and start counting again.The microcontroller used in this system is an Atmel ATmega328 microcontroller. It is an 8 bit MCU with 32KB of flash memory which can be used for programs. It uses 2KB of SRAM and can run at clock speeds up to 20MHz.

The ATmega328 in this project is used inside an Arduino Uno platform. Arduino is an open source hardware platform. Based around the Atmel ATmega microcontroller, Arduino is an environment that makes microcontrollers much more accessible. It uses hardware that allows easy communication with PC’s for programming, as well as a programming environment that is based around C/C++ but uses special libraries to simplify hardware configuration. The Arduino Uno is used in this project and the connections made to the sensor and the LCD are shown in the electrical diagram in Appendix A

10 | P a g e

Page 15: Report - Distance Counter

Below is a block diagram of the basic functions carried out by the MCU. Each function is discussed in detail over the following sections.

Figure 9Function diagram of microcontroller

Detect pulse from sensorWhen the sensor is triggered it sends a pulse to the microcontroller, the microcontroller must be constantly monitoring the sensor to detect the pulse. There is hardware on the microcontroller that can constantly monitor a pin to detect a change in voltage level. The pin is a digital pin meaning the microcontroller will either consider it HIGH (>3v) or LOW (<2v), this is also called the state of the pin. The hardware monitors the pin for a change in state; a change in pin state is called an event. An event can occur in two ways:

1. Pin changes from LOW to HIGH2. Pin changes from HIGH to LOW

When an event occurs an interrupt is called. An interrupt is a piece of software that stops the main program and runs another software function before returning back to the main program. Interrupts are used to monitor hardware attached to computers. Without them the software would have to monitor the hardware, meaning it would not be able to carry out other tasks. The interrupt can be configured to be called when the pin changes from LOW to HIGH, HIGH to LOW or just when the pin changes state. The software function run by the interrupt is called an Interrupt Sub-Routine (ISR). When the sensor sends a pulse the microcontroller detects the pulse and triggers an ISR. A counter is used to keep count of the total number of pulses from the sensor; this is called a pulse counter. It is an integer variable that is incremented every time a pulse is detected. The value of this variable (pulse counter) can be checked at any time by the software program.

Select counting modeThere are two counting modes that can be used with the distance counter: 1. Continuous counting – counts once the machine is moving forward2. Start - Stop counting – counts if the machine is moving forward and the start-stop switch is closed.

Start – stop counting uses a switch to control whether it counts or not; if the switch is closed the counter will increment and if the switch is open the counter will not increment. The switch can be placed anywhere on the machine and can be activated by a mechanical switch.

11 | P a g e

Page 16: Report - Distance Counter

The mode selection is controlled by a toggle switch connected to an input pin on the microcontroller. The start-stop switch is also connected to an input pin on the microcontroller. During the software program the state of these pins are checked to decide which mode to select and whether or not to increment the counter. The following is the software flow diagram of the check:

Figure 10Flow chart of counting mode selection

12 | P a g e

Page 17: Report - Distance Counter

Figure 10 shows that the mode selection switch is checked and then the start-stop switch is checked and only if the start – stop switch is HIGH will the counter increment.The “increment counter” will increment the pulse counter.

Set flag to update LCDThe LCD is updated every 0.1 metres; a flag called the “Update LCD Flag” is used to signal the LCD to update. The calibration value is the number of pulses in a metre and one tenth of this value is the number of pulses in tenth of a metre. This value is called the “calibration tenth”. Each time the pulse counter increments by an amount equalling the “calibration tenth” the “Update LCD Flag” is set. And the LCD is updated.To determine if the pulse counter has incremented by the calibration tenth an integer is used for comparison. The pulse counter is compared with this integer and when they are equal the flag is set. This integer is called the “next update pulse” and is calculated using the formula:

next update pulse = (calibration tenth) x (index+1)

The variable “index” in the formula above is an integer that is incremented every time the “Update LCD Flag” is set. It holds the number of flag updates and is also used to calculate the metres travelled. To calculate the “next update pulse” a value of 1 must be added to “index” because this will be the number of pulses needed for the next LCD update.

After each flag update the index will be incremented by 1. Then the “next update pulse” will be calculated. This is the value the pulse counter must reach before the flag is set again.

Rounding errorIn some cases the calibration value will not be an integer; it will have one significant digit. This means the “next update pulse” will also have one significant digit and thus will not be an integer. This cannot be compared against the pulse counter since it only holds integer values. It must be rounded to the nearest integer and then compared. This will introduce a rounding error, but as shown in the table in Appendix B this error tends to zero as the distance increases. The table shows that the rounding error results in an error of 1.7% at 0.1 metres and 0.05% at 3 metres. The table also shows the actual error in millimetres (mm), the actual error varies as the distance travelled increases but the range of the actual error (-3mm to +3mm) does not change. The reason the percentage error reduces is because the distance travelled becomes larger compared to the actual error.

Calculate metre valueWhen the “Update LCD Flag” is set the number of metres travelled must be calculated. The following formula is used for the calculation:

metres = 0.1 x index

Another way of looking at this formula is, the “index” is the number of 0.1 metres travelled.

For example if the flag has been set 10 times:

13 | P a g e

Page 18: Report - Distance Counter

metres = 0.1 x 10 = 1 metreThis is the metre value that will be sent to the LCD.

Reset CounterThe distance counter can be reset or zeroed at any time using a push button. The push button is connected to a pin on the microcontroller (MCU). The pin is at 0v when the button is not pressed, a button press connects the pin to 5v. It is configured to call an interrupt when the pin changes from LOW (0v) to HIGH (5v). The interrupt stops the software program and runs an ISR and then returns to main program. The ISR resets the variables used in the main program to zero. The variables that are reset are: the metres value, pulse counter and the index variable.

Software ProgramThe software program implements the sections above on the microcontroller and the code is included in the design folder and is very well commented. The code takes up 10 pages and is also easier to read in a C++ editor. The software code follows the logic in the sections above and along with the comments is very easy to follow. The following is a flow chart that gives an overview of the software program.

14 | P a g e

Page 19: Report - Distance Counter

Figure 11Flowchart for software program

15 | P a g e

Page 20: Report - Distance Counter

The flow diagram above shows the main program on the left, the sensor interrupt in the middle and the reset interrupt on the right. The flow diagram shows that the program is logical and straightforward. It follows the explanation of the system in the implementation section. The sensor interrupt will be called when the MCU detects a pulse on the pin connected to the sensor. The reset interrupt will be called when the reset button is pressed.

Liquid Crystal DisplayAn LCD is used to display the distance to the operator, the distance will be updated every tenth of a metre. The LCD is a transflective display which means under bright sunlight the characters on the display reflect the light and this makes them easy to read. In dull or dark conditions the LED backlight illuminates the display and is easy to read. The LCD is a 16x2 character display which means it has 2 rows of characters and 16 columns. The LCD communicates with the MCU using a parallel interface. The circuit diagram in Appendix A shows the connections to the MCU. The LCD will update when the MCU sets an update flag and sends a new value to display.

Figure 12Functional diagram of Liquid Crystal Display

Monitor Update FlagThe microcontroller uses an “Update LCD Flag” to trigger an LCD update. When this flag is set the microcontroller will send the LCD a new value to write to its display.

Write metre value to LCDWhen the “Update LCD Flag” is set the MCU starts communication with the LCD display. The MCU uses commands to write information to the LCD registers which the LCD will write to the screen. The distance travelled will be sent to the LCD registers and then the LCD will display this on the screen.

Reset Update FlagThe “Update LCD Flag” must be reset after the display is updated otherwise the LCD will update the metre value every single pulse from the sensor. This is done in the MCU software when the LCD has confirmed the information has been successfully written to the screen.

LCD BacklightThe LCD display has a powerful backlight that will illuminate the display in dull or dark conditions. The backlight can draw 200mA of current; the connection for the backlight is shown in Appendix A. The power resistor is very important to prevent high currents in the LEDs that power the backlight.

16 | P a g e

Page 21: Report - Distance Counter

How the design is usedThis design is very straightforward to use, the first part is to calibrate the device to accurately determine the distance travelled. Then the operator can actually use the device to determine the distance travelled. There are two modes of operation: continuous and start-stop, continuous is the default and is simple a point and shoot approach, drive the machine and the distance will increment. The start-stop mode is more sophisticated and uses a switch to start counting or stop counting. The idea is that the switch will be mounted on the machine and will monitor a mechanical mechanism. The mechanism will be used to control when the distance is incremented. A reset button is used to reset the counter to zero.

Calibrating deviceThe calibration value is selected using the calibration potentiometer; it is read every time the device is powered on. The potentiometer will output a value of 0v – 5v which the MCU will convert to 0 – 200 pulses per metre. The potentiometer is turned until the correct value is selected. The device must be restarted every time a different calibration value is selected. The LCD will display the value selected by the potentiometer during device start up.

The following are step by step instructions on calibrating the device:

1. Enter a calibration value of 100 pulses per metre using potentiometer2. Mark out 100 metres on flat solid ground with a measuring tape3. Drive the machine to the start of the 100m and reset the counter to zero4. Drive the machine to the 100m mark and record the value on the display5. This is now the new calibration value6. Enter this value in to the MCU using the potentiometer7. Test this calibration value over 100m as before8. Reduce the calibration value if the display value is lower than 1009. Increase the calibration value if the display value is greater than 100

The device is now calibrated; this value will be read from the potentiometer every time the device is powered on. Be sure not to change the potentiometers position unless re-calibrating the device.

Operation modes:There are two modes of counting that can be used:

1. continuous counting: keeps counting as long as the machine is moving2. start-stop counting: a switch or external event can be used to stop and start counting

Once the device is powered on a toggle switch can be used to choose between the two modes.

Continuous countingAs the name suggests the distance counter will increase once the machine is moving either in forward or reverse direction. When the reset button is pressed the counter will be zeroed and will start counting from zero.

Start – Stop countingThis mode will use a switch to start counting and stop counting, when the switch is pressed the counter will increment and when the switch is released the counter will stop. This is intended to be

17 | P a g e

Page 22: Report - Distance Counter

activated by a mechanical mechanism on the machine. For example on the turf hopper the spout is lowered to spread turf and raised to stop spreading. A switch could be mounted to the spout and close when the spout was down and open when the spout was up. This allows the operator to count the total distance of turf spread.

Reset / Zero counterA reset button is used to zero the display at any time and it can be pressed while the machine is stationary or moving. The display will start counting at zero again.

EvaluationAn evaluation must be carried out to determine how well the design meets the original requirement. The following sections will walk through the testing that was carried out to demonstrate that the design meets the original requirement.

OverviewEvaluation for this design was carried out through computer calculations, building a prototype and field testing to demonstrate that the design requirements were satisfied. The most important requirement, was the accuracy over 100 metres. The other significant requirements concerned the update distance interval of the display and the readability of the display at different distances and under different light conditions. These are important since the operator must be able to know the distance travelled with one quick glance at the display. The prototype will be discussed in the next section and then the testing and results will be shown and discussed. The following table gives an overview of the design requirements, the tests carried out and the score needed to pass the tests.Design Requirement Evaluation test Acceptable valueAccuracy of 1% at 100m 100m test 1%Overall accuracy of 2% Various distance tests 2%Update every 0.1 meters Check distance at every 0.1m 1%View display at 2 metres Changing display with operator

feedbackOperator must get all values correct

View display in all lighting conditions

Operating display in different lighting conditions with operator feedback

Operator must get all values correct

Table 1 – Design requirements

PrototypeA prototype was built to demonstrate that the design would meet the requirements. The prototype has the sensor mounted opposite a gear in the final drive of the machine. The machine is hydrostatic meaning it uses hydraulic pumps to deliver power to hydraulic motors to propel the machine. The motors are high rpm and low torque motors and cannot be used to directly drive the machine. A gearbox is used to reduce the speed from the motor and increase the torque to the machine. The sensor is mounted in this gearbox and monitors a gear with 6 teeth that spins at up to 4000 rpm. The microcontroller and LCD display are in the cabin of the machine. For the prototype they are housed in a lunch box for ease of installation. The prototype has a large LCD display, power switch, reset button and a toggle switch for selecting the counting mode.

18 | P a g e

Page 23: Report - Distance Counter

Below is a photograph of the prototype: There are two switches, power switch (left), count mode select switch (centre) and a reset button on the right.

Figure 13Photograph of prototype

The prototype will take the signal from the sensor, convert it into metres and display a new metre value on the LCD every 0.1m. The reset button can be used to reset the counter to 0. The counting mode switch will change the mode between continuous counting and start-stop counting. Continuous will continue counting once the machine is moving forward. Start-stop counting will count when the switch is in the start position and stops counting when the switch is in the stop position.

The prototype can be used to directly test the accuracy of the design by comparing a measured distance to the reading on the LCD. The prototype was used in the machine for a month which allowed the final two design requirements to be tested. The first was working with the LCD 2 metres away from the operator and the second was working the LCD under different lighting conditions.

Testing and ResultsThe design requirements were set out before the design started and each one will be evaluated in this section. The following are the design requirements:

1. Have an accuracy of 1% at 100 metres2. Have an accuracy of 2% at all other distances3. Give the operator a distance update every 0.1 metres4. The operator should be able to view the display from 2 metres away5. The operator should be able to view the display in all light conditions

19 | P a g e

Page 24: Report - Distance Counter

Design Requirement 1 – accuracy of 1% at 100mThis is the principle requirement because the main design goal was to detect when the machine travelled 100 metres.

Method of testingThe accuracy test was carried out using a 100 metre measuring tape placed along flat hard ground. The machine was then calibrated and driven over the 100 metres 5 times. The counter was set at zero at the start of each run and the display was read when at the end of the 100m tape.

Results – test 1Test No. Display Reading

at 100m% error

1 99.95 0.052 100.00 0.03 99.98 0.024 99.99 0.015 100.02 0.02Table 2 – 100m test results

DiscussionThe table above shows the results, the largest error was 0.05% which is an insignificant error. This satisfies the design requirement and proves the accuracy of the system at its operational distance is excellent.

Design Requirement 2 – accuracy of 2% overallThe accuracy at 100 metres should be the highest because this is the distance the system is calibrated at. The overall accuracy should be within 2% and this will be measured at lower values and higher values to determine the overall accuracy of the system.

Method of testingThe method of testing will use a measuring tape laid out on flat hard ground. The system will be calibrated to 100 metres as before. This time however the distances will vary and each distance will only be tested once. The distances will range from 1 m to 1000m.

Results – test 2Test Distance (metres)

Display reading at test distance % error

1 0.99 15 4.99 0.210 10.03 0.350 49.98 0.04150 150.01 0.02500 499.95 0.011000 1000.1 0.01Table 3 – test 2 results

20 | P a g e

Page 25: Report - Distance Counter

DiscussionThe theoretical system accuracy is shown in Appendix B at different distances. These were calculated from simulations of the system. The actual results from testing are in the table above. This table shows that the errors are higher but the percentage error reduces to effectively zero as the distance gets larger. The larger error in testing could be down small errors in readings and the machine not travelling in a completely straight line. If the machine veers slightly off line the distance will be increased. Also if there is a small slippage in the tracks the distance could also be increased and thereby decreasing the accuracy. These factors are small and the largest error was 1% which is inside the design requirement of 2%.

Design requirement 3 – update display every 0.1 metresThe display can be updated at any rate from every single sensor pulse to any number of metres. The requirement for every 0.1 metre was selected to provide the operator with a balance between resolution and distraction. Updating the display at a lower metre value would increase resolution but having the display changing too fast would be distracting to the operator.

Method of testingLay a measuring tape on flat hard ground, start the machine at 0m and reset the display to 0. Start moving the machine and every time the display updates measure the distance on the measuring tape. Do this until the machine reaches 1 metre and record the results.

Results – test 3 Distance on tape Display distance % error0.102 0.1 20.196 0.2 20.298 0.3 0.660.402 0.4 0.50.503 0.5 0.60.595 0.6 0.80.699 0.7 0.20.802 0.8 0.30.900 0.9 0.01.002 1.0 0.2Table 4 – test 3 results

DiscussionThe results in the table above show similar a trend to the two previous results, as the distance increases the accuracy increases. The results show that the display updates every 0.1m with and minimum accuracy of 2% which is within the overall system error allowed. Readings in this test are small which could have led to larger errors.

Design requirement 4 – view display from 2 metresThis test will evaluate the LCD displays size and readability. The operator should not have to stare at the LCD to know have far has been travelled; a quick glance should be enough to get a clear reading.

21 | P a g e

Page 26: Report - Distance Counter

Method of testingThe display is mounted 2 metres away from the operator, the metre value on the display will be changed and the operator will be asked what each the value is. If the operator gets a single value wrong then the display is not clear enough at 2 metres and it will fail this design requirement.

Results – test 4Twenty different metre values were displayed on the LCD; the operator had to say what each one was. The operator had no problem viewing the display from 2 metres away and answered correctly for all values.

DiscussionThis is a simply yet important test to verify the clarity of the display. The operator had no problems with viewing the display. The display was so clear the operator could still clearly read it from 4 metres away.

Design requirement 5 – view display in all light conditionsThis test is similar to the last only it requires the display be subject to different levels of light. The sun can be very troublesome to LCD displays when it shines directly onto them. This display will be tested to ensure it is not affected by the sun.

Method of testingSubject the display to different levels of sunlight and different angles of sunlight to get a complete picture of its lighting capabilities. The first test will be to subject it to direct sunlight and have the operator read the display value, if the operator can read the display value this will be satisfactory. The display will be moved around at different angles to find a spot where it cannot be seem. The last test will be in the dark and the operator must be able to read the display.

Results test 5Lighting Condition View metre value?Direct sunlight YesSunlight at 45 degrees YesMorning sunlight direct YesMidday sunlight direct YesLow evening sunlight direct YesEvening dusk YesComplete darkness yesTable 5 – test 5 results

DiscussionThe tests show that the display could be viewed at different light levels. While carrying out the tests the display was clearly visible in all lighting conditions. This is due to the technology used in the display called “transflective”. This means that the display reflects the light during the day when the sun is shining and uses its built in backlight when the light levels drop. The result is that the display text is purple when the sun is shining on it and black when uses its own backlight.

22 | P a g e

Page 27: Report - Distance Counter

AssessmentThe distance counter design is a success and this was proved in the evaluation section, its main highlights are its accuracy, simple yet effective interface and easy to read display. Yet it has drawbacks, installation is complicated, the calibration process could be more automated and there could be more functionality in the device.

Design positivesThe accuracy error was almost 0% at the normal working distance and it was less than 2% at all other distances. This was the most important measurement for the design and went above and beyond what was expected. The display was very clear and easy to read at distance and under different light conditions. This is important because when working machines in the summer the sunlight can be very disruptive to LCD displays when directly shining on them. The display in this design resolves this with transflective technology that can reflect the sunlight off the text and make it completely visible.

The prototype shows how easy this system is to work; counting starts once the machine is moving and the reset button can be pressed at any time to reset the counter to zero. The counting modes offer an extra function to allow the operator count only when needed. The start-stop counting mode can be controlled by any event on the machine with a switch to signal the event. The prototype used a switch on the spout of the machine. When the spout is lowered the machine is going to spread turf and counter starts, when the spout is raised the turf spreading stops and so does the counter. This means the counter only counts while spreading turf.

Design negativesThis design is very positive but it does have some drawbacks. The installation of the sensor can be a difficult job because the sensor must be mounted in the gearbox and this means modification to the gearbox. In the prototype machine a hole was drilled in the side of the gearbox and the sensor was fixed in the hole. Installation of the sensor only needs to be carried out once and from that point of view is not a big problem.

The calibration process is a bit cumbersome, having to enter the calibration value with a potentiometer. Also having to re-enter the new calibration value should not be necessary. This process should only involve measuring out 100m then driving the machine the 100m and letting the microcontroller calculate the value needed. This is also a one off job though and will not be an issue for operators.

The prototype showed that the design is simple, having only one extra function. This could be improved to add other functions to make it more versatile. Although this would really be up to individual users, many users would prefer a simple system that is easy to use and reliable. Designs with more functions and complexity tend to be more difficult to use for new operators and less reliable.

Next StepsThis project would be useful to many turf cutting contractors especially in the west of Ireland where there are many more self-propelled turf cutting machines. There is further work needed on the design before it could be installed in these machines.

23 | P a g e

Page 28: Report - Distance Counter

1. Installation of proximity sensorA mounting system is needed for the proximity sensor to provide an easier installation process. A mounting bracket would not be complicated to design. The design and manufacture of the bracket could be carried out by an agricultural manufacturing company or by a mechanical engineer outside of their workplace.

2. Installation for microcontroller and displayThe microcontroller and LCD display need to be housed in a small tidy and rugged case. The case should have mounting brackets so it can be installed in a machines cab with four screws. The case could be metal or Perspex. A design engineer would be needed to make the case.

3. Wiring and installationThe sensor will be mounted in the chassis – gearbox section of the machine and the display will be in the cab. There will be cabling that is needed between the two. The cable must be properly sized and then properly routed through the machine to avoid getting damaged during operation. An electrician would be required to carry out this work. The electrician could also be hired to carry out the full installation if the bracket was made for the sensor and the case was made to house the display and microcontroller.

The work outlined above should be coordinated by a company manager who would contact the persons mentioned above to carry out the work outlined. They could also get their opinions as each would be experts in their own fields and might have information on how to reduce the cost of installation.

Appendices

Appendix A – Circuit DiagramThe complete circuit diagram is shown below. The sensor and switches are on the left, the MCU is in the middle and the LCD is on the right.

24 | P a g e

Page 29: Report - Distance Counter

The complete circuit diagram shows the circuit in full, it will be broken down below and each part of the circuit will be explained.

NOTE: See circuit parts for accurate diagram of “Mode Select” switch.

NOTE: See circuit parts for accurate diagram of “Sensor Input” circuit

Circuit parts:The following will show each part of the schematic on its own and explain what its function is and how it works.

25 | P a g e

Page 30: Report - Distance Counter

Power:

The power comes from a 12 volt battery; the 5v regulator is used on the inputs to the MCU. The circle with indicate 12v and the triangle will indicate 5v as shown above.

Sensor:

NOTE: This is the actual circuit a third resistor is added for protection.

The proximity sensor is symbolised above by the relay. When a metal object comes within the proximity sensors detection range (4mm) the switch will close. This will short the two bottom resistors and connect D2 to ground. When the switch is open the three resistors create a voltage divider dividing 12v by 3. This means 4v will be dropped across each resistor. The voltage at pin D2 will be 4v. Two resistors could have been used here as explained in the sensor section in the report but the third resistor protects the MCU. The proximity sensor actually has an open collector NPN transistor output and the 10k pull down resistor is connected to the collector. If 24v was connected to the

26 | P a g e

Page 31: Report - Distance Counter

collector the bottom two resistors will split this voltage in two and reduce the risk of damaging the MCU by overvoltage.

Reset Push Button

The reset circuit is used to prevent switch bounce from calling more than one reset interrupt when the button is pressed. The Schmitt trigger is used to add hysteresis to the circuit. Hysteresis means there is a voltage gap between a high and low output from the Schmitt trigger. As the input voltage increases from 0v to 5v the trigger point will be 3v. As the input voltage falls from 5v to 0v the trigger will be 2v. There is a 1v hysteresis gap; this prevents the output jumping between high and low. If there was a single crossover point at say 2.5v and the input voltage was hovering around this point the output would be constantly changing between high and low.

The Schmitt trigger is also an inverter, so in the circuit above when the switch is open and the capacitor is charged, the resistor is pulling the Schmitt trigger input to 5v and the inverter will output 0v to the pin D3. When the PB is pressed the Schmitt trigger will be connected to 0v and the output will be 5v which will be seen on pin D3. This will trigger the reset interrupt. The switch will bounce on and off for a few milliseconds but the capacitor is discharged when the switch is on and charges when it is off. This will keep the input voltage to the Schmitt trigger near zero until the switch stops bouncing. The capacitor will then charge to 5v and the Schmitt trigger will output a 0 to pin D3.

27 | P a g e

Page 32: Report - Distance Counter

Mode select switch

The mode select switch is a toggle switch which connects the pin D10 to 5v or 0v through the pull down resistor.

28 | P a g e

Page 33: Report - Distance Counter

Start – Stop switch

The start – stop mode uses a push button style switch which will be held closed by a mechanical mechanism and stay open when the mechanism moves the other way. The Schmitt trigger is used to invert the signal to the pin D11. A normally closed switch could be used instead and mechanism would open the switch to increment the counter. The Schmitt trigger is needed because the counter increments when it sees 5v on pin D11 and the switch outputs 0v when it is closed. This could be changed in software but it is more logical to do it this way.

Calibration potentiometer

29 | P a g e

Page 34: Report - Distance Counter

The potentiometer has an output voltage between 0 – 5v. The MCU has a 10 bit analogue to digital converter (ADC) that converts [0 – 5v] to [0 – 1023 value]. The digital value is used for the calibration value in the program. The potentiometer is read during setup and converted to a digital value. A command in software called ‘map’ can map the range [0 – 1023] to any range within the range 0 – 1023. For example 0 – 1023 is mapped to 0 – 200 in the distance counter.

Microcontroller:Below is the MCU, the pins are not in the correct positions relative to the Arduino Uno. The pin numbers are listed to allow the circuit be built using an Arduino Uno.

The diagram above shows the connection of the inputs (sensor, switches, etc) and LCD to the Arduino Uno and not the microcontroller itself. The pins on the Arduino Uno are given above inside the middle PDIP package.

30 | P a g e

Page 35: Report - Distance Counter

Liquid Crystal Display:

The potentiometer changes the contrast of the LCD display by changing the input voltage from 0 – 5v. The anode and cathode terminals are for the LED backlight which has a current limit of 300mA. A 2W resistor is used to limit the current to around 200mA. The limit from the battery and the resistor is around 380mA (I = V/R) but the LED will drop some voltage across it. This means there is less than 5v dropped across the resistor and then the current through it will be lower. In this case it was tested to be around 200mA.

31 | P a g e

Page 36: Report - Distance Counter

Appendix B – Theoretical System Accuracy

The system accuracy calculations are shown above. The important point to note is that the percentage error reduces to zero as the distance increases. Also note the distance error does not reduce as the distance increases. The distance error reduces in relation to the distance and thus the percentage error reduces.

32 | P a g e

Page 37: Report - Distance Counter

Appendix C – SoftwareThe software flow diagram is shown above in the implementation section. The actual code follows the flow diagram closely; the software code is also very well commented and does a good job of explaining what is happening. For these reasons the code will be included in the folder the report document will be presented in.

33 | P a g e