# Robot follower HELP PLZ its just small thing can't fix it :(

#### goldfish300

Joined Mar 12, 2009
12
well this is my project topic:
Line follower robot; the robot has two IR sensors that detect a black line. The PIC16f628 has to read the sensor values, and compare them, and then decides if the robot should turn left or right.

well i'v done the code and im trying to fix what i have and my question is when i try to enable the switch nothing happen in which a led must turn on and i don't have an error
and also the motor right problem. so anyone can help. i will post the code with the graph and see the attachmet for the file im working with

Rich (BB code):
;LINE FFOLLOWER ROBOT USING PIC16F628,L298
#INCLUDE	"P16F628A.INC"

#DEFINE		PB_FORWARD		PORTA, 0
#DEFINE		PB_STOP			PORTA, 1
#DEFINE		ENABLE			PORTA, 2
#DEFINE 	        LS_RIGHT		        PORTA, 3
#DEFINE 	        LS_LEFT			PORTA, 4

;outputs
#DEFINE 	M1L1			PORTB, 1
#DEFINE 	M1L2			PORTB, 2
#DEFINE 	M2L1			PORTB, 3
#DEFINE 	M2L2			PORTB, 4
#DEFINE 	START		PORTB, 0

CBLOCK	0X20
A1, A2, A3
ENDC

ORG 	0X000
GOTO	MAIN

MAIN
CALL	SETUP
CALL 	MAIN_START

REPEAT
BTFSC	PB_FORWARD
CALL	        GO_FORWARD
BTFSC	PB_STOP
CALL	        STOP
BTFSC	LS_LEFT
CALL	        SENSOR_LEFT
BTFSC	LS_RIGHT
CALL	        SENSOR_RIGHT
GOTO	        REPEAT

GO_FORWARD
BCF		M1L1
BSF		M1L2
BCF		M2L1
BSF		M2L2
RETURN

STOP
BCF		M1L1
BCF		M1L2
BCF		M2L1
BCF		M2L2
RETURN

MAIN_START
BTFSC	ENABLE
BSF		START
CALL 	        DELAY_10MS
BCF		START
RETURN

SENSOR_RIGHT
BSF		M1L1
BCF		M1L2
BSF		M2L1
BCF		M2L2
BTFSS 	LS_RIGHT
GOTO 	$+3 CALL DELAY_10MS GOTO$-3
CALL	        GO_FORWARD
RETURN

SENSOR_LEFT
BCF		M1L1
BSF		M1L2
BCF		M2L1
BSF		M2L2
BTFSS 	LS_LEFT
GOTO	        $+3 CALL DELAY_10MS GOTO$-3
CALL	        GO_FORWARD
RETURN

DELAY_10MS
MOVLW		D'5'
MOVWF		A1
MOVLW		D'108'
MOVWF		A2
MOVLW		D'5'
MOVWF		A3
DECFSZ		A3
GOTO		        $-1 DECFSZ A2 GOTO$-5
DECFSZ		A1
GOTO		        $-9 RETURN DELAY_1S MOVLW D'46' MOVWF A1 MOVLW D'189' MOVWF A2 MOVLW D'37' MOVWF A3 DECFSZ A3 DECFSZ A2 GOTO$-5
DECFSZ		A1
GOTO		        \$-9
RETURN

SETUP

CLRF	         PORTA
CLRF	         PORTB
BSF		STATUS, RP0
CLRF	         TRISB
MOVLW	B'00011111'
MOVWF	TRISA
BCF		STATUS, RP0
MOVLW	B'00000111'
MOVWF	CMCON
RETURN

END
the PIC:

#### Attachments

• 45.6 KB Views: 18

#### steinar96

Joined Apr 18, 2009
239
I was wondering, since you have no capacitors to protect your IC's circuitry, if you werent worried about the motors destroying the chip.

The motors could produce a voltage spike at the inputs since they act like inductors. Usually capacitors are placed around power pins to stabilize the pics vs fluctuations in voltage inputs. If the motors draw alot of power from the power supply it could easily bring the pic's input voltage momentarily bellow operating voltage and cause the PIC to halt.

#### goldfish300

Joined Mar 12, 2009
12
I was wondering, since you have no capacitors to protect your IC's circuitry, if you werent worried about the motors destroying the chip.

The motors could produce a voltage spike at the inputs since they act like inductors. Usually capacitors are placed around power pins to stabilize the pics vs fluctuations in voltage inputs. If the motors draw alot of power from the power supply it could easily bring the pic's input voltage momentarily bellow operating voltage and cause the PIC to halt.
10x for that
but do u have any idea on fixing the led at start up not turning on ??

#### steinar96

Joined Apr 18, 2009
239
I dont have any experience as of yet programming PICS so i can't help you regarding the code.

The only tip i can give you however is that you need to make sure the pin can source enough current to drive the led.