当前位置:网站首页>Principle and application of the most complete H-bridge motor drive module L298N
Principle and application of the most complete H-bridge motor drive module L298N
2022-06-27 09:07:00 【Embedded Yuexiang Garden】
The most complete H Axle motor drive module L298N Principle and Application
H Bridge - Basic knowledge of
Usually ,H A bridge is a fairly simple circuit , Contains four switching elements , The load is in the center , A similar H Configuration of .

Switching element (Q1…Q4) Usually bipolar or FET The transistor , For some high voltage applications IGBT. There are also integrated solutions , However, whether the switching element is integrated with its control circuit is irrelevant to most of this discussion . diode (D1…D4) It is called clamp diode , Usually Schottky type .
The top of the bridge is connected to the power supply ( For example, batteries ), The bottom end is grounded .
Generally speaking , All four switching elements can be opened and closed independently , Despite some obvious limitations .
Although theoretically the load can be anything you want , But so far , If H The bridge has a brush DC or bipolar stepping motor ( Stepper motors each motor requires two H Bridge ) load , Is the most common application . In the following , I will focus on the application as a brush DC motor driver .
H Static operation of the bridge
H The basic working mode of the bridge is quite simple : If Q1 and Q4 Conduction , The left lead of the motor will be connected to the power supply , The right lead is connected to the ground . The current begins to flow through the motor , Motor forward ( For example ) Electrify , The motor shaft starts to rotate .

If Q2 and Q3 Connect , Will be reversed , The motor is energized in reverse , The shaft will begin to rotate in the opposite direction .

In the bridge , You should never close at the same time Q1 and Q2( or Q3 and Q4). If you do , You're just in power and GND Creates a very low resistance path between , Effectively shorting your power supply . This situation is called “ breakdown ”, It is almost guaranteed to quickly destroy your bridge or other things in the circuit .

Due to the limitation of the four possible states ,A There are probably only three side switches that make sense :
| Q1 | Q2 |
|---|---|
| open | open |
| close | open |
| open | close |
For the same B Noodles :
| Q3 | Q4 |
|---|---|
| open | open |
| close | open |
| open | close |
Therefore, the whole bridge can have 9 Different states :
| Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|
| close | open | open | open |
| close | open | open | close |
| close | open | close | open |
| open | close | open | open |
| open | close | open | close |
| open | close | close | open |
| open | open | open | open |
| open | open | open | close |
| open | open | close | open |
There are also some combination patterns , No power supply to the motor . For example, when all four crystal switches are off , At this time, the motor load is equivalent to the suspension at both ends . If the motor is moving at this time , The kinetic energy of its rotor will be gradually consumed under the action of friction , The motor stops slowly .
The two cases shown in the figure below :H The upper half of the bridge circuit ( Or the lower half ) The two transistors of the are closed , The other two corresponding transistors are off . At this time, both ends of the motor are actually short circuited by the bridge circuit . The voltage at both ends of the motor is 0. If the motor is moving at this time , Then the kinetic energy of its rotor will pass through the generated reverse electromotive force (EMF) The braking current is formed in the circuit loop of the external short-circuit bridge , The motor will brake quickly .

