
Various control signals used in traditional electrical equipment must be converted to digital signals compatible with the microcontroller input/output ports. User devices must input various control signals into the microcontroller, such as limit switches, operation buttons, selection switches, travel switches, and other sensor outputs, through input circuits that convert them into signals that the microcontroller can receive and process. The output circuit should convert and amplify the weak control signals sent out by the microcontroller to strong output signals required on site, in order to drive the execution components of controlled devices such as power transistors, electromagnetic valves, relays, contactors, and motors, making it convenient for actual control systems. This article discusses several common driver and isolation circuit design methods for microcontroller I/O, which are practically significant for reasonably designing electrical control systems, improving circuit interface capabilities, and enhancing system stability and anti-interference capabilities.
1. Input Circuit Design
Figure 1 Switch Signal Input
Generally, the input signal will ultimately be input to the microcontroller in the form of a switch. From engineering experience, the effective state of the control instruction for switch input is much better when using low level than high level, as shown in Figure 1. When the switch S1 is pressed, the instruction signal output is a low level, while when the switch S1 is not pressed, the level output to the microcontroller is high. This method has strong noise immunity.
If considering that the TTL level voltage is relatively low, making it susceptible to external interference during long line transmission, the input signal can be raised to +24 V, and at the microcontroller entrance, the high voltage signal is converted into a TTL signal. This high voltage transmission method not only improves noise immunity but also ensures good contact and reliable operation of the switch contacts, as shown in Figure 2. Here, D1 is a protection diode with reverse voltage ≥50 V.
Figure 2 Increasing Input Signal Level
Figure 3 Input Protection Circuit
To prevent external spikes and static electricity from damaging the input pins, a pulse protection diode can be added to the input end, forming a resistance bidirectional protection circuit, as shown in Figure 3. The forward conduction voltage drop of diodes D1, D2, and D3 is UF≈0.7 V, and the reverse breakdown voltage UBR≈30 V. Regardless of the polarity of the destructive voltage appearing at the input end, the protection circuit can limit the voltage amplitude within the range that the input end can withstand. That is: when a positive pulse appears between VI and VCC, D1 conducts forward; when a negative pulse appears between VI and VCC, D2 breaks down in reverse; when a positive pulse appears between VI and ground, D3 breaks down in reverse; when a negative pulse appears between VI and ground, D3 conducts forward, and the diode acts as a clamping protection. The buffer resistor RS is approximately 1.5~2.5 kΩ, forming an integration circuit with the input capacitor C, delaying the external induced voltage for a period of time. If the duration of the interference voltage is less than τ, the effective voltage that the input end bears will be far lower than its amplitude; if the duration is longer, D1 conducts, and the current forms a certain voltage drop across RS, thus reducing the input voltage value.
In addition, a common input method is to use an opto-isolation circuit. As shown in Figure 4, R is the input current-limiting resistor, which limits the current of the LED in the opto-isolator to 10~20 mA. The input end relies on optical signal coupling, achieving complete electrical isolation. At the same time, the forward impedance of the LED is relatively low, while the internal resistance of external interference sources is generally high. According to the voltage divider principle, the interference noise that can be fed to the input end from the interference source is very small, preventing ground interference or other crosstalk, enhancing the circuit’s anti-interference capability.
Figure 4 Input Opto-Isolation
Under the premise of meeting functionality, the simplest solution to improve the reliability of the microcontroller input end is to parallel a capacitor between the input end and ground to absorb interference pulses or to connect a metal film resistor in series to limit the peak current flowing into the port.
2. Output Circuit Design
The output port of the microcontroller is limited by driving capability, and generally requires dedicated interface chips. Although the outputs vary greatly depending on the controlled objects, they generally meet the requirements for output voltage, current, switching frequency, waveform rise and fall rates, and isolation anti-interference. Here, several typical circuit implementation methods from the microcontroller output end to the power end are discussed.
2.1 Direct Coupling
In the direct coupling output circuit, it is necessary to avoid the circuit shown in Figure 5.
Figure 5 Incorrect Output Circuit
During the cutoff of T1 and conduction of T2, to provide sufficient base current to T2, the resistance value of R2 must be very small. Since T2 operates in an emitter follower mode, it is necessary to control the voltage drop between collector and emitter within a small range to reduce T2 losses. Thus, the voltage drop between base and collector is also very small, and the resistance value of R2 must be small enough to provide sufficient base current. If R2’s resistance value is too large, it will greatly increase T2’s voltage drop, causing T2 to heat up significantly. Moreover, during T2’s cutoff, T1 must be turned on, and the high voltage +15 V will drop entirely across the resistor R2, generating a large current, which is clearly unreasonable. In addition, T1’s conduction will pull the microcontroller’s high-level output down to near ground potential, causing instability at the output end. If T1 pulls T2’s base to ground potential, and if it is followed by an inductive load, due to the back electromotive force of the winding, T2’s emitter may have a high level, easily leading to T2’s base-emitter junction breakdown in reverse.
Figure 6 shows a direct coupling output circuit composed of T1 and T2 coupling circuit to drive T3. When T1 is turned on, current is generated in the series circuit of R3 and R4, and the voltage drop across R3 exceeds the base-emitter voltage drop of T2, causing T2 to turn on. T2 provides the base current for the power transistor T3, making T3 conductive. When T1’s input is low, T1 cuts off, the voltage drop across R3 is zero, T2 cuts off, and finally T3 cuts off. The role of R5 is: on one hand, it serves as a load for T2’s collector, and on the other hand, when T2 is off, the charge stored at T3’s base can be rapidly released through resistor R3, speeding up T3’s cutoff and reducing losses.
Figure 6 Direct Coupling Output Circuit
2.2 TTL or CMOS Device Coupling
If the microcontroller outputs via TTL or CMOS chips, it generally uses open collector devices, as shown in Figure 7(a). Open collector devices connect to the +15 V power supply through collector load resistor R1, enhancing the driving voltage. However, it should be noted that the switching speed of this circuit is low, and if it is used to directly drive power transistors, the phase relationship of the power transistors may affect the waveform rise time, causing increased dynamic losses.
To improve switching speed, two improved output circuit forms can be used, as shown in Figure 7(b) and Figure 7(c). Figure 7(b) is an improved circuit that can switch on quickly. When the TTL output is high, the output point obtains voltage and current through transistor T1, enhancing the charging capability and thus speeding up the turn-on time, while also reducing the power consumption on the open collector TTL device. Figure 7(c) is a push-pull improved circuit, which not only increases the turn-on speed but also enhances the turn-off speed. The output transistor T1 works as an emitter follower, avoiding saturation and not affecting the output switching frequency.
Figure 7 TTL or CMOS Device Output Circuit
2.3 Pulse Transformer Coupling
Pulse transformers are typical electromagnetic isolation components, converting the switching signals output by the microcontroller into a high-frequency carrier signal, which is coupled to the output stage through the pulse transformer. Since there is no circuit connection between the primary and secondary coils of the pulse transformer, the output is a floating signal that can be directly coupled to strong electrical components such as power transistors, as shown in Figure 8.
Figure 8 Pulse Transformer Output Circuit
This circuit must have a pulse source, and the frequency of the pulse source should be at least 10 times higher than the microcontroller output frequency. The output pulse of the pulse source is sent to control gate G, and the microcontroller output signal is input to gate G from the other end. When the microcontroller outputs a high level, gate G opens, and the output pulse enters the transformer, whose secondary coil outputs pulses at the same frequency as the primary side. After detection through diodes D1 and D2, the signal is filtered and restored to a switching signal sent to the power transistor. When the microcontroller outputs a low level, gate G closes, and the pulse source cannot enter the transformer through gate G, resulting in no output from the transformer.
Here, the transformer transmits both signals and energy, increasing the frequency of the pulse source, which helps reduce the weight of the transformer. Since the transformer can adapt to different power-driving requirements by adjusting the inductance, primary and secondary turns, it is relatively flexible in application. More importantly, there is no electrical connection between the primary and secondary coils of the transformer, allowing the secondary coil output signal to float with the voltage of the power components, unaffected by its power supply size.
When the microcontroller outputs a high-frequency pulse signal, it is possible to avoid using the pulse source and gate G, making appropriate adjustments to the primary and secondary circuits of the transformer.
2.4 Photoelectric Coupling
Photoelectric coupling can transmit linear signals and switching signals. When used at the output stage, it is mainly for transmitting switching signals. As shown in Figure 9, the control signal output by the microcontroller is amplified by buffer 7407 and sent to the opto-coupler. R2 is the load resistor for the output transistor of the opto-coupler, and its selection should ensure that when the opto-coupler is conducting, its output transistor is reliably saturated; while when the opto-coupler is cut off, T1 is reliably saturated. However, the slow response speed of the opto-coupler causes an increased switching delay time, limiting its operating frequency.
Figure 9 Opto-Coupler Output Circuit