Radio Frequency Module on Small Gasoline Engine Application by Tian Huang A thesis submitted to the Graduate Faculty of Auburn University in partial fulfillment of the requirements for the Degree of Master of Science Auburn, Alabama May 05, 2013 Keywords: Radio Frequency, Gasoline Engine, Wireless Application, Microcontroller Copyright 2013 by Tian Huang Approved by Robert Dean, Chair, Associate Professor of Electrical Engineering Thomas Baginski, Professor of Electrical Engineering Michael Hamilton, Assistant Professor of Electrical Engineering ii Abstract Radio frequency communications applications are typically more applied than plain research in many aspects. A new application for radio frequency communications has been investigated for controlling the small gasoline engine on a lawn mower. The purpose of this application is proposed and its practicability is investigated. Circuit design is presented and the resulting printed circuit board is experimentally verified. The implementation cost is estimated and could possibly be further reduced. The design could be used in commercially manufactured lawn mowers and could potentially be the initial step in changing the way consumer lawn mowers operate. iii Acknowledgments I would like to thank my advisor, Dr. Robert Dean, without whom none of this work could have been done. I would also like to thank my research sponsor, Biggs & Stratton, for providing this great opportunity for me. Furthermore, I would like to thank Dr Thomas Baginski and Dr. Michael Hamilton for their guidance of my graduate studies. I would also like to thank William Abell, Aubrey Beal, Sidni Hale, Chong Li, Colin Stevens, John Tennet and Yu Wang for their generous help throughout this project. I am also appreciative of my parents and my beloved fianc?e, Amy Li, for their consistent support. iv Table of Contents Abstract ..................................................................................................................................... ii Acknowledgments .................................................................................................................... iii List of Tables ............................................................................................................................. v List of Illustrations ................................................................................................................... vi List of Abbreviations ............................................................................................................... vii Chapter 1 Introduction ............................................................................................................... 1 Chapter 2 Literature Review ..................................................................................................... 3 Section 1 Actuators and Solenoid ...................................................................................... 3 Section 2 Wireless approaches ........................................................................................... 5 Chapter 3 Problem Statement .................................................................................................. 10 Section 1 Principle of lawn mowers ................................................................................ 10 Section 2 Customer?s requirement ................................................................................... 12 Section 3 Comparison between the devices ..................................................................... 14 Section 4 Realization of the wireless system ................................................................... 17 Chapter 4 System Development .............................................................................................. 20 Section 1 Working principle ............................................................................................ 20 Section 2 Circuit Design .................................................................................................. 21 Section 3 H bridge block with logic ................................................................................ 37 Section 4 Circuit board installation.................................................................................. 44 v Section 5 Mechanical Design .......................................................................................... 49 Section 6 Integration ........................................................................................................ 61 Chapter 5 Testing and Results ................................................................................................. 67 Section 1 Assembling....................................................................................................... 67 Section 2 Product safety .................................................................................................. 68 Section 3 Power consumption .......................................................................................... 69 Chapter 6 Conclusions ............................................................................................................. 71 Chapter 7 Future Work ............................................................................................................ 72 Section 1 Duplex transmission ........................................................................................ 72 Section 2 Add sensors to the engine ................................................................................ 72 Section 3 Safety protections ............................................................................................ 74 Section 4 Power source on the transmitter end ................................................................ 75 References ............................................................................................................................... 76 Appendix A transmitter end MPLAB code ............................................................................. 77 Appendix B Receiver end MPLAB code ................................................................................ 79 vi List of Tables Table 1 Truth table of NOR gate ........................................................................................... 42 vii List of Figures Figure 1: Solenoid. .................................................................................................................... 4 Figure 2.The two sides of transmitter (upper) and receiver (lower) ........................................ 22 Figure 3. Transmitter circuit bread board. ............................................................................... 23 Figure 4 Receiving circuit bread board ................................................................................... 23 Figure 5. Waveform of the transmission at both ends ............................................................. 24 Figure 6. Pin assignment of dsPIC18F2455 ............................................................................ 25 Figure 7 Schematic of transmitter end MCU configuration .................................................... 27 Figure 8 Printed circuit board design of the transmitter .......................................................... 28 Figure 9. Actual printed circuit board (back and forth) ........................................................... 29 Figure 10. Printed circuit board with components .................................................................. 29 Figure 11 Flow chart of state machine in MCU ...................................................................... 31 Figure 12 State chart of start machine in MCU ....................................................................... 31 Figure 13 the receiver board schematic ................................................................................... 34 Figure 14 PCB design of the receiver board............................................................................ 35 Figure 15 Actual print circuit board ........................................................................................ 36 Figure 16 Actual printed circuit board with component on. .................................................... 36 Figure 17 H bridge for the solenoid ........................................................................................ 37 Figure 18 Full H bridge control circuit .................................................................................... 39 Figure 20 Current flows through the solenoid ......................................................................... 41 Figure 21 Voltage drop across the solenoid ............................................................................. 42 viii Figure 22 NOR logic schematic .............................................................................................. 43 Figure 23 modified PCB design with logic ............................................................................. 44 Figure 24 transmitter attachment plate .................................................................................... 45 Figure 25 the attachment plate on the handle bar control ........................................................ 46 Figure 26 Transmitter attachment plate with the board ........................................................... 46 Figure 27 Handle bar on the final product ............................................................................... 47 Figure 28 Box with the plastic plate ........................................................................................ 48 Figure 29 Box with the board and the plate ............................................................................ 49 Figure 30 linear regression of the spring ................................................................................. 50 Figure 31 spring constant ........................................................................................................ 51 Figure 32 solenoids alignment in opening position ................................................................. 56 Figure 33 solenoids alignment in closing position .................................................................. 57 Figure 34 connect point of switch and the solenoid junction .................................................. 57 Figure 35 the cable between the movable adjusting screw and the flat shelf .......................... 58 Figure 36 schematic of the solenoid control ............................................................................ 59 Figure 37 wire configuration and wire connectors .................................................................. 60 Figure 38 control end power line ............................................................................................. 62 Figure 39 Handle bar with the control button.......................................................................... 63 Figure 40 Handle bar without the control button .................................................................... 63 Figure 41 fuses to protect the battery ...................................................................................... 64 Figure 42 Function board box with the lid covered ................................................................. 65 Figure 43 back view of the final product ................................................................................. 67 ix Figure 44 Front view of the final product ............................................................................... 68 x List of Abbreviations ASK Amplitude-shift Keying MCU Microcontroller Unit LCD Liquid Crystal Display USART Universal Synchronous/Asynchronous Receiver/Transmitter WPAN Wireless Personal Area Network IEEE Institute of Electrical and Electronics Engineers RF Radio Frequency PCB Print Circuit Board LED light-emitting diode MOSFET Metal Oxide Semiconductor Field Effect Transistor 1 Chapter 1 Introduction As the development of industrial machinery, more and more electrical circuit had been integrated into the mechanical design in order to realize more function of the machine. There are lots of electronic applications that could make the original machine more convenient to use. This is the trend of development in engineering industry. Thus, a new design is brought to improve the performance of a lawn mower, a common engine that used in daily life, to enhance the reliability and extend the product life of the engine. The primary purpose of this system is to replace the original mechanical cable with a wireless transmission system to control the engine without lift the cost of the product significantly at the same time. The system should also have the same reliability and product life as the metal cable. Background information, including possible mechanical and electrical devices in this application is introduced. The customer?s requirement and the comparison among the possible approaches are indicated and analyzed. The CPSC government safety regulation is also introduced. The system design and optimize is also provided including two parts, electrical design and mechanical design. Electrical design includes circuit design, schematic, print circuit board layout and the actual product illustration. The transmission is in 434M Hz in ASK modulation. Microcontrollers are used to control the RF transmitter and receiver. The principle is explained and the MCU program code is in the appendix A and B. Mechanical 2 design includes introduction of primary and secondary solenoid and solenoids alignment, system integration and safety protection. Testing results are also provided to evaluate the product. Future work planning is also listed in order to improve the product from this stage. 3 Chapter 2 Literature Review Section 1 Actuators and Solenoid Actuators are devices that can produce linear or rotating force by consuming energy in another form. [1] Electromagnets, solenoids and stepper motors are typical kinds of actuators and were investigated in this application. The electromagnet is a very common actuator that can convert electricity to physical motion by utilizing the Lorentz force generated by the magnetic field. Usually, however, it?s applied in relays and doesn?t perform well in heavy duty applications. In this particular design, the electromagnet will consume too much electricity and drain down the battery very quickly, which makes it not very suitable for this application. The solenoid is a kind of actuator that is specifically designed for providing linear motion and is electromechanically (AC or DC) driven. The major difference between DC solenoids and DC motors is that the former one doesn?t rotate. Also, the power usage of the DC solenoid is much smaller than with a DC motor, which makes it so that it could be assisted by a spring. Figure 1 shows a photograph of one of the solenoids tested in this project. 4 Figure 1: Solenoid. The principle of the solenoid is similar to that of an electromagnet. The solenoid consists of ferromagnetic shaft, an electromagnet and a well where the shaft is placed. The electromagnet?s coiled wires are inside the solenoid around the well. Two electrodes are connected to the electromagnet. The shaft could move into or out of the well without any friction if no voltage is applied. If there is a sufficiently high voltage applied across the device, a magnetic field will be generated by the electromagnet and start to affect the ferromagnetic shaft by the Lorentz force. With high enough voltage, the magnetic field is strong enough to pull the metal shaft back into or to push it out of the well. One kind of solenoid, a latching solenoid, could also be applied a forward or a reverse bias so that it could either generate a complementary or an opposing magnetic field in regard to an integrated permanent magnet, so that the shaft can be pulled into the well and held there by the permanent magnet without continued power applied to the coil, until the opposite polarity current is applied to the electromagnet to release the shaft from being held. A mechanical load could be attached at the opening end of the shaft so that the solenoid could drive the load linearly by the control voltage applied to the solenoid. The force 5 providing by the solenoid is determined by the voltage applied and therefore the current it consumes. Solenoids can be categorized into two types, permanent magnet or residual magnet. The main difference among these two categories is if it consumes power to latch the shaft and hold it. A permanent magnet can latch the metal core and hold the shaft in place without using any externally supplied power while the residual ones cannot. A stepper motor is another kind of actuator that provides rotating motion. It is powered by electricity and is controlled by current pulses at a certain frequency. In non-overload circumstances, the position and the rotational speed is only determined by the frequency and the number of pulses. Every pulse will drive it to rotate a certain angle amount and it can therefore be more accurately controlled than the solenoid. Furthermore, it can produce much more force than a solenoid could. However, the reason that the solenoid was chosen over the stepper motor is that a stepper motor requires a certain H bridge chip to match the device while solenoid doesn?t. Also, the price of a stepper motor is much higher than a solenoid, which doesn?t match the customer driven purpose of this design. Section 2 Wireless approaches Wireless communication utilizes radiated electromagnetic energy instead of a conventional cable to transmit signals and data. Wireless communication schemes have two main categories, microwave communication and satellite communication, and the former one is widely applied in mobile communications. IEEE passed standard 802.11 for wireless local area networks and mainly defined the standard in the physical layer and the MAC layer (Media 6 Access Control). Three methods are specified in the MAC layer, including spread spectrum technology, infrared technology and narrow band technology. The wireless business has been expanding rapidly ever since, including Bluetooth, third generation and fourth generation wireless communications and so forth. Several approaches are considered to realize this application, including regular electronic methods like Bluetooth, zigbee and RF transmission links. An optical approach has been considered as well. Also, using an infrared source and detector could be another low cost way to realize the application. Bluetooth Bluetooth is a WPAN (Wireless Personal Area Network) standard for communicating over short distances, usually within several meters. It has been integrated into lots of personal devices like laptop, cell phone and wireless headsets. Bluetooth was first developed by Ericsson in 1994 and then the Bluetooth 1.0 version was released in 1999. Then the next version of Bluetooth (Bluetooth 1.1 and 1.2) became IEEE standard 802.15.1-2002 and standard 802.15.1-2005, respectively. [2] The second version of Bluetooth came out several years later and provided an enhanced data rate greater than the first version, and the third version of Bluetooth (4.0) was released recently. In Bluetooth 4.0, transmission of large amounts of data can be much faster than Bluetooth 2.0 or 1.0 while keeping the power consumption of these technologies low as well. Bluetooth devices? frequency range is 2.4015 to 2.4805 GHz and they support point-to-point and point-to-multipoint connections. Two or more devices could form a piconet 7 where one of them is the master and the rest are the slaves in this connection session. All the devices in a piconet are synchronized by the master device's clock. One device could be in more than one piconet at the same time. One device could be the master in one piconet and a slave in the other piconet simultaneously. There's no outstanding documentation that so far indicates that a Bluetooth has ever been used on a small gasoline engine like in this application before. Zigbee Zigbee is a series of WPAN protocols that support mash, star and tree topologies. The frequency band is 2.400 GHz to 2.4835 GHz and the corresponding data rate is 250K bps with O-QPSK modulation. [2] The Zigbee standard includes self-healing and self-configuration features. Self-healing means that the connection between zigbee devices can dynamically update connection and prevent route failure. Self-configuration means it can detect additional new devices and update the best path in the network accordingly. Compared to Bluetooth devices, zigbee devices are cheaper but have lower data rates. There is also no documentation at this point that suggests that zigbee technology has been applied to this type of application. Other RF Links RF is the frequency range from roughly 300 KHz to 30 GHz. Bluetooth is one particular widely used radio frequency application, and other devices that work in lower frequency bands are very common as well. Usually they use between 300 MHz and 1 GHz, and the modulation method varies. [3] 8 Typically an RF system contains a transmitter and a receiver, which usually works in simplex operation or it could contain two transceivers which usually work in half-duplex or duplex operation[3][4]. Transceivers are devices that can both transmit and receive signals when properly used. The frequency of every application varies and so does the modulation method. The configuration of the RF link will be similar to the zigbee or Bluetooth systems. There is one transmitter and a receiver which work in the same frequency in a typical system. Compared to the former two, RF links are more commercialized in the marketplace and easier to develop. Furthermore, the cost of lower frequency RF devices would also be the lowest cost of the three methods. However, the data rate of RF links is usually unsatisfactory low for many modern applications like data transmission or data processing. Radio frequency links are used in lots of similar applications, such as remote control, remote car entry, etc. Lots of off the shelf modules could realize the similar function in this project, although a lawn mower that is based on wireless transmission had not been previously developed. Infrared data transmission Infrared is an invisible light whose wavelength is longer than the color red. Infrared transmission utilizing a transmitter that can generate a 950nm wavelength of light as the carrier wave and pulse position modulation, can modulate the binary data into a pulse sequence at a certain frequency. The pulse will modulate the infrared emission tube and send the carrier wave in optical light. The receiver will convert the optical signal into an electronic signal. After amplification, filtering and demodulation, the message signal will be recovered. 9 The data rate of the infrared transmission is up to 4 Mbps. The major limitation of this method is that the transmitter has to point to the receiver directly and precisely. Also, since the signal is light based, the power of transmission will attenuate significantly when the transmission length exceeds 1 meter. Likewise, infrared transmission has not being used in an application involving a small gasoline engine. Section 3 Wireless Control System A wireless control system is a series of system components that are based on wireless modules and certain transmission protocol that accomplish desired actions via remotely control. Techniques such as WIFI, Bluetooth and radio frequency are commonly used in normal applications. Wireless control systems usually contain a transmitter and one or more receivers. The transmitter could be based on a microcontroller or any interface. Sensors could also be added to be the source of the transmitter. The receiver is usually connected to the processer and controls other components like actuators accordingly. Wireless control is widely applied in many aspects such as remote car door entry, TV remote controls and wireless keyboards. Usually it operates in the high frequency band of 2.4 GHz or lower. 10 Chapter 3 Problem Statement Section 1 Principle of lawn mowers The purpose of this work is to improve the gasoline powered lawnmower system by replacing the mechanical engine control cable with a wireless transmission in order to enhance performance and lower the product cost. Additionally, integrated sensors based on the wireless system could be added to monitor the operating condition of the engine or blade. There are two kinds of widely used lawnmowers in the marketplace, the first one is called a push mower and the second one is called a riding mower. The lawnmower in this project is a push mower which is manufactured by Tory-Bilt? with a Briggs & Stratton one cylinder, four-cycle internal combustion engine. The model number of the machine is Troy-Bilt? 12AGA26E011 with Briggs & Stratton BBSXS 1901VH family engine. A push mower requires a person standing right behind the mower and placing the hands on the handle bar to push it during operation. There?s a lever system placed on the handle bar which controls the brake of the engine. Furthermore, in order to make the lawn mower move, the operator has to push or pull the handle bar. There's a spinning blade in the bottom of the mower which is connected to the shaft of the engine. Once it's powered on, the running speed of the blade could reach more than 120 revolutions per minute. Grass is usually considered as heavy load, so it could be very dangerous if lawn mower is misused. Normally, a push mower has a handle bar with a lever mechanism attached above it. This lever system is connected to a mechanical switch located near the engine through a metal cable. The switch, which is placed at the end of the cable, has two positions, one is open and the 11 other one is closed. This mechanical switch contains a brake and two circuit switches which control the starter motor and the spark plug, respectively. It is attached to a spring on the engine which will usually keep the mechanical switch off. If the switch is off, the friction of the brake will keep the flywheel in place, the spark plug grounded and the starter motor cut off. In order to prevent any injury hazard, CPSC blade safety regulation [8] requires that the push mower should be initiated by two separate steps: releasing the brake and ignition. It is also indicated in the safety regulation that after the operator is away from the lawn mower, the engine has to be shut down completely in three seconds. This feature prevents the rotary blade from operating unless the operator actuates the control. CPSC blade safety regulations also require a foot shield which is the area at the rear of the mower that might be reached by the foot when using the mower. Mowers are subjected to a probing test using a foot-like probe. A label with ?Meets CPSC blade safety requirements? is also required to be attached on the machine. When the handle is pushed down and held in place, the lever system will conduct the holding force that comes from operator?s hands and turn on the switch. If the switch is being pulled, it will turn to another angle and release the brake from the flywheel. Also if the switch is on, the circuit switch is also turned on physically which will disconnect the spark plug from ground and make it possible for ignition. The starter motor is also ready to be turned on and waiting for the operator?s further motion. However, the engine will not be started until it's ignited. This is the first step of starting the engine. After the handle bar is pulled, the engine is ready to be ignited by either pulling the cord connected to the flywheel or by turning the key for the starter motor to initiate the flywheel electronically. Only the later one consumes electricity and that's the reason why this 12 lawnmower model is equipped with a battery. The engine is ignited when the flywheel starts spinning and begins to consume gasoline. This is the second step in starting the engine. At this time, the coil near the flywheel will react with the magnet on the flywheel and generate electricity. This AC voltage powers the spark plug which means the engine only consumes gasoline from this point. The handle bar should be pulled consistently in order to continue operating the mower. If the handle bar is released, intentionally or unintentionally, the mechanical switch which is connected to the bar by a metal cable will turn back off, ground the spark plug and apply the brake immediately. On one hand, the air pressure in the cylinder of the engine will rise significantly and prevent the piston from further reciprocating action and finally stop. On the other hand, when the mechanism switch is put back to its original position, the brake will apply to the flywheel and stop it due to the friction. This could protect the user who is operating the mower from unexpectedly falling down or other occasions where the operator has to be away from the machine. These two methods ensure that the cutting blade will be stopped completely within 3 seconds to prevent anybody from getting injured form the cutting blade and it meets the safety regulations. This is a typical protection system which is applied on most lawnmowers manufactured and used at this time. Section 2 Customer?s requirement Usually the mechanical cable and other connections cost roughly $9. However, they are more likely to wear out compared to the other parts of the mower which makes the cable 13 system a main reason that the mower breaks down. The customer suggests that if a wireless module could be integrated on the machine to replace the cable mechanism system of the original design, it would improve the performance and enhance the reliability. A wireless system is required to realize the exact function as the cable. One of the approaches is to design a system that includes a transmitter at the handle bar and a motor which is powerful enough to hold and release the switch against the spring and the motor should be controlled by the receiver near the engine. Also, the system has to meet the safety regulation in order to implement it on a commercial product. [7][8] Furthermore, after electronic devices, processors for instance, are on board; further improvement could be developed in the future. By using the wireless transmitting system, more data other than on and off commands could be transmitted though the wireless transmission. By adding sensors to the engine and an LCD at the handle bar, the operator could monitor the gasoline that remains in the engine, see if the oil needs to be changed or monitor the operation temperature and so forth. With electronic devices integrated in the engine, certain criteria have to be established to evaluate if it?s an appropriate design. Safety is the primary concern of this system. According to the CPSC blade safety regulation [8] under no circumstance should the engine be operating unexpectedly, additionally, if the handle bar is released, the engine should be shut down completely in 3 seconds. And since it?s a replacement of the cable system which is very stable, stability is also very important to this design. The product life with the new design should at least last as long as the mechanical system does. It also should be robust enough to resist any influence from 14 vibration, electronic or magnetic fields, and humid weather like the cable mechanism does. The system should be easy to maintain like the cable. Thirdly, the wireless transmission can?t cause any interference to other mowers and can?t be interfered with by any other devices operating at the same frequency. After pushing the button of the handle bar, only the receiver on the same mower should respond to this transmission code. Finally, the cost of this system should be comparable to a metal cable system, which is usually $9 each in order to make this product profitable. Section 3 Comparison between the devices All the wireless approaches have been considered and the presumptions of all the devices are as follows. Bluetooth technology If Bluetooth technology is used, one Bluetooth transmitter could be placed on the handle bar side of the mower and a receiver could be placed near the engine. They could send out signals in simplex mode or duplex mode. And, with proper coding and frequency band assignment, there will be no interference with other Bluetooth devices nearby. Bluetooth devices can provide stable communications in normal circumstances. Additionally, further development could make the product more competitive in the marketplace. If a Bluetooth module is applied, it?s possible to control and monitor the lawn mower by one?s smart phone or other portable device with a Bluetooth module. The user could download an application to realize that. Also, with a powerful MCU, the mower could record 15 the grass cutting session information and upload the data to a computer, send it online, and be gather by the manufacturer to evaluate the performance of the lawn mower. However, the cost of this application will be the highest of all these approaches and the development time is much longer than other approaches because normally, Bluetooth technology is used to realize more complex communication. However, this doesn?t mean it?s not an accessible approach in future designs. If more functionality is required or the cost of the Bluetooth devices goes down significantly, Bluetooth could still be a reasonable approach to consider. Zigbee devices Zigbee device application is similar to Bluetooth application: place one terminal on the handle bar and another near the engine. Compared to the Bluetooth technology, Zigbee devices cost less but still require a fairly long time to develop and likewise, Zigbee devices have the capability to be upgraded to more complicated systems. Infrared transmission Infrared transmission is a very promising approach in this application. The configuration of this system is different from the electrical approaches. At the top of the handle bar an infrared emitter would be pointed right at the detector mounted at the engine. As long as the detector is receiving the infrared signal, it will keep the engine on. However, since the lawn mower is operated outdoors, the optical transmission could be easily blocked by leaves or dust. In order to avoid unexpected engine shut down for this reason, two emitters and two detectors should be used and be placed in different locations. This will nearly double the cost of it, but the price will still be reasonable compared to other 16 approaches. However, infrared devices are easily interfered with if exposed to the environment, which might cause unsafe operation or unexpected engine turn on or off. Another short coming of infrared communication is that it could not be easily upgraded to a duplex transmission system and the data speed is much lower than the other transmission techniques. RF transmission Similar to Zigbee and Bluetooth technology, RF transmission requires a transmitter on the top of the handle bar and a receiver near the engine. A MCU will be equipped with each device to control the behavior of the transmitter or the receiver. To realize this application, an RF device was chosen over Bluetooth, zigbee devices or infrared devices for the following reasons. First of all, various radio frequency transmitters and receivers are available off the shelf, Zigbee and Bluetooth devices on the other hand usually requires more development time, including PC board design, MCU coding and further testing. Some companies do offer evaluation boards or study boards for their zigbee chips, but using RF devices could save months of chip integration and reliability testing. Secondly, the price of building up an RF link is as much as 30% cheaper than to build up a 2.4 GHz transmission link. Since it?s a consumer commercialization application, the cost of the system should be as low as possible. This makes the RF approach the best option among these three technologies. Furthermore, the principle and the protocol of RF links are much less complicated than the other two techniques, which means it?s easier to maintain the system and to make 17 further improvements. Finally, although the transmission speed of the RF link (normally less than 8 Kbps) is slower than Bluetooth (2 Mbps) and Zigbee (256 Kbps) devices, the data rate required in this application is less than 1 Kbps, which means the data rate of the RF system is sufficient to support this transmission and still have the potential for further improvements. And compared to infrared devices, electrical transmission is more stable and has more ability to integrate additional functions. Section 4 Realization of the wireless system The whole system contains four basic function blocks: transmission control, receiving control, h bridge switch and the solenoid attachment. Transmission and receiving control The core of the transmission control is the RF transmitter which is controlled by an MCU. The MCU sends a coded signal to the transmitter and the signal is modulated in ASK modulation by the transmitter and sent to the receiver with a data rate of 8 Kbps. Since both the MCU and the transmitter should be powered by a 5V DC voltage supply, and the only power source is the 12V DC battery near the engine, a voltage regulator is applied to convert 12V DC to 5V DC. The receiver control is very similar to the transmitter control. It contains an RF receiver, an MCU and a voltage regulator just like the transmitter control does. The receiver will receive and demodulate the signal in a certain frequency and send the message to the MCU. The MCU is used to analysis the signal that the receiver receives and then sends out the 18 control bit to the h bridge accordingly. H bridge switch The h bridge consists of one integrated NOR gate based logic circuit which includes 4 NOR logic gates, and one integrated MOSFET assembly which includes two NMOSFETs and two complementary PMOSFETs. These four MOSFETs, which are controlled by the logic which is controlled by the MCU, function as a switch. It will turn on or off the solenoid by the instructions that the MCU sends out. Although it?s unlikely, if the two control nodes of the MOSFETs are set to high at the same time, the voltage supply (battery) will connect directly to the ground through the h bridge and cause the device burn up. The NOR logic circuit is therefore applied to protect the MOSFETs. If the two nodes of the MCU are set to high at the same time due to a malfunction, the logic will set the two inputs of the MOSFETs gates to low so that although the circuit is not functioning properly, it will not cause any damage to the components. Since the h bridge and the logic are controlled directly by the receiver MCU, these two blocks share the same printed circuit board to reduce manufacturing costs and to enhance the reliability of this system. Solenoid attachment Solenoids are attached to the switch to move it between the off and on positions. In this application, both a non-latching solenoid and a latching solenoid are used to provide enough force to turn on or hold the switch. Usually, a solenoid that can provide this much force requires a lot of current to power it. These two solenoids combined will consume 3A of current for one second, which can?t be 19 provided by the MCU. An H bridge circuit is introduced that uses MCU signals to control the solenoid. 20 Chapter 4 System Development Section 1 Working principle The working principle of this design is as follows: a pushbutton switch is placed on the top of the handle bar lever. When the switch is pressed, the transmitter (controlled by the MCU) on the handle bar will be powered up and begin to send out a one byte signal constantly. If the receiver receives this particular signal two times in a row, the MCU on the receiver end will recognize the signal and send out the control bit to the h bridge block with logic, power up both solenoids for exactly 0.6 seconds, which is sufficient for the solenoid to pull the shaft into the well and keep the switch on. After that, the latching solenoid will provide enough holding force to keep the switch in place against the spring force without consuming electricity. During operation the receiver will keep looking for the signal that is sent from the handle bar transmitter. The receiver control MCU will not send out any command bits in this session and there would be no voltage applied on the solenoid during operation. The latching solenoid will hold the switch and keep the engine on as long as the status is not changed. At the same time, due to radio frequency noise and other white noise outdoors, the system is designed to have a signal blocking tolerance. The MCU will send out control bits to shut off the engine only if the receiver misses 120 signals in a row (approximately 0.6 second). If the button is released, the transmitter will stop the transmission immediately because it?s disconnected from the power and after about 0.6 second, the receiver control MCU will time out and send another signal to the h bridge to apply a reverse voltage to the latching solenoid and shut down the engine. The signal blocking tolerant time is 0.6 second and normally the 21 influence of regular noise doesn?t last that long. And even with a 0.6 seconds delay, the mechanical system can still shut down the engine completely within 3 seconds. Another switch is designed on the receiver end board in order to extend the battery life. Both boards should be powered up by the same battery since adding another voltage source would raise the cost of the product and increase the difficulty of maintenance. Section 2 Circuit Design Transmitter and receiver pair This application requires a wireless transmission system that works within 1 meter and the transmission should be able to be encrypted or coded so that it won?t interfere with similar devices on other engines. Plus, cost should also be taken into consideration. After comparison of several possible devices and elimination of other devices that don?t meet the criteria, a transmitter and receiver pair is chosen because this kind of device is relatively cheap in price, possesses lots of available resources and is easy to maintain. The transmission pair is manufactured by Wenshing Electronics CO and the part number is TWS-BS-3 (transmitter) and RWS-371-6 (receiver). They operate at 434 MHz with ASK modulation at 5 volts and the transmitting distance is 500 feet at perfect conditions. They also offer other transmitter-receiver pairs online in different modulation frequencies and data rates. The picture of both sides of both devices is shown in Figure 2. The retail price of this pair is $6.8 , and with large orders the price should go down 30%. 22 Figure 2.The two sides of transmitter (upper) and receiver (lower) The working principle of this pair is relatively simple. The transmitter can modulate ASCII code in ASK modulation and transmit the signal at 434. 8MHz with a 4.8 Kbps data rate. This data rate allows it to send out 600 control bits per second, which makes the system achieve an accuracy of 1.6ms. The pin assignment of the transmitter (upper left corner) is ground, data in, power and antenna (from left to the right), and the pin assignment of the receiver (lower left corner) is antenna, ground, ground, power, power, linear out (which is not connected in this case), digital output and ground (from top to the bottom). In perfect conditions, the transmission of these devices could reach 500 ft of distance (close to 150 meters). In this situation, an antenna is required. In order to achieve optimal 23 transmission, the length of the antenna should be a quarter of the wavelength. Using the following formula: ?=v/f, (1) where ? is the wavelength, v is the speed of this wave which in this case is the speed of light and f is the frequency of this wave which is 434 MHz The wavelength of this transmission is 0.691m; so the length of the antenna should be 0.173m. However, in this case the transmission distance is much shorter than the device is designed for. An antenna could be added to enhance the transmission quality, but not necessary. The output power is sufficient to support transmission up to 1m. So in this design the antenna at both ends is not connected. Figures 3 and 4 shows the testing circuit on a bread board. Figure 3. Transmitter circuit bread board. Figure 4 Receiving circuit bread board 24 In this application, the number ?3? is chosen to be the transmission coded signal. ?3? is number 51(Dec) in ASCII code which is 00110011 in binary. And the MCU has added three header bits at the beginning of the signal due to the communication protocol, therefore the waveform of the signal becomes little longer than expected. Figure 5 is the waveform that is observed from the scope when the experiment is conducted on a bread board. The yellow line on the top is the receiver end after demodulation and the green line on the bottom is the transmitter end before modulation. The header bits are 011 and followed by the actual message 00110011. Figure 5. Waveform of the transmission at both ends There?s a screw at the back of the receiver to tune the receiving frequency. If distortion on the scope is observed it means the device needs to be tuned. Transmission control The MCU is a very significant part of this design. At the transmitter end, the MCU controls which code should be transmitted, and at the receiver end, the MCU is used to recognize the signal after demodulation and to make certain it responds accordingly. The MCU in this application is the dsPIC18F2455 manufactured by Microchip 25 Technology. This MCU is a 28-pin 16 bits microcontroller with 24KB of flash memory and 24 I/O pins and integrated with an internal oscillator, but it also supports external oscillators. Other characteristics of this microcontroller include an enhanced USART module, and dual analog comparators with input multiplexing, and an in-circuit debugger is available in this device. There are two packaging options for this device and the price of this kind of MCU is $3.94 each for 28-dip and $3.74 each for surface mount. The 28-dip package is used in this application. MCU coding is performed using the MPLAB X environment with a C complier. To debug or program the DsPIC18F2455 device, PICkit devices are needed, in this application a PICkit 3 is used. To program or debug the MCU, a certain configuration is required. Pin No.1, 27, 28, are connected to the PICkit 3, note that pin 27 and 28 are program pins and pin No.1 is the main clear and when it?s enabled the MCU is not working. Figure 6 shows the pin assignment of a dcPIC18F2455 device. [9] Figure 6. Pin assignment of dsPIC18F2455 Although it has an internal oscillator integrated in the device, an external oscillator will stabilize the transmission and make it easier to synchronize. So an oscillator is used in this 26 circuit with the MCU. USART is the core part of transmission. USART is short for universal synchronous / asynchronous receiver / transmitter. It is a duplex transceiver module that can translate data between parallel and serial forms. The function of the transmitter MCU is to send the signal ?3? every 5ms. The transmitter will open the USART module and translate the number into ASCII code and send it to the transmitter through the TX pin. Also, the system has a power on indicator which is an output pin which will set to digital 1 when the MCU is functioning properly. This pin is connected to an LED and a resistor. After the device is powered on and running correctly, the LED will be on to indicate that the transmitter is in operation. The MCU programming code is attached in appendix I. During operation, pin No. 1, the MCLR (Main clear) pin, should always be pulled high during operation. Pin No. 8 and 19 are connected to ground. Pins No. 9 and 10 are connected to the external 8 MHz crystal oscillator. Pin No. 17 is the transmit bit of the USART module and should be connected to the transmitter. The schematic is shown in Figure 7, excluding the voltage regulator. 27 Figure 7 Schematic of transmitter end MCU configuration The voltage regulator is manufactured by Texas Instruments and the model number is LM341T50 which is a 3 pin through-hole device. The configuration of it is relatively simple. For 12V input and 5V output circumstances, a 0.1uF capacitor is needed between the output and the ground, another 0.33uF capacitor between the input and ground is sufficient to stabilize the voltage regulator. However, the device will still function correctly without the capacitors. The PC board design is shown in Figure 8. All of the function blocks are shown in this circuit. This is a typical 2 layers printed circuit board design with a ground plane in the middle. From the top left corner is the ICSP block which is a 6-pin interface. This allows the PICkit 3 device to communicate the program and to debug the MCU. C11 to C14 are capacitors that function as a high pass filter to block low frequency noise. The value of these four capacitors is 1uF. C9 and C10 are capacitors for the voltage regulator and the value of them is 28 0.1uF and 0.33uF respectively. LED3 is a power on indicator and R8 is the resistor associated with it. If the board is connected to the power, the LED will emit and stay on until the power is turned off. The MCU2 block is for the MCU. LED2 is a transmission indicator; it will begin to emit when the MCU is sending signals to the transmitter. OSC is for the crystal oscillator, with two capacitors on each pin of it. When an 8 MHz oscillator is utilized, the capacitances of these two capacitors should both be 22uF. Trans1 is for the 4 pin transmitter, and although the antenna is not required, the ant2 lock is still reserved for unforeseen future uses. Dr11 to Dr14 are drill holes to attach the board to the handle bar. In the red rectangle there?s the buried metal as the common ground. Any node will be grounded if it directly connects to the metal layer. Figure 8 Printed circuit board design of the transmitter Figure 9 and 10 shows the actual printed circuit board (back and forth) and the one with all the components soldered on the board respectively. 29 Figure 9. Actual printed circuit board (back and forth) Figure 10. Printed circuit board with components Receiver control In the receiver end, the debug configuration is the same as the transmitter MCU. The MCU is connected to the ICSP interface. And very similar to the transmitter, a crystal oscillator and voltage regulator are needed for the MCU. [10] The function of the receiver end MCU is to keep track what the receiver receives from the transmitter, recognize and respond. If it keeps getting the right signal, it will control the MOSFETs to initiate the engine. Since the latching solenoid is used in this system, the device couldn?t be powered on all the time, which will not only reduce the battery life, but also 30 damage the solenoid. The solenoids in this application are both intermittent ones, which means they have a certain duty cycle and exceeding the duty cycle could result in overheating and solenoid failure. So programming the MCU as a finite state machine is an appropriate approach for this system. The flow chart is shown in Figure 11 and the state diagram is shown in Figure 12. S t a r t E n g i n e O f f P o r t 1 = 0 P o r t 2 = 0 R e c e i v i n g a ? 3 ? ? N o S w i t c h O n Y e s P o r t 1 = 1 P o r t 2 = 0 E n g i n e O n K e e p r e c e i v i n g ? 3 ? ? Y e s I n t e r r u p t N o K e e p R e c e i v i n g ? 3 ? ? P o r t 1 = 0 P o r t 2 = 0 P o r t 1 = 0 P o r t 2 = 0 Y e s T i m e O u t N o S w i t c h o f f E n d P o r t 1 = 0 P o r t 2 = 1 P o r t 1 = 0 P o r t 2 = 0 31 Figure 11 Flow chart of state machine in MCU S 1 / 0 , 0 S 2 / 1 , 0 S 3 / 0 , 0 S 4 / 0 , 0 S 5 / 0 , 0 S 6 / 0 , 1 C o n d i t i o n : if a ? 3 ? is re c e iv e d 0 1 0 00 1 1 1 Figure 12 State chart of start machine in MCU The state machine has six states including ?engine off?, ?switch on?, ?engine on?, ?interrupt?, ?time out? and ?switch off?. The state of the MCU determines the two output status, pin No.7 (RA5) and pin No.11 (RC0). These two pins connect directly to the logic and control the h bridge. If both pins are set to logic 0, there will be no voltage difference between the two outputs of the h bridge. If RA5 is set to logic 1, it will apply a forward voltage to it. On the contrary, if RC0 is set to logic 1, a reverse bias will be applied. Because of the NOR logic gates, two terminals of the H bridge could not be set to logic 1 at the same time to avoid the MOSFETs burning out. After the MCU is powered up, it will stay at the ?engine off? state by default; both control pins (RA5 of port A and RC0 of port C) are set to low at this time, which means there?s no voltage difference across the solenoid. The MCU will remain in this state until the transmitter end is powered up and starts to send the signal (the number ?3? in ASCII code). The receiver will receive the beacon and the MCU will recognize it and proceed to move on to the next state ?switch on?. At ?switch on? state, one of the two control pins (RA5) will remain low and the other one (RC0) will be set to high for 0.6 second. That will cause a 12V DC voltage to be applied to 32 the solenoid and 0.6s is sufficient to pull the shaft into the well and at this time the engine is ready to initiate. After that, the MCU will enter the next state ?keep on? automatically. At this time, the brake is released and the spark plug is ungrounded but the engine doesn?t have to be ignited. If the cord is pulled or the starter motor starts running, the engine will start immediately. When the MCU is in the state of ?engine on?, both of the control pins are set to low and shuts off the h bridge. So the solenoid is cut off from power in order to protect the device and save power at the same time. Since one of the solenoids is a latching one, it will hold the brake in place without consuming any electricity. In this state, as long as one?s hand remains on the control bar, the transmitter will keep sending ?3? to the engine. And the receiver MCU will receive ?3? consistently. If the transmission is interrupt by any reason such as handle bar button release, transmission failure or interference by noise, which means the receiver end doesn?t receive a ?3? in 5ms, the MCU in the receiver end will enter ?interrupt? state. At this state the MCU will behave just like the ?engine on? state, keep the two control pins at low but initialize a counter at the same time. It will check if it?s receiving the signal in every 5ms, if not, the counter will increase by 1 and enter the ?time out? state. If it does receive the signal in 5ms, it will clear the counter and switch back to the ?engine on? state. In the state of ?time out?, the MCU is checking the counter, if it doesn?t exceed the number of 120, it will move back to the ?interrupt? state. However if the receiver misses the ?3? for 120 times in a row, which will cause the counter to exceed 120 in 0.6 seconds, it will proceed to the ?switch off? state. The reason for having a time out state instead of just shutting down the engine anytime the signal is interrupted is because the transmission system is working in the 434 MHz frequency band, it might be interfered with by other ambient noise sources. Sometimes the noise sources are strong enough 33 to cover the signal transmission for more than 0.1 second. A product with no interference tolerance is not desirable, so the timeout feature is applied in order to maintain the stability of this system. Finally, when the MCU is in the ?switch off? state, one of the two control pins (RC0) will set to high and the other one (RA5) will remain low for 0.6 seconds. This will cause reverse current flow though the solenoid and the force of the mechanical spring will pull the shaft out of the shaft. After this 0.6 seconds, the MCU goes into the default state ?engine off? again automatically, waiting for the next operation cycle. The two control pins (RA and RC) will control the gates of four MOSFETs through logic, two of them are NMOSFETs and two of them are complimentary N- and PMOSFETs. The MOSFETs we are using are manufactured by Siliconix. The price of it is more than $1 each for the complimentary MOSFETs and less than $2 each for the N MOSFETs (two device package). The receiver end schematic is shown in Figure 13 (with the MOSFET and the solenoid). The solenoid is represented by an inductor and a resistor in series. 34 Figure 13 the receiver board schematic The PCB design and the actual PC board without/with the component pictures are illustrated in Figures 14, 15 and 16 respectively. Similar to the transmitter board, components like the voltage regulator, the ICSP interface and the filter capacitors are applied in this board also. PWRM3 and PWRM2 are power MOSFETs, they are complementary 8 pins MOSFETs manufactured by Vishay, Siliconix. The receiver is labeled as Rev1 and Rev2, and similarly, even an antenna is not necessary, there?s still a reserved place for the antenna to attach. SW1 is for the additional switch. Since the receiver board will always be on during operation, it will consume 26mA at 5V voltage supply. During operation this power consumption is negligible, however, when the mower is stored in the warehouse or garage, a 26mA continuous current could discharge the battery in months. In order to prevent that, an additional switch is necessary. After the 12V battery is connected, turning on the switch will power on the receiver, and the MCU will start to 35 look for the certain trigger signal to make a further response. Drill holes 1 to 10 are designed for easy assembling. Tp1 and Tp3 are test points to make this board easier to evaluate and debug. Tp2 is another test point to monitor the signal demodulated form the receiver. S4 and S6 are connected to the ground while S3 and S5 are connected to the 12V battery. The Tp1 node will be connected to both solenoids while the Tp2 node will only connect to the latching solenoid. The other end of the non-latching one will directly connect to the ground since the non-latching one does not require a reverse current. Figure 14 PCB design of the receiver board 36 Figure 15 Actual print circuit board Figure 16 Actual printed circuit board with component on. 37 Section 3 H bridge block with logic H bridge introduction The current to drive a solenoid is 1.5 A for the latching one and 3A for the non-latching one. The MCU could not control this much of power, so an H bridge block is applied. Normally an H bridge contains two pairs of transistors and usually it is utilized to driver a motor. Figure 17 illustrates the H bridge circuit in this design. Figure 17 H bridge for the solenoid Two devices which contain four transistors are placed in this circuit; all of them are power MOSFETs manufactured by Vishay and the part number of it is Si4500BDY. This is an N-P channel complementary MOSFET device where each device contains an NMOS and a PMOS which share the same drain node. In the schematic two of these (T1 and T3) four devices are PMOSs and the rest of them (T2 and T4) are NMOSs. By applying the proper voltage on the gate of each of transistor, it can open the channel between the source and drain of the device and 38 conduct the current, when the channel is opened, the equivalent impendence of the channel is much less than 1 ohm. The latching solenoid (represented by L1 and R5 in series) is placed between the two common drains of the H bridge while the non-latching one is between one drain and ground. The equivalent resistance and inductance of these two devices are 34.3 ohms / 0.693 mH and 25 ohms /3.3 mH, respectively. The sources of the two PMOSs are connected directly to the 12V battery while the sources of the NMOSs are grounded. The four transistors are controlled by two signals. T4 and T1 are tied which means they could be opened or closed together; likewise, T2 and T3 are tied together and will have the same behavior. All four transistors could be switched off at a certain state, engine off or engine on state for instance, but under no circumstances would all four transistors be turned on at the same time. Because if so, since the impedance of the transistor is much smaller than the resistance of the solenoid, the current would bypass the load and the 12V DC voltage would apply across the 1 ohm impedance device. This would dissipate more than 150W of power and permanently damage the device. The signal that is generated by the MCU is not sufficient to control both channels of the complementary MOSFET pair because the MCU can only provide a 5V voltage. In order to completely shut off the channel of the PMOS device, the voltage difference between source and gate (S2 and G2 of each device) should be less than 0.6V. Since the source of the PMOS is connected to the battery and will always be 12V, in order to ensure that the channel is closed completely, the voltage of the gate should also be close to 12V which cannot be provided by the MCU. Thus, two other MOSFETs are added to accomplish this function in the first stage and 39 the complementary devices becomes the second stage. These two devices in the first stage are also manufactured by the same company that made the power MOSFETs, the part number is Si4204BDY and it?s an NMOS and could also be used as a power MOSFET. The full control H bridge schematic is illustrated in Figure 18. Figure 18 Full H bridge control circuit This complete circuit has four terminals and is controlled by two signals. Each two of them are tied together and controlled by the same pin of the MCU. Since the Si4204DY is an NMOS, it can be opened or closed directly by the MCU. There are two resistors in series with the device on each side and the resistance of them are 3.3k ? and 5.1k ? respectively. These two resistors function as a voltage divider; the gate of the PMOS in the H bridge is tied to the middle of the divider. The gate of NMOS from the complementary devices is tied to the gate of the first stage NMOS on the other side. The principle of this circuit is as follows: there?s absolute no output from the MCU in four of the six states of the MCU. During this time, all the gates of the NMOS are tied to ground and none of their channels are open. Because T5 and T6 are closed, the resistance between the source and the drain is close to 1012 Ohm. Since R3 and R4 are in series with this MOSFET, the 40 voltage drop of these two resistors is negligible which makes the voltage on T1?s gate 12V, the same as the battery voltage. Since VGS = 0, the PMOS will also be closed. Likewise, T3 is closed too. And since T1 through T4 are closed, there?s no current flow across the solenoid. The engine will remain at the same state until the MCU status changes. When the MCU enters the ?switch on? state, it will send out a 5V signal to T6 and T2 and open these two transistors while T5 and T4 are still closed. The status of T1 is not changing because the status of T5 is not changing. On the other hand since there?s a 5V voltage applied on the gate of T6, the channel of T6 will be open and the resistance of it will drop significantly to nearly zero Ohms. So there?s a 12V voltage drop across the voltage divider of R1 and R2, according to Ohm?s law, the voltage at the middle point is the ratio of their resistance times the total voltage drop across them. The voltage at the gate of T3 will fall down to 7.8V and the VGS of T3 will rise to 4.2V, which is large enough to open the channel of this transistor. As a result, one side of the solenoid will connect to the 12V DC power; since one end of the non-latching solenoid is always grounded; it will start working immediately and generate the pulling force. At the same time, the gate of T2 has 5V applied too so it will also be turned on. This grounds the other side of the latching solenoid and makes it start working. The two solenoids together will have enough force to pull the brake against the spring away from the flywheel and lock it in place. At this time, the engine could be turned on and start operation. When the MCU enters the ?switch off? state, it will send a 5V signal to T4 and T5. Likewise, it will open the channel of T5, T1 and T4 and reverse the current of the ?switch on? state. This time, the non-latching solenoid is grounded and only the latching solenoid is functioning. The reverse current will temporarily demagnetize the metal core and release the 41 shaft. The spring on the mechanism will force the brake to be applied, stop the flywheel and ground the sparkplug at the same time. Pspice simulation of the model provided by the manufacturer has been simulated and the results are shown in Figure 19, 20 and 21. Figure 19 shows the control signals at the two terminals of the MOSFET. Figure 20 shows the current flow through the solenoid and Figure 21 shows the voltage across the solenoid device. ; Figure 19 Pspice simulation of the MOSFET, control terminals Figure 20 Current flows through the solenoid 42 Figure 21 Voltage drop across the solenoid Circuit optimization The H bridge is very sensitive to some certain circumstances, for instance if bothT2 and T5 are set to 5V, a short between power and ground via the MOSFET will occur. Although it does not happened by design, due to the parasitic capacitance associated with each of the electronic devices, the microcontroller or the MOSFETs, the signal that is generated by the MCU could have an undesirable rising or falling time which could prevent the whole system from working properly. This might cause a significant issue because after the circuit board is fabricated and all the components are placed, the MOSFET is very difficult to replace after it fails. A NOR logic circuit was therefore introduced in order to solve this problem. A two input NOR gate is a simple logic gate where the output is digital 1 if and only if both inputs are digital 0. In other words, if both of the two inputs of the H bridge are set to high, the NOR logic will convert them both to low. The solenoid will not operate while the H-bridge circuit is not burning up. The schematic of the NOR logic circuitry is illustrated in Figure 22. The MCU is connected from the right and the output is on the left. 43 Figure 22 NOR logic schematic The NOR gate in this design is manufactured by On Semiconductor and the part number is MC14001B. It?s a 14-pin device with 4 NOR gates integrated, where each one has two inputs and one output, and it uses 3V to 18V DC to power up. Table 1 is the truth table of the inputs and outputs. The two inputs, node A and node B, are from the MCU control pins and Node 4 and 11 are connected to the MOSFETs? gates. The four output nodes of the NOR gate chip (3, 4, 10, 11) will perform as follows. Input nodes Internal nodes Output nodes Node A Node B Node 3 Node 10 Node 4 Node 11 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 0 0 0 Table 1 Truth table of NOR gate When both of the outputs are set to digital 1 by mistake, node 6 and node 12 will also be digital 1. This will set both outputs of the logic to digital 0 in order to protect the circuit 44 board and the MOSFETs. Figure 23 is the modified printed circuit board design with the logic in between the MCU and the MOSFETs. The NOR logic chip is labeled as ?NOR? in the middle of the board. Figure 23 modified PCB design with logic Section 4 Circuit board installation This project is an actual commercialized product instead of a theoretical proposal. The boards have to be attached to the actual product. In order to approach this, some holes are drilled and some mounting plates are added. In order to minimize the modification of the product, the transmitter board is attached on the back of the handle bar, where the speed control lever is located. A plastic board was built 45 to fit the shape of the speed control. The transmitter board is powered by the 12V battery directly; the wires were placed in the handle bar frame. There are two wires already in that place by the original design and there?s still room for two more. The wires then go through the hollow pipe of the handle and come out from the central hole of the plate and then connect to the board. The transmitter attachment plate and board are shown the Figures 24, 25 and 26. Eight holes are drilled in this plate, besides the largest one that for the wires, the three unoccupied holes are for the plate to attach to the handle bar speed control and four are occupied for the circuit board attachment to the plate. All the holes are designed based on the existing screw holes on the handle or on the board. Figure 24 transmitter attachment plate 46 Figure 25 the attachment plate on the handle bar control Figure 26 Transmitter attachment plate with the board Figure 27 shows the transmitter board on the final product. Washers and nuts are 47 placed between the board and the plate to reduce the mechanical vibration when the lawn mower is operating. Figure 27 Handle bar on the final product The receiver end is larger than the transmitter board, also it has power components on the board. There are six more wires on that board that make it more crowded than the transmitter board. To protect the components on the receiver board from dust, humid weather or rain drops, the receiver board was placed in a plastic box that was located at the right size. The box is approximately 1?? by 3?? by 4?? in size, which is a little larger than the circuit board. Two holes were drilled on one side of the box for the wires and another hole was drilled for possible moisture drainage. The box was located on the back of the battery holder. This could make the power wiring shorter and avoid unexpected results. The box also came with a lid; however the 48 lid can only cover the fundamental components of the board but not the antenna. So another hole had to be made on the lid for the antenna. Another plate was fixed in the box to connect the board and the box to reduce the vibration from the lawn mower during operation. Four holes were used to attach the plates Figure 28 is the box with the plate settled in. Figure 29 is the box with the receiver board with all the wires connected. Figure 28 Box with the plastic plate 49 Figure 29 Box with the board and the plate Beside the power and ground wires of the electronic components, there were 6 wires that connected to the ground and power of the battery, and the two drain nodes of the power MOSFETs separately. Section 5 Mechanical Design Spring constant Due to federal regulations, the engine should be stopped completely in 3 seconds after the handle bar is released. This procedure requires a strong spring that can provide enough pulling force in a short distance. The spring is crucial in this application and it could not be replaced because any 50 spring weaker than this one would not provide sufficient force to shut down the engine completely in three seconds and any spring stronger than this one would require larger pulling force from the actuator and increase the product cost and reduce the battery life at the same time. After analysis, the spring on the engine follows the spring constant equation which is F = k?, (2) where F is the pulling force, k is the spring constant and ? is the displacement of the spring. The linear regression test results are shown in the Figure 30; three experiments were conducted and three charts were plotted. Figure 30 linear regression of the spring Averaging the three test results; the spring constant could be calculated and shown in Figure 31. 51 Figure 31 spring constant The spring constant is 84.80 N/mm which is close to 19 lb/mm. The displacement of the spring during engine operation is approximately 1 cm (0.4 inch) and the ratio of the switch mechanism lever is close to1:1.5, which means the initial force that could move the switch is approximately 16 pounds and the holding force to keep the spring fully stretched is 126 pounds when the mechanical cable is applied. In reality, the cable is stretching the spring much longer than it has to. The total displacement of the switch is almost 2 centimeters. But the minimum movement that could turn on the engine and connect the circuit is 0.3 cm. A 0.5 cm displacement could ensure that the engine is stably on. As a conclusion, in order to replace the cable, the actuator should provide 16 pounds of initial force and 32 pounds of holding force. The initial point in this system is defined as a 0.5 cm displacement of the closing 52 position, which means at the initial point, the shaft of the solenoid will be drawn out from the well approximately 0.5 cm. And the final point is defined as the point that the switch is far enough to start the engine safely. The initial point should make the solenoid shaft extend the longest distance and the final point should make the solenoid shaft fully extracted into the well. One Solenoid application Because of the pricing concerns, a solenoid device was chosen over other actuator types including step motors. After comparison, a latching solenoid which is made by Shih Shin Technology was chosen and the product number is SH-K1253.SH-K1253. It is a latching open frame solenoid utilizing an intermitting current supply. The latching function relies on a permanent magnet. The particular one in this application is a custom designed solenoid with a 25% of duty cycle and the maximum duty time is 20 seconds. The solenoid could be damaged (overheated or demagnetized) irreversibly if operated with over a 12V DC voltage supply, exceeds the maximum duty time or exceeds the duty cycle. It consumes 4.6A current during normal operation. When it is properly used, the device could provide more than 80 pounds of holding force. The particular one in this application is not performing as good as it indicated on the datasheet. It can provide 8 pounds of pulling force at the initial point and 60 pounds of holding force when it?s latched. The pulling force is determined by the displacement of the shaft. There are two polarities on this device and applying a forward voltage on two polarities of the solenoid will generate a magnetic field on the coil and pull the shaft into the well and make it attached to the permanent magnet, and a reverse voltage on the polarities will produce a magnetic field with 53 coil the causes the shaft to be repelled from the permanent magnet, the pushing force will be generated by a weak spring on the device. However, in this application, another much stronger spring on the engine will perform this function so the spring on the solenoid is no longer required. From all the off the shelf products, this one provides the most powerful force within the reasonable price range, which is close to 7 dollars. The solenoid in this application operates as follows: The brake mechanism of the engine is attached to one side of the metal core in the middle of a coil. If a current pulse is applied on the coil, the coil will generate a magnetic field and pull the iron core in and make it attach to the permanent magnet. The core will lock in place if the magnetic force between the two parts is large enough. In this way the brake of the engine is released and it is ready to be turned on. This motion only requires a single current pulse, which the battery can afford. When the engine needs to be turned off, a reverse current pulse is applied to the solenoid. With the magnetic force and the force from the spring combined, the core will be pulled back and apply the brake to the engine flywheel. Although a lot of factories offer personalized solenoid devices designed which can make the device to provide any pulling and holding force. The initial manufacturing cost is too high to afford on the project. After the product is in high volume production, customizing the solenoid could be the best way to do it, however, it?s still valid to use an off-the-shelf product at this initial development phase. The main problem of the solenoid is that, since the pulling force is provided by the Lorentz force of the metal core, which is generated by the magnetic field of the coil, as the shaft 54 moves into the well, the effective area of the coil will increase and so will the pulling force; the pulling force is not linearly proportional to the displacement. The initial force of the solenoid is quite small and rises significantly when the shaft is pulled all the way into the well. The spring force, on the other hand, is linearly proportional to the displacement. So the solenoid which can provide enough holding force will most probably fail to meet the initial force to pull the shaft in the first place. The solenoid which is used in this application suffers from this problem and the device is not powerful enough to open the switch, but it?s strong enough to hold the switch in place when it?s latched. Several approaches could solve this problem; the first one is using a lever system, secondly an extra magnet could be added to the side of the solenoid to enhance the pulling force, a third one is to weaken the spring that holds the brake and the last one is using a more powerful solenoid instead of the one that is being used. A lever system is not the best way to do it because although using a lever, the initial force required will reduce, however the distance of movement will increase by linear proportional magnification. The initial force generated from the solenoid still couldn?t match the force required, hence this method is impractical. An extra magnet is another attempt in the development. Several powerful magnets were added on one side of the solenoid to provide more pulling force and enhance the holding force at the same time. However, the holding force of the solenoid is already enough; with the help of extra magnets, the switch couldn?t be unlatching by the spring alone when the engine needs to be turned off. At this point, the extra magnet is still not providing enough pulling force to turn on the brake. 55 A weaker spring could not be employed because that might lead to failure to shut off the engine within 3 seconds. And it?s impossible to find a more powerful solenoid without customizing the device. However, it?s possible if two solenoids are combined together. Assisting solenoid Since one latching solenoid is not strong enough to pull the switch but it is strong enough to hold it, another non-latching one could be added to assist the former one. The other solenoid is a non-latching pulling tubular solenoid utilizing continuous current. The current of normal operation is 4.8A under 12V DC and the pulling force at the initial point is 18 pounds and the final position force is 60 pounds. Unlike the latching one, there?s not polarity on this device. Applying a forward or backward 12V DC voltage pulls the shaft into the well. The pulling force on the shaft will vanish after the power is disconnected; so the solenoid shaft will stay at the same place if there?s no other force affected it. Although it is a continuous solenoid which means technically it can be latched by applying a continuous voltage, it?s still not efficient because it will drain down the battery in one grass cutting session. The second solenoid is used to assist the first one; it can provide an extra 18 pounds adding to the 10 pounds that was generated from the first one. That is sufficient to start pulling the switch against the spring. Solenoid alignment The two solenoids are aligned in parallel and attached to each other with a flat shelf. It fits the gaps of the two shafts and combines them together. Additionally, the shelf itself is a lever system as well. The pivot of the system is in the middle of the two shafts? connectors and 56 makes the arm of force of the latching solenoid longer than before which will further increase the holding force. The arm of force of the non-latching solenoid is shorter than it could be if it?s operating alone. Figure 32 illustrates the configuration of the two solenoids on opening position with the shaft extracted and Figure 33 shows the closing position with the shaft extended. Figure 32 solenoids alignment in opening position 57 Figure 33 solenoids alignment in closing position And Figure 34 is the connection between the switch on the engine and the metal base plate which is specially designed for this system. Figure 34 connect point of switch and the solenoid junction A metal plate was bent into an L shape and connects the original switch by a screw in 58 one end. It is connected to the middle point of the flat shelf on the other end though a metal based cable by a large nut. The fix point of the cable and the base plate is adjustable in order to fit the best initial position of the solenoid movement. The initial position could be moved forward or backward within a distance of 0.2cm. This cable is added to enhance the flexibility of the mechanical system. Figure 35 shows the cable between the movable adjusting screw and the flat shelf that combines the two solenoids together. Figure 35 the cable between the movable adjusting screw and the flat shelf Solenoid control The solenoids on the engine are powered by the batteries and controlled by the MCU on the receiver board. The schematic of the receiver board including the H bridge is shown in Figure 36. 59 Figure 36 schematic of the solenoid control As it is shown in the schematic, the latching solenoid is connected between the circuit board H bridge block. The non-latching solenoid on the other hand is connected between the first effective side of the H bridge and the ground. When the engine needs to be turned on, T6 and T2 receives the control signal and the channel is conductive. Node A of the H bridge is pulled to 12V DC and node B will be grounded. Both solenoids will be powered and generate 25 pounds of force to the connecting cable at the initial position. The MOSFET will be shut off in 0.6 second while the solenoid can pull the switch in 0.3 second. After all the MOSFETs are turned off, the latching solenoid will provide approximately 70 pounds of holding force against the 32 pounds of pulling force from the spring. When the communication transmission ends, the channels of transistor T4 and T3 will be opened and node B will be tied to the 12V DC and node A will be grounded. This will generate a reverse current in the latching solenoid while grounding the non-latching solenoid. The spring will be released and apply the break. To make sure that the latching solenoid is not exceeding its duty cycle, which is 25%, A B 60 the MCU is coded to not send another control signal in 2.4 seconds (0.6/25%). The minimum time interval of the MCU sending the on and off control signal is 2.4 seconds. Two solenoids are sharing one common electrode at one side of the H bridge and thus they could be connecting together. For the convenience of assembling and dissembling, wire connecters were added and functioned as interfaces to connect the solenoids and circuit board which were powered directly by the battery. Figure 37 shows the connectors and wiring configuration of the solenoids. Figure 37 wire configuration and wire connectors The black wire goes to the negative electrode of the battery and both of the two red wires go to the two sides of the h bridge. There?s no direct connection between the solenoids and the battery. If the power to the receiver board is cut off, the solenoid will not power up either. This makes the system easier to control. 61 Section 6 Integration Circuit board Both the transmitter and the receiver boards are powered by the 12V DC battery, the transmitter board is placed at the handle bar on the top of the frame and the receiver board is placed at the back of the battery holder. Transmitter board The transmitter will start to transmit the signal as long as it?s powered up. A switch on the bar functions as the power switch of the board. A ground and a power wire are added from the battery to the board. If the switch is pressed, the MCU and the RF transmitter start operation immediately. Figure 38 is the wiring configuration of the transmitter board powering (red and black). The wire is not connected and goes in the hollow handle bars pipes in the final product. 62 Figure 38 control end power line In order to keep the original design of the lawn mower, all the wires are inside the handle bar pipe frame in this design. To minimize the change is another way to limit the cost of the product line. In the middle of the top handle bar, a hole was drilled to fit the plate which is designed for this application. Power wires are connected to the circuit board though this hole. Inside the top handle bar, the wire is connected to the board, battery and the switch internally. Figure 39 and 40 are showing that handle bar modification with or without the switch in this design. It is placed at the same place that used to have the pushing lever. 63 Figure 39 Handle bar with the control button Figure 40 Handle bar without the control button Three extra holes were drilled to implant the switch, the central one was for the wires and the two smaller ones on the side were for mounting screws . Fuse In the original design, a fuse was used between the starter motor and the battery to protect the motor and the battery form unexpected shorts in the circuit. However, the starter motor is only functioned after the brake is released; so it can?t be shared with the circuit boards 64 and the solenoids. The solenoids consume 7.3A of current during opening and 4A of current during closing. The transmitter and the receiver board consume 50mA total. However, if one of the solenoids is shorted by some reason, the current through it could rise up to more than 40A which is large enough to overheat the battery. In order to prevent this, another fuse is applied between the battery and the receiver circuit. Since the receiver circuit fully controls the solenoids, the fuse could provide protection of any component in the low side of the lawn mower. Figure 41 shows the two fuses in this design, the black one is the original one and has a current tolerance of 20A and the blue one is added for this project with a current tolerance of 10A. Figure 41 fuses to protect the battery The two fuses are connected in series and the original one overdrives the other one. The black fuse controls the battery. If the fuse is pulled out, neither the transmitter nor the receiver nor the starter motor will be powered. The new fuse is only protects the receiver circuit 65 and the solenoid. Receiver The receiver board (function board) is placed in the black box near the engine battery, however, the antenna is longer than the thickness of the box. In order to place the antenna, a hole had to be drilled at the lid of the box to let the antenna through. Figure 42 is the box with the antenna when the lid is covered. Figure 42 Function board box with the lid covered The box is placed on the metal plate that is implanted at the back of the battery holder. The box is placed here rather than anywhere else because it could make the wires shorter and it is far enough from the spark plug which could be a source of electrical noise. The metal between the box and the battery could also block some undesired electrical signals from the 66 back. 67 Chapter 5 Testing and Results Section 1 Assembling After integrating the circuit board to the mower, a few tests were conducted, including power consumption, thermal behavior and safety risk. Figure 43 and 44 show the final product of this lawn mower, back view and front view respectively. Figure 43 back view of the final product 68 Figure 44 Front view of the final product Section 2 Product safety Safety is a very important aspect of any commercial product. This design meets the safety regulation which is required. However, since the solenoid is driven by the circuit and powered by the battery, the brake down of any of them would fail to shut down the engine during operation which would potentially lead to an injury risk. 69 When the battery is fully charged, the voltage across it is 13.2V and as the battery discharges, the voltage drops non-linearly. When the battery is almost discharged, the voltage it can provide is 11.7V. The solenoids will not function at this voltage. There?s a minimum voltage to drive the coil inside the solenoid to pull the shaft. If the voltage of the battery is below this voltage the solenoid will not function properly. The minimum voltage of the solenoid to pull the shaft against and open the engine is 12.8V while the minimum voltage of the solenoid to release the shaft and close the engine is 12.5V. If the battery voltage is above 12.8V before operation but drops below 12.5V, the engine would not be able to be shut off. Section 3 Power consumption The control circuit consumes 12mA of current at 12V voltage supply during operation and the functioning circuit consumes 44mA of current during operation and 32mA of current under the same condition during standby. The total power consumption is 0.93mAh of power per minute during operation. When turning on the engine, the solenoids will consume 9.4A of current for 0.6 second at 12V DC power supply. When the engine is switching off, the latching solenoid will consume 4.6A of current for 0.6 second. Turning on and off the engine will consume 2.32mAh of power per session. After the engine brake is released, the starter motor will consume 20A of current for 3-4 seconds, and the operating time is determined by the operator. This will cost 16.7mAh to 22.2mAh of power per time. 70 One grass cutting session normally lasts 10 minutes in average and the capacity of the battery on the engine is 5000mAh. Assume in every cutting session, the engine is turned on and off for two times. The whole power consumption in one grass cutting session is 52.66mAh which is 31% more than the traditional lawn mower which means the battery usage time between recharging is 31% less than with the traditional mower. 71 Chapter 6 Conclusions This design shows the accessibility and advantage of integrated electronic devises on the machinery. The reliability test shows that RF transmission has strong resistivity to white noise and the noise produced by a four cycle combustion engine spark plug. Also, instead of relays, power MOSFETs could also allow massive current flow through them and be controlled by the MCU output pin or a logic circuit. This product is a beginning stage of lawnmower improvement, more applications and function could be added on the lawnmower with a more powerful MCU and transmission module if the cost of the product is no longer limited. 72 Chapter 7 Future Work Section 1 Duplex transmission This system utilizes a simplex transmission by one transmitter and one receiver. However, since both ends of the transmission have a MCU on board, other features could be integrated without increasing the cost of the product significantly. For these improvements, duplex transmission could be introduced. The transmitter and the receiver in the system could be replaced by transceivers in order to realize a duplex transmission system. With proper MCU coding and synchronization, the two circuits could send data back and forth. The control circuit which is placed at the top of the handle bar is still sending signals to the function circuit which is placed near the engine to control the engine, half of the transmission time. And in the other half of the transmission time, the function circuit will send the data of the engine back to the control circuit and monitor the operation parameters of the mower for the user. The duplex system is more likely to interfere with other devices than the simplex system. The interference could be avoided or reduced by coding the transmitting signal individually and adjusting the antenna of the transmission terminal. Section 2 Add sensors to the engine For the convenience of the lawn mower user, a visual interface could be added at the handle bar of the mower to indicate that if the mower is low in power, low in gas or the oil should be changed. This will save user?s time and avoid some unexpected dangerous 73 conditions. Some kinds of sensors could be applied in order to realize this function. The output of the sensor could be connected to an operational amplifier or a digital comparator to convert the analog signal to a digital signal. After converting, the signal could trigger the MCU on the function circuit and send the signal accordingly. The MCU on the control end of the system will be demodulated and decode the signal, distinguish the sensing result and tell the operator if an alert has occurred. A simple LED could be placed on the handle bar to indicate if the engine is overheating or the gasoline is low. The sensor?s principle works as follows. Normally, sensors use resistance as a sensing method. The configuration of this type of the sensor is relatively simple. A fixed resistor is connected in series with the sensor and with the power source applied, it consists of a voltage divider. The node in the middle of the two components is the output of this circuit. Usually, a voltage follower will come after the output to match the impedance to a digital circuit. A voltage will reduce the output impedance to approximately 2k ohms without changing the voltage of the output signal. The level shifter will come after the voltage follower to offset the voltage level of the output. A voltage amplifier will be placed in the third stage to amplify the signal and make it easier to be recognized by the MCU. And finally, the signal will be received by the analog to digital converter module in the MCU and be recognized by the processer. By setting the proper criteria, the processor could trace the trend of the signal and send out messages to the user. It can even shut down the engine automatically if necessary. 74 Section 3 Safety protections Safety protections could be achieved in this application. The MCU could be enforced to shut off to prevent further harm to human. Because the switch is controlled by the solenoid alone and the solenoid is driven by the battery, if the voltage of the battery falls below 12.5V, there?s no other proper way to shut down the engine until it run out of gasoline. In this case, a sensor could be added to provide safety protection. Normally, the battery should be above 12.8V to initiate the solenoid to turn the engine on, and only if the battery voltage drops below 12.5V in the cutting session will make it unable to close it. The engine doesn?t consume electricity from the battery at all during the operation and the two circuit boards consume 56mA of current during operation. The scenario that the engine could be properly turned on but unable to shut off is possible but very unlikely to happen. However, if this really happens, the engine will be out of control and could be very dangerous. In order to prevent that, a voltage divider could be implanted at the power line of the battery and monitor the voltage drop of the battery. If the battery voltage is dropping below 12.6V? the comparator module in the MCU will be triggered and send out the switch off control bit regardless of the current state of the MCU state machine. This feature might cause inconvenience but it will protect the user ultimately. Overheating is another issue that the engine might encounter although it?s very unlikely to happen. A temperature sensor could be placed near the engine cylinder and monitor if it?s overheated. A similar technique could be applied to close the engine if overheating occurs. 75 Other safety protection like oil change and so forth could be added if necessary. Another safety sensor could be a MEMS gyroscope or accelerometer, which could detect lawnmower rollover and command the MCU to shutoff the engine. Section 4 Power source on the transmitter end The transmitter board in this design is powered by the 12V battery located near the engine. In fact, the control board could be powered separately from the other part of the system and this will eliminate the power wires of the board. The major components on the control circuit, the MCU and transmitter, could work under 3V conditions. It can be powered by two AA or AAA batteries. This requires a battery holder and extended printed circuit board area, and there is an extra cost of the battery. Another approach is to use a photovoltaic cell to replace the battery for the power source of the circuit. A photovoltaic cell, which is also known as solar cell, is a power generator that can convert sunlight to electricity. Usually the lawn mower is operating outdoor and normally people do that at day time under direct or indirect sunlight. In this case, a photovoltaic cell might fit the working condition perfectly. It can save the trouble of replacing the batteries all the time and save some power from the 12V battery at the same time. Another option would be to add an alternator to the lawnmower engine. Although this raises product cost, it obviates the issue with the 12V battery discharging to where the solenoids cannot turn off the engine. 76 References [1] Alex Goldman 2002 by Kluwer Academic Publishers in USA. [2] Ismail Guvenc, Sinan Gezici, Zafer Sahinoglu and Ulas C. Kozat 2011 by Cambridge University press in U.K. [3] Jeffrey H. Reed, Theodore S. Rappaport Brain D. Woerner 1997 by Kluwer Academic Publishers in USA [4] William Stallings 2007 by Pearson education INC in NJ USA [5] Theodore S. Rappaport, Brian D. Woerner Jeffrey H. Reed William H. Tranter 1997 by Kluwer Academic Publishers in USA [6] George E. Stephenson 1984 by Delmar Publishers INC. om USA. [7] Darrell L. Roberts 1978 by Clemson University cooperating with United States Department of Agriculture [8] www.saferproduct.gov [9] Microchip,?PIC18F2455/2550/4455/4550 datasheet? DS39632E ,2009 [10] Texas Instrument. ?LM341,LM78M05,LM78M12,LM78M15? SNVS090E, August 2005 [11] Microchip, ?dcPIC30F SMPS flash programming specification? DS70284C 2010 77 Appendix A transmitter end MPLAB code #include #include #include #include #include #pragma config FOSC = HS // Oscillator Selection: Internal oscillator #pragma config WDT = OFF // Watchdog Timer #pragma config LVP = OFF // Lo w Voltage ICSP(PIN 6):Disabled #define SWITCH PORTBbits.RB0 #define PRESSED 0 void main(void) { TRISCbits.TRISC6 = 0; //PORTC Bit 6 Is TX (PIN 25) TRISCbits.TRISC7 = 1; //PORTC Bit 6 Is RX (PIN 26) //Configure USART OpenUSART( USART_TX_INT_ON & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & 78 USART_BRGH_LOW, 51 ); while(1) //Short Pause { putcUSART( '3' ); Delay10KTCYx(4); } CloseUSART();} 79 Appendix B Receiver end MPLAB code #include #include #include #include #include #pragma config FOSC = HS // Oscillator Selection:External oscillator #pragma config WDT = OFF // Watchdog Timer #pragma config LVP = OFF // Low Voltage ICSP(PIN 6):Disabled #define SWITCH PORTBbits.RB0 #define PRESSED 0 unsigned char recvBuff; unsigned int count; unsigned int state; void InterruptHandlerHigh (void); void main(void) { count = 0; state = 0; TRISC = 0; TRISC = 0; TRISCbits.TRISC6 = 0; 80 TRISCbits.TRISC7 = 1; PORTAbits.RA4 = 0; PORTAbits.RA1 = 0; PORTAbits.RA2 = 0; INTCON = 0b11000000; Delay10KTCYx(10); OpenUSART( USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 51 ); Delay10KTCYx(10); while (1) switch (state) { case (0): PORTAbits.RA3 = 0; PORTCbits.RC0 = 0; if (recvBuff == '3') { state = 1; } else {state = 0;} 81 break; case (1): if (recvBuff == '3') {PORTCbits.RC0 = 1; PORTAbits.RA3 = 0; Delay10KTCYx(120); state = 2;} else {state = 0;} break; case (2): PORTAbits.RA3 = 0; PORTCbits.RC0 = 0; if (recvBuff == '3') {count = 0;} else {Delay10KTCYx(1); count ++; if (count >120){ PORTAbits.RA3 = 1; Delay10KTCYx(120); state = 0; } else {state = 2;} 82 break; default: PORTAbits.RA3 = 0; PORTCbits.RC0 = 0; break;} } CloseUSART(); } #pragma code InterruptVectorHigh = 0x08 //interrupt pointer address (0x08 high priority) void InterruptVectorHigh (void) { _asm //assembly code starts goto InterruptHandlerHigh //interrupt control _endasm //assembly code ends } #pragma code #pragma interrupt InterruptHandlerHigh //end interrupt control void InterruptHandlerHigh() // Declaration of InterruptHandler { if(PIR1bits.RCIF){ recvBuff = ReadUSART(); 83 PIR1bits.RCIF = 0; //Clear RCIF Flag } INTCONbits.GIE = 1; //Re-enable all interrupts return; }