centralized control elevator

37
Centralized control elevator Multiple elevators controlled using single control Kavi Pandya 131020 Parth Patel 131033 Urvika Sonar 131060 19-Apr-15

Upload: pandyakavi

Post on 06-Nov-2015

27 views

Category:

Documents


0 download

DESCRIPTION

The idea is to have a centralized control for 2 elevators where in one can give the call direction of the interest (up or down) and the call would then be transferred to the elevators based on their proximity with respect to the call position while stationary or with respect to the travel direction or based on the wear and tear if the elevators are equidistant from the call position. Here the count of the elevators is taken in to consideration; one having lower count is given the priority, for the cases where both the elevators traveled equal distance the priority is given to the elevator 1.

TRANSCRIPT

  • Centralized control elevator

    Multiple elevators controlled using single control Kavi Pandya 131020 Parth Patel 131033

    Urvika Sonar 131060

    19-Apr-15

  • 1 Centralized Control Elevator

    Table of Contents 1. Project Idea and Application

    2. Introduction

    3. Detailed Description

    4. Schematic Diagram

    5. Bill Of materials

    6. Flowchart of firmware

    7. Photos

    8. Learning, failures and outcomes

    9. C Code

  • 2 Centralized Control Elevator

    1. Project Idea and Application

    The centralized control elevators revolve around the needs of cutting down power

    usage in commercial complexes and optimizing their usage of elevators. In

    commercials, where there are multiple elevators to cater the needs of the users, we

    have always observed that different people use different elevators to reach the

    same destination, so our main objective is to optimize this usage pattern. The

    centralized control elevators aim at reducing the power consumption as well as the

    wear and tear of the elevators. Power utility is one of the burning issues of todays

    urbanization, so it is of tremendous importance that the power utility in industrial

    and commercial sector is cut down so that we can use and supply power to the

    villages where even today there is no electricity. The centralized control elevators

    have wide applications from the shopping centers to hospitals, corporate offices,

    multi storied towers, etc. where there is a requirement for multiple elevators.

    Initially, the project was supposed to have centralized control for 4 elevators. 4 elevators

    means requirement of 4 motors. Thus, the input requirement for 4 elevators and 4 motor

    was neck to neck with the pin capacity of Atmega32. As there will be 16 internal buttons (4

    for each lift), 6 external call buttons, 8 inputs for motor (2 for each motor). Overall resulting

    in 30 input requirement whereas Atmega32 has 32 pins. As inputs were nearly equal to pin

    capacity therefore it would have been difficult if we wanted to incorporate any interface in

    future. Thus, we scaled down to 3 elevator system. As we began to develop code we found

    that we would not be able to complete code for 3 elevator system within time frame.

    Hence, we finally settled to 2 elevator system and developed our project on it.

    The idea is to have a centralized control for 2 elevators where in one can give the

    call direction of the interest (up or down) and the call would then be transferred to

    the elevators based on their proximity with respect to the call position while

    stationary or with respect to the travel direction or based on the wear and tear if the

    elevators are equidistant from the call position. Here the count of the elevators is

    taken in to consideration; one having lower count is given the priority, for the cases

    where both the elevators travelled equal distance the priority is given to the

    elevator 1.

  • 3 Centralized Control Elevator

    2. Introduction

    In the existing elevator control-system, most of the cases there is a dedicated

    control for each elevator. That is, if a given building has 2-elevators then there will

    be two-controls (one control for one lift) on each floor.

    This system is unable to handle two problems effectively.

    1. Calling multiple lift on a given floor: Many a times we call number of lifts on a given floor with a tendency/aim of going into the lift that comes first. This results in power wastage as multiple lifts have been sent request to attend just one external call. Thus, there is in inefficiency in handling such external calls where multiple lifts are called.

    2. Maintenance of lift: When there are multiple lifts then, it is very crucial to take care that there is not much load on just one specific lift. As such conditions would decrease the efficiency of such lift and increments the maintenance cost incurred.

    Taking into consideration the above mentioned points, the system developed by us contain hardware as well as software/logical modification as compared to the existing elevator system.

    Centralized Control Elevator System: Centralized Control Elevator System works on the concept of having one dedicated control for the lifts on a given floor. That is, if a given building has 2-elevators then there will be one dedicated control on each floor for both the lifts. This concept is applicable to n-elevator system. Thus, the model we created has 4-floors, 2-elevator system and the button arrangement on each floor is as described: Ground [1-up button], First [1-up button, 1-down button], Second [1-up button, 1-down button], Third [1-down button].

    Concept/Logic incorporated: In the system there is only one centralized control on every floor and all the lifts are

    governed by only that central control. Thus, whenever a user presses external

    button/request then the request is processed and checked that which lift is nearest

    to the user. If we find only one lift that is nearest to the user then we send that

    particular lift to fulfill user request. But, if there are multiple lift that are equidistant

    from the request floor and stand an equal chance of fulfilling the request then we

    find for the lift that has travelled the least distance till this instant and then we send

    the least distance travelled lift to fulfill users request.

  • 4 Centralized Control Elevator

    Thus the significant points of Centralized control logic are that by sending the least

    distance travelled lift to fulfill users request we are equalizing the load on all the

    lifts and thus reducing maintenance cost after only a specific lift. Also, lift being

    governed by only one control completely eliminates the chances of calling multiple

    lift on a given floor for a single external request. Thus, power saving is accomplished.

  • 5 Centralized Control Elevator

    3. Detailed Description

    Keywords:

    External calls the calls placed from the request floors, the buttons outside the

    elevator

    Internal Calls the destination calls placed from inside the elevator

    Transition state Stationary or Moving condition of the elevator

    Transition Direction Up or down movement of the elevator

    Call Direction the direction of the call (i.e. the aprior information regarding the

    internal calls given by the user)

    Call Position the position/floor from which the call is placed

    Final Position the final floor where the elevator has to reach attending various

    intermediate calls

    Count Number of floors travelled by the elevators

    Idea:

    As described earlier, the elevator closest to the call position would be sent for

    attending the call. If both the elevators are in transition position, one having the

    transition direction similar to the call direction would be sent to attend the call. The

    elevators moving in opposite direction, if have their final position same as the call

    position, attends the call based on the time required to approach as compared to

    the other elevator. Also, the number of floors travelled would be taken into account

    for distributing the calls to reduce wear and tear, also for equal travel, the by default

    priority is given to elevator 1.

    Algorithm:

    The calls are processed based on the transition state of the elevators, if the

    elevators are at rest the case becomes simple, we can easily associate the calls. The

    calls for the elevators in transition needs to be processed in an ascending or

    descending order based on the transition direction of the elevators. The project

    started with very basic understanding about the call attending patterns of a single

    elevator, followed by discussions regarding the algorithms for it. The later part

    involved the discussions about the worst case and best case scenarios.

    The algorithms in implementation were possible only for the cases when both the

    lifts are stationary and not when even one of the lifts is moving. This was due to the

    hardware, firmware and logical limitations. The later part was to generalize the code

  • 6 Centralized Control Elevator

    for the various cases. The current position of the elevators is 0 initially. Later on,

    based on the request of calls, when the elevator stops the next request should be

    placed because, it is only for the stationary and so no calls placed while transition of

    the elevators can be processed. Now only when, external calls are placed, do we get

    an opportunity to place internal calls. The internal calls should be given in within 5

    seconds after the elevator stops at any position. This part is the logical

    interpretation of the fact that the doors of the elevators are open only for few

    seconds, thus, it requires pressing the same button on the elevators current

    position, if the call position is same as the users position for the logical

    interpretation of opening the doors for the entry of the users. Moreover, the

    elevator can process multiple internal calls given at a time. The internal calls are

    placed into an array where in the calls are processed based on the elevators for

    which they are placed. The control is then transferred to the movement of the

    motor, where the motor direction of the movement are decided and also the time

    for which it should keep on rotating. The motors are stopped after the particular

    time. Since, the project involves the idea of time based floor keeping, which means

    that the elevator current position, final position are determined by determining

    time. After each transition the current position, moving state, transition direction,

    and count of the elevator are updated. The project is not yet capable of handling

    external calls and internal calls in transition.

    Model:

    The model is made up of plywood. It consists of travelling slots for 2 elevators for 4

    floors. The floors are marked as 0,1,2,3.

    Hardware:

    The centralized control elevators for demonstration are built up using AT mega 32,

    motor drivers, 12 volt DC motors, the hardware constitutes of the project are

    minimal. The motors are given 7 V power supply.

  • 7 Centralized Control Elevator

    4. Schematic Diagram

    Title

    Size Document Number Rev

    Date: Sheet of

    Centralized Control Elev ator

    B

    1 1Monday , April 20, 2015

    S7SW_PB_SPST

    J26

    POWER SUPPLY

    12

    7V

    VCC_ARROW

    S8SW_PB_SPST

    S9SW_PB_SPST

    S10SW_PB_SPST

    S11SW_PB_SPST

    S12 SW_PB_SPST

    C2

    22p

    S1

    SW_PB_SPST+ C31u

    R14k7

    S13 SW_PB_SPST

    J22

    CON2

    12

    J23

    CON2

    12

    S14 SW_PB_SPST

    U2

    78XX/SIP

    VIN1

    VOUT3

    GN

    D2

    + C4470u

    J3

    CONN JACK PWR

    321

    C5

    100n

    R2

    330R D3

    LED

    D2

    DIODE

    SW1

    TOGGLE PWR

    IC1

    ATMega32-DIP40

    PB0/(XCK/T0)1

    PB1/(T1)2

    PB2/(INT2/AIN0)3

    PB3/(OC0/AIN1)4

    PB4/(SS)5

    PB5/(MOSI)67

    PB6/(MISO)8PB7/(SCK)

    RE

    SE

    T9

    XTAL212

    XTAL113

    PA6/(ADC6)34

    PA2/(ADC2)37

    PC0/(SCL)22

    PC1/(SDA)23

    PC2/(TCK)24

    PC3/(TMS)25

    PC4/(TDO)26

    PC5/(TDI)27

    PC6/(TOSC1)28

    PC7/(TOSC2)29

    AVCC30AREF32

    PD0/(RXD)14

    PD1/(TXD)15

    PD2/(INT0)16

    PD3/(INT1)17

    PD4/(OC1B)18

    PD5/(OC1A)19

    PD6/(ICP)20

    PD7/(OC2)21

    PA0/(ADC0)40

    PA1/(ADC1)39

    PA7/(ADC7)33

    PA3/(ADC3)38

    PA4/(ADC4)36

    PA5/(ADC5)35

    L1

    10uH

    C7100n

    S15 SW_PB_SPST

    S16 SW_PB_SPST

    S17 SW_PB_SPST

    Y1

    CRYSTAL

    S18 SW_PB_SPST

    C1

    22p

    S19 SW_PB_SPST

    U3

    L293D

    IN12

    IN27

    IN310

    IN415

    EN11

    EN29

    OUT13

    OUT26

    OUT311

    OUT414

    VSS16

    VS8

    J24

    DC MOTOR 1

    12

    J25

    DC MOTOR 2

    12

    S6SW_PB_SPST

  • 8 Centralized Control Elevator

    5. Bill of Materials

    Item Quantity Price Wooden Frame 1 1300

    Spray(Silver) 3 625

    At mega 32 1 500 Wires + Nut Bolts + Nails - 200

    Feviquick + Fevicol + Sellotape + Marker

    - 130

    Total - 2755

  • 9 Centralized Control Elevator

    6. Flowchart of firmware

  • 10 Centralized Control Elevator

    7. Photos

  • 11 Centralized Control Elevator

    8. Learning, failures and outcomes

    Learning:

    Interfacing of motor driver with motors and port of ATmega32.

    Understanding power requirement of motors and diverting power respectively.

    Basic wooden framing and soldering

    Difficulties in logical part regarding the declaration of global variables

    While the project was about to finish, we faced a severe problem regarding the microcontroller, the PORTC pins were short and we could not figure it out, so its good to keep a check on hardware regularly.

    Outcomes: All the calls external as well as internal are successfully being executed for the

    stationary state of lift.

    Successful application and implementation of logic of sending the nearest and the least travelled lift to attend external calls.

    The goal of centralized control logic of controlling two elevators using single dedicated controls can be shown successfully.

    Failure:

    The biggest drawback on our part regarding the project was the inability to

    generalize the code for transition of elevators, i.e. placing external calls while

    the elevator is moving. There are various approaches through which we have

    tried to resolve this problem. The outcomes and learning here are described

    for the case

    Outcomes: We decided to take an array of 30 elements, based on the

    movement of the lift, ascending or descending it was evenly distributed in

    terms of 10 elements for each floor, every 10th element displayed the

    position of the elevator based on the floors. Initially the array had all its

    values equal to zero and based on the divisions when that position is crossed

    we get a value 1 in that element.

    Drawback: Updating of such an array is a very tedious task alongside

    managing the functions and updating of positions and directions of the

    elevator based on the array. Also, the same array is to be used for placing the

    calls in ascending or descending order. Also, alongside the use of array, if the

    increment of array is placed in while loop the loop executes and each time it

    updates, it sends feedback to the timer, but now within while loop we have

    while loops, like one for polling, and then for motor selection and also for the

  • 12 Centralized Control Elevator

    timer to reach a certain count before the motor stops, even when one of

    them is executing, the other one stops and hence there were issues like we

    are not able to receive and process the calls while one of the elevators is

    moving

    Learning: Working on code where in there is only one loop and the rest

    functionalities are called using functions.

    Outcomes: We worked on one such part where we tried to generalize and

    assemble the code based on functions

    Failures: The functions written execute themselves only once for the given

    condition, so we cannot use it where there is continuous looping also, it

    might happen in that case that only for certain time after feedback we can

    give calls and it can be processed.

    Learning: As above, functions cannot be used for the continuous loops and so

    we cannot use that, now we need to add something that would run

    continuously and also that it would not obstruct the normal execution of

    placing and processing calls.

    Outcomes: This one included the inclusion of the motor stop logic in the

    timer compare function itself; this gave us the ease of parallel processing the

    calls. Here we take each call and add it in descending or ascending order as

    required. Now, based on the elements in the array, those are the floors

    where the lift needs to stop and attend the calls and also the calls are

    attended based on the direction of movement of the elevator. But, we could

    not test the code due to time constraints and some last minute failures.

  • 13 Centralized Control Elevator

    9. C Code

    /*

    Centralized Control Elevator

    131020 - Kavi Pandya

    131033 - Parth Patel

    131060 - Urvika Sonar

    */

    /*

    Connections TO Driver:

    1A -> PORTA.A0

    1B -> PORTA.A1

    2A -> PORTA.A4

    2B -> PORTA.A5

    Connection of other Ports:

    PORTB.B0 to PORTB.B5 = external Buttons Of Lift

    PORTC.C0 to PORTC.C3 = internal call of lift1

    PORTD.D4 to PORTD.D7 = internal call of lift2

    */

    #define floors 4

    typedef struct //declaration of lift1 and lift2 internal call pin

    {

    char internal_calls[floors];

    }

    elevator;

    typedef elevator *elevator_t;

    elevator_t elevator_1,elevator_2;

    int destination1[4]; //destination array of lift1

    int destination2[4]; //destination array of lift2

  • 14 Centralized Control Elevator

    int position1=0; //current position of lift1

    int position2=0; //current position of lift2

    //for timer increment

    int count1=0;

    int count2=0;

    int count3=0;

    int count4=0;

    //variable

    int i=0;

    //for up , down direction of lift1 and lift2

    int flag_1=0;

    int flag_2=0;

    //for timer on

    int flag1=0;

    int flag2=0;

    //array of external button

    char external_button[6];

    //define active1 and active 2 for external call position

    int active1=-1;

    int active2=-1;

    //travel times of lift1 and lift2

    int travel_times1=0;

    int travel_times2=0;

    //rotate motor for internal call

    void motor(int position,int internal,int motor_se)

    {

    if(motor_se==1) //motor select is 1

    {

    if(position>internal) //if position>internal motor in reverse mode

    {

    TCCR0=0x0B; //define TCCR2 : 0 0 0 1 0 1 1 , pre-scalar is 64 , CTC mode

    flag1=2; //flag1 is 2 for timer0

    //reverse

    PORTA.B0=0;

    PORTA.B1=1;

    while(count2!=(position-internal)*8000); //wait till reach the internal

    call's postion

  • 15 Centralized Control Elevator

    if(count2==((position-internal)*8000)) //when it reach to call position

    motor stop

    {

    count2=0; //timer0 reset to 0

    flag1=0; //flag1 is 0

    TCCR0=0; //TCCR0 is 0

    //motor stop

    PORTA.B0=0;

    PORTA.B1=0;

    }

    }

    if(position

  • 16 Centralized Control Elevator

    flag2=2; //flag2 is 2 for timer2

    //reverse

    PORTA.B4=0;

    PORTA.B5=1;

    while(count4!=(position-internal)*8300); //wait till reach the internal

    call's postion

    if(count4==((position-internal)*8300)) //when it reach to call position

    motor stop

    {

    count4=0; //timer2 reset to 0

    flag2=0; //flag2 is 0

    TCCR2=0; //TCCR2 is 0

    //motor stop

    PORTA.B4=0;

    PORTA.B5=0;

    }

    }

    if(position

  • 17 Centralized Control Elevator

    }

    }

    //add internal call

    void add(int call_pos,int motor_se)

    {

    int za;

    if(motor_se==1) //motor selcect is 1

    {

    for(za=0;za

  • 18 Centralized Control Elevator

    //assign the value of looper1

    if(destination1[0]==-1)

    {

    looper1=0;

    }

    else if (destination1[1]==-1)

    {

    looper1=1;

    }

    else if (destination1[2]==-1)

    {

    looper1=2;

    }

    else if(destination1[3]==-1)

    {

    looper1=3;

    }

    //assign the value of looper2

    if(destination2[0]==-1)

    {

    looper2=0;

    }

    else if (destination2[1]==-1)

    {

    looper2=1;

    }

    else if (destination2[2]==-1)

    {

    looper2=2;

    }

    else if(destination2[3]==-1)

    {

    looper2=3;

    }

    if(motor_se==1)

  • 19 Centralized Control Elevator

    {

    if(active1 == 1|| active1==3|| active1==5) //if external call is 1 down,2 down

    or 3

    {

    //sort in descending order

    for (a = 0; a < 4; a++)

    {

    for (b = a + 1; b < 4; b++)

    {

    if (destination1[a] < destination1[b])

    {

    temp = destination1[a];

    destination1[a] = destination1[b];

    destination1[b] = temp;

    }

    }

    }

    }

    if(active1==0|| active1==2|| active1==4) //if external call is 0,1 up or 2 up

    {

    //sort in ascending order

    for (a = 0; a < looper1; a++)

    {

    for (b = a + 1; b < looper1; b++)

    {

    if (destination1[a] > destination1[b])

    {

    temp = destination1[a];

    destination1[a] = destination1[b];

    destination1[b] = temp;

    }

    }

    }

    }

    //rotate motor1 till looper

    for(c=0;c

  • 20 Centralized Control Elevator

    if(position1>destination1[c]) //update travel time of lift1

    {

    travel_times1 = travel_times1 + (position1 - destination1[c]);

    }

    if(position1

  • 21 Centralized Control Elevator

    {

    if (destination2[a] > destination2[b])

    {

    temp = destination2[a];

    destination2[a] = destination2[b];

    destination2[b] = temp;

    }

    }

    }

    }

    //rotate motor1 till looper

    for(c=0;cdestination2[c]) //update travel time of lift2

    {

    travel_times2 = travel_times2 + (position2 - destination2[c]);

    }

    if(position2

  • 22 Centralized Control Elevator

    delay_ms(5000); //wait for 5 second

    //add internal call of lift1

    if(motor_se==1)

    {

    if(PINC.B0==0) //floor 0 is add

    {

    add(0,motor_se);

    }

    if(PINC.B1==0) //floor 1 is add

    {

    add(1,motor_se);

    }

    if(PINC.B2==0) //floor 2 is add

    {

    add(2,motor_se);

    }

    if(PINC.B3==0) //floor 3 is add

    {

    add(3,motor_se);

    }

    }

    //add internal call of lift2

    if(motor_se==2)

    {

    if(PIND.B4==0) //floor 0 is add

    {

    add(0,motor_se);

    }

    if(PIND.B5==0) //floor 1 is add

    {

    add(1,motor_se);

    }if(PIND.B6==0) //floor 2 is add

    {

    add(2,motor_se);

    }

    if(PIND.B7==0) //floor 3 is add

    {

    add(3,motor_se);

  • 23 Centralized Control Elevator

    }

    }

    ic_rotatemotor(motor_se); //rotate motor for internal call

    }

    // TIMER0_COMPARE MATCH

    void TIMER0_COMP() org 0x014

    {

    if(flag1==1) // timer0 increment of motor 1 forward or up direction

    {

    count1++; //count1 is increment

    }

    if(flag1==2) // timer0 increment of motor 1 reverse for down direction

    {

    count2++; //count2 is increment

    }

    }

    // TIMER0_COMPARE MATCH

    void TIMER2_COMP() org 0x008

    {

    if(flag2==1) // timer1 increment of motor 2 forward or up direction

    {

    count3++; //count3 is increment

    }

    if(flag2==2) // timer1 increment of motor 2 reverse for down direction

    {

    count4++; //count4 is increment

    }

    }

    //calculate the distance of call position and lift's

    int distance(int pos,int call_position)

    {

    int dist=0;//

    dist=call_position-pos; //calculate dist

    return dist;

    }

  • 24 Centralized Control Elevator

    void initialize(void)

    {

    //PORTA Set-Up

    DDRA=0X33; //set PORTA.B0,PORTA.B1,PORTA.B4,PORTA.B5 as O/P

    PORTA=0XCC; // Initialize PORTA.B0,PORTA.B1,PORTA.B4,PORTA.B5 to 1

    //PORTB Set-Up

    DDRB=0X00; //set as o/p

    PORTB=0XFF; //set all to 1

    //PORTC Set-Up

    DDRC=0x00; //set as o/p

    PORTC=0xFF; //set all to 1

    //PORTD Set-Up

    DDRD = 0X00; //set as o/p

    PORTD = 0XFF; //set all to 1

    OCR0=0x7D; //value is 125

    OCR2=0x7D; //value is 125

    SREG.B7=1; // Enable Global interrupt

    TIMSK.B1=1; //OCIE0 Enable

    TIMSK.B7=1; //OCIE2 Enable

    elevator_1 = (elevator_t)malloc(sizeof(Elevator));

    elevator_2 = (elevator_t)malloc(sizeof(Elevator));

    //Assign the value

    for(i = 0; iinternal_calls[i] = 0;

    destination1[i]=-1;

    elevator_2->internal_calls[i] = 0;

    destination2[i]=-1;

  • 25 Centralized Control Elevator

    }

    //assign the PINC.B0 to B4 for first lift's internal call

    elevator_1->internal_calls[0]=PINC.B0;

    elevator_1->internal_calls[1]=PINC.B1;

    elevator_1->internal_calls[2]=PINC.B2;

    elevator_1->internal_calls[3]=PINC.B3;

    //assign the PIND.B4 to B7 for first lift's internal call

    elevator_2->internal_calls[0]=PIND.B4;

    elevator_2->internal_calls[1]=PIND.B5;

    elevator_2->internal_calls[2]=PIND.B6;

    elevator_2->internal_calls[3]=PIND.B7;

    for(i = 0; i

  • 26 Centralized Control Elevator

    TCCR0=0; //TCCR0 is 0

    //motor-stop

    PORTA.B0=0;

    PORTA.B1=0;

    add_internal_call(motor_se); //add internal call of motor1

    }

    }

    //if motor 1 is selected and it's going down

    if(motor_se==1 && flag_1==2)

    {

    TCCR0=0x0B; //define TCCR0 : 0 0 0 1 0 1 1 , pre-scalar is 64 , CTC mode

    flag1=2; //flag1 is 2 for timer0

    //reverse

    PORTA.B0=0;

    PORTA.B1=1;

    while(count2!=time_distance*8000); //wait till reach the external call's

    postion

    if(count2==(time_distance*8000)) //when it reach to call position motor

    stop

    { //wait till i become 2000

    count2=0; //timer0 reset to 0

    flag1=0; //flag1 is 0

    TCCR0=0; //TCCR0 is 0

    //motor-stop

    PORTA.B0=0;

    PORTA.B1=0;

    add_internal_call(motor_se); //add internal call of motor1

    }

    }

    //if motor 2 is selected and it's going up

    if(motor_se==2 && flag_2==1)

    {

    TCCR2=0x0C; //define TCCR2 : 0 0 0 1 1 0 0 , pre-scalar is 64 , CTC mode

    flag2=1; //flag2 is 1 for timer2

    //Forward

    PORTA.B4=1;

    PORTA.B5=0;

  • 27 Centralized Control Elevator

    while(count3!=time_distance*10000); //wait till reach the external call's

    postion

    if(count3==(time_distance*10000)) //when it reach to call position motor

    stop

    {

    count3=0; //timer2 reset to 0

    flag2=0; //flag2 is 0

    TCCR2=0; //TCCR2 is 0

    //motor-stop

    PORTA.B4=0;

    PORTA.B5=0;

    add_internal_call(motor_se); //add internal call of motor2

    }

    }

    //if motor 2 is selected and it's going down

    if(motor_se==2 && flag_2==2)

    {

    TCCR2=0x0C; //define TCCR2 : 0 0 0 1 1 0 0 , pre-scalar is 64 , CTC mode

    flag2=2; //flag2 is 2 for timer2

    //reverse

    PORTA.B4=0;

    PORTA.B5=1;

    while(count4!=time_distance*8300); //wait till reach the external call's

    postion

    if(count4==(time_distance*8300)) //when it reach to call position motor

    stop

    {

    count4=0; //timer2 reset to 0

    flag2=0; //flag1 is 0

    TCCR2=0; //TCCR2 is 0

    //motor-stop

    PORTA.B4=0;

    PORTA.B5=0;

    add_internal_call(motor_se); //add internal call of motor2

    }

    }

  • 28 Centralized Control Elevator

    }

    void main()

    {

    int motor_select=0; //select motor 1 or 2

    int dist1=0; //distance of lift1's current position from its call position

    int dist2=0; //distance of lift1's current position from its call position

    int dist_count=0; //for calculate count

    initialize(void); //intialization

    while(1)

    {

    //check which external button is pressed

    //Floor 0 up button

    if(PINB.B0==0) //PINB.B0 IS pull down

    {

    while(PINB.B0==0);

    active1=0; //assign that external call is 0

    external_button[0]=1; //set as 1

    dist1=distance(position1,0); //calculate distance of lift1 from its current

    position

    dist2=distance(position2,0); //calculate distance of lift2 from its current

    position

    if(dist1 dist2 then send lift 2 because it's near

    {

    motor_select=2; //select motor2

    dist_count=dist2; //set dist_count as dist2

    travel_times2=travel_times2+dist_count; //update motor2's count

    add(0,motor_select); //add floor 0 in destination array of lift2

    position2=0; //update position2 to 0

    }

  • 29 Centralized Control Elevator

    if(dist1travel_times2) //if travel_times1 > travel_times2 then

    send lift 2 because it less travel

    {

    motor_select=2; //select motor2

    dist_count=dist2; //set dist_count as dist2

    travel_times2=travel_times2+dist_count; //update motor2's count

    add(0,motor_select); //add floor 0 in destination array of lift2

    position2=0; //update position2 to 0

    }

    else

    {

    motor_select=1; //select motor1

    dist_count=dist1; //set dist_count as dist1

    travel_times1=travel_times1+dist_count; //update motor1's count

    add(0,motor_select); //add floor 0 in destination array of lift1

    position1=0; //update position1 to 0

    }

    }

    rotate_motor(motor_select,dist_count);//decide which motor rotate and

    how many times

    }

    //Floor 1 down button

    if(PINB.B1==0) //PINB.B1 IS pull down

    {

    while(PINB.B1==0);

    active1=1; //assign that external call is 1 down

  • 30 Centralized Control Elevator

    external_button[1]=1; //set as 1

    dist1=distance(position1,1);

    dist2=distance(position2,1);

    if(dist1

  • 31 Centralized Control Elevator

    add(1,motor_select); //add floor 1 in destination array of lift1

    position1=1; //update position1 to 1

    }

    }

    rotate_motor(motor_select,dist_count);

    }

    //Floor 1 up button

    if(PINB.B2==0) //PINB.B2 IS pull down

    {

    while(PINB.B2==0);

    active1=2; //assign that external call is 1 up

    external_button[2]=1; //set as 1

    dist1=distance(position1,1);

    dist2=distance(position2,1);

    if(dist1

  • 32 Centralized Control Elevator

    motor_select=2;

    dist_count=dist2;

    travel_times2=travel_times2+dist_count;

    add(1,motor_select); //add floor 1 in destination array of lift2

    position2=1; //update position2 to 1

    }

    else

    {

    motor_select=1;

    dist_count=dist1;

    travel_times1=travel_times1+dist_count;

    add(1,motor_select); //add floor 1 in destination array of lift1

    position1=1; //update position1 to 1

    }

    }

    rotate_motor(motor_select,dist_count);

    }

    //Floor 2 down button

    if(PINB.B3==0) //PINB.B3 IS pull down

    {

    while(PINB.B3==0);

    active1=3; //assign that external call is 2 down

    external_button[3]=1; //set as 1

    dist1=distance(position1,2);

    dist2=distance(position2,2);

    if(dist1

  • 33 Centralized Control Elevator

    {

    motor_select=1;

    dist_count=dist1;

    travel_times1=travel_times1+dist_count;

    add(2,motor_select); //add floor 2 in destination array of lift1

    position1=2; //update position1 to 2

    }

    if(dist1==dist2)

    {

    if(travel_times1>travel_times2)

    {

    motor_select=2;

    dist_count=dist2;

    travel_times2=travel_times2+dist_count;

    add(2,motor_select); //add floor 2 in destination array of lift2

    position2=2; //update position2 to 2

    }

    else

    {

    motor_select=1;

    dist_count=dist1;//2

    travel_times1=travel_times1+dist_count;

    add(2,motor_select); //add floor 2 in destination array of lift1

    position1=2; //update position1 to 2

    }

    }

    rotate_motor(motor_select,dist_count);

    }

    //Floor 2 up button

    if(PINB.B4==0) //PINB.B4 IS pull down

    {

    while(PINB.B4==0);

    active1=4; //assign that external call is 2 up

    external_button[4]=1; //set as 1

    dist1=distance(position1,2);

    dist2=distance(position2,2);

    if(dist1

  • 34 Centralized Control Elevator

    if(dist2dist2)

    {

    motor_select=2;

    dist_count=dist2;

    travel_times2=travel_times2+dist_count;

    add(2,motor_select); //add floor 2 in destination array of lift2

    position2=2; //update position2 to 2

    }

    if(dist1travel_times2)

    {

    motor_select=2;

    dist_count=dist2;

    travel_times2=travel_times2+dist_count;

    add(2,motor_select); //add floor 2 in destination array of lift2

    position2=2; //update position2 to 2

    }

    else

    {

    motor_select=1;

    dist_count=dist1;

    travel_times1=travel_times1+dist_count;

    add(2,motor_select); //add floor 2 in destination array of lift1

    position1=2; //update position1 to 2

    }

    }

    rotate_motor(motor_select,dist_count);

  • 35 Centralized Control Elevator

    }

    //Floor 3 down button

    if(PINB.B5==0) //PINB.B5 IS pull down

    {

    while(PINB.B5==0);

    active1=5; //assign that external call is 3 down

    external_button[5]=1; //set as 1

    dist1=distance(position1,3);

    dist2=distance(position2,3);

    if(dist1

  • 36 Centralized Control Elevator

    }

    else

    {

    motor_select=1;

    dist_count=dist1;

    travel_times1=travel_times1+dist_count;

    add(3,motor_select); //add floor 3 in destination array of lift1

    position1=3; //update position1 to 3

    }

    }

    rotate_motor(motor_select,dist_count);

    }

    }

    }