Method and device for accurately timing by utilizing RS232 serial port

文档序号:1651164 发布日期:2019-12-24 浏览:14次 中文

阅读说明:本技术 一种利用rs232串口精确对时的方法及装置 (Method and device for accurately timing by utilizing RS232 serial port ) 是由 程加强 赵小凤 罗培城 毛敏 于 2019-09-12 设计创作,主要内容包括:一种利用RS232串口精确对时的方法,包括如下步骤:S1.授时装置输出串口信号到二次监测装置RS232串口的RXD引脚,S2.二次监测装置串口响应中断后,根据串口包含的年月日时分秒时间信息对时系统秒级以上大时间信息;S3.授时装置输出秒脉冲信号到RS232接口的DCD引脚,秒脉冲信号上升沿触发所述DCD引脚的串口控制器中断,以微秒时间偏差为基础,通过PID算法计算的步长值对系统的微秒时间计数器步长值进行修正;S4.所述二次监测装置根据步骤S2和S3对时系统秒级以上大时间信息和修正系统微秒时间计数器步长值从而对装置系统时间进行整体对时。本发明还公开了一种利用RS232串口精确对时的装置。本发明在不增加硬件成本和接口的情况下,可以利用原有装置硬件串口实现精确对时。(A method for accurately timing by utilizing an RS232 serial port comprises the following steps that S1, a timing device outputs a serial port signal to an RXD pin of the RS232 serial port of a secondary monitoring device, S2, after the serial port of the secondary monitoring device responds to interruption, large time information above a system second level is timed according to year, month, day, hour and minute time information contained in the serial port, S3, the timing device outputs a second pulse signal to a DCD pin of an RS232 interface, the rising edge of the second pulse signal triggers a serial port controller of the DCD pin to interrupt, the step value of a microsecond time counter of the system is corrected through a step value calculated through a PID algorithm on the basis of microsecond time deviation, and S4, the secondary monitoring device corrects the large time information above the system second level and the step value of the system microsecond time counter according to the steps of S2 and S3, so that the system time of the device is integrally timed. The invention also discloses a device for accurately setting time by utilizing the RS232 serial port. The invention can realize accurate time synchronization by utilizing the hardware serial port of the original device under the condition of not increasing hardware cost and interfaces.)

1. A method for accurately synchronizing time by utilizing an RS232 serial port is characterized by comprising the following steps:

s1, the time service device outputs a serial port signal to an RXD pin of an RS232 interface of the secondary monitoring device,

s2, after the secondary monitoring device responds to the serial port interruption, the secondary monitoring device compares the big time information of the time system with the second level or more according to the year, month, day, hour, minute and second time information contained in the serial port signal;

the S3 time service device outputs a pulse-per-second signal to a DCD pin of the RS232 interface, and the rising edge of the pulse-per-second signal triggers the serial port controller of the DCD pin of the RS232 interface to interrupt;

setting the secondary monitoring device to read the microsecond-level time calculation time deviation by taking the time of triggering interruption of the rising edge of the pulse per second signal as the starting point of the microsecond time zero time, and then correcting the step value of the system microsecond time counter by the step value calculated by a PID algorithm on the basis of the microsecond time deviation;

and S4, the secondary monitoring device performs overall time synchronization on the system time of the device according to the large time information above the system second level and the step value of the system microsecond time counter corrected by the secondary monitoring device according to the steps S2 and S3.

2. The method for accurately setting time with the RS232 serial port according to claim 1, wherein the algorithm used in the correction in step S3 is a PID algorithm, and the PID algorithm specifically is:

in each sampling period, according to a PID algorithm, according to the current real-time deviation Xn, the integral time error Xy is Xn + X (n-1) + … + X (n-k), n =1, 2, 3 … and the differential time error Xz is Xn-X (n-1), a system microsecond counter is comprehensively calculated to adjust the step value y, y = AXn + BXy + DXz until the real-time deviation Xn measured in S3 is smaller than the error tolerance C;

yn is a microsecond counter step value, A, B, D is weight coefficients of a time deviation, an integral time error and a differential time error respectively, A + B + D =1, k is an integral accumulation number, and n represents an nth sampling period.

