elevator code for three floors

Go To Last Post
117 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want to do elevator with eight floors but i started with 3 for now. the problem which i faced when i call the elevator from 3rd or 4th floor  to the first floor . i need to stop it if somebody presses the button in 2nd floor using floor1 function ,so i put floor1 function after i give the order for the  elevator to move down but it didn't stop i need to know the reason.

 

///// elevator program for 3 floors
/////////////////////////////////
#include <mega16.h>
#include <delay.h>

#define BUTTON_0  PINC.0
#define BUTTON_1  PINC.1
#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

#define SENSOR_0  PIND.0
#define SENSOR_1  PIND.1
#define SENSOR_2  PIND.2
#define SENSOR_3  PIND.3
#define SENSOR_4  PIND.4
void main(void)
{
PORTB=0x00;DDRB=0xFF;
PORTC=0x00;DDRC=0x00;
PORTD=0x00;DDRD=0x00;
while (1)
      { 

 //////////////////////////1st floor call  
if(PINC.0==1)  
    {
        delay_us(10);
       while(PIND.0==0)  
        {
        PORTB.2=1; 
       floor1();// check if 2nd floor  calling during moving down to 1st floor
        }
     }
   
///////////////////2nd floor call 
 else if(PINC.1==1)  
     {    
       delay_us(10);
   while(PIND.1==0)
   {
     if(PIND.3==1||PIND.2==1) //sensor 3,4
     {  
     PORTB.2=1;   //motor down 
     floor2();           //check if third floor calling
     }
     else if(PIND.0==1) //sensor1
     {
     PORTB.1=1;//motor up
     }
    
    }
     }      
///////////////////3rd floor call
else if(PINC.2==1)
     {
      delay_us(20);
      while(PIND.2==0)
      {
      if(PIND.0==1||PIND.1==1)//sensor1,2
       {  
        PORTB.1=1;//motor UP
        delay_us(10);
    
        } 
        
    else if(PIND.3==1||PIND.4==1)  //sensor 4th and 5th floor
     {
     PORTB.2=1;//motor DOWN
     }
      } 
      }
      
 PORTB=0;//motor stop 
     } 
     }    
  /////////////////////////////////   
       void floor1(void)
  {
    if(PIND.1==1&&PINC.1==1)
     {     
       delay_us(20);

          PORTB=0;//motor stop
      }
      }
  /////////////////////////////
       void floor2(void)
  {
    if(PIND.2==1&&PINC.2==1)
     {     
       delay_us(20);

          PORTB=0;//motor stop
      }
      }    

 

Last Edited: Mon. Nov 10, 2014 - 03:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the forum!

I take it your a student working on a school assignment? 

Have you learned about "state machines" yet?

 

I once pushed the up button for an elevator and heard it fall rapidly from the 3rd floor of a 3 story building,  the people inside were injured pretty badly, so if this is not a school project,

you are wise to start from a lower floor and work your way up!

 

 

JC

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
Have you learned about "state machines" yet?

Probably, this is the homework for the "State Machines" module ... ?

 

mado88 wrote:
i need to know the reason.

Then you'd better get debugging - to find the reason!

 

Debugging is a key skill in any kind of development work!

 

Here's some tips to get you started:

 

http://www.8052.com/faqs/120313

 

http://www.eetimes.com/discussion/break-point/4027526/Developing-a-good-bedside-manner?pageNumber=0

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How does your code 'know' where the elevator is in the shaft?  Will the elevator suddenly reverse direction if it is between the second and first floor if the button is pressed?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no, this isn't a homework. i know about state machines i used switch case instead of floor1 function but it got stuck when switching from case to another . if you know how to insert state machines i will be grateful to here from yousmiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

How does your code 'know' where the elevator is in the shaft?  Will the elevator suddenly reverse direction if it is between the second and first floor if the button is pressed?

it won't reverse its direction if it was between first and second floor ,but it will stop at the 2nd floor if the button pressed before passing it down to the first floor. if it passed the 2nd floor the the button pressed it will go to the first then moving up to the 2nd.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Have you learned about "state machines" yet?

 

Probably, this is the homework for the "State Machines" module ... ?

Indeed, "elevator" is a classic exercise (along with traffic lights).  It forces one to deal with all possible combinations in an orderly fashion.

 

Thus, OP's approach probably won't get you where you need to go.  No debouncing on the inputs; maintained signal operation vs. edge-detection on triggers.  Brute-force handling of new inputs during non-idle operation will rapidly become onerous.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:
 how to insert state machines

You don't "insert" state machines - you need to design your system as a state machine.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

 

mado88 wrote:

 how to insert state machines

 

You don't "insert" state machines - you need to design your system as a state machine.

why state machines? can't i do it as it i posted it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:
why state machines?

Because they are a particularly good fit for this kind of problem.

 

Quote:
can't i do it as it i posted it?

Evidently not!

 

theusch wrote:
Thus, OP's approach probably won't get you where you need to go.  No debouncing on the inputs; maintained signal operation vs. edge-detection on triggers.  Brute-force handling of new inputs during non-idle operation will rapidly become onerous.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why state machines? can't i do it as it i posted it?

No.  Only for a trivial configuration.  Consider, for example:

 

floor1();// check if 2nd floor  calling during moving down to 1st floor

--  Suppose you are at floor 2.1, and too late to stop for the call button.

--  What happens when the floor 2 call button is pushed when you are at floor 1.5?

--  Are the call buttons latching?  If not, what happens with a momentary press of the call button?  If they are latching, when are they unlatched?  If too late to service the floor 2 call, then where is the latching/remembering to service it later when the current operation is complete?

 

Just a start.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

awneil wrote:

 

 

mado88 wrote:

 how to insert state machines

 

You don't "insert" state machines - you need to design your system as a state machine.

 

why state machines? can't i do it as it i posted it?

 

 

First of all you ARE writing a state machine. Almost all embedde programs have at least one state machine, most have several.

But your code obfuscates it

 

A state machine is what controls your program. It sequences operations from one step to the next and know where it's been and where it can go. Each state has a limited number of states it can transition to. This allows you to tightly control what your program is going to do when something happens.

 

For example. If your elevator is moving and a button is pressed, it will behave differently than if the elevator is stopped on the wrong floor, and another way if stopped on the right floor.

Knowing the state lets you do the right thing.

 

Hint: the current floor is NOT a state. Moving up, moving down, stopped..they are states

 

You need to reorganize your code into an explicit state machine. there are lots of ways, but the simplest is just a switch statement.

 

Each case is a state, it stays in that state until there is a reason to move too the next state. really simple, really easy to read ( for simple state machines )

 

heres a simple state machine

int state  = Initialize;

while(running)
{
    switch(state)
    {
        case Initialize:
        if(something happened)
        {
            state = state1;
        }
            break;
        case state1:
        if(something happened)
        {
            state = state3;
        }
            break;
        case state2:
        if(something happened)
        {
            state = state1;
        }
            break;
        case state3:
        if(something happened)
        {
            state = state2;
        }
            break;
        default:
         state = Initialize;
    }
}

 

 

 

 

