2021年4月9日 星期五

Manmade Wireless Monitor System

Manmade Wireless Monitor System

    MC68HC908-based wireless monitoring system is adaptable for use in domes-tic and industrial settings. The central monitoring station, which consists of a computer-controlled receiver with a relay output and LCD, logs and displays data from up to 20 dif-ferent sensors. Read on to learn how to build, program, and test your own system.

    One of the things I have learned from my everyday engineering prac-tice is that there is always room for ingenuity and improvement. This is particularly true for this project,which applies a couple of inexpensive MCU to an unusual device: a live-catch mousetrap. Mousetraps of this kind imprison mice instead of killing them with chemicals or bloody mechanisms.

    They are useful when regulations,laws, or just plain common sense for-bid the use of poisons and chemicals.This applies to the food industry, fromfarms to your preferred restaurant, as well as places like schools and homes (where children and pets can open traps) and even hospitals and pharma-ceutical facilities (where contamination should be avoided). As you cansee, I’m talking about a worldwide market with millions of  customers. 

    Unfortunately, live-catch traps are extremely expensive to maintain because of the labor costs required to continuously check them. Although a single mouse catch is a rare event in today’s hospitals or harmaceutical depots, the traps must be checked every few days. Making matters worse, the traps are often located in places that are difficult to access.

    I designed my system with the objective of drastically cutting the labor costs involved with checking traps (see Figure 1). Now you can leave the traps unattended until the system calls for assistance.. 

    My system consists of a monitoring station—a computer-controlled receiver with an LCD and relay output—and up to 20 mouse sensors. It works by placing a mouse sensor (a small plastic box) inside each trap. When a mouse is captured, the sensor transmits its trap identifier to the monitoring station, which logs and displays it where it’s conveniently viewed.

    Alternatively, the receiver can dispatch the call to an  external service,triggering an ordinary automatic phone dialer connected to its relay out. Refer to the “The System at Work” sidebar for more information.

NONTRIVIAL REQUISITES

    Although conceptually simple, such a system design is nontrivial. The parts count must be kept to a minimum in order to contain costs. The dimensions are essential to fit even the smallest traps on the market. In addition, mouse sensors must be battery operated, so the batteries must last for years of continuous service.

    This calls for low-power parts and carefully designed  software. Another requirement is that the system be able to resolve collisions that result from the simultaneous transmission of two or more mouse sensors. It should also tell you when the batteries need to be replaced and be able to detect when a trap is lost or destroyed, which isn’t an unlikely event in industrial environments.

    And, of course, the system must be simple, resistant to dirt, reliable, and easy to manufacture.On the receiver side, the monitoring station must be cost-effective, dependable, and easy to set up and use. It must show complete trap information,and the configuration data must be retained after power interruptions.

    The design should be compact, modular, and flexible. As with all new products, additional requirements are expected to emerge as work on the design progresses; therefore, high-level programming languages are preferable.

    Figure 1—My goal was to cut labor costs and eliminate the need for 
                        weekly trap checks. A transmitter is placed in every trap to 
                        signal the presence of mice. If a trap needs to be emptied, 
the system automatically calls home.

MCU SELECTION

    Not many years ago, I would have started this design by selecting a specialized remote control encoder/decoder IC pair, looking for ultralow power parts, and adding glue logic. If a microcontroller were required, I would have selected an MCU with a familiar architecture and instruction set. The time it takes to learn the development tools (not to mention the cost) would have influenced my choice. 

    Nowadays, the design path is some what reversed: MCU selection is one of the first steps in the design process.You can use general-purpose, low-cost microcontrollers for tasks previously done with dedicated ICs, with the extra advantage of adding functionalities in the software. Tools are inexpensive and sometimes free. In addition, it’s no longer necessary to know assembly language because high-level language compilers are available for programming (including the smallest possible controllers).

    I selected the 8-bit MC68HC908 microcontroller for this design. The same MCU core comes in a tiny eight-(QT suffix) or 16-pin (QY) package, with 128 bytes of RAM and 1 to 4 KB of flash memory. This IC includes unique features that make it perfect for this application. It does not require external reset, and its flash memory-calibrated internal oscillator is suitable for battery-operated devices because it keeps steady despite varying power voltages.

    Therefore, all of the pins—except the power supply—are available for input and output, which makes the eight-pin packaging effective for the trap transmitter. The 16-pin version nicely fits the receiver’s requirements. 

    At an aggressive price, I’m talking about a truly classic MCU, with a true stack, capable of running true ANSI C code. Note that there is also hardware support for one-pin in-cir-cuit debugging (ICD), so an emulator isn’t required. Furthermore,flash memory can conveniently emulate EEP-ROM, a feature I used tostore trap IDs.

    As for the tools, the Metrowerks Codewarrior IDE includes an assembler, ANSI C compiler,simulator, programmer,in-circuit emulator/debugger, and even a light version of Processor Expert, which is an automatic C code generator.Although the tools are professional grade, they are  available for free.

— Figure 2—
     As you study the transmitter and receiver block diagrams,keep in mind that the microcontrollers contain most of the functions required by the system.This keeps the number  of  external parts to a minimum. The functions listed in the MCU boxes are implemented with a mixture of software and on-chip peripherals.

