A kind of real-time data storage method
Technical field
The present invention relates to a kind of real-time property storage methods.
Background technique
In electrically driven control system, especially motor driven systems need the ginseng by real-time monitoring motor feedback
It counts to understand the working condition of motor.In some particular surroundings, motor is too far apart from operator or is in closed state, if
System breaks down at this time, and operator just cannot observe the situation of motor in real time, can only pass through the data convert failure of feedback
Preceding situation.
The parameter in operating status and operational process to record electrically driven control system, currently used method be by
Data are stored in individually storage equipment, mostly use the form of storage chip, SD card or storage dish greatly, wherein storage dish and SD
The form of card will increase other relevant devices, and increase expense simultaneously causes system cumbersome.In electric machine control system, accordingly it will usually be desirable to
The electric parameter data of observation are constantly stored into external memory chip, can not only be increased without additional equipment in this way, but also can
To realize the permanent storage of data, but equally exist problem: firstly, since micro-control unit (MCU,
Microcontroller Unit) and peripheral hardware between traffic rate it is limited, to guarantee on before data storage next time is initiated
Data storage movement has been completed, and general using the method for increasing data memory gap, this largely affects data
Real-time, and feed back data density directly affect reduction pre-fault status accuracy;Secondly, if shortening number by force
According to memory gap, increase the communication frequency between micro-control unit and peripheral hardware, then it is big to occupy micro-control unit for frequent communication
The operation resource of amount, influences the process of micro-control unit, and electrically driven control system is caused to be unable to operate normally.So how to make
The data of update can be stored in real time and influence to occupy its excessive operation resource by micro-control unit, for electrical
The long-range control and also original highly important effect of malfunction of drive system.
In internet information field, the storing process of data is completed by the interaction of network mostly, with hard disk or solid-state
Driver is storage medium, the long-range uninterrupted storage of multi-channel data may be implemented, whole realization is large server pair
The storage of mass data, hardware system of the realization of store function dependent on high performance storage server and complexity.
It is different from internet information field, in electrically driven control field, especially drive and control of electric machine field, to system
The volume of hardware has a corresponding limitation, data storages more it is emphasised that in short-term, high real-time is locally stored, and do not increasing
Additional equipment can characterize motor control system status to some under the premise of not influencing motor driven systems normal work
Electric parameter stored, and the requirement to data volume well below internet information data store.In drive and control of electric machine
In system, the renewal frequency of electric parameter and the interruption frequency of electrical system control program have direct relation, it is generally the case that electricity
The renewal frequency of gas parameter is not higher than the interruption frequency of electrical system control program, up to tens KHZ, and micro-control unit and outer
If traffic rate between is limited, cannot reach so high frequency.
Summary of the invention
The purpose of the present invention is overcoming the prior art, so that in micro-control unit piece outside data update rate and piece
Memory rate matching, proposes a kind of real-time data storage method.
The reality of data storage can be improved on the basis of not increasing original electrically driven control system hardware in the present invention
Shi Xing can reach the data that memory gap is Microsecond grade and store, and realize that data update in micro-control unit piece and the outer data of piece are deposited
That stores up is fully synchronized, while not influencing micro-control unit normal operation process.
The present invention opens up data buffer area in micro-control unit ram in slice, records electricity by the way of trigger-type storage
Gas drive autocontrol system operating status and operating parameter, the rate updated according to data is first by data buffer storage in micro-control unit
In ram in slice, the data of setting time length are cached in real time.When meeting trigger condition, micro-control unit will cache in RAM automatically
Data pass through data/address bus be stored in piece external storage chip in.Data transfer operation between RAM and piece external storage chip only exists
It is carried out when meeting trigger condition primary.
It is either given by man according to electrically driven control system needs that the trigger condition can be fault-signal
Signal.
Specific step is as follows by the present invention:
1, data cached
Data buffer storage in micro-control unit ram in slice divides into data buffer area after the preceding data buffer area of triggering and triggering
Two sector addresses.When trigger condition is unsatisfactory for, the electrically driven control system electric parameter monitored will be needed to recycle covering
Mode is buffered in the preceding data buffer area of triggering of micro-control unit internal RAM, and data cached time interval is according to real-time
Demand setting, grade can be achieved from Microsecond grade to second.The present invention is delayed with the size of data cached time span characterize data amount
The time span of deposit data is set according to the time interval of data buffer storage and the capacity of corresponding data buffer area.It is data cached micro-
In the preceding data buffer area of control unit internal trigger, according to the first address from the data buffer area to the sequential storage of last address.
It is every to pass through a data cached time interval, data cached one group of update during data buffer storage.It is every to update one group
It is data cached, be just stored in into the preceding data buffer area of triggering of micro-control unit internal RAM one group it is data cached.Trigger condition is not
When meeting, more alternately data buffer area is stored before activation for the datacycle of caching, after data buffer area is write completely, new data
It is written since the first address for triggering preceding data buffer area, covers original data.Finally in the touching of micro-control unit internal RAM
The data for caching of sending out data buffer area preceding are the data nearest apart from triggering moment.
When a triggering condition is met, the automatic data latched before triggering start data buffer area caching triggering on triggering
Signal occur after data, the data after triggering need not carry out circulation and substitute storage, only need to will be after the triggering of setting time length
Data buffer area after data deposit triggering, is deposited still according to the sequence of the first address from the data buffer area to last address
Storage.Time span data cached at this time and data cached time interval are set as needed.
2, data cached before triggering is recombinated
The data extracted before triggering to facilitate host computer preferably analyze electrically driven control before trigger condition occurs
The operating status of system needs the sequencing according to the data cached time, recombinates to data cached before triggering.It will delay
Deposit data, which starts to write the process for trigger the last address of preceding data buffer area from the first address write-in for triggering preceding data buffer area, to be determined
Justice is once to trigger the full storage of preceding data buffer area.The datacycle for needing to cache more alternately data buffer area before activation
Storage, the full storage that definition is completed once to trigger preceding data buffer area is a bat, wherein the data cached are current clap
Data, substitute covering data be it is upper one clap data.When trigger condition is unsatisfactory for, the data currently clapped constantly substitute covering
Upper one data clapped.
When trigger condition meets, the data for triggering preceding data buffer area stop updating and being latched.It is full with trigger condition
The triggering moment of foot is boundary, from the first address of the preceding data buffer area of triggering to the corresponding preceding data buffer area of triggering of triggering moment
Data between address are the current data for clapping caching, and the data that the timing node apart from triggering moment is nearest;When triggering
It is clapped to the data between the last address for triggering preceding data buffer area for upper one the address for carving the corresponding preceding data buffer area of triggering
The data of caching.
Data cached before triggering is recombinated according to the sequencing of data cached time, the data after recombination were both wrapped
A partial data for clapping caching, and the data including currently clapping update are included, upper one claps the data of caching in preceding, current bat caching
Data rear, separation is the address of the preceding data buffer area of triggering corresponding to triggering moment.
3, it writes data into piece external storage chip and stores
Permanent storage in piece external storage chip is written into data after data before triggering after recombination and triggering.Microcontroller list
Communication between member and piece external storage chip only carries out once, will not influence other of micro-control unit when trigger condition meets
Process.After the data uploading instructions for receiving host computer initiation, micro-control unit arrives the reading data in piece external storage chip
In internal RAM.Trigger condition can be fault-signal and either need signal given by man according to electrically driven control system.
4, data are uploaded into host computer
By setting data read rates in host computer, micro-control unit sets matched data automatically and uploads speed
Rate.Micro-control unit will pass through in CAN bus according to the data uploading instructions received from the data that piece external storage chip reads back
It is transmitted to host computer, fetched data is analyzed and handled in host computer.
The present invention is while making full use of high-speed RAM in micro-control unit piece, by the interaction of micro-control unit and peripheral hardware
Frequency is preferably minimized, and makes data update rate and the outer data storage rate of piece in micro-control unit piece fully synchronized, realization
The high real-time of data stores.The real-time of data storage greatly improved under the premise of not influencing micro-control unit process.
When having demand simultaneously, the data stored in piece external storage chip can be accessed by micro-control unit, and stored data is passed through
CAN bus uploads in host computer, realizes the real-time storage and retransmission function of critical data, this is for electrically driven control system
The research of operating status and after breaking down the reduction of fault message all play the role of it is highly important.
The present invention is suitable for electrically driven control system, is particularly suitable for driving control system for electric machine.
Detailed description of the invention
Fig. 1 real-time data storage method block diagram of the present invention;
Fig. 2 present invention implements data storage procedure schematic diagram;
Data are in MCU inner buffer process schematic before Fig. 3 is triggered;
Fig. 4 trigger condition meets moment MCU internal data buffer schematic diagram;
Fig. 5 data recombination process schematic.
Specific embodiment
The present invention is further illustrated below in conjunction with the drawings and specific embodiments.
Real-time property storage method of the present invention is applied to driving control system for electric machine.The storage of driving control system for electric machine
Part consists of three parts: micro-control unit, external memory chip and host computer.As shown in Figure 1, micro-control unit and outside are deposited
Data communication is carried out between storage chip, completes the storage of data;Data communication is carried out between micro-control unit and host computer, is completed
The monitoring and display of data.
As shown in Figure 1, real-time property storage method of the present invention will need the variable cached in micro-control unit ram in slice
In, it is cached in a manner of recycling covering;After data buffer storage, the data of all cachings are written to piece external storage by micro-control unit
In chip;Host computer, which issues, reads instruction, after micro-control unit receives reading instruction, the data stored before is read back into micro-
In control unit ram in slice;Host computer sends to micro-control unit and uploads data command;Micro-control unit will be in the data of reading
Pass to host computer.
It is specific such as shown in Figure 2:
1, data cached
When trigger condition is unsatisfactory for, electrically driven control system is needed into the electric parameter monitored to recycle the side of covering
Formula is buffered in the preceding data buffer area of triggering of micro-control unit internal RAM, and data cached time interval is according to real-time need
Ask setting.The present invention is with the size of data cached time span characterize data amount, and data cached time span is according to data
The time interval of caching and the capacity setting of corresponding data buffer area.The data cached data before micro-control unit internal trigger are slow
It deposits in area, according to the first address from the data buffer area to the sequential storage of last address.
It is every to pass through a data cached time interval, data cached one group of update during data buffer storage.It is every to update one group
It is data cached, be just stored in into the preceding data buffer area of triggering of micro-control unit internal RAM one group it is data cached.Trigger condition is not
When meeting, more alternately data buffer area is stored before activation for the datacycle of caching, after data buffer area is write completely, new data
It is written since the first address for triggering preceding data buffer area, covers original data.Finally in the touching of micro-control unit internal RAM
The data for caching of sending out data buffer area preceding are the data nearest apart from triggering moment.
When a triggering condition is met, the automatic data latched before triggering start data buffer area caching triggering on triggering
Signal occur after data, the data after triggering need not carry out circulation and substitute storage, only need to will be after the triggering of setting time length
Data buffer area after data deposit triggering, is deposited still according to the sequence of the first address from the data buffer area to last address
Storage.Time span data cached at this time and data cached time interval are set as needed.
2, data cached before triggering is recombinated
The data extracted before triggering to facilitate host computer preferably analyze electrically driven control before trigger condition occurs
The operating status of system needs the sequencing according to the data cached time, recombinates to data cached before triggering.Caching
Data start to write the process definition for triggering the last address of preceding data buffer area from the first address write-in for triggering preceding data buffer area
For the full storage for once triggering preceding data buffer area.More alternately data buffer area is deposited before activation for the datacycle for needing to cache
Storage, the full storage that definition is completed once to trigger preceding data buffer area is a bat, wherein the data cached are currently clapped
Data, the data for substituting covering are upper one data clapped.When trigger condition is unsatisfactory for, the data currently clapped constantly substitute in covering
One data clapped.
When trigger condition meets, the data for triggering preceding data buffer area stop updating and being latched.It is full with trigger condition
The triggering moment of foot is boundary, from the first address of the preceding data buffer area of triggering to the corresponding preceding data buffer area of triggering of triggering moment
Data between address are the current data for clapping caching, and the data that the timing node apart from triggering moment is nearest;When triggering
It is clapped to the data between the last address for triggering preceding data buffer area for upper one the address for carving the corresponding preceding data buffer area of triggering
The data of caching.
Data cached before triggering is recombinated according to the sequencing of data cached time, the data after recombination were both wrapped
A partial data for clapping caching, and the data including currently clapping update are included, upper one claps the data of caching in preceding, current bat caching
Data rear, separation is the address of the preceding data buffer area of triggering corresponding to triggering moment.
3, it writes data into piece external storage chip and stores
Permanent storage in piece external storage chip is written into data after data before triggering after recombination and triggering.Microcontroller list
Communication between member and piece external storage chip only carries out once, will not influence other of micro-control unit when trigger condition meets
Process.After the data uploading instructions for receiving host computer initiation, micro-control unit arrives the reading data in piece external storage chip
In internal RAM.Trigger condition can be fault-signal and either need signal given by man according to electrically driven control system.
4, data are uploaded into host computer
By setting data read rates in host computer, micro-control unit sets matched data automatically and uploads speed
Rate.Micro-control unit will pass through in CAN bus according to the data uploading instructions received from the data that piece external storage chip reads back
It is transmitted to host computer, fetched data is analyzed and handled in host computer.
As shown in figure 3, the process that data recycle covering caching inside micro-control unit MCU is as follows:
Assuming that the quantity for the electric parameter for needing to store is m, the value of m observes the quantity of electric parameter according to actual needs
It determines, m is usually no more than 20.Defining m parameter is one group.The value of electric parameter is continuously updated over time, selected to need to observe
M parameter value also with the time constantly update.Micro-control unit is every to store one group by a data cached time interval
Data, the time interval can be manually set, and grade can be achieved from Microsecond grade to second.With the data cached time interval that sets as
Standard stores the parameter value after each time interval.Assuming that needing to store N group altogether, the value of N depends on used
The amount for the data that the size and needs of CPU memory size cache, Nm are data cached length.From the 1st group sometime
Data start to cache, and cache next group according to the time interval set, after the completion of N group caching, data buffer storage before triggering
Area is filled with, and completes the full storage for once triggering preceding data buffer area.New data covers triggering after a time interval
The corresponding 1st group of data of preceding data buffer area first address, that is, trigger preceding data buffer area write it is full after, new data start again
From the first address write-in for triggering preceding data buffer area, upper one data for clapping storage are covered.After having covered the 1st group of data, continue to cover
The 2nd group of lid, and so on, after having covered N group, new data continue to cover the 1st group of data, and such 1-N group data are according to ground
The sequencing of location is cached to last address from the first address for triggering preceding data buffer area.
When being unsatisfactory for trigger condition, data recycle covering according to the data cached time interval of setting.Each of caching
The electric parameter of storage is designed with caching array ID number, and the ID number of the array that a data length is Nm, the 1st group of data is
0~m-1, the ID of the 2nd group of data are m~2m-1, and so on, the ID of N group data is (N-1) m~(Nm-1).
When trigger condition meets, data stop caching and latching automatically, as shown in figure 4, the process is as follows:
It is assumed that trigger condition is fault-signal, and is broken down when data buffer storage is to t group, and 1≤t≤N, t group data
ID be (t-1) m~[tm-1].Definition once triggered preceding data buffer area full storage be one bat, it is data cached from
The first address for triggering preceding data buffer area starts to be written, and is defined as one to the process for triggering the last address of preceding data buffer area is write
The full storage of the secondary preceding data buffer area of triggering.1 group shown in Fig. 4~(t-1) group data buffered for current bat, (t+1)
Group is to the data that N group is that a upper bat caches, that is, will cover data cached.Such as meet trigger condition at this time, number
According to the stopping caching after t group has updated, and the ID of data at this time is recorded, prepared for next data recombination.According to
Normal time sequencing, t+1 group~N group is data earlier, and 1 group~t group is later data.
In order to facilitate the data before analysis triggering, data recombinate sequentially in time before triggering, as shown in figure 5, according to
Time sequencing successively stores t+1 group~N group from the start address of external memory chip, 1 group~t group N group below successively
Storage.The sequence of data is at this time: (t+1) group, (t+2) group ... (N-1) group, N group, 1 group, 2 groups ... (t-1) groups, and t group.
It is written in external memory chip after data recombination, when data are read back, the sequence of data is the sequence after recombination, is conducive to
Analysis to system mode before triggering.