Keith Vasilakes

Firmware engineer

Minnesota

Last Edited: Mon. Nov 10, 2014 - 08:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now, I'd like you to think through this yourself.  But Google search results indicate "been there done that"...

https://www.youtube.com/watch?v=...

https://www.avrfreaks.net/forum/h...

http://jjmie.hu.edu.jo/files/v5n...

...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

why state machines? can't i do it as it i posted it?

No.  Only for a trivial configuration.  Consider, for example:

 

floor1();// check if 2nd floor  calling during moving down to 1st floor

--  Suppose you are at floor 2.1, and too late to stop for the call button.

--  What happens when the floor 2 call button is pushed when you are at floor 1.5?

--  Are the call buttons latching?  If not, what happens with a momentary press of the call button?  If they are latching, when are they unlatched?  If too late to service the floor 2 call, then where is the latching/remembering to service it later when the current operation is complete?

 

Just a start.

I still don't have idea about momentary press and remembering .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you def need to get the current floor number out of the code!

floor number is a variable not codeable

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

keith v wrote:

 

mado88 wrote:

 

 

awneil wrote:

 

 

mado88 wrote:

 how to insert state machines

 

You don't "insert" state machines - you need to design your system as a state machine.

 

why state machines? can't i do it as it i posted it?

 

 

 

 

First of all you ARE writing a state machine. Almost all embedde programs have at least one state machine, most have several.

But your code obfuscates it

 

A state machine is what controls your program. It sequences operations from one step to the next and know where it's been and where it can go. Each state has a limited number of states it can transition to. This allows you to tightly control what your program is going to do when something happens.

 

For example. If your elevator is moving and a button is pressed, it will behave differently than if the elevator is stopped on the wrong floor, and another way if stopped on the right floor.

Knowing the state lets you do the right thing.

 

Hint: the current floor is NOT a state. Moving up, moving down, stopped..they are states

 

You need to reorganize your code into an explicit state machine. there are lots of ways, but the simplest is just a switch statement.

 

Each case is a state, it stays in that state until there is a reason to move too the next state. really simple, really easy to read ( for simple state machines )

 

heres a simple state machine

i already did that

  while(1){  
  
      switch( state ) {       
 case PARKED_0: ////check floor 1 call
 if(PINC.0==1)  
    {
        delay_us(10);
        while(PIND.0==0)  
        {
        PORTB.2=1;    /// down
 state= PARKED_1;   

        } 
     }
        
  break;
  case PARKED_1:   
 if(PINC.1==1) ///////2nd floor call 
     {    
       delay_us(10);
   while(PIND.1==0)
   {
     if(PIND.3==1||PIND.2==1)
     {  
     PORTB.2=1;//motor down 
      state= PARKED_2;   

     }
     else if(PIND.0==1)
     {
     PORTB.1=1;//motor up 
   state= PARKED_2;   

     }
    
    }
     }
     break;
    ///////////////////3rd floor call
 case PARKED_2:   
      if(PINC.2==1)
     {
      delay_us(20);
      while(PIND.2==0)
      {
      if(PIND.0==1||PIND.1==1)//sensor1,2
       {  
        PORTB.1=1;//motor UP
        delay_us(10);  
        
        } 
        
    else if(PIND.3==1||PIND.4==1)
     {
     PORTB.2=1;//motor DOWN 

     }
     } 
      
      }  
  	    break;

      } // end switch(state) 
                    PORTB=0;     //stop

      }    
      }

but every time i should start with the first floor call . if i pressed any other buttons it doesn't respond every case delivering to the next the beginning from the first floor is a must. and i can't leave the 1st floor , also when i pressed button of 1st floor for a second  time it don't respond.

Last Edited: Mon. Nov 10, 2014 - 09:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since you are using the Mega16 and 3 of your buttons are on pins used by JTAG I hope you have turned off the JTAG fuse as you are not doing that in your code.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

Since you are using the Mega16 and 3 of your buttons are on pins used by JTAG I hope you have turned off the JTAG fuse as you are not doing that in your code.

which pins? will it affect?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

keith v wrote:

 

First of all you ARE writing a state machine. Almost all embedde programs have at least one state machine, most have several.

But your code obfuscates it

Excellent point, worth repeating.  Most embedded programs have one or more state machines, but often they are ad-hoc, created on the fly, and maintain state information in a motley (and ever-growing) assortment of flags, counters and other variables (and the PC/IP is often one of those variables!).  Far better to make the state machine visible and explicit and regular.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Since you are using the Mega16 and 3 of your buttons are on pins used by JTAG I hope you have turned off the JTAG fuse

Absolutely the very last thing you want to be doing is cutting off your visibility into how your code is running!!

 

Keep those JTAG pins and use them!!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

mado88 wrote:

no, this isn't a homework.

Ohhh. Please tell me which city will be using this elevator control so I can avoid it. Or I suppose I should use the stairs. crying

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

valusoft wrote:

 

mado88 wrote:

 

no, this isn't a homework.

 

 

Ohhh. Please tell me which city will be using this elevator control so I can avoid it. Or I suppose I should use the stairs. crying

 

i am working on 8 floors but i started with 3 for simplifying.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
... visibility into how your code is running!!

Or, more to the current point, why it is not running as expected!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Keep those JTAG pins and use them!!

He is "using them"

#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

valusoft wrote:

 

 

mado88 wrote:

 

no, this isn't a homework.

 

 

Ohhh. Please tell me which city will be using this elevator control so I can avoid it. Or I suppose I should use the stairs. crying

 

 

i am working on 8 floors but i started with 3 for simplifying.

 

 

I will definitely use the stairs. What city?

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Probably best to avoid the city entirely?!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The real purpose of this exercise is to learn about the 'elevator seek' algorithm which is used in multitasking operating systems to improve disk access by queing disk read requests by track and sorting them so they are worked off in order as the head moves in, then the head starts heading out and the sorted qued requests are accessed in order. In the elevator, imagine a guy gets on at 3 and presses the button for 11, and it starts up. Folks at 5,7 and 9 press the button and the car stops to pick them up. When it gets to 11, it looks and lo and behold, there are now folks that have hit the button on 8,6,4 and 1.

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

mado - you're getting the piss taken out of you simply because you haven't done your research. You've got the power of the inter webs at your fingertips but you thought the easiest way was to ask at a forum.

As you've been informed that this problem is a 'classic' problem that has most likely been solved a million times on the inter web - much better than we would do here.

Let me give you a few pointers:

1. pushbutton switches 'bounce' - you need to debounce them. use 'debounce' to search on. We've discussed it millions of times (maybe not millions, but a LOT)

2. the monkey pushing the button is slow compared to a microprocessor. Response times are of the order of 100ms.

3. Real lifts don't move far in 20us. Again, we're talking in the order of 10's of milliseconds.

4. you don't need to use a finite state machine - you can do it in combinatorial logic if you like. Using a state machine is much easier to design and debug.

