Design of CPU-type IC card gas meter based on SAM module

Publisher:脑电狂徒Latest update time:2013-06-17 Source: 与非网 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Prepaid smart IC card gas meter is a civil high-tech product that can automatically charge and control gas consumption according to the amount of gas purchased by the user's IC card. It can realize prepayment in conjunction with the gas sales management system, thereby eliminating the many inconveniences caused by manual meter reading at home, and can solve the problem of arrears. It has incomparable advantages over traditional manual meter reading and charging gas meters. At present, with the in-depth development of the national "Golden Card Project" and the official launch of the "West-to-East Gas Transmission" project in the northwest, IC card gas meters have shown a very broad application prospect. And improving ordinary IC cards into CPU cards (smart cards) will further enhance the confidentiality of this gas meter. This paper introduces the core technology of this product - the hardware and software design of the prepaid smart CPU IC card gas meter based on NEC single-chip microcomputer, and discusses the working principle, function, reliability design, low power consumption and low cost design of the IC card gas meter and its actual application.

1 Working principle of prepaid smart CPU IC card gas meter

The prepaid smart CPU IC card gas meter is composed of an intelligent measurement and control system based on a single-chip microcomputer installed on a conventional mechanical gas meter. The measurement and control system is mainly composed of a single-chip microcomputer, a SAM (Secure Access Module) module, a CPU IC card interface, a metering circuit, a protection detection circuit, and a gas circuit control valve. The system structure is shown in Figure 1.

Working principle: When the user inserts a CPU-type IC card containing a certain amount of gas purchased into the meter, the control valve opens the gas circuit valve under the control of the electronic control system software. Every time the user uses a tiny unit of gas (such as 1/1000L, the value is set according to the parameters of the mechanical meter), the metering circuit will send a metering pulse. If the pulse is determined to be valid by the electronic control system, it will enter the software for accumulation. When it reaches a certain number (such as 1/100L), it can subtract 1 metering unit from the purchased gas volume stored in the SAM module. When the remaining gas volume reaches a certain set value, the gas meter enters the alarm state and closes the control valve, cutting off the gas path to remind the user to purchase gas. At this time, the user can still open the valve to continue using gas after pressing a button once; when the remaining gas volume is zero, the control valve closes again, and the user can only open the valve after inserting a card storing a certain amount of gas purchased.

2 Functions realized by prepaid smart IC card gas meters

(1) Metering and control functions: Make full use of the single-chip microcomputer to measure various gas usage; control user gas usage through the control valve.

(2) Encryption function: A CPU card with extremely high encryption strength is used and one card is assigned to each household. After passing multiple internal and external authentications, gas purchase and other operations can be realized only when a certain authority is reached.

(3) Display function: It can display the remaining gas, monthly cumulative and quarterly cumulative gas, etc.; various system status displays, such as battery undervoltage, alarm status, gas overcurrent, etc.

(4) Reminder function: When the remaining gas is not much (equal to a certain set value), the valve is closed once to remind the user to purchase gas.

(5) Alarm function: Battery undervoltage alarm, gas overcurrent alarm to prevent pipeline rupture, valve opening and closing fault alarm, alarm of external combustible gas alarm interface, card abnormal operation alarm, gas meter cover opening alarm, etc. When an alarm occurs, the control valve is closed first, then the buzzer sounds and the LCD displays. Each alarm event will be recorded in the SAM module, and will be written back to the user's gas purchase card when the user purchases gas next time, and then returned to the gas sales department by the gas purchase card, so that it can be queried by the competent department or bank.

(6) Self-protection function: prevent high voltage attack and short circuit at IC card port and battery connection, cover opening detection, battery-free detection, select special pulse sensor that is not afraid of strong magnetic field, etc.

3 Hardware design of prepaid smart IC card gas meter

Because this prepaid IC card gas meter is a civilian product for families, the following principles should be taken into account when designing the hardware: low cost; low power consumption, extend battery life as much as possible; high reliability, no crash and loss of purchased gas data.