3. The method for accurately setting time according to claim 1, wherein in step S1, after the time service device outputs the serial signal to the RXD pin of the RS232 interface of the secondary monitoring device, the TXD pin of the RS232 interface outputs a response signal to the time service device.

4. The device for accurately calibrating the time by utilizing the RS232 serial port is characterized by comprising a time service device and a secondary monitoring device, wherein a TXD pin of the time service device is connected with an RXD pin of an RS232 interface of the secondary monitoring device, the RXD pin of the time service device is connected with the TXD pin of the RS232 interface of the secondary monitoring device, and a PPS pin of the time service device is connected with a DCD pin of the RS232 interface of the secondary monitoring device.

5. The device for accurate time synchronization by utilizing the RS232 serial port as claimed in claim 4, wherein the time-service device is a GPS or Beidou time-service device.

6. The device for accurate time synchronization by utilizing the RS232 serial port as claimed in claim 4, wherein the secondary monitoring device is provided with a large time register above the system second level and a system microsecond counter.

7. The device for accurate time synchronization by utilizing the RS232 serial port as claimed in claim 4, wherein the secondary monitoring device is a fault recorder, a letter protection substation, a measurement and control device or a telecontrol device and the like.

Technical Field

The invention belongs to the technical field of power systems, relates to a time service technology, and particularly relates to a method and a device for accurately timing time by utilizing an RS232 serial port.

Background

With the increasing requirement of secondary monitoring devices of transformer substations on time precision, especially the higher requirement of devices such as wave recorders, measurement and control, protection and PMU (synchrophasor measurement devices) on time precision, the time signals output by GPS or Beidou time service devices are prompted to output higher-precision time service signals, the current GPS/Beidou time service devices output time service signals in the modes of PTP (high precision time synchronization protocol), B codes, pulses (time, minute, second), NTP (SNTP), serial ports and the like, the microsecond-level precision time service signals comprise PTP and B codes, the millisecond-level precision time service signals comprise NTP (network time protocol) or SNTP (simple network time protocol), serial ports and the combination time of serial ports and second pulses can also achieve microsecond-level precision time service, the current transformer substation monitoring devices largely use B codes (optical and electrical) time service, other time service modes are poor in time service precision, or the requirement on device hardware is high and the cost is increased, and some older monitoring devices only support serial port time synchronization.

At present, the secondary monitoring device of the transformer substation adopts the following 2 modes frequently through an RS232-C serial port pair:

firstly, the RS232-C serial port is adopted for time synchronization, and the time synchronization of the secondary monitoring device is realized by accessing the serial port on the GPS (or Beidou) time service device. The time synchronization can only be accurate to seconds, the time synchronization capability does not exist for milliseconds and microseconds, the time synchronization error is less than or equal to +/-1 s, and the time synchronization precision cannot meet the requirement of accurate time synchronization. Secondly, RS232-C serial ports and second pulse combination are adopted for time synchronization; the time synchronization of the secondary monitoring device is realized by connecting a serial port + second pulse on the GPS (or Beidou) time service device. The requirement of time setting precision can be met, but some secondary monitoring devices cannot access pulse per second without pulse interfaces and cannot finish precise time setting, so the application range is limited.

Disclosure of Invention

The invention discloses a method and a device for accurately timing by utilizing an RS232 serial port, aiming at solving the problems that the current secondary monitoring device of a power system substation has large serial port timing error and cannot meet the requirement of time accuracy, and particularly, some old secondary monitoring devices only support serial port timing without increasing hardware cost and interfaces.

The invention discloses a method for accurately setting time by utilizing an RS232 serial port, which comprises the following steps:

s1, the time service device outputs a serial port signal to an RXD pin of an RS232 interface of the secondary monitoring device,

s2, after the secondary monitoring device responds to the serial port interruption, the secondary monitoring device compares the big time information of the time system with the second level or more according to the year, month, day, hour, minute and second time information contained in the serial port signal;

the S3 time service device outputs a pulse-per-second signal to a DCD pin of the RS232 interface, and the rising edge of the pulse-per-second signal triggers the serial port controller of the DCD pin of the RS232 interface to interrupt;