5. There are simulators available where you can step through your code. I'd suggest you use one of these. Atmel Studio has one.

6. Run your state machine every 10ms. That way you can count ticks rather than use delays.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried this code using state machines to go up for 5 floors just for now . it gave error message when i add (enum) for the motor direction

Error: C:\Users\madoo\Pictures\e.c(26): '}' expected, but '.' found
#include <mega16.h>
#include <delay.h>
#define BUTTON_0  PINC.0
#define BUTTON_1  PINC.1
#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

#define SENSOR_0  PIND.0
#define SENSOR_1  PIND.1
#define SENSOR_2  PIND.2
#define SENSOR_3  PIND.3
#define SENSOR_4  PIND.4
//////////////////////////
#define MOVE_UP    PORTB.1
#define MOVE_DOWN  PORTB.2

///////////////////////////////// 
enum elevator_state {
  PARKED_0,PARKED_1,PARKED_2 ,PARKED_3 , PARKED_4  ,
  UP_TO_1   , UP_TO_2  , UP_TO_3   , UP_TO_4  ,
  };  
 ////////////////////////
 enum motor_direction {
  STOP      = 0,   // send 0 to portb to stop the elevator
  MOVE_UP   = 1,    // send 1 to PORTB.1
  MOVE_DOWN =1 ,     // SEND 1 PORTB.2
};

//////////////////////////// 
 
unsigned char state = PARKED_0;
unsigned char  motor=STOP;
////////////////////////////
void error(void) 
{
  motor = STOP;
  for(;;) {
  	PORTB.5 = 1;
  }	
}
////////////////////////////////

void main(void)
{
PORTB=0x00;DDRB=0xFF;
PORTC=0x00;DDRC=0x00;
PORTD=0x00;DDRD=0x00;
for( ;; ) {
  	
  	switch( state ) {
  	  case PARKED_0:
  	    if (BUTTON_1 | BUTTON_2 | BUTTON_3 | BUTTON_4) {
  	      state = UP_TO_1;
            motor = MOVE_UP;
  	    }
  	  
  	    break;
  	    
      case PARKED_1:  	
        if (BUTTON_2 | BUTTON_3 | BUTTON_4) {
          state = UP_TO_2;
            motor = MOVE_UP;
        }
      
                      
          break;

      case PARKED_2:      
        if (BUTTON_3 | BUTTON_4) {
          state = UP_TO_3;
            motor = MOVE_UP;
        }
                     
          break;

      case PARKED_3:      
        if (BUTTON_4) {
          state = UP_TO_4;
            motor = MOVE_UP;
        }
                     
          break;
                 
      case PARKED_4:      
        if (BUTTON_0 | BUTTON_1 | BUTTON_2 | BUTTON_3) {
         PORTB.2=1;      // down
        }
                      
          break;
          
        case UP_TO_1:
          if (SENSOR_2 | SENSOR_3 | SENSOR_4) {
            error();
          }
          
          else if (SENSOR_1) {
            state = PARKED_1;
            motor = STOP;    
          }
          else {
            motor = MOVE_UP;
          }
          break;

        case UP_TO_2:
        
           if (SENSOR_2) {
            state = PARKED_2;
            motor = STOP;    
          }
          else {
            motor = MOVE_UP;
          }
          break;

        case UP_TO_3:
        if (SENSOR_3) {
            state = PARKED_3;
            motor = MOVE_UP;
          }
          else {
            motor = MOVE_UP;
          }
          break;

        case UP_TO_4:
          if (SENSOR_4) {
            state = PARKED_4;
            motor = STOP;    
          }
          else {
            motor = MOVE_UP;
          }
          break;
      }
    }  
    }
      

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define MOVE_UP    PORTB.1
#define MOVE_DOWN  PORTB.2

 

  MOVE_UP   = 1,    // send 1 to PORTB.1
  MOVE_DOWN =1 ,     // SEND 1 PORTB.2

