1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Line Follower, Help Needed Badly

Discussion in 'Robotics & Mechatronics' started by a2zmoviebuff, Oct 5, 2004.

  1. a2zmoviebuff

    a2zmoviebuff New Member

    Joined:
    Oct 5, 2004
    Messages:
    4
    Likes:
    0
    I have the checked out the following link

    http://www.kmitl.ac.th/~kswichit/LFrobot/LFrobot.htm

    These are the problems i am facing.

    1. This is a robot for following black line. I need my robot to follow a white line.
    2. we are very new to microcontrollers, and rom writing

    Hence when he says, "MY Code" and then there is a follow up in it. Could someone explain how this program works and how one can modify it to follow a white line on a black background.

    3. In the link given as robot_asm what does the initial paragraph mean.
    Help needed urgently.
     
  2. bmcculla

    bmcculla New Member

    Joined:
    Sep 5, 2003
    Messages:
    898
    Likes:
    0
    Location:
    California, USA
    The 4 sensors output a digital '1' when it sees white and a '0' when it sees black. You can modify the code to invert the input which will switch the black and white. You could also switch the inputs to the opamps to invert the sensor outputs.

    For rom writing you need to look at the website of the manufacturer of your microcontroler.
     
  3. a2zmoviebuff

    a2zmoviebuff New Member

    Joined:
    Oct 5, 2004
    Messages:
    4
    Likes:
    0
    thanks for the reply.
    could you just tell me where exactly, i mean which part of the code, you see this digital '1' or digital '0' coming out.

    It would be very helpful if you can just explain me the program under "My Code"

    "You could also switch the inputs to the opamps to invert the sensor outputs. "

    hope you have seen the circuit, but switching inputs just puts the sensor cutdown right.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey

    this was written for an 8051 .. it could probably be adapted to your processor..
    what controller are you using?


    Code (text):
    *#cpu 8051 Tiny
    *
    * DDS MICRO-C 8031/51 Startup Code & Runtime library for TINY model
    *
    * Copyright 1991-1999 Dave Dunfield
    * All rights reserved.
    *
            ORG    $0000         $0800  CODE Starts here (Normally in ROM)
            LJMP   START

            ORG    $0003
            LJMP   SERVICE_EX0

            ORG    $000B
            LJMP   SERVICE_TIMER0_INTERRUPT


    * Fixed memory locations for alternate access to the R0-R7 register bank.
    * If you are NOT useing BANK 0, these equates must be adjusted.
    ?R0 EQU 0       Used for "POP" from stack
    ?R1 EQU ?R0+1       Used to load index indirectly
    ?R2 EQU ?R0+2       ""      ""      ""      ""
    ?R3 EQU ?R0+3       Used by some runtime lib functions
    ?R4 EQU ?R0+4
    ?R5 EQU ?R0+5
    ?R6 EQU ?R0+6
    ?R7 EQU ?R0+7
    *
    * Startup code entry point
    *
    * If you are NOT using interrupts, you can reclaim 50 bytes
    * of code space by removing the following TWO lines.
    *        AJMP    *+$0032         Skip interrupt vectors
    *        DS      $0032-2         Reserve space for interrupt vectors
    *
    START   EQU     *
        MOV SP,#?stk-1  Set up initial stack
            ORL  TMOD,#%00000001    set timer 0 to be counter 16 bit
            SETB    IE.7            $AF  EA
            SETB    IE.1            $A9  ET0 Enable timer 0 interrupt
            SETB    TCON.4          start timer 0


        LCALL   main        Execute program
            SJMP    *               JUMP HERE

    * EXIT to MON51 by calling the 'timer1' interrupt vector ($001B).
    * This causes MON51 to think that a single-step operation has just
    * completed, and therefore it saves the user registers, and performs
    * a context switch back to the monitor.
    *
    * When using 2K addressing (CC51: -Z option, ASM51: -A option) this LCALL
    * may fail "Out of range" because it gets translated to ACALL, and $001B
    * may not be in the same 2K block as your program. Since 2K devices cannot
    * support a debugger, change the ORG to $0000, and ...<continue below>...
    *
    * If you are NOT using MON51 (or MONICA which works the same), you will
    * need to change this to whatever action you desire when main() returns.
    * Suggestions: 1:freeze (SJMP *) 2:Restart (SJMP *&$FF00)
    exit    LCALL   $001B       Call Timer-1 interrupt
        SJMP    exit        Incase he go's again

    **************************** My code *********************************

    SERVICE_TIMER0_INTERRUPT   EQU *
       PUSH ACC
       PUSH PSW
       MOV  TH0,#$FF      reload timer 0 for ms
       MOV  TL0,#$00
       INC  tick

       MOV  A,tick
       CJNE A,#100,RIGHT
       MOV  tick,#0

    RIGHT
       CLR  C
       SUBB A,speedright
       JC   ON_RIGHT
       CLR  P1.0
       SJMP LEFT

    ON_RIGHT
       SETB P1.0

    LEFT
       MOV  A,tick
       CLR  C
       SUBB A,speedleft
       JC   ON_LEFT
       CLR  P1.1
       SJMP EXIT_I

    ON_LEFT
       SETB P1.1

    EXIT_I
       POP  PSW
       POP  ACC
       RETI

    SERVICE_EX0 EQU *
       INC  cputick
       RETI


    $SE:1
    *#map1 Segment 1, initialized variables
    $SE:2
    *#map2 Segment 2, internal "register" variables
        ORG $0008       Internal ram ALWAYS starts here

    tick         DS  1
    speedright   DS  1
    speedleft    DS  1  
    cputick      DS  1

     
     
  6. aquinn_21

    aquinn_21 New Member

    Joined:
    Aug 19, 2004
    Messages:
    1
    Likes:
    0
    Location:
    India
    yes i am using 8051 micorprocessor only and hte controller is the same mentioned in hte website.

    could you make us understand in plain terms what the program is doing.

    Like for example

    PUSH ACC
    PUSH PSW
    MOV TH0,#$FF reload timer 0 for ms
    MOV TL0,#$00
    INC tick

    MOV A,tick
    CJNE A,#100,RIGHT
    MOV tick,#0

    What is happening once the programme starts from the first statement. With that we will know where exactly one can modify the code and get the desired output. As you say it is only the alteration of logic '0' and logic '1' that is to be done.



    Secondly, when you say "You could also switch the inputs to the opamps to invert the sensor outputs. "

    do you mean to say that this is another alternative, the first being altering the code. The latter one requires the hex code to be altered, could you tell me where i should be doing that.

    Thanks for the reply.
     
  7. a2zmoviebuff

    a2zmoviebuff New Member

    Joined:
    Oct 5, 2004
    Messages:
    4
    Likes:
    0
    an altered progrom for the 'my code' thereby making it follow the white line would be most welcome
     
  8. williB

    williB New Member

    Joined:
    Aug 30, 2004
    Messages:
    2,217
    Likes:
    3
    Location:
    New Jersey
    i have a question..
    what assembler are you using ?
     
  9. jrz126

    jrz126 Active Member

    Joined:
    Sep 17, 2004
    Messages:
    1,189
    Likes:
    5
    Location:
    Erie, PA - USA
    You would modify the hardware (the circuit) instead of the code.
    You would swap the + and - (inputs) on the op amps. so for sensor one, instead of the + (pin 3) being connected to the 20k pot, it would be connected to the photo transistor (where pin 2 of the op amp is connected) and pin 2 would go to the 20k pot.
    you should be able to use the code as-is then...
     
  10. bmcculla

    bmcculla New Member

    Joined:
    Sep 5, 2003
    Messages:
    898
    Likes:
    0
    Location:
    California, USA
    You can change the code without too much trouble

    replace :
    sensors = (P3 &=0x0f);
    with :
    sensors = ((~P3) & 0x0f);


    All this does is take the bits in from the sensor and change all the ones to zeros and and zeros to ones. The ~ is the bitwise NOT operation.
     

Share This Page