3.1 Selection of control microcontroller

The control microcontroller is the 8-bit microcontroller uPD789167 produced by NEC. uPD789167 is a low-cost microcontroller with 44pin package, with 24KB ROM, 512B RAM, 8-channel 8-bit A/D converter, external 32kHz subclock, 6 timers, 4 external interrupts and other resources, and has a very low cost after masking.

3.2 Design of clock circuit

This design uses the 3.58MHz main clock and 32kHz sub-clock of the uPD789167 microcontroller. The former runs when the microcontroller is working at high speed, and is provided to the SAM module and the external CPU-type IC card after internal 2-frequency division. In order to reduce power consumption, the 3.58MHz main clock stops oscillating when the power is turned on, the SAM module and the IC card are accessed, and the 32kHz crystal keeps oscillating to complete the internal software running time, the accumulation and statistics of gas volume, and assist in judging the gas volume per unit time, determining whether the gas is over-flowing, and driving the display of the LCD module when necessary.

3.3 Selection of SAM module and CPU-type IC card

Compared with ordinary memory cards and logic encryption cards, CPU cards have higher security because they use advanced technologies such as CPU, on-chip operating system (COS), file system, encryption and decryption algorithms. In order to improve the confidentiality performance of the smart gas meter, this design selects the SAM module and CPU card of Beijing Wuqi Company as the medium for security authentication, data storage and transmission. This product has independent intellectual property rights and complies with international standards and industry standards such as ISO7816 and PBOC. It supports hierarchical file structure and can establish a three-level application directory, which is suitable for the requirement of one card for multiple uses. It supports multiple file types including binary, fixed (variable) length records, wallet records, etc. It contains an E2PROM that can be erased and written 500,000 times, with a capacity ranging from 0.5K to 16KB. It has been successfully applied in industries such as electric meters. The interface between the CPU and the SAM module is shown in Figure 2. The standard stipulates that the CLOCK frequency must be greater than 1MHz. In this design, the CLOCK is 1.79MHz. When the SAM module is not accessed, the power supply of the SAM module is cut off, and the -RST and CLOCK pins of the CPU also output low levels, and the I/O pins of the CPU are set to input and internal non-pull-up mode.

3.4 Power supply circuit

As shown in Figure 3, the power supply is divided into two routes. One route is 3 batteries after 3V voltage regulation, and VCC supplies power to CPU, etc.; the other route is not voltage regulated, and VDD supplies power to the switch valve circuit. The two routes use their own Farad capacitors, which do not interfere with each other, ensuring the reliable closure of the valve when the power is off and the reliable storage of data transmitted to the SAM module.

The power supply circuit provides a 3.3V and 3V battery voltage detection mechanism. After voltage division, it enters the A/D conversion input terminal of the single-chip microcomputer. The single-chip microcomputer detects the voltage once at a fixed time interval. When it is found to be lower than 3.3V, the LCD displays a low voltage alarm; when it is lower than 3V, the valve is closed. In addition, the power supply circuit also provides a battery removal or short circuit detection circuit. When such a situation occurs, the collector of 9015 becomes high, and the single-chip microcomputer is activated in the form of an external interrupt, so that the single-chip microcomputer closes the valve in time. With the BAT54 dual diode, the purpose of preventing battery short circuit attacks is achieved.

In order to prevent high voltage attacks from the battery terminals, TVS tubes and 200mA recoverable fuses are configured. Combined with the protection of the IC card port, the safety of this gas meter is guaranteed.

3.5 Watchdog circuit