Do you see it now?  You have conflicting meanings for those two terms.  (and don't you want a value of 2 for the second? )

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok. how to declare this ? to give  it a value at the same time make it readable .
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the current floor is a variable.

you need to add a FIFO to store the next floor to go to

 

I think your states are;

Moving

stopped

door open

door closed

 

 

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

keith v wrote:

the current floor is a variable.

you need to add a FIFO to store the next floor to go to

 

I think your states are;

Moving

stopped

door open

door closed

 

 

I think that door open and closed are output not states ? am  right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that door open and closed are output not states ? am  right?

A Google image search for "elevator state machine" uncovers much discussion, from simple  concepts to "useful"/"practical"  -- speed control; exception handling; queueing; ...

 

For example:  "Figure 14: Finite State Machine of an Elevator Controller" is a good starting point, along with the discussion of the UML

http://www.jot.fm/issues/issue_2...

 

As always, the Cornell ECE476 projects are great examples:

https://courses.cit.cornell.edu/...

 

...and many others.

 

If indeed you are trying to design a "real" system, as hinted above I don't think you are experienced enough to develop a reliable system with movement and possible danger to people and equipment.

 

There are interacting subsystems in this type of app.  Indeed, the "state machine" for idle, moving up, moving down, opening, opened, closing, closed, ...  Then there is the actual movement system and position tracking.  In any real app of this type, there isn't just a single "at floor" sensor.  At the minimum there would be "at floor", plus 'a little above" and "a little below".  Or there might be an encode or other position sensing.  Movement is not just moving or not--smooth acceleration, smooth deceleration, "full speed" between those points.

 

Then there is the detail of latching call button presses, and latching the "call pressed" indicator, and unlatching when serviced.

 

Floor reporting is very common--see the youtube video.

 

Door opening and closing are other movement subsystems.  Speed also important, and safety switches especially when closing.

 

Exception handling when there is a movement fault, or the target position is "missed".

 

In all the states, pertinent events need to be checked and handled properly.

 

And we haven't even started to talk about the "queue" of requests, and handling them such as Bob described.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

keith v wrote:

 

the current floor is a variable.

you need to add a FIFO to store the next floor to go to

 

I think your states are;

Moving

stopped

door open

door closed

 

 

 

I think that door open and closed are output not states ? am  right?

 

Door open is definitely a state, and I'm sure there's more, openING, closING etc

States are what the elevator is doING.

Theres also sub states...

 

I can be walking, standing, sitting, all different states

if I'm walking I have sub states, lifting foot, moving arm

They also have sub states,Lifting foot has;  bending knee, lifting thigh...

Bending knee has substates; send signal to thigh muscle, etc

 

It's state machines all the way down

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

how to add a FIFO to store the next floor to go to?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd suggest that real lifts use a 'scoreboard' rather than a fifo. Basically an array of size n floors each with a flag. When someone requests a floor, the flag for that floor is set. 

This is all fundamental stuff - if you're having trouble this means you're trying to run before you can walk. All this can be found on the interwebs - you really don't want us to do your homework do you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you really don't want us to do your homework do you?

kartman--I trust you saw above...

valusoft wrote:

 

 

mado88 wrote:

 

no, this isn't a homework.

 

 

Ohhh. Please tell me which city will be using this elevator control so I can avoid it. Or I suppose I should use the stairs.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am here to learn from you freaks . to ask for help if you could i will be grateful or stop this sarcasm

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

i am here to learn from you freaks . to ask for help if you could i will be grateful or stop this sarcasm

That's fair enough, I'm starting to cringe at the comments myself.

 

So, the reason you don't need a FIFO is that it doesn't matter in what order the floor request buttons are pressed.  If you're going down you want to stop at the floors in floor order, not pushed order.  Same if you're going up.

 

Think through the situation, starting with an initial state (say, elevator on floor 1, waiting).

 

What happens if somebody enters the elevator and presses floor 3?

 

What happens if 1 second later somebody on floor 2 pushes their UP button?

 

What happens if 1 second later somebody on floor 2 pushes their DOWN button?

 

You need to work through all the possible interactions when the elevator is at rest, and all the possible interactions when it is moving, given that any button could be pressed at any time, and that the elevator takes time to move from floor to floor.  This is where the "scorecard" mentioned earlier comes into play.  Every time the elevator stops at a floor (including waiting at the first floor), it has to decide whether to start moving, and if so, in what direction.  Every time the elevator is moving it has to decide when to stop.  Write up that document and you're on your way to a successful software implementation.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado did you understand the point I was making above about the JTAG?

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

mado did you understand the point I was making above about the JTAG?

excuse me i there wasn't a chance to know about JTAG before so please simplify it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kk6gm wrote:

 

 

You need to work through all the possible interactions when the elevator is at rest, and all the possible interactions when it is moving, given that any button could be pressed at any time, and that the elevator takes time to move from floor to floor.  This is where the "scorecard" mentioned earlier comes into play.  Every time the elevator stops at a floor (including waiting at the first floor), it has to decide whether to start moving, and if so, in what direction.  Every time the elevator is moving it has to decide when to stop.  Write up that document and you're on your way to a successful software implementation.

i know what to do with all of these states but how to implement it , this is the problem. so if there is example about scoreboard please refer to it and i will start . i think it is difficult to describe running for a baby and ask him to run before you learn him how to walk.i wrote state machines for up and down but how to remember requests  is still the problem . i will search for array and flags as you mentioned .

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado, it does seem implausible that you want to implement a lift controller tor a real lift using an atmega16 and very little knowlege of programming in C. This is the source of the sarcasm. A real lift controller would most likely be implemented using a PLC. 

 If you continue on your current track, i'd suggest you get a good book on programming in C otherwise leaning on forums to write your code is not going to be too productive. Disclosing what you're actually doing might help your case.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is always useful to provide background information.

 

A Lift simulation is a common project for a school assignment.

It is perfectly reasonable to choose a Lift simulation as a hobbyist project.

 

You have been offered lots of sensible advice.

 

Personally,   I would attempt any design by sketching ideas with pencil and paper.

Then hand-tracing the logic flow.

 

You will discover that it is a fairly complex project but do-able.

 

If you claim that this is a lift that takes real humans,    there are very serious safety considerations.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why aren't you able to believe that it is a real elevator ,should i said from the beginning it is a 20 floor . i started with 3 floors to make it simple then i will generalize the idea for even 100 floors .

Last Edited: Wed. Nov 12, 2014 - 09:06 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go on.    We are not stupid !!!

 

No one would give the job of designing a 100-floor elevator to someone that is a learner.

 

We are quite happy to help people with their projects.

Of course,    we can't give complete solutions to school assignments.

But there is no problem with hobbyist projects.

 

Likewise,   you can use advice in your commercial project.     However,    I certainly don't want to be connected in any way to a safety-critical project.     Especially if I am aware that the manufacturer is not competent.      The internet enables untrained people to produce sophisticated 'designs' that may not be understood by them.      And a naive employer sets them to work on stuff that is well beyond their skill level.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado - seriously, the logic for the floor control is trivial compared with controlling the dynamics of the lift car. What prior education have you got that might qualify you for such a task?

 

Note that I work for a multinational that has a major business in lifts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

why aren't you able to believe that it is a real elevator

Because this implies that someone who owns/builds lifts has given the job of building a (safety critical!) control system to a total beginner who doesn't understand basic programming skills.

 

Frankly this thread worries me. Most people here come along to help beginners in programming to learn about AVRs and programming in general but that's making small, benign projects like alarm clocks, logging thermometers and things like that. The idea of putting the control of several tons of human transporting machinery in the hand of such a beginner is just mind boggling. In fact it's close to being criminal.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes,    but it is a perfectly good exercise in Simulation.

 

What worries me is when people do not study the replies to their questions.

All the replies seem both sensible (and polite) to me.

 

Yes,    I often misinterpret a question.    And offer an answer to a completely different question !

 

We are all human.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The OP should be aware that most countries have very stringent safety regulations for lifts which have requirements which start before the design phase. For instance, in Europe we have 95/16/EC.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

+1 on Cliffs observation.

Here in NYC any of the elevator control systems I have seen that were installed in the last 20years use distributed processing(controller in car for buttons, another in the motor room for the heavy stuff, and a dispatcher professor to control multiple elevators).

 

I wonder if the OP is having this much trouble with three floors and just the call buttons how do you plan on controlling motor speed based on the variable loads(people) in the cars, the holding brake and the position reporter(usually a rotary encoder with a wheel touching a guide rail, or an optical switch with a performed strap that runs the length of the shaft).  Then there are the timers for door open times and the various key switches for independent, inspection, fire service. Then there is also the lobby control station too.

 

All of this is controlled using 32bit processors, not an 8bit AVR.

 

If this is not a school homework assignment, then can you provide some background as to your capabilities, and/or the group you are working with?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wikipedia has 16 completed buildings with 100 floors or more.

 

And 18 buildings that are still under construction.

 

So we can possibly guess which building the OP is designing for.     (Probably one of the ones on the list with 0 floors completed yet)

 

It is a perfectly good exercise to simulate an Elevator system.     I would guess that the algorithms change for the really tall skyscrapers.

All the same,    it is a complex subject.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

I'd suggest that real lifts use a 'scoreboard' rather than a fifo. Basically an array of size n floors each with a flag. When someone requests a floor, the flag for that floor is set. 

This is all fundamental stuff - if you're having trouble this means you're trying to run before you can walk. All this can be found on the interwebs - you really don't want us to do your homework do you?

 

Good point. the FIFO would not be optimal :P

scoreboard is an interesting concept. I would have just called is an array with a flag set for called floors.

And yes, someone is trying to save pennies here if it is a real elevator.

I mean really doesn't Otis etc have this figured out already???

Why is he trying to reinvent the elevator if it's not a class project.

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course it's homework. Strange that the OP won't admit it. Maybe they think they won't get an answer to a homework question?

On the other hand, I don't think there'll be much help forthcoming if we believe it's for a real elevator!

 

Even without the motor control, I'd think it's a pretty complex problem, as one would have to trade-off moving the elevator the minumum distance against the possibillity of starving a floor.

Four legs good, two legs bad, three legs stable.

Last Edited: Wed. Nov 12, 2014 - 03:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Look at it from the OP's point of view.

 

She has got a homework assignment and wants it to be completed by someone else.

 

If she admits that it is schoolwork,   no one will give a ready-made solution.

 

If she says that it is a hobbyist project,    she would get lots of assistance.

 

If she says that she is chief design engineer for Otis,    she just looks foolish.

 

Even if it is schoolwork,   she can still ask intelligent questions.     And will probably get good suggestions and advice to specific questions.

Of course,   all her classmates can see exactly the same replies.     It may irritate the teacher,   but this is the way that the real world works.      And yes,    the teacher will have a pretty good idea who has understood the question and understood how the solution works.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the last couple of weeks I've read an interesting article about elevator control algorithms and real ones have way more 'intelligent' algorithms than you might think. I can't for the life of me remember where it was though. It might have been in a trade mag but the 'library' had a clear out at the weekend.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
the 'library' had a clear out at the weekend.

You mean, the bin men have been...?

 

wink

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:
real ones have way more 'intelligent' algorithms than you might think.

 

"it takes a great deal of effort to make something appear effortless"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is a school project then the complexity is minimal.

One gets to ignore all of the real world factors mentioned above, (redundancy, positioning, dynamic speed control, door safety, etc., etc.)

It turns into a simple simulation again.

Start at Floor 1 (or "Ground Level").

Wait for someone to push a button.

Go up and keep going up until you have reached the highest requested floor.

Then wait until someone pushes a down button, or a request is made from another floor.

If you have a down request, the elevator is now committed to down, and goes down until it reaches the lowest number anyone has requested.

If it was answering a call request, once again its direction has been committed from the requester, and it again starts up or down from the requester's floor.

 

This could be made into a really nice "simulation" with the push button switches and LEDs for floors all laid out correctly.

 

I love riding in real elevators with all glass walls so one can see the cabling, counterweights, rail systems, etc.

My wife doesn't like heights, and is terrified of riding in such elevators.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Floor 1 (or "Ground Level").

 

Floor 0, surely...?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i searched for bit array which put struct in my way, i found out some codes and i understand some, while my digging i found out that there is a bit field which can handle one byte . which mean 8 bits , so i can use it for my 8 floors . every bit will represent a single button.  i will try bit field for now then update to the higher level

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you want an interactive class in turning algorithms into code. Forget about elevators for a couple of days. The freaks will dream up simple little program specs, and you edit, compile, burn and run them them several times until you think they meet the spec, and submit them. Here's program spec 1: 2 momentary pushbuttons and 3 leds. Led 1 is on for 250ms, off for 750ms. Button 1 is software toggle that sets and resets a boolean variable in the program. Led 2 shows the output of the variable. Button 2 initiates a sequence on led 3 of on for 100ms, off for 200ms, repeat 3 times when pressed.

 

Imagecraft compiler user

Last Edited: Wed. Nov 12, 2014 - 07:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried this code in code vision 


#include <mega16.h>


/* define bit buffer array type*/
typedef struct { 
 unsigned char b0:1; 
 unsigned char b1:1; 
 unsigned char b2:1; 
 unsigned char b3:1; 
 unsigned char b4:1; 
 unsigned char b5:1; 
 unsigned char b6:1; 
 unsigned char b7:1; 
} bits_t; 

/* Set Bit Function */
void SetBit(bits_t* array, unsigned char loc, bit val)
{
    switch(loc)      /* loc has values in between 0 and 7 */
    {
    case 0: array->b0 = val; break;
    case 1: array->b1 = val; break;
    case 2: array->b2 = val; break;
    case 3: array->b3 = val; break;
    case 4: array->b4 = val; break;
    case 5: array->b5 = val; break;
    case 6: array->b6 = val; break;
    case 7: array->b7 = val; break;
    }
}

/* Get Bit Function */
bit GetBit(bits_t* array, unsigned char loc)
{
    bit result;

    switch(loc)        /* loc has values in between 0 and 7 */
    {
    case 0: result = array->b0; break;
    case 1: result = array->b1; break;
    case 2: result = array->b2; break;
    case 3: result = array->b3; break;
    case 4: result = array->b4; break;
    case 5: result = array->b5; break;
    case 6: result = array->b6; break;
    case 7: result = array->b7; break;
    }

    return result;
}

/* Main */
void main(void)
{
    unsigned char i;

    bits_t bit_array[10];               // Declare 10 bytes long bit array
	
	SetBit(&bit_array[1], 3, 1);      // Set bit3 of bit_array[1]

	if(GetBit(&bit_array[1], 3))	  // Check bit3 of bit_array[1]
		SetBit(&bit_array[1], 0, 1);  // Set bit0 of bit_array[1]

	for(i=0;i<8;i++)   // Use for loop to access the bits
		SetBit(&bit_array[0], i, 1);  	

	while(1)
	{}

but it give error , however every thing is ok

Error: C:\Users\madoo\Music\8051\new.c(18): 'bit' type not allowed in this context " referred bit val in Setbit function argu"

 

Last Edited: Wed. Nov 12, 2014 - 09:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You appear to be using Codevision.     You can return a bit from a function.     You cannot use bit as a parameter to a function.   So just make val a char or uint8_t.

 

The regular rules for type promotion will mean that you can pass a bit as an argument to the function.

 

I would try to do the project design in flowcharts or state machines.      Get your logic correct before you even think of coding.

 

If you are unsure of the coding,    just ask.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Never mind."  -- Emily Litella

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Wed. Nov 12, 2014 - 09:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado - writing the code before you've figured out the logic is working backwards. As David is apt to advise - get it working on paper first. Once you've got the process sorted out, writing the code is easy. Go for a ride in a real lift and see how it operates. 

Create 'rules'

eg: if going up and no more requests above and no requests below then park

if going up and next floor is requested then ....

if going down and no floors requested

 

if you lay out all the possibilities logically, your rules will be simple. Once you've got your set of rules, the code basically writes itself. The rules would also form part of your documentation that would earn brownie points with the teacher. 

Note: using an array of bits is a compact method. I would  have used an array of chars to simplify the process. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

You appear to be using Codevision.     You can return a bit from a function.     You cannot use bit as a parameter to a function.   So just make val a char or uint8_t.

 

David.

how to do val char or uint8 however it is a single bit ? it should be bit not char.

i tried to remove setbit function and compile getbit but error message said that

Error: C:\Users\madoo\Music\8051\new.c(21): functions can't return 'bit' type

 

Last Edited: Wed. Nov 12, 2014 - 09:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops.     I should have checked the docs first.

 

It looks as if you need to use char or unsigned char for the function parameter and return values.     Any promotion or truncation will happen transparently.

As Lee said,   bit is a non-standard extension.     It is an efficient way to store or access Boolean variables at the hardware level.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wasn't a chance to know about JTAG before so please simplify it.

If you don't know about JTAG and what it does please STOP YOUR PROJECT RIGHT NOW!!! You WILL KILL people.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

 

Note: using an array of bits is a compact method. I would  have used an array of chars to simplify the process. 

why array of chars however i just need 8 bits for 8 floors ? could you clarify your point ? do you intend to use them in any  stuff except buttons ?.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

wasn't a chance to know about JTAG before so please simplify it.

If you don't know about JTAG and what it does please STOP YOUR PROJECT RIGHT NOW!!! You WILL KILL people.

please i won't wake up in the morning to kill people i am trying to learn and train my self as this is my hobby . i will make a model  for my self so it will be real . if i stopped now because i don't know about jtag i won't learn any thing so please refer to a source to read about it and don't say stop.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado88,

 

Could you please get everyone one on the same playing field here by answering some basic questions?

 

1) What is your electrical/Electronic education and experience?

2) IS this a school project, hobby education, or a REAL system you are working on?

 

 