setting the secondary monitoring device to read the microsecond-level time calculation time deviation by taking the time of triggering interruption of the rising edge of the pulse per second signal as the starting point of the microsecond time zero time, and then correcting the step value of the system microsecond time counter by the step value calculated by a PID algorithm on the basis of the microsecond time deviation;

and S4, the secondary monitoring device performs overall time synchronization on the system time of the device according to the large time information above the system second level and the step value of the system microsecond time counter corrected by the secondary monitoring device according to the steps S2 and S3.

Preferably, the algorithm used in the correction in step S3 is a PID algorithm, and the PID algorithm specifically includes:

in each sampling period, according to a PID algorithm, according to the current real-time deviation Xn, the integral time error Xy is Xn + X (n-1) + … + X (n-k), n =1, 2, 3 … and the differential time error Xz is Xn-X (n-1), a system microsecond counter is comprehensively calculated to adjust the step value y, y = AXn + BXy + DXz until the real-time deviation Xn measured in S3 is smaller than the error tolerance C;

yn is microsecond counter step value, A, B, D is weight coefficient of time deviation, integral time error and differential time error, A + B + D =1, k is integral accumulation number, n represents nth sampling period

Preferably, in step S1, after the time service device outputs a serial port signal to the RXD pin of the RS232 interface of the secondary monitoring device, the TXD pin of the RS232 interface outputs a response signal to the time service device.

The invention also discloses a device for accurately calibrating time by utilizing the RS232 serial port, which is characterized by comprising a time calibrating device and a secondary monitoring device, wherein a TXD pin of the time calibrating device is connected with an RXD pin of an RS232 interface of the secondary monitoring device, the RXD pin of the time calibrating device is connected with the TXD pin of the RS232 interface of the secondary monitoring device, and a PPS pin of the time calibrating device is connected with a DCD (carrier monitoring) pin of the RS232 interface of the secondary monitoring device.

Specifically, the timing device is a GPS or Beidou timing device.

Specifically, the secondary monitoring device is provided with a large time register above a system second level and a system microsecond counter.

Specifically, the secondary monitoring device is a fault recorder, a signal protection substation, a measurement and control device or a telecontrol device and the like.

The method and the device for accurately timing by utilizing the RS232 serial port can provide accurate timing of the serial port, realize accurate timing by utilizing the hardware serial port of the original device under the condition of not increasing hardware cost and interfaces, have the characteristics of high precision, good compatibility, high reliability, good real-time property, wide practical range and the like, and meet the requirement of accurate timing of secondary power monitoring devices such as a power transformation and distribution station, a power plant and the like.

The invention has the advantages that:

1. and when accurate time synchronization is finished by adopting an RS232-C serial interface, the time synchronization precision can be lower than 20 us.

2. The method is compatible with the original serial port time synchronization protocol software, and time PID algorithm software is added to ensure time synchronization precision.

3. The method is compatible with the serial port time synchronization mode of the original device, does not need to increase hardware cost and interface, and is connected on site

The wire is connected singly, the construction is convenient, and the application range is wide.

Drawings

Fig. 1 is a schematic diagram of a specific embodiment of the device for accurately setting time by using an RS232 serial port according to the present invention.

Detailed Description

The following provides a more detailed description of the present invention.

The method for accurately calibrating the time by utilizing the RS232 serial port is based on a device for accurately calibrating the time by utilizing the RS232 serial port, and comprises a time service device and a secondary monitoring device, wherein a TXD pin of the time service device is connected with an RXD pin of an RS232 interface of the secondary monitoring device, the RXD pin of the time service device is connected with the TXD pin of the RS232 interface of the secondary monitoring device, and a PPS pin of the time service device is connected with a DCD (carrier monitoring) pin of the RS232 interface of the secondary monitoring device.

The DCD (carrier monitoring) pin is a carrier detection pin of an RS 2329-core serial port, and the level change of the pin can trigger the interruption of the serial port controller, so that accurate microsecond time of the system is obtained.

The time service device outputs a serial port signal to an RXD pin of an RS232 interface of the secondary monitoring device through the TXD pin, and the secondary monitoring device reads time information of year, month, day, minute and second contained in the serial port information after responding to the serial port signal and corrects the time information of a system of the secondary monitoring device above the second level.

