Wiki source code of Dual H-Bridge Motor Driver

Last modified by Eric Nantel on 2023/02/02 15:06

Show last authors
1 {{html wiki="false" clean="true"}}
2 <body><table border="0" cellpadding="0" cellspacing="0" >
3 <tbody><tr>
4 <td valign="top" ><font size="2" face="verdana"><strong>Dual
5 H Bridge Motor Driver.</strong></font><p><font size="2" face="verdana"><strong>01.22.04</strong></font></p>
6 <p><font size="2" face="verdana">This is a step-by-step procedure of
7 connecting a Lynxmotion Dual H-Bridge motor driver to the OOPic-R
8 microcontroller. These two products were designed at about the same
9 time, but a misunderstanding of the actual pinout for the connector
10 resulted in a mismatch. However it's not a difficult fix. Follow the
11 instructions below to get your project up and running quickly.&nbsp;</font></p>
12 </td>
13 <td align="center" valign="bottom" width="320"><img src="https://wiki.lynxmotion.com/info/wiki/lynxmotion/download/wheeled-tracked/dual-h-bridge-motor-driver/WebHome/dhbmd01.jpg" border="2" hspace="10" ><br>
14 <font size="2" face="verdana"><strong>Finished Project</strong></font></td>
15 </tr>
16 <tr>
17 <td colspan="2" >&nbsp;</td>
18 </tr>
19 <tr>
20 <td valign="top" ><font size="2" face="verdana"><b>Step 1.</b> Plug
21 in the +5vdc / GND connector (red and black wires) as shown.&nbsp;If
22 you are already using the serial LCD port, then any I/O bus connector
23 with +5vdc available can be used. Take care not to install this
24 backwards.</font></td>
25 <td align="center" valign="bottom" ><img src="https://wiki.lynxmotion.com/info/wiki/lynxmotion/download/wheeled-tracked/dual-h-bridge-motor-driver/WebHome/dhbmd05.jpg" border="2" hspace="10" ><br>
26 <font size="2" face="verdana">Figure 1-1.</font></td>
27 </tr>
28 <tr>
29 <td colspan="2" >&nbsp;</td>
30 </tr>
31 <tr>
32 <td valign="top" ><font size="2" face="verdana"><b>Step
33 2.</b> You need to rearrange some of the wires, and to do so you must unplug
34 them from the black housings. Use a hobby knife and gently slide
35 it under the tab holding the wire in. Lift the tab and slide the wire
36 out. Don't bend it too far as damage could result. You will need to remove the following wires:<br>
37 &nbsp;</font>
38 <div align="center">
39 <center>
40 <table border="1" bordercolor="#FFFFFF">
41 <tbody><tr>
42 <td bordercolor="#FFFFFF" colspan="2" align="center"><font size="2" face="Verdana">4-wire
43 housing</font></td>
44 </tr>
45 <tr>
46 <td align="center" bordercolor="#808080" bgcolor="#C0C0C0"><font size="2" face="Verdana">Wire
47 Color</font></td>
48 <td align="center" bordercolor="#808080" bgcolor="#C0C0C0"><font size="2" face="Verdana">From
49 DHB</font></td>
50 </tr>
51 <tr>
52 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">Brown</font></td>
53 <td bordercolor="#C0C0C0"><font size="2" face="verdana"> (A (-) in)</font></td>
54 </tr>
55 <tr>
56 <td bordercolor="#C0C0C0"><font size="2" face="verdana">
57 Dark Blue</font></td>
58 <td bordercolor="#C0C0C0"><font size="2" face="verdana"> (B (+) in)</font></td>
59 </tr>
60 <tr>
61 <td bordercolor="#C0C0C0"><font size="2" face="verdana">
62 Pink</font></td>
63 <td bordercolor="#C0C0C0"><font size="2" face="verdana"> (B (-) in)</font></td>
64 </tr>
65 <tr>
66 <td bordercolor="#FFFFFF" colspan="2" align="center"><font size="2" face="Verdana">2-wire
67 housing</font></td>
68 </tr>
69 <tr>
70 <td align="center" bordercolor="#808080" bgcolor="#C0C0C0"><font size="2" face="Verdana">Wire
71 Color</font></td>
72 <td align="center" bordercolor="#808080" bgcolor="#C0C0C0"><font size="2" face="Verdana">From
73 DHB</font></td>
74 </tr>
75 <tr>
76 <td bordercolor="#C0C0C0"><font size="2" face="verdana">
77 Yellow</font></td>
78 <td bordercolor="#C0C0C0"><font size="2" face="verdana"> (A enable)</font></td>
79 </tr>
80 <tr>
81 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">Light
82 Blue *</font></td>
83 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">(B
84 enable)</font></td>
85 </tr>
86 <tr>
87 <td bordercolor="#FFFFFF" colspan="2" align="center"><font size="2" face="Verdana">Table
88 2-1</font></td>
89 </tr>
90 </tbody></table>
91 </center>
92 </div>
93 <p><font size="2" face="verdana">&nbsp;* The Light Blue (B
94 enable) wire can optionally be removed and repositioned so that the 2-wire connector will be facing the same way
95 as the 4-wire connector. It's purely an aesthetic choice.</font></p>
96 </td>
97 <td align="center" valign="top" ><img src="https://wiki.lynxmotion.com/info/wiki/lynxmotion/download/wheeled-tracked/dual-h-bridge-motor-driver/WebHome/dhbmd02.jpg" border="2" hspace="10" ><br>
98 <font size="2" face="verdana">Figure 2-1.</font></td>
99 </tr>
100 <tr>
101 <td colspan="2">&nbsp;</td>
102 </tr>
103 <tr>
104 <td valign="top" ><font size="2" face="verdana"><b>Step
105 3.</b> Now you need to insert the wires into the black housings&nbsp; in a
106 different order. Look at the "Dual DC Motor I/O" section on
107 the OOPic-R board, and match the numbers by the pins to the correct
108 wire from the Dual H-Bridge board. Then simply slide the wires back into
109 the correct slot of the housing. If you make a mistake, just follow
110 Step 2 to get the wire out again.<br>
111 &nbsp;</font>
112 <div align="center">
113 <center>
114 <table border="1" bordercolor="#FFFFFF">
115 <tbody><tr>
116 <td colspan="3" bordercolor="#FFFFFF">
117 <p align="center"><font face="Verdana" size="2">4-wire housing</font></p></td>
118 </tr>
119 <tr>
120 <td bordercolor="#808080" bgcolor="#C0C0C0">
121 <p align="center"><font face="Verdana" size="2">OOPic-R
122 Pin Number</font></p>
123 </td>
124 <td bordercolor="#808080" bgcolor="#C0C0C0">
125 <p align="center"><font face="Verdana" size="2">Wire Color</font></p></td>
126 <td bordercolor="#808080" bgcolor="#C0C0C0">
127 <p align="center"><font face="Verdana" size="2">From
128 DHB</font></p>
129 </td>
130 </tr>
131 <tr>
132 <td bordercolor="#C0C0C0" align="center"><font size="2" face="Verdana">24</font></td>
133 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">Purple</font></td>
134 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">(A
135 (+) in)</font></td>
136 </tr>
137 <tr>
138 <td bordercolor="#C0C0C0" align="center"><font size="2" face="Verdana">17</font></td>
139 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">Yellow</font></td>
140 <td bordercolor="#C0C0C0"><font size="2" face="verdana">(A
141 enable)</font></td>
142 </tr>
143 <tr>
144 <td bordercolor="#C0C0C0" align="center"><font size="2" face="Verdana">25</font></td>
145 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">Brown</font></td>
146 <td bordercolor="#C0C0C0"><font size="2" face="verdana">(A
147 (-) in)</font></td>
148 </tr>
149 <tr>
150 <td bordercolor="#C0C0C0" align="center"><font size="2" face="Verdana">26</font></td>
151 <td bordercolor="#C0C0C0"><font size="2" face="Verdana">Dark
152 Blue</font></td>
153 <td bordercolor="#C0C0C0"><font size="2" face="verdana">(B
154 (+) in)</font></td>
155 </tr>
156 <tr>
157 <td colspan="3" bordercolor="#FFFFFF">
158 <p align="center"><font face="Verdana" size="2">2-wire housing</font></p></td>
159 </tr>
160 <tr>
161 <td bordercolor="#808080" bgcolor="#C0C0C0">
162 <p align="center"><font face="Verdana" size="2">OOPic-R
163 Pin Number</font></p>
164 </td>
165 <td bordercolor="#808080" bgcolor="#C0C0C0">
166 <p align="center"><font face="Verdana" size="2">Wire
167 Color</font></p>
168 </td>
169 <td bordercolor="#808080" bgcolor="#C0C0C0">
170 <p align="center"><font face="Verdana" size="2">From
171 DHB</font></p>
172 </td>
173 </tr>
174 <tr>
175 <td bordercolor="#C0C0C0" align="center"><font face="Verdana" size="2">18</font></td>
176 <td bordercolor="#C0C0C0"><font face="Verdana" size="2">Light
177 Blue</font></td>
178 <td bordercolor="#C0C0C0"><font size="2" face="verdana">(B
179 enable)</font></td>
180 </tr>
181 <tr>
182 <td bordercolor="#C0C0C0" align="center"><font face="Verdana" size="2">27</font></td>
183 <td bordercolor="#C0C0C0"><font face="Verdana" size="2">Pink</font></td>
184 <td bordercolor="#C0C0C0"><font size="2" face="verdana">(B
185 (-) in)</font></td>
186 </tr>
187 <tr>
188 <td bordercolor="#FFFFFF" align="center">&nbsp;</td>
189 <td bordercolor="#FFFFFF">
190 <p align="center"><font face="Verdana" size="2">Table 3-1</font></p></td>
191 <td bordercolor="#FFFFFF">&nbsp;</td>
192 </tr>
193 </tbody></table>
194 </center>
195 </div>
196 &nbsp;
197 </td>
198 <td align="center" valign="top" ><img src="https://wiki.lynxmotion.com/info/wiki/lynxmotion/download/wheeled-tracked/dual-h-bridge-motor-driver/WebHome/dhbmd03.jpg" border="2" hspace="10" ><br>
199 <font size="2" face="verdana">Figure 3-1.<br>
200 <br>
201 </font></td>
202 </tr>
203 <tr>
204 <td colspan="2">&nbsp;</td>
205 </tr>
206 <tr>
207 <td valign="top" ><font size="2" face="verdana"><b>Step
208 4.</b> Your wires should look like the picture when you are done. If they
209 are in the wrong order, then refer to Table 3-1 for the wire order.</font></td>
210 <td align="center" valign="bottom" ><img src="https://wiki.lynxmotion.com/info/wiki/lynxmotion/download/wheeled-tracked/dual-h-bridge-motor-driver/WebHome/dhbmd04.jpg" border="2" hspace="10" ><br>
211 <font size="2" face="verdana">Figure 4-1.</font></td>
212 </tr>
213 <tr>
214 <td valign="top" colspan="2">&nbsp;</td>
215 </tr>
216 <tr>
217 <td valign="top" ><font size="2" face="verdana"><b>Step 5.</b> On
218 the Dual H-Bridge, attach wires from the battery and the motors as the
219 diagram shows. Take care to observe polarity to prevent
220 problems.&nbsp;</font></td>
221 <td align="center" valign="bottom" ><img src="https://wiki.lynxmotion.com/info/wiki/lynxmotion/download/wheeled-tracked/dual-h-bridge-motor-driver/WebHome/dhbmd08.jpg" border="2" hspace="10" ><br>
222 <font size="2" face="verdana">Figure 5-1.</font></td>
223 </tr>
224 <tr>
225 <td valign="top" colspan="2">&nbsp;</td>
226 </tr>
227 <tr>
228 <td valign="top" colspan="2">
229 <p align="left"><font size="2" face="verdana"><b>Step 6.</b> This code will
230 give you a good start on making your bot move around and be able to
231 change direction with only two variables. By Jim
232 Babcock</a>.</font></p></td>
233 </tr>
234 <tr>
235 <td valign="top" colspan="2">&nbsp;</td>
236 </tr>
237 <tr>
238 <td valign="top" colspan="2">
239 <div align="center">
240 <center>
241 <table border="1" bordercolor="#000000">
242 <tbody><tr>
243 <td bordercolor="#FFFFFF"><font face="Courier New" size="2">' This
244 small program is designed to give you the basics to move your bot around<br>
245 ' and change direction with just 2 variables (speed and turn)<br>
246 <br>
247 ' Speed is a value between 127 and -128 with 0 being neutral Or
248 Stop<br>
249 ' When speed is set from 1 to 127 the bot will move forward and
250 faster As the value goes up<br>
251 ' When speed is set from -1 to -128 the bot will move backward
252 and faster As the value goes down<br>
253 <br>
254 ' Turn is a value between 127 and -128 with 0 being no turn at all<br>
255 ' When turn is set from 1 to 127 the bot will move to the left. As the value goes up the bot turns harder.<br>
256 ' When turn is set from -1 to -127 the bot will move to the right. As the value goes down the bot turns harder.<br>
257 <br>
258 ' It should be noted that since the objects Navcom, LeftMotor,
259 and RightMotor have been linked<br>
260 ' by Virtual Circuit that the main() program doesn't have to be
261 loop for the bot to keep moving since the VC is<br>
262 ' constantly running in the background. By the way VCs run about 5
263 times faster the the other code.<br>
264 <br>
265 Dim RightMotor As New oDCMotor2 ' Right motor bank<br>
266 Dim LeftMotor As New oDCMotor2 ' Left motor bank<br>
267 Dim Turn As New oWord ' One number used to turn both left
268 and right using the object Navcon through VC<br>
269 Dim Speed As New oWord ' One number used to
270 command both forward and reverse using the object Navcon through VC<br>
271 Dim Nav As New oNavCon ' Object used to command your bot around using one speed value
272 and one turn value<br>
273 Sub main()<br>
274 <br>
275 Call motorsetup ' Sub program to set your
276 motors up to run. (Only used once)<br>
277 <br>
278 Speed.signed = 1 ' Sets up the value property
279 to use positive and negative numbers 127 to -128<br>
280 turn.signed = 1 ' Sets up the value property
281 to use positive and negative numbers 127 to -128<br>
282 <br>
283 Speed = 2 ' Change this variable to
284 control speed and direction in this small program<br>
285 Turn = 0 ' Change this variable to
286 control left Or right turning in this small program<br>
287 <br>
288 Nav.Input1.Link(Speed) ' Links the speed variable to the Navcon object<br>
289 Nav.Input2.Link(Turn) ' Links the turn variable to the Navcon object<br>
290 Nav.Output1.Link(LeftMotor) ' Links the first output of Navcon
291 to LeftMotor value using VC<br>
292 Nav.Output2.LInk(RightMotor) ' Links the second output of Navcon
293 to RightMotor value using VC<br>
294 Nav.Limit = cvTrue ' Limits the left and right motor values from 127
295 to -128<br>
296 Nav.Operate = 1 ' Used to make this object active in the list
297 loop<br>
298 <br>
299 End Sub<br>
300 </font><font face="Courier New" size="2"><br>
301 '**************************************************************************<br>
302 '<br>
303 '**************************************************************************</font><font face="Courier New" size="2"><br>
304 <br>
305 Sub motorsetup ()<br>
306 <br>
307 LeftMotor.IOLineP = 17 'Enable line of motor control PWM is used IOLINE P<br>
308 leftMotor.InvertoutD=cvTrue 'Changes direction moves when
309 commanded forward<br>
310 leftMotor.prescale=2 'Used to step down the
311 frequ. of PWM<br>
312 leftMotor.period=255 'Used to set resalution of PWM (# of steps
313 for value)<br>
314 LeftMotor.IOLine1 = 24 'First control line for an L293 H-Bridge IOLINE 1<br>
315 LeftMotor.IOLine2 = 25 'Second control line for an L293 H-Bridge IOLINE 2<br>
316 LeftMotor.Operate = 1 'Used to make this object active in the list looop<br>
317 LeftMotor.Brake = cvOff 'Makes sure brake is set to
318 off<br>
319 LeftMotor.value = cvOff 'Makes sure motor value set
320 to 0<br>
321 <br>
322 RightMotor.IOLineP = 18 'Enable line of motor control PWM is used IOLINE P<br>
323 RightMotor.InvertoutD=cvTrue 'Changes direction moves when
324 commanded forward<br>
325 RightMotor.prescale=2 'Used to step down the
326 frequ. of PWM<br>
327 RightMotor.period=255 'Used to set resalution of PWM (# of steps
328 for value)<br>
329 RightMotor.IOLine1 = 26 'First control line for an L293 H-Bridge IOLINE 1<br>
330 RightMotor.IOLine2 = 27 'Second control line for an L293 H-Bridge IOLINE 2<br>
331 RightMotor.Operate = 1 'Used to make this object active<br>
332 RightMotor.Brake = cvOff 'Makes sure brake is set to
333 off<br>
334 RightMotor.value = cvOff 'Makes sure motor value set
335 to 0<br>
336 <br>
337 End Sub</font></td>
338 </tr>
339 </tbody></table>
340 </center>
341 </div>
342 <p>&nbsp;</p></td>
343 </tr>
344 </tbody></table>
345 <br></body>
346 {{/html}}
Copyright RobotShop 2018