soloktanjung
Full Member level 6
guys,
can anyone explain to me the function of the signal count_motor in this code. is it equivalent to the state (state machine)? this code i got from a book. i need to understand this code because it is part of my design project.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY MOTOR_CONTROL IS
PORT ( clk_1khz : IN STD_LOGIC;
lmotor_dir, rmotor_dir : IN STD_LOGIC;
lmotor_speed, rmotor_speed : IN STD_LOGIC;
lmotor, rmotor : OUT STD_LOGIC):
END MOTOR_CONTROL;
ARCHITECTURE BEHAVIOR OF MOTOR_CONTROL IS
SIGNAL count_motor : STD_LOGIC_VECTOR (4 DOWNTO 0);
BEGIN
PROCESS
BEGIN
WAIT UNTIL clk_1khz’EVENT AND clk_1khz = ‘1’;
IF count_motor /=19 THEN
count_motor <= count_motor+1;
ELSE
Count_motor=”00000”;
END IF;
IF count_motor=17 THEN
--don’t generate any pulse
IF lmotor_speed = ‘0’ THEN
lmotor<=’0’;
ELSE
lmotor<=’1’;
END IF;
IF rmotor_speed = ‘0’ THEN
rmotor<=’0’;
ELSE
rmotor<=’1’;
END IF;
ELSEIF count_motor=18 THEN
IF lmotor_speed=’1’ THEN
CASE lmotor_dir IS
--FORWARD
WHEN ‘0’=>
lmotor<=’1’;
--reverse
WHEN ‘1’=>
lmotor<=’0’;
WHEN OTHERS=> NULL;
END CASE;
ELSE
Lmotor<=’0’;
END IF;
IF rmotor_speed=’1’ THEN
CASE rmotor_dir IS
--FORWARD
WHEN ‘0’=>
rmotor<=’0’;
--reverse
WHEN ‘1’=>
rmotor<=’1’;
WHEN OTHERS=> NULL;
END CASE;
ELSE
Lmotor<=’0’;
END IF;
ELSE
Lmotor<=’0’;
Rmotor<=’0’;
END IF;
END PROCESS;
END BEHAVIOR;
thanks in advance.
regards,
hairo
can anyone explain to me the function of the signal count_motor in this code. is it equivalent to the state (state machine)? this code i got from a book. i need to understand this code because it is part of my design project.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_ARITH.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY MOTOR_CONTROL IS
PORT ( clk_1khz : IN STD_LOGIC;
lmotor_dir, rmotor_dir : IN STD_LOGIC;
lmotor_speed, rmotor_speed : IN STD_LOGIC;
lmotor, rmotor : OUT STD_LOGIC):
END MOTOR_CONTROL;
ARCHITECTURE BEHAVIOR OF MOTOR_CONTROL IS
SIGNAL count_motor : STD_LOGIC_VECTOR (4 DOWNTO 0);
BEGIN
PROCESS
BEGIN
WAIT UNTIL clk_1khz’EVENT AND clk_1khz = ‘1’;
IF count_motor /=19 THEN
count_motor <= count_motor+1;
ELSE
Count_motor=”00000”;
END IF;
IF count_motor=17 THEN
--don’t generate any pulse
IF lmotor_speed = ‘0’ THEN
lmotor<=’0’;
ELSE
lmotor<=’1’;
END IF;
IF rmotor_speed = ‘0’ THEN
rmotor<=’0’;
ELSE
rmotor<=’1’;
END IF;
ELSEIF count_motor=18 THEN
IF lmotor_speed=’1’ THEN
CASE lmotor_dir IS
--FORWARD
WHEN ‘0’=>
lmotor<=’1’;
--reverse
WHEN ‘1’=>
lmotor<=’0’;
WHEN OTHERS=> NULL;
END CASE;
ELSE
Lmotor<=’0’;
END IF;
IF rmotor_speed=’1’ THEN
CASE rmotor_dir IS
--FORWARD
WHEN ‘0’=>
rmotor<=’0’;
--reverse
WHEN ‘1’=>
rmotor<=’1’;
WHEN OTHERS=> NULL;
END CASE;
ELSE
Lmotor<=’0’;
END IF;
ELSE
Lmotor<=’0’;
Rmotor<=’0’;
END IF;
END PROCESS;
END BEHAVIOR;
thanks in advance.
regards,
hairo