2647 views|20 replies

16

Posts

0

Resources
The OP
 

I have some doubts about using a microcontroller to drive an optocoupler and then drive a relay. [Copy link]

 

When designing a relay module, I encountered a problem. The microcontroller is STM32F407, and I want to use the I/O port to control the optocoupler (I am mainly responsible for the hardware direction and don’t know much about microcontroller development)

First, according to my teammates, the maximum voltage that the microcontroller can withstand is 3.3V, but the voltage used to drive the optocoupler is 5V. When looking for references at Jiali Chuang, I found the following design

The description says 5-7.5V power supply, IN is connected to MCU I/O, and the voltage drop of LED and optocoupler seems to be about 1V. So if a power supply exceeding 5.3V is used, won't the MCU be burned? When looking up information, I found that it can be driven directly according to the MCU, but the current needs to be large enough.

Secondly, in the part of driving the transistor (I use s9013), a diode is connected between the transistor emitter and the power supply for freewheeling protection. The references I found use 1N4148, SS34, and 1N4007. Which of these three diodes should be preferred when driving a songle relay at 5V?

After checking the information, it seems that Schottky diodes and switching diodes can both be used as freewheeling diodes.

Finally, some designs directly drive the switching diode to control the relay switch, and some add optocoupler isolation. It seems that optocoupler isolation can avoid interference and prevent the transistor from turning on and causing the relay to work, which is better. I have seen that some designs use another transistor to drive the optocoupler. If the transistor is interfered with again, then will the optocoupler be meaningless soon?

This post is from Electronics Design Contest

Latest reply

The IO port can be used as an open collector. As long as the current does not exceed the limit, there should be no problem.  Details Published on 2024-9-13 08:19
 
 

2926

Posts

0

Resources
2
 

