Background technology
RS-422 and RS-485 are the serial data interface standards.Wherein, RS-422 and RS-485 can support a plurality of nodes, therefore can constitute the network of bus-type.During by the RS-485/422 building network, a plurality of RS-485/422 equipment in parallel communicate on the bus.The network that RS-485/422 constitutes can be widely used in fields such as Process Control System, remote data acquisition system, safety-protection system, sub-district gate control system, intelligent building, laboratory automation.
For the RS-422 network, be full duplex mode, have only a main frame (Master) on the bus, other is a slave.When main frame sent data to bus, slave received data from bus simultaneously; When slave uploaded data to main frame by bus, the same moment can only have a slave to upload data, and other slaves must discharge bus and upload power control data, otherwise bus contention occurs, caused the bus paralysis, can't communicate by letter.
For the RS-485 network, be half-duplex mode, allow multiple host on the bus, the same moment also can only have a RS-485 main frame or slave to send data, and other main frame or slave are in accepting state.Therefore before each communication transmitting-receiving control must be set earlier, sending must the release bus control right after the data.
The RS-485/422 interface chip comprises two control pin/RE and DE pin./ RE is for receiving the enable port, and low level is effective; DE is for sending the enable port, and high level is effective.Putting DE earlier when sending data is high level, and must put DE after data send and finish is low level, otherwise bus data is followed the input of RS-485/422 interface chip always, and bus is in occupied state, and the data that other equipment send just can be lost.
At present, during RS-485/422 transmission data, adopt following two kinds of methods to carry out data flow control more:
A kind of is to utilize to control with the front stage circuits that links to each other, as the DTR leg signal of utilizing the RS-232 interface die terminals inserts the DE end of RS-485/422, and the high-low level of the end of the DE by software control RS-485/422 interface chip, thereby finish data flow control.The method is used the DTR pin of RS-232, certainly will need to add a holding wire accordingly, makes circuit complicated, and has increased software overhead simultaneously.
Another kind is to increase by a microprocessor, data is handled and is analyzed, and export the DE end of a signal controlling RS-485/422 interface chip, to finish data flow control.The method has improved cost, and has made hardware circuit and complicating of debugging owing to increased microprocessor.
Summary of the invention
In view of this, main purpose of the present invention is to provide the circuit of a kind of automatic stream control device, control method and application thereof, to realize and to flow to control to the RS-485/422 interface chip automatically according to input signal, do not need to introduce microprocessor, do not need front stage circuits to control.
Automatic stream control device provided by the invention comprises: with non-Schmidt trigger, charging delay circuit, wherein, be used for receiving inputted signal with non-Schmidt trigger first input end; Contact with non-Schmidt trigger second input and to link to each other receiving inputted signal with first input end behind the described charging delay circuit; Be used to export control signal with non-Schmidt trigger output. wherein, described charging delay circuit comprises: first resistance R 1, second resistance R 2, capacitor C, diode D; R1, R2 reach and link to each other with non-Schmidt trigger first input end; The other end of R2 links to each other with diode D negative pole; Diode D positive pole links to each other with the other end, the capacitor C of R1, and is connected to and non-Schmidt trigger second input; The other end ground connection of capacitor C, and the R1 value is greater than the value of R2.
Wherein, described automatic stream control device baud rate is from 300~115200bps self adaptation.
Corresponding automatic stream control method provided by the invention comprises: send idle period of time in data, with the input signal of non-Schmidt trigger first input end be high level, the charging delay circuit capacitor C through charging make with non-Schmidt trigger second input be high level, make and non-Schmidt trigger output low level; When importing a low level signal with non-Schmidt trigger first input end, with non-Schmidt trigger output high level, charge simultaneously delay circuit capacitor C by first resistance R 1 and diode D, 2 two paths discharges of second resistance R make with non-Schmidt trigger second input be low level, make and non-Schmidt trigger output high level; When being high level by low transition with non-Schmidt trigger first input end input signal, first resistance R 1 by the charging delay circuit is charged to capacitor C, make with non-Schmidt trigger second input terminal voltage to raise gradually, this voltage less than with non-Schmidt trigger forward threshold voltage Vp during with non-Schmidt trigger output high level; When the capacitor C charging of charging delay circuit make with non-Schmidt trigger second input terminal voltage greater than with non-Schmidt trigger forward threshold voltage Vp the time, with non-Schmidt trigger output low level.
The circuit that comprises automatic stream control device and RS-485 provided by the invention, automatic stream control device wherein comprises: with non-Schmidt trigger, charging delay circuit; Be used to receive the input signal that is input to RS-485 simultaneously with non-Schmidt trigger first input end; Contact with non-Schmidt trigger second input and to link to each other receiving inputted signal with first input end behind the described charging delay circuit; Be used to export control signal with non-Schmidt trigger output, link to each other with enable port/RE, the transmission enable port DE of RS-485; The forward pin A of RS-485 connecting bus connects and draws resistance, and oppositely pin B connects pull down resistor.Wherein, described charging delay circuit comprises: first resistance R 1, second resistance R 2, capacitor C, diode D, and wherein, R1, R2 reach and link to each other with non-Schmidt trigger first input end; The other end of R2 links to each other with diode D negative pole; Diode D positive pole links to each other with the other end, the capacitor C of R1, and is connected to and non-Schmidt trigger second input; The other end ground connection of capacitor C, and the R1 value is greater than the value of R2.
The circuit that comprises automatic stream control device and RS-422 provided by the invention, automatic stream control device wherein comprises: with non-Schmidt trigger, charging delay circuit; Be used to receive the input signal that is input to RS-422 simultaneously with non-Schmidt trigger first input end; Contact with non-Schmidt trigger second input and to link to each other receiving inputted signal with first input end behind the described charging delay circuit; Be used to export control signal with non-Schmidt trigger output, link to each other with the transmission enable port DE of RS-422; The enable port of RS-422/RE ground connection; The forward end Y of RS-422 connecting bus connects and draws resistance, and backward end Z connects pull down resistor.Wherein, described charging delay circuit comprises: first resistance R 1, second resistance R 2, capacitor C, diode D; R1, R2 reach and link to each other with non-Schmidt trigger first input end; The other end of R2 links to each other with diode D negative pole; Diode D positive pole links to each other with the other end, the capacitor C of R1, and is connected to and non-Schmidt trigger second input; The other end ground connection of capacitor C, and the R1 value is greater than the value of R2.
As seen from the above, automatic stream control circuit provided by the invention does not need to introduce microprocessor, does not need front stage circuits to control.Automatic stream control circuit of the present invention for receiving and sending two signals, need not to add the transmitting-receiving control signal, can finish the conversion of signals such as RS-485/422 and RS-232.Not only reduce software overhead, and baud rate 300~115200bps self adaptation, hardware circuit are simple.Greatly reduce the subscriber software-hardware cost.Especially, when the original RS-232 of user system changes the RS-485/422 system into, need not revise software, directly use the present invention to get final product.
Embodiment
The present invention is described in detail below in conjunction with accompanying drawing.
Show the annexation of automatic stream control device and RS-485 interface chip as Fig. 1.Wherein, in uplink signal transmissions, the output RO of RS-485 interface chip is used to export the upward signal from bus.In the downstream signal transmission, the input DI of RS-485 interface chip is used to receive downstream signal to send to bus; Simultaneously, the automatic stream control circuit also receives the signal that sends RS-485 interface chip input DI to, and this signal analysis and processing is generated control level signal send to the reception Enable Pin/RE of RS-485 interface chip and send Enable Pin DE, to finish to the control of the automatic stream of RS-485 interface chip, the following reception of passing to bus and data that realizes the RS-485 data from bus.The present invention can realize that the automatic stream control device baud rate is from 300~115200bps self adaptation.
Be applied to the circuit diagram of RS-485 interface below with reference to the control of the automatic stream shown in Fig. 2.Further automatic stream control device of the present invention is described.
Automatic stream control device comprises: first resistance R 1 and second resistance R 2, capacitor C, diode D, with non-Schmidt trigger UIA.
Wherein, receive send RS-485 input DI to input with R1, R2 and link to each other with non-Schmidt trigger UIA one input; The other end of R2 links to each other with diode D negative pole; Diode D positive pole links to each other with the other end, the capacitor C of R1, and is connected to another input of UIA; The other end ground connection of capacitor C.
Wherein, between the general desirable 30K~40K of R1 resistance, so that capacitor charging time elongates, R2 resistance is generally got several K, and capacitor C is got 300pF, when input signal is low level like this, and diode D conducting, capacitor C is discharged rapidly by R2.
And the output of UIA is connected to the reception Enable Pin/RE of RS-485 interface chip and sends Enable Pin DE.The bus forward pin A of RS-485 interface chip connects and draws resistance; The reverse pin B of bus connects pull down resistor.
When carrying out the transmitting-receiving of data, it is as follows to the principle that flows to control, can participate in passing through shown in Fig. 3 and flow to the flow chart that control realizes that the RS-485 data send, and may further comprise the steps:
Step 301: in idle period of time, input signal remains high level, and capacitor C has been charged and finished, be high level with two inputs of non-Schmidt trigger, with non-Schmidt trigger output low level, make the RS-485 interface chip send Enable Pin DE and forbid that it is effective to receive Enable Pin/RE.When on the RS-485 bus data being arranged, enable/the RE continuously effective because receive, receive bus data.When on the RS-485 bus during free of data, the bus forward pin A of RS-485 interface chip is pulled down to high level in the pull-up resistor effect, and the reverse pin B of bus is pulled down to low level in the pull down resistor effect.
Step 302: when low level of input signal input, with input of non-Schmidt trigger be low level, immediately export high level with non-Schmidt trigger, make the RS-485 interface chip /RE forbids, the DE end is effective, and RS-485 outputs to the signal of bus and follows DI variation, i.e. A output low level, B exports high level, has realized the DI data are delivered on the RS-485 bus.
Simultaneously capacitor C is discharged rapidly by resistance R 1 and two paths of diode D, R2, becomes low level with another input moment of non-Schmidt trigger, keeps the output high level with non-Schmidt trigger.
Step 303: when input signal is high level by low transition, charge to capacitor C by resistance R 1, with the forward threshold voltage Vp of non-Schmidt trigger about 2.9V, raise gradually with non-Schmidt trigger input 2 voltages, when capacitance voltage less than with non-Schmidt trigger forward threshold voltage Vp the time, still keep high level with non-Schmidt trigger output, RS-485 interface chip DE enables to remain valid, bus A follows DI and changes, and A exports high level, B output low level.
Step 304: when capacitance voltage greater than with non-Schmidt trigger forward threshold voltage Vp the time, become low level with non-Schmidt trigger output, RS-485 interface chip DE Enable Pin forbids that bus A is because pull-up resistor still keeps high level, and B is because pull down resistor still keeps low level.
When next low level is imported, then return step 302, export high level once more with non-Schmidt trigger, it is effective that the transmission of RS-485 interface chip enables DE, comes and goes action successively, realizes the automatic stream controlled function, repeats no more.
After the transmission data stop, then returning the transmission idle condition, promptly input signal remains high level, makes RS-485 interface chip DE Enable Pin forbid that/RE Enable Pin is effective, and the RS-485 interface chip is in accepting state.Can be about sending idle condition referring to the description of step 301.Repeat no more herein.
Above process also can flow to the oscillogram that control realizes that the RS-485 data send referring to passing through shown in Fig. 4.The moment of corresponding diagram 3 is understood in the figure acceptance of the bid, from figure, can obviously find out, when DI is high level by low transition, postpone the output high level with non-Schmidt trigger, after making that the conversion of RS-485 interface chip A and B output level finishes fully, the RS-485 interface chip sends and to enable just to forbid, A and B last draw with the pull down resistor effect under still keep level before transmission enables to forbid.
The process that is applied to self check is described, errorless for some program in order to ensure sending, when sending data, also to receive the data of being sent out from bus, bus data whether occurs and lose to carry out verification.In this case, the DE that only connects the RS-485 interface chip with non-Schmidt trigger output holds, the RS-485 interface chip /RE ground connection, receive and enable continuously effective.When sending data, the DE of RS-485 interface chip end is effective, and data send on the bus, simultaneously/RE ground connection, receive and enable continuously effective, the data of transmission can be received again, are used for the software verification.
Fig. 5 is applied to the application of RS-422 for automatic stream control device of the present invention, the connection diagram of itself and RS-422 interface chip as shown in the figure, because RS-422 is a full duplex mode, send and receive independent, so, reception Enable Pin/RE the ground connection of RS-422 interface chip, promptly the RS-422 interface chip receives and enables continuously effective.Automatic stream control circuit output is only controlled and is sent Enable Pin DE, and bus driver output forward end Y connects and draws resistance, and backward end Z connects pull down resistor.The same RS-485 of the operation principle of its control no longer does at this and to give unnecessary details.
As seen from the above, the present invention does not need to introduce microprocessor, do not need front stage circuits to control, can be applicable to all RS-232 changes in RS-485/422, TTL commentaries on classics RS-485/422, USB commentaries on classics RS-485/422, the transducers such as Ethernet commentaries on classics RS-485/422, CAN bus commentaries on classics RS-485/422.Automatic stream control circuit of the present invention for receiving and sending two signals, need not to add the transmitting-receiving control signal, can finish the conversion of signals such as RS-485/422 and RS-232.Not only reduce software overhead, and baud rate 300~115200bps self adaptation, hardware circuit are simple, greatly reduce the subscriber software-hardware cost.
The above only is preferred embodiment of the present invention, and is in order to restriction the present invention, within the spirit and principles in the present invention not all, any modification of being done, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.