We are simulating the operation of the elevator and dealing with the logic of up and down movement and door opening and closing. The simplest case is to press the button to input the floor signal. When the elevator moves to the floor, the door opens and closes. LED lights or digital tubes represent the elevator position; It’s a little more complicated. To traverse the remaining floors of the elevator, if I’m currently on the third floor and someone needs the elevator to open the door, then the elevator should go directly to the second floor instead of continuing to go up to the top floor and then do the down calculation. Single unit Elevators should be like this, and this is also a phenomenon in life. Then add a little peripheral motor to indicate that the elevator is going up, reverse rotation to indicate that the elevator is going down, and language broadcast to remind some situations, so we have the structure as shown below:
shake_top is a button debounce module. There are many buttons used in the design, so one module is used to encapsulate the debounce of the entire button. 10 independent buttons and 16 matrix buttons are used to differentiate the debounce signals and send them to the main control module.
Control is the main control module for elevator operation. Its main function is to detect the key signal to register the up and down requirements and when to open and close the door, and at the same time output some information.
control_uart_send is a serial port output control module, a voice device connected to a serial port. To drive this device, the serial port needs to send data according to certain requirements. This module receives three flag signals from the main control and determines whether it is “elevator up”, “elevator down”, or “Close the door please pay attention” and then process and send serial port data
UartSend is a serial port sending module. After receiving the enable and send data, it will send the data according to the serial port format. The Tx is externally connected to the input of the voice device.
Moster’s four-phase five-wire stepper motor control. This stepper motor is driven by four wires. According to certain requirements, I wrote the forward and reverse outputs separately, and then judged based on the signal from the main control. Whether it is valid to output the corresponding control
digital is a dynamic scanning module used to display the number of floors and time display
The difficulty of the design lies in the control of the elevator. The control code of the elevator logic is listed below.
//********State Machine************ //0: Determine whether the floor where the elevator is located is open based on the up and down directions. //1: 4 seconds door opening timer //2: 4 seconds on //3: 3 seconds door closing timer //4: Delay //5: Assign the starting value of the traversal address according to the upstream and downstream directions. //6: Traverse whether there is still a pre-opening state in this direction //7: Timing on the next floor always@(posedge clk or negedge rstn) begin if(!rstn)begin state <= 0; direction <= 1; count <= 0; lift_floor <= 0; c_time <= 0; reg_state4 <= 0; end else begin case(state) 0:begin if(direction)begin//Determine the direction, and then determine whether the current floor is open if(upbusy[lift_floor] || lift_busy[lift_floor])begin state <= 1; end else begin state <= 5; end end else begin if(downbusy[lift_floor] || lift_busy[lift_floor])begin state <= 1; end else begin state <= 5; end end reg_state4 <= 0; end 1:begin//Open the door if(c_time == 4 & amp; & amp; flag_1s)begin c_time <= 0; state <= 2; end else if(flag_1s)begin c_time <= c_time + 1; end end 2:begin//The door is open if(c_time == 8 & amp; & amp; flag_1s)begin c_time <= 0; state <= 3; end else if(quicken)begin c_time <= 0; state <= 3; end else if(flag_1s)begin c_time <= c_time + 1; end end 3:begin//Close the door if(c_time >= 4 & amp; & amp; flag_1s)begin c_time <= 0; state <= 4; end else if(suspend)begin c_time <= 0; end else if(flag_1s)begin c_time <= c_time + 1; end end 4:begin state <= 5; reg_state4 <= 1; end 5:begin state <= 6; if(direction)begin//Traverse floors and assign values count <= 7; end else begin count <= 0; end end 6:begin if(direction)begin if(count == lift_floor)begin//The floor traverses to the current floor, indicating that the elevator does not need to go up direction <= 0; count <= 0; state <= 0; end else if(upbusy[count] || lift_busy[count] || downbusy[count])begin//The elevator needs to go up state <= 7; count <= 7; end else begin count <= count-1; end end else begin if(count == lift_floor)begin direction <= 1; count <= 7; state <= 0; end else if(upbusy[count] || lift_busy[count] || downbusy[count])begin state <= 7; count <= 0; end else begin count <= count + 1; end end end 7:begin if(c_time == 2 & amp; & amp; flag_1s)begin//next floor count c_time <= 0; state <= 0; if(direction)begin lift_floor <= lift_floor + 1; end else begin lift_floor <= lift_floor-1; end end else if(flag_1s)begin c_time <= c_time + 1; end end default: state <= 0; endcase end end
B station video effecthttps://www.bilibili.com/video/BV1Ep4y177TR/Physical display (both development board and elevator module DIY it by yourself, if you need it, you can buy it from me)