The time service device outputs a serial port signal to a DCD pin of an RS232 interface of the secondary monitoring device through the PPS pin, and the secondary monitoring device reads sub-second-level time information contained in the serial port information after responding to the serial port signal and corrects the sub-second-level time information of the self system.

After receiving the serial port time information, the RXD of the secondary monitoring device can send a response to the RXD pin of the time service device through the TXD pin of the secondary monitoring device, so that the time service device knows that the time information is successfully received.

The secondary monitoring device is auxiliary equipment for protecting, monitoring, measuring and operating and controlling primary equipment such as a main transformer and auxiliary equipment thereof in a transformer substation, such as a fault recorder, a letter protection substation, a measurement and control device or a telecontrol device and the like.

The method for accurately synchronizing the time by using the device for accurately synchronizing the time by using the RS232 serial port comprises the following steps of:

s1, the time service device outputs a serial port signal to an RXD pin of an RS232 interface of the secondary monitoring device,

s2, after the secondary monitoring device responds to the interruption of the serial port, the software reads the year, month, day, hour, minute and second time information contained in the serial port information and the large time information above the second level of the time synchronization system;

the serial port signal contains time information of year, month, day, hour, minute and second level, and the secondary monitoring device reads the information of the large time of year, month, day, hour, minute and second level contained in the serial port signal and the information of the large time of system second level or above by responding to the interruption of the serial port.

After receiving the serial port time information, the RXD of the secondary monitoring device can send a response to the RXD pin of the time service device through the TXD pin of the secondary monitoring device, so that the time service device knows that the time information is successfully received.

The time synchronization of the big time information above the second level refers to the time synchronization of the big time information above the second level of the secondary monitoring device system receiving the information through the year, month, day, hour, minute and second level of the big time information in the time service device serial port transmission signal. The large time of second level or more after time synchronization can be stored in a register of second level or more of the system.

Setting the moment of triggering interruption by the secondary monitoring device according to the rising edge of the second pulse signal as a microsecond time zero moment starting point, and immediately reading a system time value when the rising edge arrives, wherein the system time value comprises 2 integer numbers of second and microsecond, the microsecond number is 0 theoretically, and the microsecond time value is compared with 0.5S due to an error, wherein the microsecond time value is more than or equal to 0.5S and is considered as a negative deviation, and Xn (time deviation) = microsecond time value-1000000 at the moment; a positive deviation is considered when less than 0.5mS, when Xn (time deviation) = microsecond time value-0; and calculating to obtain the magnitude and the direction of the microsecond time deviation value, and storing the microsecond time deviation value into a buffer cache. And then, on the basis of the system time deviation, correcting the microsecond time counter step value of the system by calculating the step value through a PID algorithm.

In order to avoid the clock signal from oscillating repeatedly due to excessive correction, the algorithm used in the correction in step S3 is a PID algorithm, a step value is adjusted by calculating a microsecond counter of the system using a proportional, integral, and derivative algorithm, and a microsecond-level time error is continuously reduced in each sampling period, instead of directly correcting according to the calculated time error.

P represents the ratio: control currently, proportional control is the simplest control method. The output of the controller is proportional to the input error signal. There is a Steady-state error in the system output when there is only proportional control (Steady-Steady).

I denotes the integral: control in the past, the output of the controller was proportional to the integral of the input error signal. For an automatic control System, if there is a Steady-state Error after entering a Steady state, the control System is called as a System with a Steady-state Error or a System with a difference Error for short. To eliminate steady state errors, an "integral term" must be introduced into the controller. The integral term integrates the error over time, increasing with time. Thus, even if the error is small, the integral term increases with time, which drives the output of the controller to increase, further reducing the steady state error until it equals zero. Therefore, the proportional Plus Integral (PI) controller can enable the system to have no steady-state error after the system enters the steady state.

D represents the differential: in the future of control, the output of the controller is in a direct proportion relation with the differential of the input error signal (namely the change rate of the error), and increasing the differential time is beneficial to accelerating the response speed of the system, so that the overshoot of the system is reduced, the stability is increased, but the suppression capability of the system to disturbance is weakened. The differential control has a look-ahead and predictive characteristic.