In a power supply circuit with a large-capacity capacitor, the power supply charges and discharges slowly, and the ordinary RC reset circuit often cannot produce a correct reset. In the normal use of the user, the gas meter is not allowed to crash. For this purpose, a reset and monitoring circuit (low-cost watchdog circuit) with power-on reset, watchdog, low-power and low-cost oscillator type is designed using 74HC14, as shown in Figure 4. In the figure, a 30kΩ resistor is combined with a 104 capacitor and a diode to form an RC power-on reset; at a working voltage of 3V, the watchdog clearing time interval must be less than 0.9 seconds. In the gas meter designed in this design, the CPU wakes up once every 0.5 seconds to detect and accumulate gas pulses, and at the same time sends a high-level clearing pulse with a width of 20μs. In addition, other gates of 74HC14 are also used in the shaping circuit of gas pulses and the isolation circuit of the IC card holder clock line.

3.6 Control valve drive circuit

The gas valve uses a specially designed low-power self-holding valve, which consumes power only during the switching process and does not consume power at other times. The solenoid valve drive circuit is shown in Figure 5. The minimum switching voltage requirement is 2.5V. The maximum current when opening the valve is about 120mA, and the maximum time is 2 seconds; the maximum current consumption when closing the valve is 100mA, and the maximum time is 1 second. The valve opening has a detection switch in place. If the valve opening timeout occurs, the CPU will issue a valve failure alarm signal and close the valve at the same time. The valve drive circuit uses a separate power supply VDD with a 0.22ΩF/5.5V capacitor (see Figure 3) to ensure the success of the valve opening and closing. 

3.7 IC card interface circuit

The IC card interface directly performs human-computer interaction and is most likely to be damaged intentionally or unintentionally. The most common phenomena are short circuit and high voltage series connection. Therefore, the interface circuit must have a complete protection function. The IC card holder and protection circuit are shown in Figure 6. After the CPU finds that IC SWITCH is at a low level, it knows that a card has been inserted, and then starts the 3.58MHz crystal oscillation, outputs -IC PWR CTRL low level, and supplies power to the card holder. Then, after a 5ms delay, it checks whether the power supply of the card holder is accurate from the IC VCC end. This can be detected by the A/D converter of the microcontroller. If the voltage is too low, the power supply is immediately turned off and the card reading is abandoned. Each signal line has a current and voltage limiting protection circuit composed of a positive temperature coefficient thermistor (MZ12A-75S102M008, resistance value is 1000Ω, operating current is 16mA) and an embedded diode (1N4148) to prevent external high voltage series connection. Because the resistance on the power line cannot be too large, the thermistor must be selected separately, so MZ12A-3R5N010 (resistance is 3.5Ω, operating current is 200mA) is selected.

3.8 Cover opening detection circuit

As shown in Figure 7, S1 is a reed, which is closed when the gas meter is covered at the factory. When the gas meter is opened, S1 is disconnected. Although both the left and right circuits in Figure 7 can detect the cover opening, that is, the level of the "cover opening detection" terminal changes when the cover is opened, the power consumption of the left circuit is obviously greater than that of the right circuit. First, since the input pin of the CPU allows a maximum leakage current of 3μA, the resistance of the 200kΩ resistor cannot be increased, otherwise it will affect the judgment of the high and low levels. Assuming VCC=3V, the static current on the left is 3V/200kΩ=15μA, and the static current on the right is 3V/1MΩ=3μA, which is 1/5 of the former, so this design uses the circuit on the right. The CPU detects the "cover opening detection" terminal within the wake-up time of every 0.5 seconds. Once the cover is opened, the valve will be closed, an alarm will be sounded, and an open cover event will be recorded in the SAM module.

3.9 Alarm and LCD display circuit The

uPD789167 single-chip microcomputer drives the LCD module to display in a serial communication mode, but the LCD is disconnected from the power supply when it is not displaying to save energy. In addition, a buzzer alarm circuit is provided to remind the user when a fault is just discovered.

4 Low-power design technology

The design of this gas meter is: not only must the CPU maintain the real-time clock and have a watchdog, but the power consumption must be very low (the normal working current is slightly greater than 30μA). To this end, the following measures are adopted to ensure the low-power operation of the machine.

