The lookup method of the last record of accumulative total power consumption
Technical field:
The present invention relates to the electric energy meter technical field, specifically is a kind of lookup method that is used for the last record of accumulative total power consumption of electric energy meter.
Background technology:
It generally is to adopt to calculate power consumption through the umber of pulse that reads electric pulse that electric energy meter calculates power consumption; For example: if be connected the pulse constant that uses electric pulse with the electric energy meter chip is 200; Then 1/200 degree is represented in each pulse; The power of supposing load that ammeter connects is 1kW, and then ammeter per hour just will produce 200 pulse outputs.Because the life-span of storer is determined by erasable number of times, so if deposit the accumulative total power consumption with fixed address, then if the erasable number of times of storer calculates by 100,000 times, this storer also can only use 20 days, the life-span is too low.Therefore; At present generally be to adopt the erasable mode of circulation to store the accumulative total power consumption; Promptly in storer, open up a circulation memory block with a plurality of addresses and be used for depositing the accumulative total power consumption specially, then from first address correct stored record backward of circulation memory block be 0001,0002,0003....0009,0010,0011..., after having write last address; Get back to first address cycle operation once more, so just prolonged the serviceable life of storer greatly.
In said method, the method that writes the accumulative total power consumption is waited for pulse exactly, when having detected pulse; The value that just will add up last record of power consumption adds 1 and writes next address, and it is then extremely important therefore to search the last record of accumulative total power consumption, and the lookup method of prior art generally has sequential search method and binary search or the like; These methods all can find accumulative total power consumption last record, but if there is a record to make mistakes in the loop-around data district, then can cause searching mistake occurring; Influence down-stream; Cause electric energy meter system to calculate electricity consumption and mistake occurs, fault-tolerance is relatively poor, and reliability is low.
Summary of the invention:
The technical matters that the present invention will solve is, overcomes existing technological deficiency, and a kind of zmodem is provided, the lookup method of the last record of accumulative total power consumption that reliability is high.
Technical solution of the present invention is, the lookup method of the last record of a kind of accumulative total power consumption is provided, and it may further comprise the steps:
(1), beginning, read article one record of memory block and be made as preceding record;
(2), read next bar and write down and be made as back one record;
(3), with preceding content recorded add 1 and back one record relatively, if equate, then back one record is made as preceding record, continue to search, return step (2);
(4), if unequal, then read next bar record as back two records, with preceding content recorded add 2 with back two records relatively, if equate, judge that then mistake appears in back one recording storage, back two records are made as preceding record, continue to search, return step (2):
(5), if unequal, content recorded is the last numerical values recorded of accumulative total power consumption before then judging, back one recorded address is for writing next recorded address;
(6), up to finding last record, do not find accumulative total power consumption last numerical values recorded yet, judge that then the last item is recorded as the last numerical values recorded of accumulative total power consumption, article one recorded address is for writing next recorded address.
After adopting said method, the present invention has the following advantages:
The method that the lookup method of the last record of the present invention's accumulative total power consumption adopts continuous three records to compare is searched the last record of accumulative total power consumption; If have a record to make mistakes in the circulation memory block; This method can be discerned automatically; Skip error logging and continue to search correct record, fault-tolerance is high, thereby improves the reliability of system greatly.
Embodiment:
Below in conjunction with embodiment the present invention is done further detailed explanation.
The present invention provides the lookup method of the last record of a kind of accumulative total power consumption, and it is characterized in that: it may further comprise the steps:
(1), beginning, read article one record of memory block and be made as preceding record;
(2), read next bar and write down and be made as back one record;
(3), with preceding content recorded add 1 and back one record relatively, if equate, then back one record is made as preceding record, continue to search, return step (2);
(4), if unequal, then read next bar record as back two records, with preceding content recorded add 2 with back two records relatively, if equate, judge that then mistake appears in back one recording storage, back two records are made as preceding record, continue to search, return step (2);
(5), if unequal, content recorded is the last numerical values recorded of accumulative total power consumption before then judging, back one recorded address is for writing next recorded address;
(6), up to finding last record, do not find accumulative total power consumption last numerical values recorded yet, judge that then the last item is recorded as the last numerical values recorded of accumulative total power consumption, article one recorded address is for writing next recorded address.
For example: the address in the storer is that the zone of 01H~60H is made as the circulation memory block, and 01H is recorded as 1000, and 02H is recorded as 1010, and 03H is recorded as 1002, and 04H is recorded as 0078, and 05H is recorded as 0079.Then the record 1000 with 01H is made as preceding record.
Read next bar record and be made as back one record; The record 1010 that next bar is recorded as 02H is back one record.
With preceding content recorded add 1 with back one record relatively, promptly 1000 add 1 with among the 02H 1010 relatively.
Unequal, then with the record 1002 of 03H as back two records, add 2 and 1002 relatively with 1000, equate, then with the record of 03H as preceding record, with next bar record and 04H 0078 as after a record,
With preceding content recorded add 1 with back one record relatively, 1002 add 1 with 0078 relatively, unequal,
The record 0079 of 05H as back two records, is added 2 with 0079 relatively with 1002, and unequal, that then judges 03H is recorded as the last numerical values recorded of accumulative total power consumption, then the numerical value that the next one writes is write among the 04H.
The method that the lookup method of the last record of the present invention's accumulative total power consumption adopts continuous three records to compare is searched the last record of accumulative total power consumption; If have a record to make mistakes in the circulation memory block; This method can be discerned automatically; Skip error logging and continue to search correct record, fault-tolerance is high, thereby improves the reliability of system greatly.