H-Bridge circuit principle and DC motor drive programming

Source: Internet
Author: User

Source: http://blog.sina.com.cn/s/blog_6035432c0100hb1p.html



A typical DC motor control circuit is shown in the figure above. The circuit is named after the "H-Bridge drive circuit" because its shape resembles the letter H. 4 transistors make up the 4 vertical legs of h, and the motor is the horizontal bar in H (Note: The figure is a schematic, not a complete circuit diagram, where the transistor's drive circuit is not drawn).


The H-bridge motor drive circuit consists of 4 transistors and one motor. To make the motor run, a pair of transistors on the diagonal must be on. Depending on the conduction condition of the transistor pair, the current may flow from left to right or from right to left to control the motor steering.
For the motor to operate, a pair of transistors on the diagonal must be made to pass. For example, as shown in the following figure, when the Q1 tube and the Q4 tube are on, the current is passed from the power supply positive to the Q1 from left to right through the motor, and then back to the power supply negative by Q4. As indicated by the current arrow in the figure, the current flow will drive the motor clockwise. When the transistor Q1 and Q4 are on, the current flows from left to right through the motor, which drives the motor to rotate in a specific direction (the arrows around the motor indicate clockwise direction).



As shown in the figure above for another pair of transistors Q2 and Q3 conduction, the current will flow from right to left through the motor. When transistor Q2 and Q3 are on, the current flows from right to left through the motor, which drives the motor to rotate along the other side (the arrows around the motor are indicated counterclockwise).


Typical H-bridge drive circuits are as follows:


PWM1 for 1,pwm2 1 o'clock, Q1 and Q2 conduction, nodes 1 and 2 are low level, Q15 and Q16 conduction, motor not working

PWM1 for 0,pwm2 0 o'clock, Q1 and Q2 conduction, nodes 1 and 2 are high level, Q13 and Q14 conduction, motor not working

PWM1 for 1,pwm2 0 o'clock, Q1 conduction and Q2 not conduction, node 1 is low and 2 is high, Q14 and Q15 conduction, motor counterclockwise rotation

PWM1 for 0,pwm2 1 o'clock, Q1 is not conduction and Q2 conduction, Node 1 is high and 2 is low, Q13 and Q16 conduction, motor clockwise rotation


C language code:

Function: Can be the motor is turning, reversing, stop.
#include <AT89X52.h>
#define UCHAR unsigned char
#define UINT unsigned int

Sbit key_up=p3^2; Positive Turn button
Sbit key_down=p3^3; Invert keys
Sbit key_stop=p3^4; Stop button

Sbit zz=p1^0; Control end, with single-chip microcomputer P1.0 Port
Sbit fz=p1^1; Control end, with single-chip microcomputer P1.1 Port

Sbit fmq=p3^6;
Uchar Keyv;
Uchar Tempkeyv;


void Delaynms (UINT AA)
{
UCHAR BB;
while (aa--)
{
for (bb=0;bb<115;bb++)//1ms Reference delay Program
{
;
}
}

}

void Delay500us (void)
{
Int J;
for (j=0;j<57;j++)
{
;
}
}

void beep (void)
{
Uchar T;
for (t=0;t<100;t++)
{
DELAY500US ();
fmq=!   FMQ; Generate pulses
}
Fmq=1; Turn off the buzzer
DELAYNMS (300);
}



void Main (void)
{
Zz=1;
Fz=1; Stop the DC motor from running
while (1)
{
if (! KEY_UP)
Keyv=1;
if (! Key_down)
keyv=2;
if (! Key_stop)
keyv=3;
if (keyv!=0)
{
DELAYNMS (10);
if (! KEY_UP)
Tempkeyv=1;
if (! Key_down)
tempkeyv=2;
if (! Key_stop)
tempkeyv=3;
if (KEYV==TEMPKEYV)
{
if (keyv==1)
{
Beep ();
Zz=1;
fz=0;
}
if (keyv==2)
{
Beep ();
zz=0;
Fz=1;
}
if (keyv==3)
{
Beep ();
Zz=1;
Fz=1;
}
}
}
keyv=0;
tempkeyv=0;
}
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.