Introduction: Motor Control Encoder
An essential part of a rotational component in robotics, the encoder is a sensor that encodes angle and linear displacement and is often used in speed and position control. This type of sensor that's mounted on an electric motor provides feedback for the control system to read. Usually, motor encoders are installed on industrial robotic arms, that often require a good precision and fast reaction, to comply with the speed of the production line, and can be found in many heavy operations such as crane lifting and stone crushing.
The code that we made uses an AB system that is preset for the state machine that remembers the previous condition of the pulses from the position encoder motor is in, so we have 4 states in total which are "S00", "S01", "S11", and "S10". We can set the present state as an internal signal and also the next state as an internal signal. We also made a reset input just in case we need to reset the system. The up_en and the Dwn_en of the next state is used to determine the direction of the motor, is going clockwise or counterclockwise.
Step 1: Signal Inputs and Outputs
In this part, we will present the main input and output of the code used in the operation
INPUT
CLOCK : in STD_LOGIC; --(Used in timing for both components)
RST : in STD_LOGIC; --(Resetting both components)
A1 : in STD_LOGIC; --(Used in the left encoder)
B1 : in STD_LOGIC; --(Used in the left encoder)
A2 : in STD_LOGIC; --(Used in the right encoder)
B2 : in STD_LOGIC; --(Used in the right encoder)
OUTPUT
Up_en1 : out STD_LOGIC; --(Used in the left encoder)
Dwn_en1 : out STD_LOGIC; --(Used in the left encoder)
Up_en2 : out STD_LOGIC; --(Used in the right encoder)
Dwn_en2 : out STD_LOGIC); --(Used in the right encoder)
INTERNAL SIGNAL
signal A1B1: std_logic_vector (1 downto 0);
signal present_state1, next_state1: state_type1; --(Used in the left encoder)
signal present_state2, next_state2: state_type2; --(Used in the right encoder)
Step 2: How Does It Works?
Encoders turn physical movements into closed-loop feedback signals. The signal sent is used to monitor a certain parameter such as RPM, position, distance, and speed. This signal reading was possible through the use of a certain circular pattern, where the position of "terminals" is slightly misaligned. The encoder determines the direction the disk is spinning, via the pattern that acts as a switch. For example, when rotating clockwise, terminal A will hit high first, followed by terminal B. The opposite will happen if the disk spins counter-clockwise