From reading your posts I am very confused.  The only way to get sound advice is a solid foundation.

 

Thanks

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wouldnt go to the trouble of packing booleans into bits until you have used 2041 bytes of your 2048 byte ram. Only then will those extra 7 bytes help you.

 

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

 

From reading your posts I am very confused.  The only way to get sound advice is a solid foundation.

 

 

tell me why are you confused ? i am just asking for help

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mado - download the datasheet for the AVR you are using and search for jtag. The answers are all there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

jgmdesign wrote:

 

 

From reading your posts I am very confused.  The only way to get sound advice is a solid foundation.

 

 

Is this for a real world application in a real building, or are you making an educational project?  THats what I meant, sorry.

 

tell me why are you confused ? i am just asking for help

 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

 

DocJC wrote:

Floor 1 (or "Ground Level").

 

 

Floor 0, surely...?

 

 

And then there's the danged mezzanine...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:

 

Kartman wrote:

 

 

Note: using an array of bits is a compact method. I would  have used an array of chars to simplify the process. 

 

 

why array of chars however i just need 8 bits for 8 floors ? could you clarify your point ? do you intend to use them in any  stuff except buttons ?.

 

You need at least 2 bits per floor.  1 for UP_REQUEST, and 1 for DOWN_REQUEST.   You might also want a per-floor bit that goes active when the elevator is at the floor (not sure if that would be helpful, it just popped into my head).  Maybe also a bit that indicates floors that are locked out?  So don't prematurely optimize down to an array of single bits.  For one thing, C doesn't support it (although Ada does, and is available for AVR).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What concerns people here are a couple of statements you have made in the above threads. Like:

