SUBSTRACTOR

by billychen102 in Circuits > Computers

61 Views, 0 Favorites, 0 Comments

SUBSTRACTOR

unknown11.png

As the name stated, its function nonetheless from subtracting one value from the other value. In this case, it is to calculate the subtraction of both previous and present state values. We can get the previous state value from the result of the shift registers. Meanwhile, we can get the present state value directly from the output of the counter.

Other than that, this subtractor has another function to determine not just the subtraction of both values but the direction of the motor. It is shown by comparing the previous state value and the present state value. If the present state value is bigger than the previous state value, we can say that it goes in one direction. Suppose that when the present state value is bigger than the previous state value, the motor goes CCW, then if the present state value is smaller than the previous state value, it will go CW.

Click HERE for the code sample

Supplies

We recommend to code with ISE Design Suite 14.7 as it can also be used to test the code in VHDL. However, to upload the code into BASYS 3, you will need to install Vivado (ver. 2015.4 or 2016.4) and write the constraint file with .xdc extension.

INPUT, INTERNAL SIGNAL AND OUTPUT

INPUT :

clk62hz : in STD_LOGIC; ( for the clock of the system)

RST : in STD_LOGIC; (For resetting the system)

Count_kiri : in STD_LOGIC_Vector(7 downto 0); (input from encoder)

Count_kanan : in STD_LOGIC_Vector(7 downto 0); (input from encoder)

INTERNAL SIGNAL :

signal after_1 : STD_LOGIC_VECTOR(7 downto 0); (previous state value)

signal before_1 : STD_LOGIC_VECTOR(7 downto 0); (present state value)

signal after_2 : STD_LOGIC_VECTOR(7 downto 0); (previous state value)

signal before_2 : STD_LOGIC_VECTOR(7 downto 0); (present state value)

signal hasil_pengurangan_1 : STD_LOGIC_VECTOR(7 downto 0); (the value after substraction)

signal hasil_pengurangan_2 : STD_LOGIC_VECTOR(7 downto 0); (the value after substraction)

OUTPUT :

PWM_kiri: out STD_LOGIC_Vector(7 downto 0); (feedback value for the error management code)

PWM_kanan: out STD_LOGIC_Vector(7 downto 0); (feedback value for the error management code)

direction_L : out STD_LOGIC; (feedback direction for the error management code)

direction_R : out STD_LOGIC; (feedback direction for the error management code)

Click HERE for the code sample

HOW IT WORKS

The input of the code will be in the form of 8-bit unsigned integers. Meanwhile, the output of the code consists of 2 types of data. One goes for 8-bit unsigned integers for the feedback value of the code, and the other goes for the high and low signal. The input then will be shifted using the shift registers. This subtractor will simply subtract the value before going through the shift register and the value after going through the shift register.