AN1013 gas and water metering with the PIC16F91X family

8 227 0
AN1013   gas and water metering with the PIC16F91X family

Đang tải... (xem toàn văn)

Thông tin tài liệu

AN1013 Gas and Water Metering with the PIC16F91X Family Author: Joseph Julicher John Charais Microchip Technology Inc INTRODUCTION Electronic utility meters are an important step towards automating the utility metering process Automated utility meters allow many new features that help reduce the cost of utilities to customers and reduce the cost of delivering utilities to the utility provider TYPES OF UTILITY METERS The primary utilities metered are electricity, water and gas Water and Gas are measured with very similar systems while electric meters are very unique READING FLUID FLOW Because the water flow meter uses a spinning magnet to indicate flow rate, we must use a magnetic sensor or a spinning magnet to couple the flow meter For this application, we decided to eliminate all moving parts in the display by using Hall effect switches to detect when the spinning magnet makes one revolution By using two Hall effect switches, it is possible to determine which direction the water is flowing and to take an appropriate action When using two switches, the digital outputs will sequence through the following four states as the magnets rotate (see Table 1) TABLE 1: Switch States Meaning 00 The magnet is not near the switches Electric Meters 01 The magnet has reached the first switch Electric meters measure the power consumbed at a customers site This type of meter is very easy to convert into an electronic version using an MCP3905 single-phase power metering IC 11 The magnet is between the two switches 10 The magnet has reached the second switch 00 The magnet has moved past the switches Gas and Water Meters Gas and water meters are based upon a mechanical flow meter There are many types of flow meters, but the most common type for gas is a positive displacement flow meter In this type of meter, a known volume of gas is accumulated and then released to the customer Each time the volume of gas is released, a shaft rotates The rotating shaft is attached to a meter movement to indicate the number of rotations or the total volume sold to the customer Water flow meters are typically flow rate systems The water flow impinges upon an impeller, causing rotation The rotating impeller is attached to a magnet A second magnet inside the meter movement couples to the first magnet by virtue of the magnetic fields As the fluid motion causes the first magnet to turn, the second magnet also turns and the rotations are counted by the meter mechanism (see Figure 1) If the state goes in the other direction, it means that the water has begun to backup This indicates one of three things: The system is installed incorrectly The anti-siphon system has broken The meter has been tampered with It is also possible that some bouncing between adjacent states will occur This is normal when the water has been turned off and the flow goes to zero By using a magnetically coupled system, the wetted portion of the meter can be kept clean, while the meter portion of the system can be converted to any type of sensor or display without affecting the measured fluid © 2005 Microchip Technology Inc DS01013A-page AN1013 FIGURE 1: ELECTRONIC METER Inside Gauge Inside Meter S S N N Electronic Meter Water Flow Hall Effect NC S A Hall Effect B N DATA DISPLAY ADVANCED FEATURES Electronic displays come in a large variety of types but the most appropriate type for a low-power meter application is a LCD segment type display Typically, these displays are custom built for the application they will be used in For a demonstration unit, the cost of custom LCD glass was not appropriate, so an 8-digit, 7-segment display was found in the form of a Varitronix VIM-838 display This display is available with pins to connect to the PCB which makes prototype units easier to construct Driving this display requires a LCD controller device Fortunately, Microchip Technology offers a wide variety of LCD controller equipped PICmicro® microcontrollers Thinking of the future, this application was equipped with a radio transmitter to allow the meter data to be sent wirelessly to a nearby data collection device Generally, the data collection devices are in a passing vehicle, so a wireless method to start the transmission is required A radio receiver was added to accomplish the wake-up function There are many simple RF solutions on the market When building any RF transmission system, care must be taken to ensure that emitted power and frequency are within the regulated limits for the region the transmitter will be operating DS01013A-page © 2005 Microchip Technology Inc AN1013 MICROCONTROLLER CHOICE Other advantages of using the PIC16F917 is the possibility to add additional advanced features in the application, such as: For this application, the PIC16F917 was chosen from Microchip’s new low-cost LCD family of devices (see Table 2): • Automatic contrast control with the internal comparators • Low-voltage operation to allow a simple battery backup for off-line operation • Internal nonvolatile memory (EEPROM) to backup meter readings during power failures • Variable clock speed to reduce power consumption between meter calculations • In-circuit debugging allows debugging the code in the final circuit with the final device • In-circuit programming simplifies programming of surface mount devices • It can drive the number of segments in the chosen LCD glass • It is low cost • There are enough I/O pins left for the application and communications • There is sufficient program space to handle the entire application TABLE 2: Program Memory Device Data Memory I/O 10-bit A/D (ch) LCD (segment drivers) CCP Timer 8/16-bit 256 24 16 2/1 256 35 24 2/1 352 256 24 16 2/1 352 256 35 24 2/1 Flash (words/ bytes) SRAM (bytes) EEPROM (bytes) PIC16F913 4K/7K 256 PIC16F914 4K/7K 256 PIC16F916 8K/14K PIC16F917 8K/14K FIGURE 2: BOARD LAYOUT LCD1 J1 J14 C1 U2 U5 R7 C14 C12 R5 C2 R1 C5 + C6 M U6 U3 U4 R9 RF Module + C6 P1 RF Module C4 R2 R3 R4 M R13 PIC16F917 D1 C3 C11 C10 C9 U1 C15 R8 R6 C13 R12 R10 P2 R11 C7 P69839 © 2005 Microchip Technology Inc Water Meter Demo DS01013A-page AN1013 PUTTING THE HARDWARE TOGETHER With the basic design decisions made, the next step is to assemble the building blocks into a working system WIRING THE GLASS In this system, the LCD display will require thirty of the I/O pins of the microcontroller Six of these pins have fixed functions, so the first step is to connect the commons (COM) and the LCD voltages (VLCD) The glass chosen has only three commons Looking up three common glass connections in the data sheet provides the first section of the schematic Another look at the devices reveals that there are only 23 available segment pins and 23 segment pins are required Attach all the segments from the glass to the PIC® microcontroller ADDING THE HALL EFFECT SWITCHES The Hall effect switches simply need two available input pins and two pull-up resistors, this is because they are open-drain output Looking at the pins on the left of the PICmicro device shows that the choices are: RA6 and RA7 (OSC1 and OSC2) RD0 RD1 RD2 The remaining tasks for the application are communications and detecting when the power fails Simply because it keeps the Hall effect switches together, RA6 and RA7 will be chosen for the Hall effect inputs RF COMMUNICATIONS The RF communications is being handled by a pair of RF modules The transmitter accepts an input from a digital output and produces RF energy The receiver receives the RF energy and produces a digital signal There are three choices left for pins For this application, attaching the transmitter to RD0 will save a few instructions in the serial transmit software This is because we can load the carry flag with the next bit and rotate the bit into RD0 with one instruction If we attach the receiver to RD2, it will allow the software to use the CCP module to capture the data pulses, making the software a little easier DS01013A-page POWER FAIL DETECTION The power fail detection is a simple input from the voltage regulator A diode/capacitor combination (D1, C5/C6) will keep the voltage available to the application for a few milliseconds to provide a graceful powerdown The most important task during the power-down is to save the current water usage to the EEPROM The voltage on RD1 comes before D1 allowing the voltage, at RD1, to drop faster than VDD If RD1 ever goes low, the firmware will know that the power has been removed and it must save its data WHAT IS LEFT? The last major step is providing a connection for programming and debugging A 6-pin connector will allow an MPLAB® ICD or other programmer to be attached during development Because the ICD requires the use of RB6 and RB7, there will be an affect on the LCD Fortunately, this affect is temporary and will not damage the glass Before the LCD code is finished, it will be tested without the ICD attached to verify that the software is correctly using the RB6 and RB7 segments SCHEMATIC The complete schematic for this application is located in Appendix A: Schematic SOFTWARE DEVELOPMENT The software for this application was developed in Assembly Language using the freely downloaded MPLAB development tools Debugging the software was done simply by using the included simulator, and, after the board was completed, the in-circuit debugging features Programming and the in-circuit debug were accomplished with the MPLAB ICD device from Microchip Technology The software is included, in a zip file, with this application note CONCLUSION Implementing a basic electronic water meter is very easy with the PIC16F917 It is also a very cost-effective solution towards advanced metering features © 2005 Microchip Technology Inc 4 R1 DJ005B 3 J1 S1 MCLR SEG13 SEG14 A COMO1 COMO0 SEG3 SEG2 SEG1 SEG0 SEG5 SEG4 SEG15 COM2 SEG7 SEG12 RC2/VLCD3 VSS VSS OSC1/RA7 13 OSC2/RA6 14 RB7/SEG13/ICSPDAT RC0/VLCD1 15 16 17 RD0/COM3 19 26 RC7/SEG8/RX 25 RC6/SEG9/TX 24 RC5/SEG10/CCP1 23 RC4/SEG11/SDO 18 RC3/SEG6 RB6/SEG14/ICSPCK RC1/VLCD2 RB5/COM1 RB4/COM0 RB3/SEG3 RB2/SEG2 RB1/SEG1 RB0/SEG0 RA5/SEG5 21 22 27 28 29 30 10 RD1 20 RD2/CCP2 RA4/SEG4 RA3/SEG15 RD4/SEG17 RD5/SEG18 RD6/SEG19 RD7/SEG20 RE0/SEG21 RE1/SEG22 RE2/SEG23 RD3/SEG16 U1 RA2/COM2 RA1/SEG7 RA0/SEG12 MCLR VDD VDD + OUT LM78L05ACM VLCD1 VLCD2 VLCD3 SEG6 SEG11 SEG10 SEG9 SEG8 SEG16 SEG17 SEG18 SEG19 SEG20 SEG21 SEG22 SEG23 GND GND GND GND IN U2 {Value} PIC16F914/917-TQFP 31 12 40 39 38 37 36 35 34 33 32 11 47uF 16v +VDD C1 CAP3528 1 R2 100k +5V low voltage detect C2 D1 VLCD1 +VDD BAT54C R3 C9 0.1uF R16 100k 100k 10k 0.1uF 47k +5V B 47k 47uF VLCD2 C10 + R17 200k + VLCD3 0.1uF C5 +5V +5V 0.1uF 100 R8 100 R6 100 R7 100 R5 C 2 VDD VOUT +VDD +VDD VDD U4 VOUT U3 Mount 45 degrees to each other 0.1uF R3 is needed to fine tune the contrast C11 47uF 0.1uF 10uF B 0.1uF R15 R4 R13 GND + C C14 C15 CAP3528 C8 C12 C13 C3 0.1uF GND C4 0.1uF U5 15 ANT 16 DATA GND PDN Vcc RX_GND +VDD U6 GND Data Ladj/GND Vcc ANT +VDD SEG14 SEG13 MCLR TP P1 R11 8f,8e,8an 8a,8g,8d 8b,8c,8dp 7f,7e,7an 7a,7g,7d 7b,7c,7dp 6f,6e,6an 6a,6g,6d 6b,6c,6dp 5f,5e,5an 5a,5g,5d 5b,5c,5dp 4f,4e,4an 4a,4g,4d 4b,4c,4dp 3f,3e,3an 3a,3g,3d 3b,3c,3dp 2f,2e,2an 2a,2g,2d 2b,2c,2dp 1f,1e,1an 1a,1g,1d 1b,1c,1dp TBD Number D TP P2 SEG23 SEG22 SEG21 SEG20 SEG19 SEG18 SEG17 SEG16 SEG15 SEG14 SEG13 SEG12 SEG11 SEG10 SEG9 SEG8 SEG7 SEG6 SEG5 SEG4 SEG3 SEG2 SEG1 SEG0 A Rev TP-60R38 Drawn by Sheet of Water Meter Reference Design COM2 COM1 com1 com2 com3 VIM-838-DP LCD1 July, 2005 Date Filename B Size Title R10 T-Attenuator For tuning RF output power TBD COM0 TP-60R38 LINX-TXM-XXX-LC ICD2/PICkit Programming Header J14 TX_GND R9 430 LINX-RXM-XXX-LC-S D 315 Mhz Transmitter & Receiver Attach Wire antenna to P1 & P2 Wire should be 8.9" long Trace to P1 & P2 should be less than 1/4" R12 © 2005 Microchip Technology Inc TBD APPENDIX A: C7 0.1uF A AN1013 SCHEMATIC DS01013A-page C6 1uf 10k AN1013 NOTES: DS01013A-page © 2005 Microchip Technology Inc Note the following details of the code protection feature on Microchip devices: • Microchip products meet the specification contained in their particular Microchip Data Sheet • Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions • There are dishonest and possibly illegal methods used to breach the code protection feature All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data Sheets Most likely, the person doing so is engaged in theft of intellectual property • Microchip is willing to work with the customer who is concerned about the integrity of their code • Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code Code protection does not mean that we are guaranteeing the product as “unbreakable.” Code protection is constantly evolving We at Microchip are committed to continuously improving the code protection features of our products Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act Information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates It is your responsibility to ensure that your application meets with your specifications MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE Microchip disclaims all liability arising from this information and its use Use of Microchip’s products as critical components in life support systems is not authorized except with express written approval by Microchip No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights Trademarks The Microchip name and logo, the Microchip logo, Accuron, dsPIC, KEELOQ, microID, MPLAB, PIC, PICmicro, PICSTART, PRO MATE, PowerSmart, rfPIC, and SmartShunt are registered trademarks of Microchip Technology Incorporated in the U.S.A and other countries AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB, PICMASTER, SEEVAL, SmartSensor and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A Analog-for-the-Digital Age, Application Maestro, dsPICDEM, dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, Linear Active Thermistor, MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo, PowerMate, PowerTool, Real ICE, rfLAB, rfPICDEM, Select Mode, Smart Serial, SmartTel, Total Endurance, UNI/O, WiperLock and Zena are trademarks of Microchip Technology Incorporated in the U.S.A and other countries SQTP is a service mark of Microchip Technology Incorporated in the U.S.A All other trademarks mentioned herein are property of their respective companies © 2005, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved Printed on recycled paper Microchip received ISO/TS-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona and Mountain View, California in October 2003 The Company’s quality system processes and procedures are for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001:2000 certified © 2005 Microchip Technology Inc DS01013A-page WORLDWIDE SALES AND SERVICE AMERICAS ASIA/PACIFIC ASIA/PACIFIC EUROPE Corporate Office 2355 West Chandler Blvd Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://support.microchip.com Web Address: www.microchip.com Australia - Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 India - Bangalore Tel: 91-80-2229-0061 Fax: 91-80-2229-0062 China - Beijing Tel: 86-10-8528-2100 Fax: 86-10-8528-2104 India - New Delhi Tel: 91-11-5160-8631 Fax: 91-11-5160-8632 Austria - Wels Tel: 43-7242-2244-399 Fax: 43-7242-2244-393 Denmark - Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 China - Chengdu Tel: 86-28-8676-6200 Fax: 86-28-8676-6599 India - Pune Tel: 91-20-2566-1512 Fax: 91-20-2566-1513 France - Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 China - Fuzhou Tel: 86-591-8750-3506 Fax: 86-591-8750-3521 Japan - Yokohama Tel: 81-45-471- 6166 Fax: 81-45-471-6122 Germany - Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 China - Hong Kong SAR Tel: 852-2401-1200 Fax: 852-2401-3431 Korea - Gumi Tel: 82-54-473-4301 Fax: 82-54-473-4302 China - Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 Korea - Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934 Atlanta Alpharetta, GA Tel: 770-640-0034 Fax: 770-640-0307 Boston Westborough, MA Tel: 774-760-0087 Fax: 774-760-0088 Chicago Itasca, IL Tel: 630-285-0071 Fax: 630-285-0075 Dallas Addison, TX Tel: 972-818-7423 Fax: 972-818-2924 Detroit Farmington Hills, MI Tel: 248-538-2250 Fax: 248-538-2260 Kokomo Kokomo, IN Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles Mission Viejo, CA Tel: 949-462-9523 Fax: 949-462-9608 San Jose Mountain View, CA Tel: 650-215-1444 Fax: 650-961-0286 China - Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 China - Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 China - Shenzhen Tel: 86-755-8203-2660 Fax: 86-755-8203-1760 China - Shunde Tel: 86-757-2839-5507 Fax: 86-757-2839-5571 China - Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 China - Xian Tel: 86-29-8833-7250 Fax: 86-29-8833-7256 Malaysia - Penang Tel: 60-4-646-8870 Fax: 60-4-646-5086 Philippines - Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 Italy - Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Netherlands - Drunen Tel: 31-416-690399 Fax: 31-416-690340 Spain - Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 UK - Wokingham Tel: 44-118-921-5869 Fax: 44-118-921-5820 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan - Hsin Chu Tel: 886-3-572-9526 Fax: 886-3-572-6459 Taiwan - Kaohsiung Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan - Taipei Tel: 886-2-2500-6610 Fax: 886-2-2508-0102 Thailand - Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509 10/31/05 DS01013A-page © 2005 Microchip Technology Inc ... Fax: 8 6-2 8-8 67 6-6 599 India - Pune Tel: 9 1-2 0-2 56 6-1 512 Fax: 9 1-2 0-2 56 6-1 513 France - Paris Tel: 3 3-1 -6 9-5 3-6 3-2 0 Fax: 3 3-1 -6 9-3 0-9 0-7 9 China - Fuzhou Tel: 8 6-5 9 1-8 75 0-3 506 Fax: 8 6-5 9 1-8 75 0-3 521... Fax: 8 6-7 5 5-8 20 3-1 760 China - Shunde Tel: 8 6-7 5 7-2 83 9-5 507 Fax: 8 6-7 5 7-2 83 9-5 571 China - Wuhan Tel: 8 6-2 7-5 98 0-5 300 Fax: 8 6-2 7-5 98 0-5 118 China - Xian Tel: 8 6-2 9-8 83 3-7 250 Fax: 8 6-2 9-8 83 3-7 256... Korea - Gumi Tel: 8 2-5 4-4 7 3-4 301 Fax: 8 2-5 4-4 7 3-4 302 China - Qingdao Tel: 8 6-5 3 2-8 50 2-7 355 Fax: 8 6-5 3 2-8 50 2-7 205 Korea - Seoul Tel: 8 2-2 -5 5 4-7 200 Fax: 8 2-2 -5 5 8-5 932 or 8 2-2 -5 5 8-5 934 Atlanta Alpharetta,

Ngày đăng: 11/01/2016, 16:36

Từ khóa liên quan

Mục lục

  • Introduction

  • Types of Utility Meters

  • Reading Fluid Flow

    • TABLE 1:

    • FIGURE 1: Electronic Meter

    • Data Display

    • Advanced Features

    • Microcontroller Choice

      • TABLE 2:

      • FIGURE 2: Board Layout

      • Putting the hardware together

      • Wiring the Glass

      • Adding the Hall Effect Switches

      • RF Communications

      • Power Fail Detection

      • What is left?

      • Schematic

      • Software Development

      • Conclusion

      • Appendix A: Schematic

      • Trademarks

      • Worldwide Sales

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan