Top Topics

74*245 Motor Driver

H-Bridge Driver

Simple PWM Gen.

Handy Method Measuring RPM

Measuring RPM via Photo reflector

Introduction to Robotic

DC, Stepper,and Servo Motor

Related Link

Microcontroller Tutorial

Computer Interface
Tutorial

.............more links

 

 

 

BACK

'******************************************************************
'* Program: rollybeacon1.BAS *
'* Author: Bill Sherman *
'* Notice: Copyright (c) 2001 Bill Sherman *
'* All Rights Reserved *
'* Date: 6-17-02 *
'* Version: 1.0 *
'* Notes: wheel speed con added *
'* 1021 words used *
'******************************************************************
Include "modedefs.bas"
Define osc 20
TRISA=%11110100 'set porta i/o as needed
TRISB=%00010101 'set portb i/o as needed
beakin var byte 'charactor from beacon
rest var byte 'decide to rest var
y var byte 'scan count
f var byte 'forward movement count
s var byte 'backing up count
n var word 'for/next loop counter
righteye var portb.4 'right sensor
lefteye var portb.2 'left sensor
speed con 20 'speed variable
pyro var portb.0 'pyro heat sensor
irrec var porta.4 'reciever for beacon, make different freq.
push var porta.2 'pushbutton switch
lwheel con 764 'left servo wheel zero speed
rwheel con 776 'right servo wheel zero speed
init: 'initalize key system
low portb.3 'turn off ir
low porta.3 'beeper off
s=0 'backup count zero
y=0 'scan count zero
f=0 'set backing up count to 1
rest = 0 'clear rest var to zero
gosub zero 'stop servos
flash: 'flash blue led, detect mode select, servos ON
high porta.1 'turn on motor pwr
high portb.1 'turn on blue led
if push = 0 then watchdog 'Hold down ON button for watchdog mode
pause 2000 'keep blue led on for 2 sec
low portb.1 'turn off blue led

pulseme: 'generate 38kc light
high portb.1 'blue led ON
for n= 1 to 250 'start burst 38 kc
high portb.3 'led on
pauseus 2 'led on for 2 more usec
low portb.3 'led off
pauseus 13 'off time for led
next 'repeat to complete waveform burst
low portb.1 'blue led ON
sense: 'check for objects in front, right, left
if (lefteye = 0) AND (righteye = 0) then backup
for n= 1 to 250 'start burst 38 kc
high portb.3 'led on
pauseus 2 'led on for 2 more usec
low portb.3 'led off
pauseus 13 'off time for led
next 'repeat to complete waveform burst
if righteye = 0 then advoidleft 'detect object to the right
for n= 1 to 250 'start burst 38 kc
high portb.3 'led on
pauseus 2 'led on for 2 more usec
low portb.3 'led off
pauseus 13 'off time for led
next 'repeat to complete waveform burst
if lefteye = 0 then advoidright 'detect object to the left
forward: 'move ahead
high porta.1 'pwr up servo
for n=1 to 20 'generate PWM for servos to move forward
low porta.0 'preset porta.0 to low
pulsout porta.0,(lwheel+speed) 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,(rwheel-speed) 'right servo PWM high time
pause 20 'PWM low time
if righteye = 0 then goto command 'look for IR from Remote
next 'repeat PWM for a bit of motion
low portb.6 'red led off
f=f+1 'increment forward motion counter
if f>40 then goto scan 'clear forward path has been taken
goto pulseme 'restart another burst of IR

backup: 'backup
f=0 'clear forward counts
gosub zero 'stop all servos
gosub beep 'beep
high porta.1 'pwr up servo
for n=1 to 15 'generate PWM for servos to backup
low porta.0 'preset porta.0 to low
pulsout porta.0,(lwheel-(speed-5)) 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,(rwheel+(speed-5)) 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM for a bit of motion
s=s+1 'count backups
if s>8 then goto turnright 'if >8 backups occur, then turn
goto pulseme
advoidright:
gosub avoidbackup
turnright: 'turn right
f=0 'clear forward counts
s=5 'advance backup counts by 5 when turning
high porta.1 'pwr up servo
for n=1 to 20 'generate PWM for servos to turn right
low porta.0 'preset porta.0 to low
pulsout porta.0,(lwheel+speed) 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,(rwheel+speed) 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM for a bit of motion
goto pulseme 'restart another burst of IR
advoidleft:
gosub avoidbackup 'backup a little before turning
turnleft: 'turn left
f=0 'clear forward counts
s=2 'advance backup counts by 2 when turning
high porta.1 'pwr up servo
for n=1 to 20 'generate PWM for servos to turn left
low porta.0 'preset porta.0 to low
pulsout porta.0,(lwheel-speed) 'left servo PWM high time
low portb.5 'preset portb.5 to low