In 1 second of each sampling period, according to a PID algorithm, in each sampling period, according to the PID algorithm, according to the current real-time deviation Xn, the integral time error Xy is Xn + X (n-1) + … + X (n-k) (n =1, 2, 3 …), and the differential time error Xz is Xn-X (n-1), the system microsecond counter is comprehensively calculated to adjust the step length value y, y = AXn + BXy + DXz until the real-time deviation Xn measured in S3 is less than the error tolerance C;

in the formula y = AXn + BXy + DXz, the calculated result y represents the adjustment value of the step value of the system microsecond counter in each period, the three terms on the right side of the equal sign represent three elements of the proportion P, the integral I and the differential D of the system adjustment respectively, Xn represents the current error, the adjustment of the weight coefficient A represents error proportion control, Xy represents the sum of the accumulated time deviations of k continuous periods and represents the static error of the system, and Xz represents the difference of the time deviations of the latest 2 periods and reflects the future trend of the error.

The purpose of the adjustment is to make Xn smaller than the error tolerance C in a period as short as possible, and to avoid oscillation caused by overshoot, the values of the weighting coefficients a, B, D follow the above principle, for example, if the overshoot is found to be too large, the value of a can be properly reduced, and if the constant error disappears slowly, the value of B can be properly increased; and D value can be reduced properly if the error is unstable after adjustment. Since Xy is the sum of the time deviations accumulated over k consecutive periods, k typically takes a value of 5-10 periods.

The default step value Y of the microsecond counter is 1, the error tolerance C =20 microseconds, and Y is calculated once per second by adopting a PID algorithm, namely according to sampling of a second pulse period. Yn = Y (n-1) + Y, Yn being the calculator step value per microsecond, i.e. the counter unit.

The microsecond calculator step value Yn = Y (n-1) + Y in each period, and the microsecond time of the system continuously changes to the direction of zero real-time error by continuously adjusting Yn until the real-time error Xn measured in S3 is smaller than the error tolerance C; . .

Yn is a microsecond counter step value, and error tolerance C is a self-set parameter. Because the operating system has uncertainty in responding to the interrupt time triggered by the rising edge of the second pulse, setting the error tolerance C =20 microseconds as an acceptable error.

The system time of the secondary monitoring device is calculated based on the microsecond counter value of the system, if the microsecond counter value is 1000000, the counter step value =1uS, and the time value =1000000 × 1=1000000uS =1000mS = 1S; if the change count step value =0.9995 uS, the time value =1000000 × 0.9995=999500uS =999.5mS =0.9995S, i.e. the system time is advanced in the next cycle after the step size is reduced; and conversely, similarly, the system time is delayed in the next period after the step length is increased, so that the system timing unit basis can be changed by changing the step length value of the system counter, and the system time of the secondary monitoring device including the large time of more than second and the small time of microsecond is changed.

In step S4, the secondary monitoring device corrects the step value of the system microsecond time counter according to the information about the system second or higher large time when the time is synchronized in steps S2 and S3, thereby performing the overall time synchronization of the system time of the device.

The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.

These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.

These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.

The method and the device for accurately timing by utilizing the RS232 serial port can provide accurate timing of the serial port, realize accurate timing by utilizing the hardware serial port of the original device under the condition of not increasing hardware cost and interfaces, have the characteristics of high precision, good compatibility, high reliability, good real-time property, wide practical range and the like, and meet the requirement of accurate timing of secondary power monitoring devices such as a power transformation and distribution station, a power plant and the like.

The foregoing is directed to preferred embodiments of the present invention, wherein the preferred embodiments are not obviously contradictory or subject to any particular embodiment, and any combination of the preferred embodiments may be combined in any overlapping manner, and the specific parameters in the embodiments and examples are only for the purpose of clearly illustrating the inventor's invention verification process and are not intended to limit the scope of the invention, which is defined by the claims and the equivalent structural changes made by the description and drawings of the present invention are also intended to be included in the scope of the present invention.

8页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种提高射频-激光通信系统安全性的天线选择策略

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!