Sie sind auf Seite 1von 8

AN1013

Gas and Water Metering with the PIC16F91X Family


Author: Joseph Julicher John Charais Microchip Technology Inc.

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).

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.

TABLE 1:
Switch States 00 01 11 10 00 Meaning The magnet is not near the switches. The magnet has reached the first switch. The magnet is between the two switches. The magnet has reached the second switch. The magnet has moved past the switches.

Electric Meters
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.

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). 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.

If the state goes in the other direction, it means that the water has begun to backup. This indicates one of three things: 1. 2. 3. 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.

2005 Microchip Technology Inc.

DS01013A-page 1

AN1013
FIGURE 1: ELECTRONIC METER
Inside Gauge Inside Meter

N
Water Flow
Hall Effect 1

Electronic Meter

NC A

Hall Effect 2

DATA DISPLAY
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.

ADVANCED FEATURES
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 2

2005 Microchip Technology Inc.

AN1013
MICROCONTROLLER CHOICE
For this application, the PIC16F917 was chosen from Microchips new low-cost LCD family of devices (see Table 2): 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 Other advantages of using the PIC16F917 is the possibility to add additional advanced features in the application, such as: 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

TABLE 2:
Program Memory Device Flash (words/ bytes) 4K/7K 4K/7K 8K/14K 8K/14K Data Memory I/O SRAM (bytes) 256 256 352 352 EEPROM (bytes) 256 256 256 256 24 35 24 35 10-bit A/D (ch) LCD (segment drivers) 16 24 16 24 CCP Timer 8/16-bit

PIC16F913 PIC16F914 PIC16F916 PIC16F917

5 8 5 8

1 2 1 2

2/1 2/1 2/1 2/1

FIGURE 2:

BOARD LAYOUT
LCD1 J1 C1 U1 U2 PIC16F917 C11 C10 C9 U5 RF Module R7 C14 C12 R5 R2 R3 R4 P1 J14

D1
C5 + C6 +

R13 C2

C3

C4

R1

U3

U6 RF Module

C15 R8 R6 C13 R12 R10 P2 R11

C6 U4 C7 P69839

R9

Water Meter Demo

2005 Microchip Technology Inc.

DS01013A-page 3

AN1013
PUTTING THE HARDWARE TOGETHER
With the basic design decisions made, the next step is to assemble the building blocks into a working system.

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.

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<0-2>) and the LCD voltages (VLCD<0-3>). 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.

WHAT IS LEFT?
The last major step is providing a connection for programming and debugging. A 6-pin connector will allow an MPLAB ICD 2 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.

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: 1. 2. 3. 4. RA6 and RA7 (OSC1 and OSC2) RD0 RD1 RD2

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 2 device from Microchip Technology. The software is included, in a zip file, with this application note.

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.

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.

DS01013A-page 4

2005 Microchip Technology Inc.

A
R3 is needed to fine tune the contrast 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"
1 TP

APPENDIX A:

200k R5
5 Vcc ANT 16

+5V +5V

U5 P1
6 PDN DATA GND 15
RX_GND

1
TP-60R38
VLCD3

+VDD 100 R7 0.1uF C14


8

R3

R2

U1
RE2/SEG23
SEG23 SEG22 VLCD2 SEG21 SEG20

0.1uF

C12

R1

10k

R15

100k

0.1uF

10uF

2
100k R4
RD1 20

2 RD2/CCP2

SEG15

5 21

RA3/SEG15

C15 CAP3528

R8
TX_GND

TBD

R12

1 RD3/SEG16
SEG16

COM2

RA2/COM2

C13

C10

0.1uF

SEG0 SEG8 SEG9 SEG10 SEG11

33

RB0/SEG0

SEG1

34

RB1/SEG1

SEG2

35

RB2/SEG2

SEG3

36

RB3/SEG3

COMO0

37
SEG6 VLCD3 VLCD2

RB4/COM0 RC2/VLCD3 16 17

RD0/COM3 19 26 RC7/SEG8/RX 25 RC6/SEG9/TX 24 RC5/SEG10/CCP1 23 RC4/SEG11/SDO 18 RC3/SEG6

COMO1

38

RB5/COM1

