Altera_Forum
Honored Contributor
12 years agoWhat should I use here - Need changing value in different processes
Hi, first post here and very poor VHDL knowledge. Tried my best but can't figure this out. Here is my problem:
I have 3 buttons. When any one is pressed I want to reset a corresponding variable/signal AND one (counter) or something to zero, the counter is connected to 3Hz clock. Clock works fine. Another process acts on clock ticks and increment the counter. When counter reaches a certain value the corresponding value which was set at button press gets acted upon. SO, this way I want to create a delay between button press and action (trying to avoid the debouncing and million other errors which were there before). The problem: I do not know which type of variable/signal to use for counter and the other corresponding value related to which button is pressed. I tried making both signals, it didn;t worked, error appeared about resolving multiple constant drivers. Tried with variable, same error. Can some one pleaseeeeee help me?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';
shared variable D,R:integer:=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);
-- led7<=speed_cntrol(1);
-- led6<=speed_cntrol(0);
-- led7<=clk_12Hz;
-- led6<=clk_6Hz;
-- led5<=clk_3Hz;
SPEED_BOX: process(stepper_clk_i) is
variable counter:unsigned(2 downto 0):="000"; -- FROM 1 DOWN TO 0 > CHANGE TO 2 DOWN TO 0
begin
if rising_edge(stepper_clk_i) then
counter:=counter+1;
end if;
clk_12Hz <= STD_LOGIC(counter(0));
clk_6Hz <= STD_LOGIC(counter(1));
clk_3Hz <= STD_LOGIC(counter(2));
end process;
COUNT_DELAY: process (clk_3Hz) is
begin
count:=count+1;
end process;
COUNT_ACTION: process (clk_3Hz) is
begin
if count=3 then
if D=1 then
direction_cntrl<=not direction_cntrl;
elsif R=1 then
speed_cntrl<=speed_cntrl+1;
else
D:=0;
R:=0;
end if;
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(Direction_i,Run_i,Halt_i) is
begin
if Direction_i='1' then
if halt_cntrl='0' then
count:=0;
D:=1;
end if;
elsif (Run_i='1') then
if halt_cntrl='1' then
halt_cntrl<='0';
else
count:=0;
R:=1;
end if;
elsif (Halt_i='1') then
halt_cntrl<='1';
end if;
end process CONTROL;
END structure;