LIBRARY ieee ;
USE ieee.std_logic_1164.all;
ENTITY digital_filter IS
PORT (
CHA_inp : IN std_logic;
CHB_inp : IN std_logic;
Clk : IN std_logic;
RST : IN std_logic;
CHA_out : OUT std_logic;
CHB_out : OUT std_logic
);
END digital_filter;
Quanto deve essere la frequenza di Clk per poter leggere tranquillamente gli impulsi
degli encoder con risoluzione di 500 impulsi per giro che vanno ad una velocità di 6000 RPM?
module quad(clk, quadA, quadB, count);
input clk, quadA, quadB;
output [7:0] count;
reg quadA_delayed, quadB_delayed;
always @(posedge clk) quadA_delayed <= quadA;
always @(posedge clk) quadB_delayed <= quadB;
wire count_enable = quadA ^ quadA_delayed ^ quadB ^ quadB_delayed;
wire count_direction = quadA ^ quadB_delayed;
reg [7:0] count;
always @(posedge clk)
begin
if(count_enable)
begin
if(count_direction) count<=count+1; else count<=count-1;
end
end
endmodule
----------------------------------------------------
-- Encoder Digital filter
-- G. De Luca - INFN-LNS
-- 27/12/2010
-- non per usi commerciali - solo per studio
----------------------------------------------------
LIBRARY ieee ;
USE ieee.std_logic_1164.all;
ENTITY digital_filter IS
PORT (
CHA : IN std_logic;
CHB : IN std_logic;
Clk : IN std_logic;
RST : IN std_logic;
CHA_filt : OUT std_logic;
CHB_filt : OUT std_logic
);
END digital_filter;
ARCHITECTURE arch_digital_filter OF digital_filter IS
SIGNAL temp_CHA: std_logic;
SIGNAL temp_CHB: std_logic;
BEGIN
---------------------------------------------------
Channel_A:PROCESS(CLK, RST)
VARIABLE Afilter: std_logic_vector(0 to 3);
BEGIN
IF RST = '0' THEN
Afilter := "0000";
temp_CHA <= '0';
ELSIF (CLK'event AND CLK = '1') THEN
Afilter(1 to 3) := Afilter(0 to 2);
Afilter(0) := CHA;
IF Afilter(1 to 3) = "000" THEN
temp_CHA <= '0';
END IF;
IF Afilter(1 to 3) = "111" THEN
temp_CHA <= '1';
END IF;
END IF;
END PROCESS;
CHA_filt <= temp_CHA;
--------------------------------------------------
Channel_B:PROCESS(CLK, RST)
VARIABLE Bfilter: std_logic_vector(0 to 3);
BEGIN
IF RST = '0' THEN
Bfilter := "0000";
temp_CHB <= '0';
ELSIF (CLK'event AND CLK = '1') THEN
Bfilter(1 to 3) := Bfilter(0 to 2);
Bfilter(0) := CHB;
IF Bfilter(1 to 3) = "000" THEN
temp_CHB <= '0';
END IF;
IF Bfilter(1 to 3) = "111" THEN
temp_CHB <= '1';
END IF;
END IF;
END PROCESS;
CHB_filt <= temp_CHB;
--------------------------------------------------
END arch_digital_filter;
LIBRARY ieee ;
USE ieee.std_logic_1164.all;
ENTITY digital_filter IS
PORT (
CH : IN std_logic_vector(0 to 1);
Clk : IN std_logic;
CH_filt : OUT std_logic_vector(0 to 1)
);
END digital_filter;
ARCHITECTURE arch_digital_filter OF digital_filter IS
SIGNAL temp_CH: std_logic_vector(0 to 1);
BEGIN
Channel:PROCESS(CLK)
VARIABLE filter: std_logic_vector(0 to 7);
BEGIN
IF (CLK'event AND CLK = '1') THEN
for i in 0 to 1 loop
filter((i*4)+1 to (i*4)+3) := filter((i*4) to (i*4)+2);
filter(i*4) := CH(i);
IF filter((i*4)+1 to (i*4)+3) = "000" THEN
temp_CH(i) <= '0';
END IF;
IF filter((i*4)+1 to (i*4)+3) = "111" THEN
temp_CH(i) <= '1';
END IF;
end loop;
END IF;
END PROCESS;
CH_filt <= temp_CH;
END arch_digital_filter;
LIBRARY ieee ;
USE ieee.std_logic_1164.all;
ENTITY digital_filter IS
PORT (
CH : IN std_logic_vector(0 to 5); -- for number of channels
CH_filt : OUT std_logic_vector(0 to 5); -- change CH and CH_filt
Clk : IN std_logic
);
END digital_filter;
ARCHITECTURE arch_digital_filter OF digital_filter IS
constant NUM_CHANNELS: integer := 5; -- NUM_CHANNELS base 0
SIGNAL temp_CH: std_logic_vector(0 to NUM_CHANNELS);
BEGIN
Channel:PROCESS(CLK)
VARIABLE filter: std_logic_vector(0 to ((NUM_CHANNELS+1)*4)-1);
BEGIN
IF (CLK'event AND CLK = '1') THEN
for i in 0 to NUM_CHANNELS loop
filter((i*4)+1 to (i*4)+3) := filter((i*4) to (i*4)+2);
filter(i*4) := CH(i);
IF filter((i*4)+1 to (i*4)+3) = "000" THEN
temp_CH(i) <= '0';
END IF;
IF filter((i*4)+1 to (i*4)+3) = "111" THEN
temp_CH(i) <= '1';
END IF;
end loop;
END IF;
END PROCESS;
CH_filt <= temp_CH;
END arch_digital_filter;
ENTITY digital_filter IS
generic(
NUM_CHANNELS : integer := 5 -- NUM_CHANNELS+1 base 0
);
PORT (
CH : IN std_logic_vector(0 to NUM_CHANNELS); -- for number of channels
CH_filt : OUT std_logic_vector(0 to NUM_CHANNELS); -- change CH and CH_filt
Clk : IN std_logic
);
END digital_filter;
ARCHITECTURE arch_digital_filter OF digital_filter IS
SIGNAL temp_CH : std_logic_vector(0 to NUM_CHANNELS):=(others=>'0');
BEGIN
filtri:for i in 0 to NUM_CHANNELS generate
signal filter: std_logic_vector(0 to 3):=(others=>'0');
begin
Channel:PROCESS(CLK)
BEGIN
IF (CLK'event AND CLK = '1') THEN
filter(1 to 3) <= filter(0 to 2);
filter(0) <= CH(i);
IF filter(1 to 3) = "000" THEN
temp_CH(i) <= '0';
END IF;
IF filter(1 to 3) = "111" THEN
temp_CH(i) <= '1';
END IF;
END IF;
END PROCESS;
end generate;
CH_filt <= temp_CH;
END arch_digital_filter;
Users browsing this forum: No registered users and 28 guests