4.1 Use low-power devices

In this design, low-power devices are used as much as possible. For example, the 3V regulator uses Ricoh's low-power products; a low-power self-maintaining valve is used, which only consumes power during the switching process.

4.2 Use low-power circuit design

(1) The CPU and other peripheral circuits are powered only after the battery voltage drops to 3V, so that the chip consumes less current when working at a low voltage.

(2) The SAM module and IC card holder are normally powered off and only powered during read and write authentication.

(3) When it does not affect the CPU level judgment, use a larger resistor (such as in the cover opening detection and battery detection circuits).

The pulse sampling circuit also consumes power only when there is a pulse.

4.3 Software coordination to achieve low power consumption

(1) Let the microcontroller work at a low speed as much as possible. The software only allows the 3.58MHz crystal to oscillate when accessing the SAM module and the CPU IC card. Normally, only a 32kHz crystal can be used to complete the work.

(2) Reasonably configure the various pins of the CPU, and the output pins output appropriate levels so that they do not output or absorb current normally; the input pins generally do not use internal pull-up resistors but external resistors because the internal pull-up resistors are small, with a typical value of 30kΩ when masked, and consume more power when the input is low level; the redundant pins of the CPU are set to output mode and output low level.

(3) When the CPU works under the 32kHz crystal, it is in HALT mode and wakes up once every 0.5 seconds or an interrupt. The software checks several interrupt flags, counts, runs, and clears the dog immediately after entering HALT sleep, thereby effectively saving power.

5 Software Design of Prepaid Smart IC Card Gas Meter

5.1 Software Function Modules


The software is written in NEC78k0S C language, using modular and hierarchical programming methods. The core parts include the following modules: SAM, CPU card communication module (T=0, character mode, serial rate 9.6Kbps); SAM, CPU card authentication and read/write module; gas metering module; power management module; LCD display module; alarm module; factory test module, etc. (due to space reasons, they are not described in detail here).

5.2 Authentication process of SAM and CPU card

In this gas meter, the software must receive and process multiple CPU cards: user gas purchase card, inspection card, manufacturer test card (such as valve detection card, etc.), modification master key card, etc. The directory file structure and authentication access method of each CPU card are different. Taking the user gas purchase card as an example and inserting the card into the gas meter after purchasing gas, the software authentication process is explained:

(1) Identify the type of card from the readable binary file of the card, that is, the user gas purchase card.

(2) The gas meter reads the card serial number and user number from the user card and compares the user number with the one stored in SAM. If they are not consistent, the card reading is rejected.

(3) If the user numbers are consistent, the IC card gas meter sends the card serial number to the SAM module. The SAM module encrypts the card serial number and generates a corresponding internal authentication key.

(4) The gas meter uses the internal authentication key to internally authenticate the user card.

(5) The gas meter uses the external authentication key to externally authenticate the user card.

(6) The gas meter reads the gas purchase data from the user card gas purchase application binary file, determines its integrity, and determines whether the number of gas purchases is consistent with that in the IC gas meter. If they are inconsistent, the application binary file (data) is written back to the IC card gas meter to exit; if they are consistent, enter (7).

(7) The IC card gas meter uses the gas volume external authentication key to externally authenticate the SAM module. If they are consistent, the gas volume and status data are stored in the SAM module, and the data is written back to exit, completing the gas purchase operation; otherwise, only the data is written back to exit.

6 Conclusion

The CPU IC card prepaid gas meter based on NEC single chip microcomputer and SAM module has made useful exploration in terms of security and confidentiality, anti-attack, low power consumption and low cost. After several months of actual use, it has been proved to achieve the expected effect. 

Reference address:Design of CPU-type IC card gas meter based on SAM module

Previous article:Intelligent residual current protector electromagnetic compatibility design
Next article:Multi-output flyback power supply for audio amplifiers

Latest Power Management Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号