jackomo

Posted on 14 June 2006 by jakilevy

Controlling a DC Motor

Here is a good article on H-Bridges

I am using an allegro motor driver
Click for Datasheet

PIC BASIC PRO CODE:

DEFINE OSC 4
start:
INCLUDE “modedefs.bas”
‘break

OUTPUT PORTD.0
INPUT PORTD.2 ‘Switch 1
INPUT PORTB.0
i var byte
‘Wait .5 second

‘BLINK AN LED to Test the PIC
high portd.0
pause 500
low portd.0
pause 500
high portd.0
pause 500
low portd.0
Pause 500

main:
‘IF Switch 1 is pressed
if portd.2 = 1 then

‘test LED’S
low portb.7
higH PORTD.0

‘TURN MOTOR 1 – REVERSE
HIGH PORTD.1
‘For i = 0 to 255 step 1
‘FOR a motor – 127 is 0 point
’128 is SLOW fwd … 255 is fast fwd
’126 is SLOW REV … 0 fast rev

‘PWM Pin,Duty,Cycle
PWM PORTD.1,0, 10
next
endif
‘If Switch 1 is NOT pressed – TURN MOTOR OTHER WAY
if portd.2 = 0 then

‘TEST LED
low PORTD.0

‘TURN MOTOr 1 – FWD
‘For i = 255 to 0 step -1
‘PWM Pin,Duty,Cycle
PWM PORTD.1,255, 10
next
endif

GoTo main

Socially Bookmarkit!
  • Digg
  • del.icio.us
  • Technorati
  • Reddit
Sphere: Related Content

Leave a Reply