pulsout portb.5,(rwheel-speed) 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM for a bit of motion
goto pulseme 'restart another burst of IR
zero: 'stop the servos
for n=1 to 5 'generate PWM for servos to stop
low porta.0 'preset porta.0 to low
pulsout porta.0,lwheel 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,rwheel 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM to stop motion
low porta.1 'pwr down servo
return
beep:
sound portb.7, [75,10,110,10] 'make a sound
return
scan: 'seeks ir beacon
y=0 'clear scan turn count
s=0 'clear backup counts
scan2:
gosub zero
f=0 'forward step counts
y=y+1 'scan count
high portb.1 'turn on blue led
high porta.3 'beeper on
serin porta.4,t1200,100,break,["a"],beakin 'receive beacon signal
if (beakin >64) or (beakin <91) then beacon 'if valid character then goto beacon
break: 'continue rotation if no beacon found
low portb.1 'blue led off
low porta.3 'beeper off
high porta.1 'pwr up servo
for n=1 to 8 'scan right
pulsout porta.0,(lwheel+speed) 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,(rwheel+speed) 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM to rotate
if y > 25 then hotbody 'after turning enough degrees, clear y
goto scan2 'keep turning cw

beacon:
low porta.3 'turn off beeper
sound portb.7, [80,100,120,300] 'make different sound
goto forward 'go toward beacon
hotbody: 'seeks heat
y=0 'clear number of scan turns
hotbody2: 'continue with seeking heat
gosub zero 'stop motion
y=y+1 'scan count
pause 3000 'wait for pyro to settle
high portb.1 'turn on blue led
pause 100 'keep blue led on
low portb.1 'turn off blue led
for n=1 to 500 'loop 500 seeks for heat
if pyro = 1 then high portb.6 'turn on red led
if pyro = 1 then rest = 0 'reset rest var to zero
if pyro = 1 then goto pulseme 'goto pulseme (body of program)
if irrec = 0 then goto beacon 'still can seek ir from operator
low portb.1 'turn off blue led
pause 10 'if no heat, then loop every 10 ms
next 'continue loop
high porta.1 'pwr up servo
for n=1 to 30 'start scan left
pulsout porta.0,(lwheel-speed) 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,(rwheel-speed) 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM to rotate
rest = rest + 1 'increment rest value
if rest > 18 then watchdog 'goto watchdog and wait
if y > 7 then goto pulseme 'after turning around goto pulseme
goto hotbody2 'if less than 8 turns then turn cw
command: 'operator can make it turn to the right
gosub beep 'make a beep to alert operator signal recieved
pause 500
goto turnright 'make a right turn

watchdog:
low porta.1 'turn off motor pwr
low portb.1 'turn blue led off
high porta.3 'start up a beep
pause 2000 'continue beep
low porta.3 'stop beep
s=s+1 'count watchdog disturbance
if s > 4 then flash 'rollie comes out if disturbed 5 times
watchdog2:
if pyro = 1 then watchdog 'look for heat
if push = 0 then watchdog3 'look for silent watchdog mode
if righteye = 0 then flash 'look for IR-remote signal
goto watchdog2
watchdog3: 'silent watchdog
if righteye = 0 then flash 'look for IR-remote signal
if pyro = 0 then watchdog3 'look for heat
high portb.1 'blue led turns on
pause 1000 'if it sees heat
low portb.1 'turn off blue led
goto watchdog3 'loop
avoidbackup:
for n=1 to 15 'generate PWM for servos to backup
low porta.0 'preset porta.0 to low
pulsout porta.0,(lwheel-(speed-5)) 'left servo PWM high time
low portb.5 'preset portb.5 to low
pulsout portb.5,(rwheel+(speed-5)) 'right servo PWM high time
pause 20 'PWM low time
next 'repeat PWM to backup a bit
return
end

BACK