Wednesday, November 4, 2015

Simple Elevator simulation using 8051 micro controller and multisim

Have wonder any time how elevator works and keeps track of all the user interactions like key presses from inside the elevator and the key presses from the outside world. If your answer is yes this series of posts are for you.

Let start with very simple elevator which operates between two stairs. consider ground and first.
The basic ideology behind this elevator is only two switches are available outside and no switch is available. When the simulation starts the elevator is in ground floor.

The moment of the elevator depends on the switches available outside the elevator. The elevator is simulated with two bar led graphs. Ground floor is simulated using green color led graph and first stair is represented with red led bar graph.

when the switch one is open the micro controller receives the voltage and assumes the elevator has to go to ground floor. When the switch two is open the micro controller receives the voltage on second pin of the second port assuming elevator has to go for first stair.

The circuit is very basic so the switch has to be open till the elevator reaches the desired stair. when the simulation starts the elevator is in ground floor and the switches are closed representing the zero energy state.

once the simulation starts the user can play with the switches to simulate the elevator behavior.

If you closely observes the circuit you can observe one problem the switches are the simple switches they will stay in that position once the user presses them. The user has to reset the switch to the original position once the elevator reaches him/her.


The circuit is not designed to handle the interrupts. In next post I will explain how this simple circuit can be modified further to handle the more complex behavior. You can observe the circuit simulation in video.

Below is the code snippet used to program the mcu

#include <regx52.h>

#define floor0 P2_0
#define floor1 P2_1

void main ()
{
unsigned int pressed[2]; 
unsigned int i = 0;
P3 = 0xFF;
P1 = 0x00;
while(1)
{
for(i ; i< 50;i++);
if (floor0)
{
pressed[0] = 1;
}
else
{
pressed[0] = 0;
}
if (floor1)
{
pressed[1] = 1;
}
else
{
pressed[1] = 0;
}
if (pressed[1] == 1)
{
for(i= 0;i<10;i++);
P3_7 = 0;
P1_7 = 1;
for(i = 0;i<100;i++);
P3_6 = 0;
P1_6 = 1;
for(i = 0;i<100;i++);
P3_5 = 0;
P1_5 = 1;
for(i = 0;i<100;i++);
P3_4 = 0;
P1_4 = 1;
for(i = 0;i<100;i++);
P3_3 = 0;
P1_3 = 1;
for(i = 0;i<100;i++);
P3_2 = 0;
P1_2 = 1;
for(i = 0;i<100;i++);
P3_1 = 0;
P1_1 = 1;
for(i = 0;i<100;i++);
P3_0 = 0;
P1_0 = 1;
}
if (pressed[0] == 1)
{
P1_0 = 0;
P3_0 = 1;
for(i;i<100;i++);
P1_1 = 0;
P3_1 = 1;
for(i = 0;i<100;i++);
P1_2 = 0;
P3_2 = 1;
for(i = 0;i<100;i++);
P1_3 = 0;
P3_3 = 1;
for(i = 0;i<100;i++);
P1_4 = 0;
P3_4 = 1;
for(i = 0;i<100;i++);
P1_5 = 0;
P3_5 = 1;
for(i = 0;i<100;i++);
P1_6 = 0;
P3_6 = 1;
for(i = 0;i<100;i++);
P1_7 = 0;
P3_7 = 1;
}
}
}



DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...