Forum Discussion
Altera_Forum
Honored Contributor
12 years ago --- Quote Start --- Plenty of errors, for now I suggest: those three assignments underneath [counter := counter + 1;] should be outside process process for count needs clock edge values of count, D,R should be settled each in its process --- Quote End --- Thanks. Did the above. 1) Variable counter changed to shared variable outside the process and declared there. 2) statements assigning clock12/6/3 to counter are put outside the process. 3) No idea of how to implement 3.
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';
shared variable D,R:integer:=0;
shared variable 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
shared variable count:integer:=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;
COUNT_DELAY: process (clk_3Hz) is
begin
count:=count+1;
end process;
.
.
.
.
.
.
.