hye.i hope anybody in this forum can help me to solve my problem.i'm final year student which have final year project.for my final project, i have to make maze mapper robot.i use PIC18F4550 as the microcontroller,ir distance sensor (sharp GP2D120XJ00F) and the dc motor with encoder PD3046.all component i bought from cytron cmpany.my problem is i don't know how to combine the ir sensor programming with the dc motor.actually i have make the combination between ir sensor with LED programming and it works functionally.but when i try to combine between ir sensor with dc motor,the circuit not function.i will attach the the combination of my programming.for your information i use pbp format in microcode studio software.
define osc 8
'defenition
DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
MWPWM1 VAR PORTC.2 'PWM MOTOR 1
MWPWM2 VAR PORTC.1 'PWM MOTOR 2
MRCW1 VAR PORTD.4
MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
MRCW2 VAR PORTD.6
MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
TRISD.4=0
TRISD.5=0
TRISD.6=0
TRISD.7=0
TRISA.2=1
TRISA.1=1
TRISA.0=1
ADCON1=%00000000
SENSOR1 VAR BYTE
SENSOR2 VAR BYTE
SENSOR3 VAR BYTE
HPWM 1,150,1000
HPWM 2,150,1000
'MAIN PROGRAM
MAIN:
gosub fwd 'JUMO TO FWD
GOSUB IR1 'JUMP TO IR1 SUBOUTINE
GOSUB IR2 'JUMP TO IR2 SUBROUTINE
GOSUB IR3 'JUMP TO IR3 SUBROUTINE
GOTO MAIN 'LOOP TO MAIN FOREVER
'SUBROUTINE PROGRAM
FWD:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=1
MRCW2=0
RETURN
BWD:
HPWM 1,150,500
MRCCW1=1
MRCW1=0
HPWM 2,150,500
MRCCW2=0
MRCW2=1
RETURN
RIGHT:
HPWM 1,150,500
MRCCW1=0
MRCW1=1
HPWM 2,150,500
MRCCW2=0
MRCW2=1
RETURN
LEFT:
HPWM 1,150,500
MRCCW1=1
MRCW1=0
HPWM 2,150,500
MRCCW2=1
MRCW2=0
RETURN
IR1:
ADCIN 0,SENSOR1
IF SENSOR1>46 THEN
GOSUB RIGHT
ELSE
if SENSOR1<46 THEN
GOSUB FWD
ENDIF
ENDIF
pause 1000
RETURN
IR2:
ADCIN 1,SENSOR2
IF SENSOR2>46 THEN
GOSUB LEFT
ELSE
if SENSOR2<46 THEN
GOSUB FWD
ENDIF
ENDIF
pause 1000
RETURN
IR3:
ADCIN 2,SENSOR3
IF SENSOR3>46 THEN
GOSUB BWD
ELSE
if SENSOR3<46 THEN
GOSUB FWD
ENDIF
ENDIF
pause 1000
RETURN