no, this isn't a homework.

 

why aren't you able to believe that it is a real elevator ,

 

so you are either learning, and it is therefore homework even if you are not attending a formal course OR, and this is the worrying point, you are designing and writing code for a real job in which case my comments above are valid.

 

I have been in electronics for just over 50 years now with more than 30 years using micros and I would be very hesitant taking on a job like this. I know that elevators have mechanical safety brakes in case of some failures but it is still an onerous task.

 

Going back to my JTAG comments you are using at least 3 of the 4 JTAG pins

#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

if JTAG is still enabled as the chip comes from the factory, those pins will do NOTHING in your code, in fact you are likely to DAMAGE the chip by using them, no one seems to be picking this up so I may be wrong.

 

JTAG is used to debug your code, so if you can spare another 3 pins for your buttons use them instead and leave pins C2-C5 for the debugger if you have one. If you don't have one I strongly suggest you get one and learn to use it. Others will have different ideas on this.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

JTAG is used to debug your code, so if you can spare another 3 pins for your buttons use them instead and leave pins C2-C5 for the debugger if you have one. If you don't have one I strongly suggest you get one and learn to use it. Others will have different ideas on this.

in simulation with Proteus it is working and there is no interference . i will need 16 inputs at least and also there will be outputs son i need all the ports pins , i will turnoff its fuse bits .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh boy, Proteus again!

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Proteus - it's what all the Indian students use! It's Labcenter's biggest market except they don't make any money from it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This popped up on the BBC News website a couple of days ago...

 

"The students who feel they have the right to cheat...Students are often keen to exercise their rights but recently there has been an interesting twist - some in India are talking about their right to cheat in university exams."

 

http://www.bbc.co.uk/news/magazi...

 

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the same must be happening over here as well - i've had to explain how to apply Ohm's Law to more than one recent electronic engineering graduate and had to demonstrate why you have to put a diode across a relay coil to another.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Floor 0, surely...?

I used to work for Amstrad in Brentwood. When they moved there they bought a building off Ford the US motor company (who own/employ about half of Brentwood it seems!). The curious thing about working in a building that belonged previously to Americans was that it had "American lifts". The floor at ground level was known as "1" not "G" as found in UK buildings. It often confused visitors who weren't familiar with the odd numbering our colonial cousins prefer.

 

I guess the original UK lift designers must really have been frustrated C programmers and preferred things to be 0 (or rather G) based ;-)

 

http://en.wikipedia.org/wiki/Sto...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a couple of customers in nyc who's floor numbers defy logic.  One such customer is on the 1st floor.  But that floor is six stories up as the real first six floors are open atrium of the lobby. Huh?

 

The other one I will never understand. The firm bought out floors 45 thru 49 of the building and have their own bank of elevators.  The street level is called Ground Floor, and the first stop on their elevator is floor 1.....45 stories up!  Their feeling is that's where their company's floors begin.

 

Money buys philosophy

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a couple of customers in nyc who's floor numbers defy logic.

How many of your customers have floor 13?  Remember that OP wants to extend the design to tall buildings -- is his elevator system always going to be "one floor off" once it gets higher?!?  ;)

 

 

Panel from an elevator in a residential apartment building in Shanghai. Floors 4, 13 and 14 are missing, because of the similarity between the pronunciation of the word 'four' and 'death' in Chinese; note also the "negative first floor", as the number zero is considered similarly unlucky in parts of East Asia.  (from Wikipedia)

OP was struggling with implementation of "bit mask" for floor representation earlier in the thread. Use this illustration for the prototype, and confusion will reign.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Nov 13, 2014 - 08:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i tried to use bit array inside sates but i failed i don't know how to use them. when some body call elevator to 4th floor it will go up before passing floor 1 somebody pressed  button one it should stop then complete its way to 4th . i couldn't do that inside states . do you have any idea?, also what would happen if it passed floor 1 then button 1 pressed , the elevator should go up and store button 1 to return to it while going down . in which state will this be implemented ? or i should write it outside switch cases

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We can only guess what your code does.

If you're going up and have passed floor 1 when someone has pressed 1, if there are requested floors above, you do them first then go down.

 

Again, create the rules then write the code. Or would you like us to write the code for you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I suppose that I have not used elevators very often.

 

THe obvious thing to do is "see how your University lifts work".

Then make your lift work in a similar way.

 