C9 0.1uF

+VDD
Mount 45 degrees to each other

0.1uF

SEG5

RA5/SEG5

C11

47k

R17

RB7/SEG13/ICSPDAT RC0/VLCD1
VLCD1

R16

SEG13

47k

3 GND

GND

47uF

47uF

C3 0.1uF

C4 0.1uF

C2

10k

47uF 16v

C1 CAP3528

R13

DJ005B

1uf

0.1uF

C7 0.1uF

GND GND GND GND

BAT54C

C5

C6

C8

2005 Microchip Technology Inc.


10 9 8 30 29
SEG19

VDD RE1/SEG22 RE0/SEG21 RD7/SEG20

100k

11

100

LINX-RXM-XXX-LC-S
T-Attenuator For tuning RF output power

32

VDD

MCLR

+5V R6
7 Vcc ANT 5 Ladj/GND GND Data

U6
100 + R9
3

MCLR

RD6/SEG19 RD5/SEG18
SEG18

R10 TBD
2

R11 TBD

P2
TP

SCHEMATIC

SEG12

2 28

RA0/SEG12 27
SEG17

430
4

TP-60R38

S1
RD4/SEG17 22
VLCD1

SEG7

RA1/SEG7

SEG4

2
LINX-TXM-XXX-LC

RA4/SEG4

100

SEG14

39 15 2 VOUT

J14
+VDD
1 1 2

+VDD
MCLR

SEG0

RB6/SEG14/ICSPCK RC1/VLCD2

40

U3
VDD

VIM-838-DP LCD1

SEG1 SEG2 SEG3 SEG4 SEG5

3 4 5
SEG13

SEG6 SEG7 SEG8 SEG9 SEG14 COM0 SEG10 SEG11

3
OSC1/RA7 13 2

OSC2/RA6 14

3
U4
VOUT

12

VSS

31

+VDD
VDD 1

COM1 COM2

SEG12 SEG13 SEG14 SEG15 SEG16 SEG17 SEG18 SEG19 SEG20 SEG21 SEG22

VSS

com1 com2 com3

PIC16F914/917-TQFP
low voltage detect

ICD2/PICkit 2 Programming Header

U2 {Value} LM78L05ACM
8 IN OUT 1 2

+5V
3

D1
+ +

+VDD

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

SEG23

J1

Title Size

4
Water Meter Reference Design

Number

Rev

B
July, 2005 Date Filename

Drawn by Sheet 1 of

AN1013

DS01013A-page 5

AN1013
NOTES:

DS01013A-page 6

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 Microchips 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 Microchips 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 Microchips 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 Companys 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, Microchips quality system for the design and manufacture of development systems is ISO 9001:2000 certified.

2005 Microchip Technology Inc.

DS01013A-page 7

WORLDWIDE SALES AND SERVICE


AMERICAS
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 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 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509

ASIA/PACIFIC
Australia - Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China - Beijing Tel: 86-10-8528-2100 Fax: 86-10-8528-2104 China - Chengdu Tel: 86-28-8676-6200 Fax: 86-28-8676-6599 China - Fuzhou Tel: 86-591-8750-3506 Fax: 86-591-8750-3521 China - Hong Kong SAR Tel: 852-2401-1200 Fax: 852-2401-3431 China - Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 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

ASIA/PACIFIC
India - Bangalore Tel: 91-80-2229-0061 Fax: 91-80-2229-0062 India - New Delhi Tel: 91-11-5160-8631 Fax: 91-11-5160-8632 India - Pune Tel: 91-20-2566-1512 Fax: 91-20-2566-1513 Japan - Yokohama Tel: 81-45-471- 6166 Fax: 81-45-471-6122 Korea - Gumi Tel: 82-54-473-4301 Fax: 82-54-473-4302 Korea - Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 or 82-2-558-5934 Malaysia - Penang Tel: 60-4-646-8870 Fax: 60-4-646-5086 Philippines - Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 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

EUROPE
Austria - Wels Tel: 43-7242-2244-399 Fax: 43-7242-2244-393 Denmark - Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 France - Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany - Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 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

10/31/05

DS01013A-page 8

2005 Microchip Technology Inc.

Das könnte Ihnen auch gefallen