CN102457268A - Implementation method for 32-bit capture register - Google Patents

Implementation method for 32-bit capture register Download PDF

Info

Publication number
CN102457268A
CN102457268A CN2010105157665A CN201010515766A CN102457268A CN 102457268 A CN102457268 A CN 102457268A CN 2010105157665 A CN2010105157665 A CN 2010105157665A CN 201010515766 A CN201010515766 A CN 201010515766A CN 102457268 A CN102457268 A CN 102457268A
Authority
CN
China
Prior art keywords
timer
bit
mouth
frequency
port
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN2010105157665A
Other languages
Chinese (zh)
Other versions
CN102457268B (en
Inventor
翟富昌
赵长兵
肖永华
李增利
王敬仁
刘国营
欧阳强
常红旗
陈磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing DeWitt electric Polytron Technologies Inc
Original Assignee
DEWEITE ELECTRIC POWER SYSTEM AUTOMATIC Co Ltd BEIJING
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by DEWEITE ELECTRIC POWER SYSTEM AUTOMATIC Co Ltd BEIJING filed Critical DEWEITE ELECTRIC POWER SYSTEM AUTOMATIC Co Ltd BEIJING
Priority to CN201010515766.5A priority Critical patent/CN102457268B/en
Publication of CN102457268A publication Critical patent/CN102457268A/en
Application granted granted Critical
Publication of CN102457268B publication Critical patent/CN102457268B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention provides an implementation method for a 32-bit capture register. The method comprises the following steps of: selecting an I/O (Input/Output) port of a used microprocessor; defining the I/O port as a capture port; setting an interrupt trigger mode of the I/O port as raising edge or falling edge interrupt trigger, wherein the I/O port is used for detecting a square wave signal carrying with frequency information; selecting a 16-bit timer of the used microprocessor; and configuring a first timer/counter and a second timer/counter of the 16-bit timer as a 32-bit period counter by calling a TIMER_CONFIGURE function. By setting a power system frequency measuring program, a frequency capture function of the 32-bit capture register is realized. The implementation method is simple and can guarantee the accuracy of power system frequency measurement.

Description

32 implementation methods of catching register
Technical field
The present invention relates to the implementation method of microprocessor 32 bit registers, particularly be used for 32 implementation methods of catching register that power system frequency is measured.
Background technology
Need in the electric power system accurately to measure its electric frequency, portioned product has only 16 to catch register in the more microcontroller but use in the market, and these 16 are caught the register maximum count value is 65536; Timing is spaced apart 1.31072ms; And the power frequency period of general microprocessor is 20ms, in this case, and when utilizing 16 bit frequencies to catch to send device measuring electrical frequency; Need full 15 the maximum cycle values of counting just can reach a power frequency time interval; Even if can count full power frequency period at interval, the resolution of its frequency measurement also can be lower, can not guarantee the precision that electric frequency measurement is calculated.In this case, most protective devices adopt fixed sampling frequency to sample, and perhaps adopt slotting point mode to carry out compensation data, still, when above-mentioned sample mode causes frequency change when measuring system owing to fault, just can't guarantee the accuracy of sample frequency.
Summary of the invention
The object of the present invention is to provide a kind of 32 implementation methods of catching register, can overcome deficiency of the prior art, guaranteed the precision that power system frequency is measured.
For achieving the above object, technical scheme of the present invention is: 32 implementation methods of catching register of the present invention may further comprise the steps:
Step 1: an I/O mouth (input/output of selected used microprocessor; Input/output port); Described I/O mouth is defined as catches mouth; And the down trigger mode of described I/O mouth is set to rising edge or trailing edge down trigger, and this I/O mouth is used to detect the square-wave signal that has frequency information;
Step 2: one 16 bit timing devices (timer) of selected described microprocessor; Through calling the TIMER_CONFIGURE function one first Timer (timerA) and one second Timer (timerB) of described 16 bit timing devices is configured to 32 bit period counters, makes this 16 bit timing utensil that 32 bit count functions arranged.
Preferably, described I/O mouth has higher interrupt priority level, perhaps has capturing function.
Preferably, the interrupt priority level of described I/O mouth is set to 2.
Preferably, described first Timer and second Timer are 16.
Preferably, the loading value of described first Timer is as the initial value of 32 bit period counters, and the current count value of described second Timer is the currency of described 32 bit period counters.
Preferably; Under 32 bit patterns; When first Timer and second Timer are configured to complete 32 bit period counters, to the operations of first Timer and second Timer, as loading initial value, operation control, interruption controls etc.; All be with to the control of the operations of first Timer, and the operation of second Timer is not had any effect to generally 32 bit period counters as generally 32 bit period counters.
Catch the electric frequency that register is used to measure electric power system for 32 of the present invention, realize simply, and can guarantee the precision that power system frequency is measured.
Description of drawings
Fig. 1 is 32 overview flow charts of catching the implementation method of register of the present invention;
Fig. 2 catches the flow chart of an embodiment of the implementation method of register for 32 of the present invention.
Embodiment
For making the feature and advantage of the present invention can be more obviously understandable, the present invention be done further detailed explanation below in conjunction with accompanying drawing and specific embodiment.
See also Fig. 1,32 implementation methods of catching register of the present invention may further comprise the steps:
Step 1: an I/O mouth (input/output of selected used microprocessor; Input/output port); Described I/O mouth is defined as catches mouth; And the down trigger mode of described I/O mouth is set to rising edge or trailing edge down trigger, and this I/O mouth is used to detect the square-wave signal that has frequency information;
Step 2: one 16 bit timing devices (timer) of selected described microprocessor; Through calling the TIMER_CONFIGURE function one first Timer (timerA) and one second Timer (timerB) of described 16 bit timing devices is configured to 32 bit period counters, makes this 16 bit timing utensil that 32 bit count functions arranged.
Preferably, described I/O mouth has higher interrupt priority level, perhaps has capturing function.
Preferably, the interrupt priority level of described I/O mouth is set to 2.
Preferably, described first Timer and second Timer are 16.
Preferably, the loading value of described first Timer is as the initial value of 32 bit period counters, and the current count value of described second Timer is the currency of described 32 bit period counters.
Preferably; Said TIMER_CONFIGURE function comprises two parameter values; Be respectively timer parameter and figure place parameter, present embodiment is that the timer 2 of processor is set to 32 bit period counters, and the timer parameter in the TIMER_CONFIGURE function is set to timer 2; The figure place parameter is set to 32, then can first Timer and second Timer of timer 2 be configured to 32 bit period counters.
Preferably; Under 32 bit patterns; When first Timer and second Timer are configured to complete 32 bit period counters, to the operations of first Timer and second Timer, as loading initial value, operation control, interruption controls etc.; All be with to the control of the operations of first Timer, and the operation of second Timer is not had any effect to generally 32 bit period counters as generally 32 bit period counters.
See also Fig. 2, may further comprise the steps when the present invention implements:
S101: select an I/O mouth (input/output, input/output port) of the used microprocessor of electric frequency measuring system, this I/O mouth edge is set triggers interrupt mode, be used to detect the square-wave signal that has frequency information; And
Select the one 16 bit timing devices (present embodiment is selected the timer 2 of used microprocessor) of used microprocessor, it is used to realize 32 bit period counter function;
S102: the external interrupt of closing used microprocessor;
S103: close the peripheral module of used microprocessor, this peripheral module comprises I/O mouth module, timer module, A/D sampling module and watchdog module etc.;
S104: the measuring system clock is set; Promptly enable PLL (Phase Locked Loop; Phase-locked loop or phase-locked loop) and be connected to microprocessor as system clock; It is 200MHz that the PLL output frequency is set, and the frequency division value of measuring system output frequency divider is set to 4, and then to carry out the output frequency behind four frequency divisions be 50MHz in system;
S105: enable the I/O mouth and interrupt;
S106: initialization I/O mouth, selected I/O mouth is defined as catches mouth, this is caught and mouthful is set to input port, and this is set catches mouthful rising edge or trailing edge triggering mode;
S107: initialization first Timer and second Timer, second Timer is set to have the counter of capturing function;
S108: enable first Timer and second Timer;
S109: call the TIMER_CONFIGURE function first Timer and second Timer are configured to 32 bit period counters; In 32 singles triggerings and cycle timer pattern; First Timer and second Timer connect together and are configured to 32 down counters; And according to writing the GPTM first Timer pattern (GPTMTAMR; The value of the TAMR bit field general purpose timer first Timer pattern) can be confirmed it is chosen as cyclic pattern, need not write the GPTM second Timer pattern (GPTMTBMR, the general purpose timer second Timer pattern) this moment;
S110: the loading value a that first Timer is set is (in the present embodiment; Used operation frequency of microprocessor is 50MHz; It is 1999999 that a value then is set), as the initial value of 32 bit period counters, the current count value b of second Timer is set to the currency of 32 bit period counters;
S111: the output of forbidding first Timer and second Timer triggers function;
S112: the interruption of overflowing of first Timer and second Timer is set;
S113: enable first Timer and second Timer and begin counting.
During enforcement; Catch register and begin frequency measurement when work when these 32; At first, the frequency measurement program of electric power system gets into I/O mouth interrupt service routine, and this power system frequency process of measurement gets into to have no progeny in the I/O mouth at every turn and all takes out the currency b of 32 bit period counters immediately; And the initial value of 32 bit period counters is set to a (because after frequency measuring system powers on, the data message in 1 second will be dropped) immediately.After the frequency measurement program running 1 second; When this frequency measurement program gets into I/O mouth interrupt service routine once more; Take out the currency b of this 32 bit period counter, deduct currency b with its initial value a and obtain a difference, this difference promptly is the timing numerical value of a power frequency period; With the dtd of this difference is floating number (float type), and computing formula is following:
f = 50000000.00 float ( a - b )
Wherein, f is the electric frequency values of required measurement, and the molecular moiety of this formula is the operating frequency of used microprocessor.
Result of the test shows: if adopt 16 to catch the electric frequency that register is measured electric power system, because 16 maximum count value of catching register are 0xffff, timing is spaced apart 1.31072ms; And a power frequency period is 20ms; So, in this case, catch for 16 and send device and need count full 15 maximum cycle values and just can reach a power frequency time interval; But program can't be handled this situation, also can't guarantee the power system frequency certainty of measurement; If adopt 32 of the present invention to catch the electric frequency that register is used to measure electric power system, realize simply, and can guarantee precision≤0.01Hz that power system frequency is measured.
Obviously, the foregoing description is merely the explanation of technical scheme of the present invention and unrestricted, and various changes that technical scheme of the present invention is carried out and be equal to replacement and do not break away from the spirit and scope of the present invention all should be encompassed within the claim scope of the present invention.

Claims (4)

1. 32 implementation methods of catching register is characterized in that, may further comprise the steps:
Step 1: an I/O mouth of selected used microprocessor, the down trigger mode of described I/O mouth is set to rising edge or trailing edge down trigger, and this I/O mouth is used to detect the square-wave signal that has frequency information;
Step 2: one 16 bit timing devices of selected described microprocessor are configured to 32 bit period counters through calling the TIMER_CONFIGURE function with one first Timer and one second Timer of described 16 bit timing devices.
2. 32 implementation methods of catching register according to claim 1 is characterized in that the interrupt priority level of described I/O mouth is set to 2.
3. 32 implementation methods of catching register according to claim 1 is characterized in that described first Timer and second Timer are 16 bit timings/counter.
4. 32 implementation methods of catching register according to claim 3; It is characterized in that; The loading value of described first Timer is set to the initial value of described 32 bit period counters, and the current count value of described second Timer is set to the currency of described 32 bit period counters.
CN201010515766.5A 2010-10-15 2010-10-15 Implementation method for 32-bit capture register Active CN102457268B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201010515766.5A CN102457268B (en) 2010-10-15 2010-10-15 Implementation method for 32-bit capture register

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201010515766.5A CN102457268B (en) 2010-10-15 2010-10-15 Implementation method for 32-bit capture register

Publications (2)

Publication Number Publication Date
CN102457268A true CN102457268A (en) 2012-05-16
CN102457268B CN102457268B (en) 2014-10-22

Family

ID=46040022

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201010515766.5A Active CN102457268B (en) 2010-10-15 2010-10-15 Implementation method for 32-bit capture register

Country Status (1)

Country Link
CN (1) CN102457268B (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102938197A (en) * 2012-10-26 2013-02-20 合肥移瑞通信技术有限公司 Method for decoding infrared remote control by means of input capture interrupt mode
CN105302226A (en) * 2015-10-30 2016-02-03 北京时代民芯科技有限公司 APB bus-based multi-function mode timer circuit
CN105807843A (en) * 2016-03-17 2016-07-27 东莞华芯世纪微电子有限公司 Method for achieving timer/counter and apparatus using method
CN112650119A (en) * 2020-12-22 2021-04-13 深圳市禾望电气股份有限公司 Method and device for expanding event occurrence time measurement range based on MCU

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1553336A (en) * 2003-05-30 2004-12-08 中兴通讯股份有限公司 Testing software timing method
US20090184742A1 (en) * 2008-01-23 2009-07-23 Microchip Technology Incorporated Externally Synchronizing Multiphase Pulse Width Modulation Signals
CN101495959A (en) * 2006-08-02 2009-07-29 高通股份有限公司 Method and system to combine multiple register units within a microprocessor

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1553336A (en) * 2003-05-30 2004-12-08 中兴通讯股份有限公司 Testing software timing method
CN101495959A (en) * 2006-08-02 2009-07-29 高通股份有限公司 Method and system to combine multiple register units within a microprocessor
US20090184742A1 (en) * 2008-01-23 2009-07-23 Microchip Technology Incorporated Externally Synchronizing Multiphase Pulse Width Modulation Signals

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
党力明等: "基于89C55WD单片机的32位高精度计时器", 《测绘科学技术学报》, vol. 24, no. 5, 31 October 2007 (2007-10-31) *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102938197A (en) * 2012-10-26 2013-02-20 合肥移瑞通信技术有限公司 Method for decoding infrared remote control by means of input capture interrupt mode
CN105302226A (en) * 2015-10-30 2016-02-03 北京时代民芯科技有限公司 APB bus-based multi-function mode timer circuit
CN105302226B (en) * 2015-10-30 2018-01-16 北京时代民芯科技有限公司 A kind of multifunctional mode timer circuit based on APB buses
CN105807843A (en) * 2016-03-17 2016-07-27 东莞华芯世纪微电子有限公司 Method for achieving timer/counter and apparatus using method
CN105807843B (en) * 2016-03-17 2019-07-23 东莞华芯世纪微电子有限公司 A kind of method that realizing Timer/Counter and device in this way
CN112650119A (en) * 2020-12-22 2021-04-13 深圳市禾望电气股份有限公司 Method and device for expanding event occurrence time measurement range based on MCU

Also Published As

Publication number Publication date
CN102457268B (en) 2014-10-22

Similar Documents

Publication Publication Date Title
CN103176042B (en) A kind of frequency measurement method, device and frequency meter
CN103837741B (en) Equally accurate frequency testing system based on FPGA and method for designing thereof
CN106569032B (en) A kind of detection method of signal frequency and duty ratio based on embedded microcontroller
CN102176112B (en) Method for achieving accurate clock timing by arranging RTC (real time clock) in MCU (micro control unit)
CN102457268B (en) Implementation method for 32-bit capture register
CN103487649B (en) Method and device capable of measuring both frequency of continuous waves and frequency of pulse modulation carrier waves
CN102315983B (en) Circuit and method for automatically detecting Baud rate of multiple paths of serial communication interfaces
CN106597096A (en) Clock frequency monitoring method
CN104939927A (en) Wearing state detecting method and device of intelligent wearable device and intelligent wearable device
CN105318918A (en) A non-magnetic flow metering device and a metering method thereof
CN202915962U (en) Water meter data collector
CN101865951B (en) Anti-interference frequency measuring method
CN102809725B (en) Sensitive element device for bypass signal of sensing circuit and detection method of sensitive element device
CN103197139A (en) Clock frequency test method and clock frequency test circuit
CN205725685U (en) Periodic pulse signal based on programmable logic chip detects protection module automatically
CN111008239B (en) Data synchronization method and system of asynchronous system and terminal equipment
US20140153623A1 (en) Device for auto baud rate detection
CN108809299A (en) signal frequency measuring system
CN202434049U (en) Water meter data acquirer
CN104359529A (en) Sensing detecting device for liquid level of biochemical analyzer and method
CN116559528A (en) Chip frequency measuring method, circuit, device, storage medium and computer equipment
CN107817034B (en) Method and device for correcting temperature of meter
CN206235863U (en) Gauge table and its metering module based on low-power consumption sensor interface
CN204405149U (en) Adverse current and magnetic interference testing circuit
CN108107267A (en) A kind of microelectronics equal precision frequency meter

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
ASS Succession or assignment of patent right

Owner name: BEIJING DEVOTE RELAY PROTECTION TECHNOLOGY CO., LT

Free format text: FORMER OWNER: DEWEITE ELECTRIC POWER SYSTEM AUTOMATIC CO., LTD., BEIJING

Effective date: 20120726

C41 Transfer of patent application or patent right or utility model
COR Change of bibliographic data

Free format text: CORRECT: ADDRESS; FROM: 100082 HAIDIAN, BEIJING TO: 101318 SHUNYI, BEIJING

TA01 Transfer of patent application right

Effective date of registration: 20120726

Address after: 101318 Anqing, Shunyi District Tianzhu Airport Industrial Zone B street, No. 1, Beijing

Applicant after: Beijing Devote Relay Protection Technology Co., Ltd.

Address before: 100082 No. two, No. 5, North Zhongguancun, Beijing, Haidian District

Applicant before: Deweite Electric Power System Automatic Co., Ltd., Beijing

C53 Correction of patent of invention or patent application
CB03 Change of inventor or designer information

Inventor after: Di Fuchang

Inventor after: Gao Longji

Inventor after: Chen Lei

Inventor after: Zhao Changbing

Inventor after: Li Huiyong

Inventor after: Zhang Jian

Inventor after: Li Zengli

Inventor after: Wang Jingren

Inventor after: Liu Guoying

Inventor after: Ou Yangqiang

Inventor after: Chang Hongqi

Inventor before: Di Fuchang

Inventor before: Zhao Changbing

Inventor before: Xiao Yonghua

Inventor before: Li Zengli

Inventor before: Wang Jingren

Inventor before: Liu Guoying

Inventor before: Ou Yangqiang

Inventor before: Chang Hongqi

Inventor before: Chen Lei

COR Change of bibliographic data

Free format text: CORRECT: INVENTOR; FROM: ZHAI FUCHANG ZHAO CHANGBING XIAO YONGHUA LI ZENGLI WANG JINGREN LIU GUOYING OU YANGQIANG CHANG HONGQI CHEN LEI TO: ZHAI FUCHANG ZHAO CHANGBING LI HUIYONG ZHANG JIAN LI ZENGLI WANG JINGREN LIU GUOYING OU YANGQIANG CHANG HONGQI GAO LONGJI CHEN LEI

C14 Grant of patent or utility model
GR01 Patent grant
CP03 Change of name, title or address

Address after: 101300 1, 1 yuan 17, Juyuan Road, Mapo Town, Shunyi District, Beijing.

Patentee after: Beijing DeWitt electric Polytron Technologies Inc

Address before: 101318 Beijing Shunyi District Tianzhu Airport Industrial Area B area Anqing avenue a 9

Patentee before: Beijing Devote Relay Protection Technology Co., Ltd.

CP03 Change of name, title or address