I would guess that if a lift has started going up,    it will service everyone that it meets on its upward journey (that wants to go up).

When they have all finished,   it will stop.

If there are any waiting customers,   it will go down serving any downward requests.    

Rinse and repeat.

 

This could mean that someone who has just missed the lift,   has to wait until it has completed a full return journey.

So a big building probably has more than one lift.

 

Of course,   you may have a better algorithm.

 

However you want to control the lifts,    you make your rules,   states,    flowcharts on paper.

You complete the design phase on paper before you even think of computer programming.

 

David.

Last Edited: Thu. Nov 13, 2014 - 09:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're going to have to do some sort of priority based traveling salesman algorithm. It's a non trivial implementation I'm sure, but I aint going to figure it out...

Prioritize by button press order, direction of travel, floors to service.

 

and what if theyre 2 cars, or more, being serviced by the same call button. We have 3 in my building.

It's a quite complex problem to do right and not end up with people just going up and down lol.

 

Looks like a fun problem. But one that requires a ton of design and useability testing.

 

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
You complete the design phase on paper before you even think of computer programming.

+999999

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It should be dawning by now that you actually have two distinct problems:

 

  1. Motion control - up/down; stop/start; doors open/close etc;
     
  2. Algorithm - how you will queue & service the lift requests.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and what if theyre 2 cars, or more, being serviced by the same call button.

In multi car systems there is a central controller called the Dispatcher that takes all the call buttons in, gets reports from the cabs as to their positions and call load and direction and then decides which car to send to the floor that called.  No easy task.

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folks want to go up to 10s of floors, but they all want to come down to the ground floor. I recall an article that solved the logjam to go up in the glass elevators at some big hotel. These 60+ year old synapses arent divulging much more info than that. I therefore claim that this info is lost forever and no-one will ever learn of this algorithm, or the hotel it is used in.

 

Imagecraft compiler user

Last Edited: Fri. Nov 14, 2014 - 03:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take the healthy option. Use the stairs.
 

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i changed state again to handle requests from 0 to 3 if button 4 pressed. i wrote it on paper before coding but elevator didn't stop .

if it is going to 4th floor and

if buton1 pressed then enter floor1 state

else if button 2 pressed then enter floor 2 state

else if button3 pressed then enter floor3 state

else floor 4 state

it didn't stop in any of the floors before 4th after the 4th button pressed .

 

pleased introduce a real help for this problem even a trigger to start with.

#include <mega16.h>
#include <delay.h>

#define BUTTON_0  PINC.0
#define BUTTON_1  PINC.1
#define BUTTON_2  PINC.2
#define BUTTON_3  PINC.3
#define BUTTON_4  PINC.4

#define SENSOR_0  PIND.0
#define SENSOR_1  PIND.1
#define SENSOR_2  PIND.2
#define SENSOR_3  PIND.3
#define SENSOR_4  PIND.4
//////////////////////////
#define MOVE_UP    PORTB.1
#define MOVE_DOWN  PORTB.2
///////////////////////////////// 
enum elevator_state {
  PARKED_0,PARKED_1,PARKED_2 ,PARKED_3 , PARKED_4  ,
  f1   , f2  , f3   , f4  
  };  
  ///////////////////////////////
  unsigned char state = PARKED_0;
////////////////////////////////////
   void main(void)
{
PORTB=0x00;DDRB=0xFF;
PORTC=0x00;DDRC=0x00;
PORTD=0x00;DDRD=0x00;
  for( ;; ) {
  	
  	switch( state ) {
  case PARKED_0:    // parked at floor 0 
     if (BUTTON_4|BUTTON_3|BUTTON_2){
         delay_us(10);

        PORTB.1=1;  // motor up 
       state=PARKED_1;
       } 
             break;

     case PARKED_1:
     
         if( BUTTON_1){
         delay_us(10);
         state=f1;        
         }  
         else{
         state=PARKED_2;
         }  
             break;

       case PARKED_2:
    
          if(BUTTON_2){
         state=f2;
         }
         else{
         state=PARKED_3;
         }
        break;
  
     case PARKED_3:
  
         if (BUTTON_3){
         state=f3; 
         } 

         else{
         state=f4;}
         
      break;
    case f1:
         if (SENSOR_1){
           PORTB.1=0;  // motor stop
           }
           break;
     case f2:
         if (SENSOR_2){
           PORTB.1=0;  // motor stop
           }
           break;
     case f3: 
         if (SENSOR_3){
           PORTB.1=0;  // motor stop
           } 
   break;
      case f4:
         if (SENSOR_4){
           PORTB.1=0;  // motor stop
           } 
     break;
       }
   }   
   }
   

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

real help?

You're SM is wrong, make it right.

the Sm should not know what floor it's on

Keith Vasilakes

Firmware engineer

Minnesota

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

keith v wrote:

real help?

You're SM is wrong, make it right.

the Sm should not know what floor it's on

how could that be? which part gave you that impression to fix it?

Last Edited: Fri. Nov 14, 2014 - 04:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can I just make a general observation about the difference between people throwing together LED flashing hobby projects in their bedroom and professional software engineering? In the latter you specify then design first. This is non-trivial, it could count for 20% or more of the overall project. Only when you have a fully refined design (which admittedly may involve some engineering of both hardware and software prototypes to prove a theory of part of the design) are you then ready to look at implementation. In fact this bit should be fairly trivial (in the old days "system analysts" did the design and lowly paid grunts simply called "programmers" converted those designs to code).

 

So if you are serious about this being a professional project then think about doing it properly. Put your C editor away and get out your word processor. Start by specifying what you are trying to achieve and how you see it operating (a bit like a "user manual" I guess?). Then when that is clear move to design. You can do this in the word processor too by simply describing in words how the code will operate to meet the specification. Some people prefer a drawing tool and to sketch out something like a flow chart. Some people even use special tools like UML editors to put down a "picture" of the design implementation. A clever UML tool might even generate some code out of the back of this (especially solutions based on something like state machines).

 

When you have a clear design you then sit down and implement it. If it is very simple you maybe do it in one big loop in a single C file. For anything more complex, at the design stage you will already have broken it into modules with interfaces and the joy of that is that as long as each module has a clearly defined task and interface the jobs can be handed out to multiple implementors or at the very least you split the code between multiple C files that you write but treat each as an individual, self-standing "module" that can be tested in isolation.

 

Finally a system integrator, again it could be just you, pull the module "building blocks" together and build the final solution according to original design.

 

Of course there are bugs and there may even be things you overlooked in the original design so there may be some "iteration" when it comes to coding/testing the design.

 

but if you take this approach things are manageable and you get a far superior project at the end.

 

The way not to do this is to start editing a C file and make one huge loop or switch{} statement that you keep bolting bits onto (or cutting from) until you have something that "kind of works" but here you cannot see how to fill in a solution for that next scenario you just spotted in testing that the code doesn't cater for - in a good design you thought about al this in the design phase before you edited one line of C.

 