SYSTEM BUILDING BLOCKS

    The block diagrams here show how most of the building blocks have moved from external hardware to internal software modules. The transmitter’s block diagram counts only three blocks outside the chip, as opposed to six internal function blocks supported by the MCU through a combination of software and on-chip peripherals (see Figure 2). The parts outside the microcontroller are the sensor mechanism and reed relay, two keys for setting up the trap ID and arming the trap, and a 433-MHz low-power transmitter with a rod antenna. The power comes from a couple of button batteries.

    Inside the microcontroller, software modules implement a digital generator for encoding data to be transmitted, a scheduler for cyclic “keep alive”transmissions, storage of user-pro-grammable nonvolatile ID data, a detector for the battery charge state, a manager for a simple mechanism to prevent overlapping transmissions, and a module for administration of the low-power modes. 

    The monitoring station includes a 433-MHz receiver  module and its antenna, a relay stage for driving an external alarm or phone dialer, a 2 ×16 LCD module, and a five-button keyboard. I powered the unit with a wall-cube mains adapter through a linear regulator stage. As for the transmitter, many of the functional blocks are implemented by the MCU that’s in charge of decoding the receiver output and discriminating errors that result from bad reception, interference, or the simultaneous transmission of two or more mousetraps. 

    The MCU also stores trap information. It registers trap IDs in (internal) nonvolatile memory and programmatically updates trap status records in RAM. The user interface block consists of a trap data browser and a configuration mode for learning trap IDs. A monitor station can handle up to 20 transmitters—although a transmitter ID can range among 128 different IDs—to allow more than one monitor to operate on the same or overlapping areas.

MOUSE SENSOR

    The first problem I had to solve was how to sense the presence of mice. I discarded electronics-only methods (e.g., photocells and capacitive sensing) one after another. Some were too sensitive to dirt, expensive, and difficult to clean; others were too accessible to munching rodents and con sumed too much power. In this context, drawing a continuous 5 µA (equivalent to a 1-MΩresistor at 5 V)represents significant power! 

    I was about to give up, when I saw a program on the National Geographic Channel showing the natural curiosity and vitality of mice. Realizing this, I added a little balance to the trap transmitter (see Photo 1). Sooner or later,an unwary mouse—frantically search-ing the trap for an escape route—will reach the balance. The balance freelypivots on the transmitter’s aerial. A small magnet glued on one side counterweights it. I placed a reed-relay inside the sensor body to detect magnet movements and to trigger in turn the eight-pin processor. Bingo! It’s like having the mouse switch on the transmitter for you! 

—Photo 1—

The trap sensor/transmitter unit prototype is housed in a small plastic box. Putting your fingertip on the balance brings the magnet in front of the reed switch. Note how the antenna doubles as a pivot for the balance.

—Figure 3—

The 68HC908QT4 is the heart of the transmitter. It embeds a brownout reset as well as a calibrated oscillator that makes reliable data transmission possible without crystals or resonators. The TX modulecan be changed in order to suit national regulations and frequencies. The reed switch closes when the mouse moves the sensor balance.

TRANSMITTER CIRCUIT

    The transmitter’s schematic diagram accounts for few parts other than the eight-pin processor (see Figure 3).The more that’s inside the MCU, the less that’s outside. This means not only a leaner bill of materials, but also a small circuit footprint, which is important in this application.

    I connected two of the six available I/O pins to push buttons for rearming the trap after trigger detection and to set up the trap ID. Another pin goes to the reed-switch trap trigger. These pins are pulled up internally by the MCU.A fourth pin drives the 433.92-MHz 2-5000-786 thick film transmitter module. It is compliant with European frequency standards and measures only 25.5 mm × 12.5 mm. The modulation method is on/off keying (OOK) according to the status of the PTA5 pin. When it isn’t transmitting, the module consumes as little as 0.1 µA (more on this later). Check this figure when replacing it with similar parts,because it is vital for battery life. 

    The only remaining components on the board are a bypass capacitor (CF1) and an electrolytic capacitor (C1) required to lower the output impedance of the two button-type batteries that power the circuit. The circuit is compatible with user-monitor mode in-circuit programming. Connect the ICD interface to pin 7 to watch the code run. 

MONITORING STATION

    Figure 4 reveals the receiver’s internals. I used modules for the LCD and the radio receiver; therefore, the design is noticeably neat and contains few parts. The MC68HC908QY feature set contributes to the circuit’s tidiness. It includes input pull-ups, a steady internal clock oscillator, a brownout detector and reset generation, and flash memory that can be used as a replacement for EEPROM.The 433.92-MHz receiver module takes the signal from the antenna and converts it to a more manageable digital level pulse train. The receiver can be replaced with similar models to suit national regulations and frequencies.

    The microcontroller processes the pulse train in order to distill meaningful signals from the inevitable RF noise background. It then displays the results on the 2 × 16 LCD module, which is connected in 4-bit mode, requiring six out of the 14 available MCU I/O pins.

    The LCD software driver assumes pins DB0 through DB3 to be at logic level 1 or unconnected. Depending on your LCD module, you may need to apply a contrast control voltage from 0 to 5 V to pin 3. Recent modules usually work well with this pin unconnected.The keyboard, which consists of five push buttons, takes another five pins, which have their internal pullups enabled. I kept ICD pin (port A0) free for in-circuit debugging, as I did for the transmitter, making the board user monitor-debug compatible. 

    The last available pin is used to drive the relay output, which is realized with a classic transistor stage and a diode for protection against coil’s over-voltages. The circuit is mains powered through a wall adapter supplying 9 to 12 VDC, regulated to 5 V by IC2, a classic 7805 stage. Diode D2 protects the circuit from power reversals. Resistor R2 limits the current for the LED backlight to a safe 40 mA. The backlight works from an unregulated power supply.

—Figure 4—

The receiver has few parts. Pull-ups, an oscillator, reset generation, and EEPROM are all included in the MCU. Connections to LCD pins 15 and 16 (backlight) and R2 can vary to suit your LCD’s specifications. Older LCDs need a contrast control voltage to be set on pin 3. The relay can trigger a phone dialer when a trap triggers.