Forum Discussion
Altera_Forum
Honored Contributor
12 years agoHere is my new code:
library ieee;use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity StepperMotorController is
port(
stepper_clk_i :in std_logic;
Direction_i, Run_i, Halt_i:in std_logic;
winding1A_o,winding1B_o,winding2A_o,winding2B_o:out std_logic;
Led7,Led6,Led5,Led4:out std_logic;
LED7S : OUT STD_LOGIC_VECTOR (7 DOWNTO 0)
);
end entity StepperMotorController;
architecture structure of StepperMotorController is
signal speed_cntrl : unsigned (1 downto 0):="00"; -- initiaize with value 0
signal halt_cntrl, direction_cntrl: std_LOGIC:='1';
signal D,R,H,Done:std_LOGIC:='0';
signal counter:unsigned(2 downto 0):="000"; -- FROM 1 DOWN TO 0 > CHANGE TO 2 DOWN TO 0
signal clk_12Hz, clk_6Hz, clk_3Hz, stepper_clk:std_logic; -- create a 3Hz clock for 1:2:3 speed
signal step : unsigned (2 downto 0); -- Stes go from 0 to 7 steps = TOTAL 8 STEPS
signal count:integer range 0 to 10:=0;
signal windings:std_logic_vector(3 downto 0);
constant STEP1: std_logic_vector(3 downto 0):="1000"; -- for 15 degrees we need 8 steps which get repeated
constant STEP2: std_logic_vector(3 downto 0):="1010";
constant STEP3: std_logic_vector(3 downto 0):="0010";
constant STEP4: std_logic_vector(3 downto 0):="0110";
constant STEP5: std_logic_vector(3 downto 0):="0100";
constant STEP6: std_logic_vector(3 downto 0):="0101";
constant STEP7: std_logic_vector(3 downto 0):="0001";
constant STEP8: std_logic_vector(3 downto 0):="1001";
begin
winding1A_o <=windings(3);
winding2A_o <=windings(1);
winding1B_o <=windings(2);
winding2B_o <=windings(0);
clk_12Hz <= STD_LOGIC(counter(0));
clk_6Hz <= STD_LOGIC(counter(1));
clk_3Hz <= STD_LOGIC(counter(2));
-- led7<=speed_cntrol(1);
-- led6<=speed_cntrol(0);
-- led7<=clk_12Hz;
-- led6<=clk_6Hz;
-- led5<=clk_3Hz;
SPEED_BOX: process(stepper_clk_i) is
begin
if rising_edge(stepper_clk_i) then
counter<=counter+1;
end if;
end process;
SPEED_SELECT: with speed_cntrl select
stepper_clk <= clk_12Hz when "00",
clk_6Hz when "01",
clk_3Hz when others;-- on 2 it will get 3Hz.
SPEED_DISPLAY: process (halt_cntrl,speed_cntrl) IS
begin
if halt_cntrl='1' then
LED7S <=not "01110110"; -- 'H'
elsif speed_cntrl="00" then
LED7S<= not "01001110"; --'F'
elsif speed_cntrl="01" then
LED7S<= not "00111110";--'|-|
else
LED7S<= not "01101101";-- 'S'
end if; -----.gfedcba 1low - 0 - high
end process;
STEPPER_SEQUENCER: process(stepper_clk) is
begin
if rising_edge(stepper_clk) then
if halt_cntrl='0' then
if direction_cntrl='1' then
step <= step+1;
else
step <= step-1;
end if;
end if;
end if;
end process;
COIL_DRIVER: with step select
windings <= STEP1 when "000",
STEP2 when "001",
STEP3 when "010",
STEP4 when "011",
STEP5 when "100",
STEP6 when "101",
STEP7 when "110",
STEP8 when "111",
"0000" when others;
CONTROL: process(stepper_clk_i) is
begin
if rising_edge(stepper_clk_i) then
if rising_edge(clk_6Hz) then
if count=9 then
count<=1;
elsif Direction_i='1' and halt_cntrl='0' then
count<=0;
D<='1';
elsif Run_i='1' and halt_cntrl='0' then
count<=0;
R<='1';
elsif Halt_i<='1' then
count<=0;
H<='1';
else
if Done='1' then
if D='1' OR R='1' OR H='1' then
D<='0';
R<='0';
H<='0';
end if;
end if;
count<=count+1;
end if;
end if;
end if;
end process CONTROL;
ACTION: process (stepper_clk_i) is
begin
if count>5 then
if D='1' then
direction_cntrl<=not direction_cntrl;
Done<='1';
elsif R='1' then
if halt_cntrl='1' then
halt_cntrl<='0';
Done<='1';
else
speed_cntrl<=speed_cntrl+1;
Done<='1';
end if;
elsif H='1' then
Halt_cntrl<='1';
Done<='1';
else
Done<='0';
end if;
END IF;
end process;
END structure; new error: error (10821): hdl error at steppermotorcontroller.vhd(100): can't infer register for "d" because its behavior does not match any supported register model
same error goes for h,r and count signal.