The microcontroller is STM32F407, and I want to use the I/O port to control the optocoupler (I am mainly responsible for the hardware direction and don't know much about microcontroller development-----------

Hardware newbie, you have so much to learn.

This post is from Electronics Design Contest
 
 
 

1114

Posts

2

Resources
3
 

Same as above, in fact, the knowledge points that the main post wants to understand are all in the category of hardware engineers. First, understand the characteristic parameters of each discrete component used

This post is from Electronics Design Contest
 
 
 

2w

Posts

0

Resources
4
 

[According to teammates, the maximum voltage that the microcontroller can withstand is 3.3V, but the voltage used to drive the optocoupler is 5V. When looking for references at Jiali Chuang, I found the following design]

It should say "the microcontroller power supply voltage is 3.3V" instead of "the maximum voltage that the microcontroller can withstand is 3.3V".

The power supply voltage is 3.3V, and the microcontroller can drive the optocoupler, but the microcontroller needs to be able to output enough current for the optocoupler. Secondly, the values of R1R3 in the first post need to be modified.

This post is from Electronics Design Contest
 
 
 

2w

Posts

0

Resources
5
 

[Which of these three diodes should be preferred when driving a songle relay at 5V?]

The type of diode to use depends on how much current the relay passes. If the current and voltage of the relay winding are both small, then all three types can be used.

This post is from Electronics Design Contest
 
 
 

2w

Posts

0

Resources
6
 

[Finally, there is a direct microcontroller driving the switching diode to control the relay switch]

A microcontroller drives a switching diode to control a relay? Unheard of.

This post is from Electronics Design Contest

Comments

Ah, this is a typo. It is a transistor that is used as a switch and driven by a microcontroller, not a diode.  Details Published on 2024-7-8 20:14
 
 
 

2w

Posts

0

Resources
7
 

[I've seen some designs that use a transistor to drive an optocoupler. If the transistor is interfered with, then the optocoupler will soon be meaningless? ]

The OP has not figured out what the "interference" is.

This post is from Electronics Design Contest

Comments

From what I have learned so far, the optocoupler is used for electrical isolation. I personally feel that it is easier to understand. It serves the effect of isolating two different grounds. However, this also requires two independent power supplies in the design, so the optocoupler isolates the possible interference between the two independent power supplies.  Details Published on 2024-7-13 21:01
 
 
 

16

Posts

0

Resources
8
 
maychang posted on 2024-7-8 17:50 [Finally, is there a direct MCU driving the switch diode to control the relay switch] MCU driving the switch diode to control the relay? Unheard of.

Ah, this is a typo. It is a transistor that is used as a switch and driven by a microcontroller, not a diode.

This post is from Electronics Design Contest

Comments

Using MCU GPIO to drive NPN transistor and transistor to drive relay primary coil is a common usage, no problem  Details Published on 2024-7-9 09:59
 
 
 

16

Posts

0

Resources
9
 
 
 

6062

Posts

4

Resources
10
 
This post was last edited by damiaa on 2024-7-9 09:20

It’s a bit confusing, and I feel like the original poster is worried about a lot, but doesn’t understand.

Actually, driving an optocoupler requires providing sufficient current and voltage. For details, please refer to the optocoupler documentation.

So led1 and led2 are not necessary. r1 and r3 can be used as current limiters. It is better to add a transistor to drive the optocoupler. Because the current of the optocoupler is relatively large, the driving current of some microcontroller IO may not be enough. Here you can add an npn transistor such as 8050, 9013 to expand the driving current, and the chip one is also OK. After adding the transistor, 5V can be directly added to the upper end of r1 and r3 without any problem.

This post is from Electronics Design Contest
 
 
 

1114

Posts

2

Resources
11
 
rxjsn posted on 2024-7-8 20:14 Ah, this is a typo. It is a transistor as a switch, driven by a microcontroller, not a diode

Using MCU GPIO to drive NPN transistors and transistors to drive relay primary coils is a common method and there is no problem.

This post is from Electronics Design Contest
 
 
 

6818

Posts

11

Resources
12
 

You need to look at the data sheet of the microcontroller to see its driving capability. For example, the STM32F407 can be configured as push-pull or open-drain output, and their driving capabilities are different. Of course, it is usually necessary to connect a triode or MOS tube to improve the driving capability.

This post is from Electronics Design Contest
 
 
 

6818

Posts

11

Resources
13
 

I looked up some information and found an article here that gives a very detailed introduction [STM32F407 Development Board User Manual] Chapter 15 STM32F407 GPIO Basics (Important) - Hard Guy Embedded - Blog Garden (cnblogs.com)

This post is from Electronics Design Contest

Comments

Thank you very much. I have been learning about this knowledge during this period. Before, I only knew about operational amplifiers and power supplies, and my understanding of microcontrollers was still very limited. Thank you for sharing.  Details Published on 2024-7-10 11:32
 
 
 

16

Posts

0

Resources
14
 
lugl4313820 posted on 2024-7-10 04:35 I looked up some information and found an article here that is very detailed [STM32F407 Development Board User Manual] Chapter 15 STM32F407 GPIO Basics...

Thank you very much. I have been learning about this knowledge during this period. Before, I only knew about operational amplifiers and power supplies, and my understanding of microcontrollers was still very limited. Thank you for sharing.

This post is from Electronics Design Contest
 
 
 

16

Posts

0

Resources
15
 
maychang posted on 2024-7-8 17:51 [I have seen some designs that use another transistor to drive the optocoupler. If the transistor is interfered with, will the optocoupler soon become meaningless? ] OP...

From what I have learned so far, the optocoupler is used for electrical isolation. I personally feel that it is easier to understand. It serves the effect of isolating two different grounds. However, this also requires two independent power supplies in the design, so the optocoupler isolates the possible interference between the two independent power supplies.

This post is from Electronics Design Contest
 
 
 

3

Posts

0

Resources
16
 

Feels great

This post is from Electronics Design Contest
 
 
 

1w

Posts

142

Resources
17
 

MCU is powered by 3V, so there must be a 3V power supply in the system. Then you can directly use 3V power supply to drive the optocoupler. Why use 5V? If you must use 5V, the best way is to use a transistor as a driving element. The original poster's picture is a workaround and has no cost advantage.

This post is from Electronics Design Contest
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 
 

1w

Posts

142

Resources
18
 

As for the voltage problem, the driving voltage of the optocoupler and the operating voltage of the MCU are obviously not the same thing. There is a problem with the picture in the original post, that is, the labeling of Vcc. When there are multiple voltages in the system, the label should indicate which power supply it is, such as Vcc5 and Vcc3 to distinguish them.

So is it safe for a 3V system to use the circuit in the original post to drive the optocoupler at 5V? The answer lies in current rather than voltage. MCU IO usually has a clamping diode, and as long as the clamping current does not exceed the tolerance current of the clamping diode, it is fine. In other words, the lower limit of the current limiting resistor in the original post should be paid attention to.

This post is from Electronics Design Contest

Comments

At present, the anti-interference of optocoupler isolation is already understood, but because the modules produced for participating in the competition generally use one power supply, the meaning of optocoupler isolation can be said to be meaningless. The module finally designed directly uses the microcontroller switch transistor to realize the drive of the relay.  Details Published on 2024-7-21 21:27
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 
 

1w

Posts

142

Resources
19
 

As for the other questions of the original poster, since the original poster's questions are too confusing, it is obvious that he lacks relevant basic knowledge. I suggest that the original poster post his questions separately. When organizing the language, think clearly about how to describe accurately, and be sure to provide pictures. Thinking clearly before posting is a process of learning and practice.

This post is from Electronics Design Contest
Personal signature上传了一些书籍资料,也许有你想要的:http://download.eeworld.com.cn/user/chunyang
 
 
 

16

Posts

0

Resources
20
 
chunyang posted on 2024-7-17 19:41 As for the voltage problem, the driving voltage of the optocoupler and the operating voltage of the MCU are obviously not the same thing. There is a problem with the picture in the original post, that is, the labeling problem of Vcc...

At present, the anti-interference effect of optocoupler isolation is already understood. However, because the modules produced for participating in electrical competitions generally use only one power supply, the significance of optocoupler isolation can be said to be meaningless. The final designed module directly uses the microcontroller switching transistor to realize the drive of the relay. After actual testing, it can be used with good results.

The reason for 3.3V is that the ADC part of the microcontroller is powered by 3.3V and cannot withstand high voltages, but the IO port of the microcontroller is protected by clamping diodes (inspired by this part, a similar principle was used in the design of a question later). Generally speaking, a limit value not exceeding 3.6 volts for a short time is acceptable (of course, it is best not to exceed 3.3V). As for the current part, the mechanism is currently being studied (of course, our microcontroller has learned a lesson in current during this period. Using a microcontroller to drive two DDS modules, the output current is not enough to meet the needs of the two modules. Later, the student power supply was used for detection, which should be overcurrent, and finally caused the microcontroller power supply to burn out. Because the microcontroller and DDS were not designed by me, I don’t know much about them, and I will also strengthen the research on the design of the purchased modules in the future). What the teacher said is very right. Looking at the circuit diagram, it is indeed possible to directly use the microcontroller to output 3.3V to drive the optocoupler. The only problem may be that the output current of the microcontroller is not enough to start the optocoupler diode. This may be the reason why these optocoupler designs use external power supply auxiliary drive. In this case, it is understandable to use a transistor to expand the current to drive the optocoupler.

Ah, besides, the freewheeling diode is at the collector, I typed it wrong. I am not used to typing long paragraphs, so I often make mistakes.

As for the selection of diodes, I finally chose 1N4007 (because this is the most common one on hand). My personal understanding is that it is used to discharge the relay inductance after power is removed. As long as it can withstand sufficient current, it can be used.

Some of the basic knowledge I learned in class is not solid. I think it is better to do more practical testing and research. I am used to theoretical analysis, design practice, and finally theoretical review and reason analysis. I was still studying the theory when I posted, so I didn’t make my own pictures. The circuit in the post was not drawn by me, but was a reference. Because I encountered a lot of problems at the beginning, the description is indeed confusing, so I will pay attention to it later.

I have been busy preparing for the competition recently, so I plan to study the details of this aspect slowly later.

This post is from Electronics Design Contest
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
DIY ImxRT1010 board, sharing hardware debugging experience

This post was last edited by RCSN on 2019-12-8 22:59 According to the previous post, the host bought the MIMXRT1010-EV ...

Summary of the best posts on embedded systems (2019)

At the beginning of the new year, Xiaoguan compiled some good posts in the second half of 2019 for new netizens to check ...

Could you please help me see how to filter this switching power supply circuit?

As the title says, the ACDC switching power supply outputs 5V voltage through LDO. How to filter it next? Below is the ...

Free Review - Topmicro Intelligent Display Module (5) Touch Screen

This post was last edited by wenyangzeng on 2021-11-1 16:36 Free Review - Topmicro Intelligent Display Module (5) Touch ...

Pointer type conversion issues

The code is as follows: typedef unsigned char uint8_t; typedef struct { uint8_t dwl; uint8_t dwh; } CARD_DATA; ...

Why are exceptions and interrupts designed so complicated? - Reading notes on "RISC-V Architecture Programming and Practice"

This post was last edited by jobszheng5 on 2023-5-11 15:13 In the ARM company's RISC instruction set Cortex-M3 series ...

Adaptive dynamic navigation positioning

This book first analyzes the function model error compensation and random model error compensation methods; discusses th ...

Regulations and standards for automotive millimeter wave radar (2)

This post was last edited by Hot Ximixiu on 2024-8-13 09:00 Frequency bands used by automotive millimeter-wave rada ...

[Renesas RA8D1 development board, graphic MCU evaluation based on M85 core] 5. Implement PWM duty cycle based on LVGL, control motor, etc.

The porting of LVGL9.1 was completed last time, and this time the motor PWM modulation based on the LVGL library was im ...

【NUCLEO H533RE】Light up 1.8tft

This post was last edited by zsy-s on 2024-8-18 18:03 # Introduction This test uses the spi peripheral to light up a t ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list