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

Discussion in 'Embedded Systems and Microcontrollers' started by goldfish300, May 10, 2009.

  1. goldfish300

    Thread Starter Member

    Mar 12, 2009
    12
    0
    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


    Code ( (Unknown Language)):
    1. ;LINE FFOLLOWER ROBOT USING PIC16F628,L298
    2. #INCLUDE    "P16F628A.INC"
    3.  
    4. #DEFINE     PB_FORWARD      PORTA, 0
    5. #DEFINE     PB_STOP         PORTA, 1
    6. #DEFINE     ENABLE          PORTA, 2
    7. #DEFINE             LS_RIGHT                PORTA, 3
    8. #DEFINE             LS_LEFT         PORTA, 4
    9.  
    10. ;outputs
    11. #DEFINE     M1L1            PORTB, 1
    12. #DEFINE     M1L2            PORTB, 2
    13. #DEFINE     M2L1            PORTB, 3
    14. #DEFINE     M2L2            PORTB, 4
    15. #DEFINE     START       PORTB, 0
    16.  
    17.  
    18.     CBLOCK  0X20
    19.     A1, A2, A3
    20.     ENDC
    21.  
    22.     ORG     0X000
    23.     GOTO    MAIN
    24.  
    25. MAIN
    26.     CALL    SETUP
    27.     CALL    MAIN_START
    28.                    
    29. REPEAT
    30.     BTFSC   PB_FORWARD
    31.     CALL            GO_FORWARD
    32.     BTFSC   PB_STOP
    33.     CALL            STOP   
    34.     BTFSC   LS_LEFT
    35.     CALL            SENSOR_LEFT
    36.     BTFSC   LS_RIGHT
    37.     CALL            SENSOR_RIGHT
    38.     GOTO            REPEAT
    39.  
    40. GO_FORWARD
    41.     BCF     M1L1
    42.     BSF     M1L2
    43.     BCF     M2L1
    44.     BSF     M2L2
    45.     RETURN
    46.  
    47. STOP
    48.     BCF     M1L1
    49.     BCF     M1L2
    50.     BCF     M2L1
    51.     BCF     M2L2
    52.     RETURN
    53.  
    54. MAIN_START
    55.     BTFSC   ENABLE
    56.     BSF     START
    57.     CALL            DELAY_10MS
    58.     BCF     START
    59.     RETURN
    60.  
    61.  
    62. SENSOR_RIGHT       
    63.     BSF     M1L1
    64.     BCF     M1L2
    65.     BSF     M2L1
    66.     BCF     M2L2
    67.     BTFSS   LS_RIGHT
    68.     GOTO    $+3
    69.     CALL            DELAY_10MS
    70.     GOTO        $-3
    71.     CALL            GO_FORWARD     
    72.     RETURN
    73.  
    74. SENSOR_LEFT
    75.     BCF     M1L1
    76.     BSF     M1L2
    77.     BCF     M2L1
    78.     BSF     M2L2
    79.     BTFSS   LS_LEFT
    80.     GOTO            $+3
    81.     CALL            DELAY_10MS
    82.     GOTO         $-3
    83.     CALL            GO_FORWARD
    84.     RETURN
    85.  
    86.  
    87. DELAY_10MS
    88.     MOVLW       D'5'
    89.     MOVWF       A1
    90.     MOVLW       D'108'
    91.     MOVWF       A2
    92.     MOVLW       D'5'
    93.     MOVWF       A3
    94.     DECFSZ      A3
    95.     GOTO                $-1
    96.     DECFSZ      A2
    97.     GOTO                $-5
    98.     DECFSZ      A1
    99.     GOTO                $-9
    100.     RETURN
    101.  
    102. DELAY_1S
    103.     MOVLW       D'46'
    104.     MOVWF       A1
    105.     MOVLW       D'189'
    106.     MOVWF       A2
    107.     MOVLW       D'37'  
    108.     MOVWF       A3
    109.     DECFSZ      A3
    110.     DECFSZ      A2
    111.     GOTO                 $-5
    112.     DECFSZ      A1
    113.     GOTO                $-9
    114.     RETURN
    115.  
    116. SETUP
    117.    
    118.     CLRF             PORTA
    119.     CLRF             PORTB
    120.     BSF     STATUS, RP0
    121.     CLRF             TRISB
    122.     MOVLW   B'00011111'
    123.     MOVWF   TRISA
    124.     BCF     STATUS, RP0
    125.     MOVLW   B'00000111'
    126.     MOVWF   CMCON
    127.     RETURN
    128.  
    129. END
    130.  
    the PIC:
    [​IMG]
     
  2. steinar96

    Active Member

    Apr 18, 2009
    239
    4
    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.
     
  3. goldfish300

    Thread Starter Member

    Mar 12, 2009
    12
    0
    10x for that
    but do u have any idea on fixing the led at start up not turning on ??
     
  4. steinar96

    Active Member

    Apr 18, 2009
    239
    4
    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.
     
Loading...