Now you could just keep battling on with this rather half baked, organically growing implementation you have or you could just call it a "prototype" and take anything you have learned so far and put that into doing a clean design, properly.

 

It's your choice but you will actually get to a final solution quicker and with a "better" product if you stop and think about this for a while. Perhaps continue to use what you've done so far for more prototyping "proof of concept" tests that you might then incorporate into the design.

 

My $0.02 anyway!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for your advice and your time , actually i designed it and i know the operation but i lack for experience  in this level of programming .i made simple projects before but this one i think it's hard , however i found some codes on web but i can't implement it with out understanding how was it written .
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff has offered excellent advice.   I am probably more of a "pencil and paper" person than a UML person.

 

Don't get too frightened by the 'extra considerations'.     I presume that you just want a simple simulation.

 

If you switch off the Computer,    you will probably get a logical design.

 

The write it up in your Word Processor (or UML).

 

I bet that you will spend less hours from your life if you follow this strategy.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

actually i designed it and i know the operation

Are you able to share that with us? Some of us here dabble in C a bit and can probably help you in finding the right syntax to convert your design into an implementation.

 

While looking at other implementations can help (especially during the design phase) it's too easy to think "I must be doing it like that" without fully understanding how it is their design is working. If you don't understand it then leave it alone. As I say come up wiht your own design then just implement that design. Seek advice if you are not sure how to achieve this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have a completed design and its documentation,     people would be happy to help with the coding.

 

So far,     we can't see much evidence of any paper design.

 

With any school project,   it is essential that the student does his/her own design work.

Translating it into C, C++, JAVA, Basic, ... is relatively trivial.

 

And if you post the design,     people will help you with the coding.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1-the elevator is at ground floor as a default then somebody calls it from nth floor during it's travel to up somebody in n-2 and n-3 called it so the elevator should go up to (n-3) floor then to (n-2) floor then to nth floor.

2-  there will be seven segment and arrows to display its state and floor number ( i will hold this step now)

3- during going up somebody called the elevator to go down , but the elevator will complete it's first orders then stop and go down.

the same time that happens when going up will happen when going down if somebody in between top floor and bottom pressed a button it should stop and take him

4-if two buttons pressed at the same time go to the first one the elevator way (up or down)

5- when there are no requests the elevator is waiting at the last called floor and its door is opened .

6-when it is moving the doors should be closed and make sure it isn't opened . when the elevator  stopped at the called floor don't move if the door is opened

 

i think that's all for now. the problem here is that i don't know how to store requests during its moving
 

Last Edited: Fri. Nov 14, 2014 - 07:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My favourite design tools...

 

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mado88 wrote:
1-the elevator is at ground floor as a default then somebody calls it from nth floor during it's travel to up somebody in n-2 and n-3 called it so the elevator should go up to (n-3) floor then to (n-2) floor then to nth floor.

2-  there will be seven segment and arrows to display its state and floor number ( i will hold this step now)

3- during going up somebody called the elevator to go down , but the elevator will complete it's first orders then stop and go down.

the same time that happens when going up will happen when going down if somebody in between top floor and bottom pressed a button it should stop and take him

4-if two buttons pressed at the same time go to the first one the elevator way (up or down)

5- when there are no requests the elevator is waiting at the last called floor and its door is opened .

6-when it is moving the doors should be closed and make sure it isn't opened . when the elevator  stopped at the called floor don't move if the door is opened

Well, that's a list of requirements - but it is not a design.

 

(actually, stuff like "seven segment and arrows" is implementation detail; not requirements)

 

A set of requirements is a necessary starting point for a design - but it is not a design.

 

Quote:
the problem here is that i don't know how to store requests during its moving

No, that is not a problem here (at the start of the design phase); that is an implementation issue - for later.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1-the elevator is at ground floor as a default then somebody calls it from nth floor during it's travel to up somebody in n-2 and n-3 called it so the elevator should go up to (n-3) floor then to (n-2) floor then to nth floor.

2-  there will be seven segment and arrows to display its state and floor number ( i will hold this step now)

3- during going up somebody called the elevator to go down , but the elevator will complete it's first orders then stop and go down.

the same time that happens when going up will happen when going down if somebody in between top floor and bottom pressed a button it should stop and take him

4-if two buttons pressed at the same time go to the first one the elevator way (up or down)

5- when there are no requests the elevator is waiting at the last called floor and its door is opened .

6-when it is moving the doors should be closed and make sure it isn't opened . when the elevator  stopped at the called floor don't move if the door is opened

 

That's a great start.  You have written out an algorithm that describes the operation of the elevator.

It will work whether the elevator is 3 floors for 30 floors, so it is "easily" expandable.

 

Now start thinking about what information you have available, and what are the inputs and outputs for the micro and for the system.

Up and Down push buttons for every floor.

Floor buttons inside the elevator.

 

Simple outputs for a simulation:

A led for each floor, to show what floor the elevator is on.

If you build a time delay into the processing, you might want a couple of Leds for "going up" and "going down", etc.

 

Draw a diagram of your elevator and the various inputs and outputs.

 

Make a list of them.

 

Show both here.

 

JC

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

inputs and outputs for 5 floors

inputs:

the inside buttons are connected in parallel with the outside call button just one button for up and down so i show just the inside buttons

1- BUTTON_0 //push button for first floor inside the elevator
2-BUTTON_1
3-BUTTON_2
4-BUTTON_3
5-BUTTON_4 //push button for 5th floor

6- SENSOR_0 // proximity sensor in the first floor that will sense the elevator existence
7-SENSOR_1
8-SENSOR_2
9-SENSOR_3
10-SENSOR_4

outputs:
1-go up( for the motor control)

2- go down
3- fast (for the motor working with up or down) when it is far from requested floor
4-slow (for the motor working with up or down) when reached
5-seven segment display floor number
6 - up and down arrow
7- lock for the door
 

the algorithm and input and outputs ,every thing is here except the code

this is the basic requirements for the elevator then i will update it if needed.

Last Edited: Sat. Nov 15, 2014 - 09:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are 5 sets of outside up down buttons arent there? Need 10 more inputs?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:

There are 5 sets of outside up down buttons arent there? Need 10 more inputs?

no in the outside there will be just one button to call and it will be connected in hardware with the button inside in parallel to make OR . so when the inside or outside button calls the elevator should reply as it is one signal on the pin of the MCU. there is no need for more inputs

Last Edited: Sat. Nov 15, 2014 - 10:06 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely you need and up and down button on each floor though???

Last Edited: Sat. Nov 15, 2014 - 10:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess there is just one button on the bottom floor and the top floor. The middle 3 floors need up and down buttons, so you need 8 more inputs.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson has true,

 

I was designed some peripheral boards for lifts - and it is not so simply. There are a lot of standards, norms and regulations. Lift is safety critical system.

 

If are you begginer and this is shool project:

Try look on some "amateur" construction on internet like: https://courses.cit.cornell.edu/...

or: http://www.mass.gov/anf/docs/dca...

or another...