---------------------------------------------------------------------------------- -- Company: Cal Poly CPE 133 Project -- Engineer: -- -- Create Date: 11/13/2015 06:29:30 PM -- Design Name: -- Module Name: main_circuit - Behavioral -- Project Name: Solar Room Temperature Regulator -- Target Devices: -- Tool Versions: -- Description: This module is connected to the motor port to determine when the motor will move and in which direction. -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: This code was modifed from the code given by Simon Monk from Adafruit website. -- ---------------------------------------------------------------------------------- library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.NUMERIC_STD.ALL; entity Motor is Port ( mot_clk : in STD_LOGIC; --The clock frequency for the motor. sw_dir : in STD_LOGIC; --Inputs what direction the motor will turn. sw_enable : in STD_LOGIC; --Inputs when the motor will turn on to start turning. sw_speed : in STD_LOGIC; --Always set to '0'. -- All of the outputs below are just signals to the drivers. phase_a : out STD_LOGIC; phase_b : out STD_LOGIC; phase_c : out STD_LOGIC; phase_d : out STD_LOGIC); end Motor; architecture Behavioral of Motor is signal coils : STD_LOGIC_VECTOR(3 downto 0) := "0011"; --signal that actuates the drivers (phases). signal count : UNSIGNED(17 downto 0) := (others => '0'); --signal that controls the max value for step_count. signal step_count : UNSIGNED(15 downto 0) := (others => '0'); --signal that holds the count of the coils for the motor. begin phase_a <= coils(0); --All of the phase outputs are assigned to the coil values that were made from the process block below. phase_b <= coils(1); phase_c <= coils(2); phase_d <= coils(3); p: process(mot_clk) --This process controls the rate of accuation for the drivers. begin if rising_edge(mot_clk) then if count = 0 then if sw_enable = '1' then if sw_dir = '1' then coils <= coils(0) & coils(coils'high downto 1); step_count <= step_count + 1; else coils <= coils(coils'high-1 downto 0) & coils(coils'high); step_count <= step_count - 1; end if; end if; end if; -- Logic below controls the speed (we never used this portion below since we always had the speed set to '0', but you are more -- welcome to mess around with this portion for testing. if sw_speed = '1' and count = 512000-1 then -- 500 steps every second - fast count <= (others => '0'); elsif count = 256000-1 then -- 125 steps every second - slow count <= (others => '0'); else count <= count + 1; end if; end if; end process; end Behavioral;