The short circuit of the same bridge arm is sometimes caused by poor control signal ( Didn't give enough dead time ), Sometimes power devices are not strong enough ( The withstand voltage is not enough to be broken down ). But because it concerns H The life and death of bridge circuit , So we need to avoid .
H- Bridge control motor
Take controlling a DC motor as an example , Yes H Several switch states of the bridge are briefly introduced , Among them, forward and reverse rotation are the artificial directions , In the actual project, it can be divided according to the actual situation .
Motor forward rotation control
Usually H Bridges are used to drive inductive loads , Here we drive a DC motor ;
| Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|
| open | close | close | open |
Assume that the motor is rotating forward , This current goes through in turn Q1 , M , Q4 , Use yellow line segments to mark in the diagram , The details are shown in the following figure :

Motor reverse control
Another state is that the motor reverses ; At this time, the status of the four switch components is as follows ;
| Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|
| close | open | open | close |
At this time, the motor reverses ( Contrary to the situation described earlier ), This current goes through in turn Q2 , M , Q3 , Use yellow line segments to mark in the diagram , The details are shown in the following figure :

Motor speed regulation
If you want to speed the DC motor , One of the solutions is ;
close Q2 , Q3 ;
open Q1 , Q4 Enter it on the computer 50% Duty cycle PWM wave form ;
In this way, the effect of reducing the speed is achieved , If you need to increase the speed , Will enter PWM The duty cycle of is set to 100%; The details are as follows

Motor stop
Take the motor switching from forward to stop as an example , In forward rotation ; Q1 and Q4 It's on ;
At this time, if it's closed Q1 and Q4 , The equivalent inductance can be generated inside the DC motor , That's the perceptual load , The current doesn't jump , Then the current will continue to flow in the same direction , At this time, we hope that the current in the motor can quickly decay , There are two ways :
The first one is : close Q1 and Q4 , At this time, the current will still flow through the reverse freewheeling diode , It turns on briefly Q1 and Q3 So as to achieve the purpose of rapid attenuation of current .

The second kind : Ready to stop , close Q1 , open Q2, The current doesn't decay very fast at this time , The current circulates in Q2,M,Q4 Flow between , adopt MOS-FET Consume the energy of internal resistance .

H- Bridge application
In practice , Made of discrete components H Bridges are troublesome , There are many commonly used ones on the market IC programme , For example, common L293D、L298N、TA7257P、SN754410 etc. . Connect the power supply 、 The motor , The motor can be driven by inputting the control signal .
The following is on a treasure L298N modular , More common , Very friendly to novice players , The wiring is also very simple .

L298N Module this module has an onboard 5V pressure regulator , The regulator can be enabled by jumper .
If the motor supply voltage is as high as 12V, We can enable 5V pressure regulator , also 5V Pins can be used as outputs , For example, to Arduino Board power supply .
however , If the motor voltage is greater than 12V, The jumper must be disconnected , Because these voltages can damage the onboard 5V pressure regulator .
under these circumstances ,5V The pins will be used as inputs , Because we need to connect it to 5V Power Supply , In order to make IC Normal work .
We can notice here , The IC The voltage drop is about 2V. therefore , If you use 12V Power Supply , The voltage at the motor terminals is about 10V, That means we won't be able to get from 12V Get the maximum speed in a DC motor .
Use here Arduino For example , This is one from the Internet Demo The overall framework is shown in the figure below :

Main code
#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(button, INPUT);
// Set initial rotation direction
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
void loop() {
// Read potentiometer value
int potValue = analogRead(A0);
// Map the potentiometer value from 0 to 255
int pwmOutput = map(potValue, 0, 1023, 0 , 255);
// Send PWM signal to L298N Enable pin
analogWrite(enA, pwmOutput);
// Read button - Debounce
if (digitalRead(button) == true) {
pressed = !pressed;
}
while (digitalRead(button) == true);
delay(20);
// If button is pressed - change rotation direction
if (pressed == true & rotDirection == 0) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
delay(20);
}
// If button is pressed - change rotation direction
if (pressed == false & rotDirection == 1) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 0;
delay(20);
}
}
Code explanation
Briefly describe : First of all, we need to define the pins and variables needed by the program .
stay setup() in , We need to set the pin mode and the initial rotation direction of the motor .
stay loop() in , Let's read the potentiometer first , Then take the value from 0 To 1023 change , Linear mapping to PWM The signal 0 To 255 Value , From the 0 To 100% Duty cycle of .
And then use analogWrite() Function will PWM The signal is sent to L298N Board Enable Pin , This pin actually drives the motor .
Next , We check to see if the button is pressed , If so , We're going to enter 1 And the input 2 The state of is reversed , So as to change the direction of rotation of the motor . This button will be used as a toggle button , Each time the button is pressed, the direction of rotation of the motor is changed .
There are many such cars on a treasure , As shown in the figure below ; The master control can be replaced by 51 Single chip or STM32, Of course Arduino Also no problem , Use L298N You can quickly build a car ;

summary
Although we cannot confirm all the conclusions of the original author 、 The formulas are all correct . But seeing his clear words 、 Vivid illustrations 、 The detailed formula analysis reflects his need to design a small motor H The bridge circuit drives the project , I kept thinking about the principle of each link of the bridge circuit and some control details , And finally summarized into a blog . You can feel his inner joy in the whole process of knowledge growth .
Reference material
- H-Bridges – the Basics | Modular Circuits
- https://blog.csdn.net/tiandiren111/article/details/112130898
边栏推荐
- 力扣84柱状图中最大的矩形
- Understand neural network structure and optimization methods
- 並發編程JUC的AQS底層源碼
- Improving efficiency or increasing costs, how should developers understand pair programming?
- Getting started with webrtc: 12 Rtendpoint and webrtcendpoint under kurento
- [vivid understanding] the meanings of various evaluation indicators commonly used in deep learning TP, FP, TN, FN, IOU and accuracy
- Oracle uses an SQL to find out which data is not in a table
- [cloud native] 2.3 kubernetes core practice (Part 1)
- Brief introduction to SSL encryption process
- 多网络设备存在时,如何配置其上网优先级?
猜你喜欢

Quelques exercices sur les arbres binaires
![[vivid understanding] the meanings of various evaluation indicators commonly used in deep learning TP, FP, TN, FN, IOU and accuracy](/img/d6/119f32f73d25ddd97801f536d68752.png)
[vivid understanding] the meanings of various evaluation indicators commonly used in deep learning TP, FP, TN, FN, IOU and accuracy

力扣84柱状图中最大的矩形

不容置疑,这是一个绝对精心制作的项目

Rman-08137 main library failed to delete archive file

【云原生】2.3 Kubernetes 核心实战(上)

1098 Insertion or Heap Sort(堆排序解释)(PAT甲级)

Digital ic-1.9 understands the coding routine of state machine in communication protocol

I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!

C # solve the relative path problem using SQLite
随机推荐
VIM from dislike to dependence (20) -- global command
快捷键 bug,可复现(貌似 bug 才是需要的功能 [滑稽.gif])
2022.06.26(LC_6100_统计放置房子的方式数)
Order by injection of SQL injection
Semi-supervised Learning入门学习——Π-Model、Temporal Ensembling、Mean Teacher简介
Collection framework generic LinkedList TreeSet
Win10 add right-click menu for any file
vim 从嫌弃到依赖(19)——替换
Some considerations on operation / method overloading for thread to release lock resources
[MySQL basic] general syntax 1
NoSQL database redis installation
冒牌构造函数???
Code source AQS sous - jacent pour la programmation simultanée juc
Five basic types of redis
Persistence mechanism of redis
ucore lab5
关于el-date-picker点击清空参数变为null的问题
2022.6.26-----leetcode. seven hundred and ten
Redis master-slave replication and sentinel mode
多网络设备存在时,如何配置其上网优先级?