Fig. 1 Picaxe controlling a H-bridge DC motor control.

PICAXE 18M2 H-Bridge DC Motor Control

by Lewis Loflin

In this simple demonstration we use the two pulse-width modulators on the Picaxe 18M2 with a H-bridge controlling both direction and speed at the same time as shown in the video.

switch with pullup resistor

Connect two switches as shown above to pins C.5 and B.0. When both switches are pressed at once, it goes into programmed mode.

1o K pot

The above is connected to pin B.1 while the connections for the H-bridge is the same as the Arduino links below.


init: 
pwmout pwmdiv4, B.6, 50, 500
pwmout pwmdiv4, B.3, 50, 500

main:
if pinC.5 =0 AND pinB.0 = 0 then auto1
if pinC.1 =0 then auto1
if pinC.5 =0 then fwd ;connected to switch with pullup
if pinB.0 = 0 then rev1 ;connected to switch with pullup

b0 = 0
pwmduty B.3,b0; set pwm duty
pwmduty B.6,b0; set pwm duty
goto main

rev1:

readadc B.1, b0  ;read ADC into variable b0
pwmduty B.6,b0; set pwm duty
goto main; loop back to start


fwd:

readadc B.1, b0  ;read ADC into variable b0
pwmduty B.3, b0; set pwm duty
goto main; loop back to start

auto1:
b0 = 0
pwmduty B.3, b0; set pwm duty
pwmduty B.6, b0; set pwm duty
pause 3000

pwmduty B.6, 75; set pwm duty
pause 1000
pwmduty B.6, 0
pause 1000
pwmduty B.3, 75; set pwm duty
pause 1000
pwmduty B.3, 0

pause 1000

pwmduty B.6, 150; set pwm duty
pause 1000
pwmduty B.6, 0
pause 1000
pwmduty B.3, 150; set pwm duty
pause 1000
pwmduty B.3, 0

pause 1000

pwmduty B.6, 200; set pwm duty
pause 1000
pwmduty B.6, 0
pause 1000
pwmduty B.3, 200; set pwm duty
pause 1000
pwmduty B.3, 0

goto main



Picaxe Micro-controller Projects!

The PICAXE series of micro-controllers rank as the easiest and most cost effective way to use Microchip processors. I wanted an easier and less expensive way to introduce my students to the "PIC" micro-controller. Here I hope to get those starting out past poorly written literature and lack of simple working code examples.