Hi all, I built a basic line follower, It has 4 ir sensors controlled with lm324 op-amp and uses SN754410 motor driver.
I can adjust the sensors with a pot which gives me a HIGH output when the line is detected.
I tested the line follower by connecting two of the sensors (output from op-amp) directly to the motor driver and it worked. The robot followed the line quite well once the sensors had been adjusted.
Now I built this to learn more about pic programming so I connected the sensors and motor driver to 12f629.
I all I wanted was the processor to turn on the motors when a line had been detected so I wrote the following code. but it doesn't work well I am not sure if the motors are causing the pic problems or its my code.
Please could someone have a look, I will post a schematic later
Thanks Don
I can adjust the sensors with a pot which gives me a HIGH output when the line is detected.
I tested the line follower by connecting two of the sensors (output from op-amp) directly to the motor driver and it worked. The robot followed the line quite well once the sensors had been adjusted.
Now I built this to learn more about pic programming so I connected the sensors and motor driver to 12f629.
I all I wanted was the processor to turn on the motors when a line had been detected so I wrote the following code. but it doesn't work well I am not sure if the motors are causing the pic problems or its my code.
Please could someone have a look, I will post a schematic later
Thanks Don
;******************************************************************************
; *
; Filename: first_line_follower.asm *
; Date: 13-6-10 *
; File Version: 0.1v *
; *
; Author: don *
; Company: *
; *
; *
;******************************************************************************
; *
; Files required: P12F629.INC *
;******************************************************************************
;
; Vdd IIIII Vss
;Left Sensor GP5 I I GP0
;Right Sensor GP4 I I GP1 Left Motor
; GP3 IIIII GP2 Right Motor
;
;******************************************************************************
;------------------------------------------------------------------------------
; PROCESSOR DECLARATION
;------------------------------------------------------------------------------
LIST P=12F629 ; list directive to define processor
#INCLUDE <P12F629.INC> ; processor specific variable definitions
;------------------------------------------------------------------------------
;
; CONFIGURATION WORD SETUP
;
; The 'CONFIG' directive is used to embed the configuration word within the
; .asm file. The lables following the directive are located in the respective
; .inc file. See the data sheet for additional information on configuration
; word settings.
;
;------------------------------------------------------------------------------
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;------------------------------------------------------------------------------
; OSCCAL RESTORE (not required if internal OSC is not used)
;------------------------------------------------------------------------------
RESET_VECTOR CODE 0x0000 ; processor reset vector
errorlevel -302
BSF STATUS,RP0 ; set file register bank to 1
CALL 0x3FF ; retrieve factory calibration value
MOVWF OSCCAL ; update register with factory cal value
BCF STATUS,RP0 ; set file register bank to 0
; set up inputs and outputs
;****** Turn Off Comparator
movlw b'00000111' ; Turn off Comparator 0x07
movwf CMCON ; Turn off Comparator 0x07
BSF STATUS,RP0 ; SELECT BANK 1
MOVLW B'111001' ;GP5,GP4,GP3,GP0 INPUTS GP1,GP2 OUPUTS
MOVWF TRISIO
BCF STATUS,RP0 ;BANK0
clrf GPIO ; Clear GPIO
start
BTFSS GPIO,5 ; Test Left Sensor (skip if high)
BCF GPIO,2 ; Turn off Right Motor
BTFSC GPIO,5 ; Test Left Sensor (skip if low)
BSF GPIO,2 ; Turn on right motor
BTFSS GPIO,4 ; Test right sensor (skip if high)
BCF GPIO,1 ; Turn off left motor
BTFSC GPIO,4 ; Test right sensor (skip if low)
BSF GPIO,1 ; Turn on left motor
GOTO start
END ; directive 'end of program'