CPLD读取光栅尺的值
时间:10-02
整理:3721RD
点击:
我写了个程序读光栅尺的值,我用示波器测输出,没有电平输出,苦恼中,求大神帮帮忙,在线等。
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY Meas IS
PORT( MeasIn: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
Clk: IN STD_LOGIC;
-- Updown: IN STD_LOGIC;
Count: OUT STD_LOGIC
);
END Meas;
--------------------------------------------------------------
ARCHITECTURE Rt1 OF Meas IS
CONSTANT Stata0: STD_LOGIC_VECTOR:="00";
CONSTANT Stata1: STD_LOGIC_VECTOR:="10";
CONSTANT Stata2: STD_LOGIC_VECTOR:="11";
CONSTANT Stata3: STD_LOGIC_VECTOR:="01";
--------------------------------------------------------------
SIGNAL Oldstata: STD_LOGIC_VECTOR(1 DOWNTO 0);
SIGNAL Temp0: STD_LOGIC;
SIGNAL Temp1: STD_LOGIC;
SIGNAL Temp2: STD_LOGIC;
--------------------------------------------------------------
BEGIN
PROCESS
BEGIN
WAIT UNTIL Clk = '1';
IF MeasIn = Stata0 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
ELSIF MeasIn = Stata1 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
ELSIF MeasIn = Stata2 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
ELSIF MeasIn = Stata3 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
END IF;
END PROCESS;
END Rt1;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY Meas IS
PORT( MeasIn: IN STD_LOGIC_VECTOR(1 DOWNTO 0);
Clk: IN STD_LOGIC;
-- Updown: IN STD_LOGIC;
Count: OUT STD_LOGIC
);
END Meas;
--------------------------------------------------------------
ARCHITECTURE Rt1 OF Meas IS
CONSTANT Stata0: STD_LOGIC_VECTOR:="00";
CONSTANT Stata1: STD_LOGIC_VECTOR:="10";
CONSTANT Stata2: STD_LOGIC_VECTOR:="11";
CONSTANT Stata3: STD_LOGIC_VECTOR:="01";
--------------------------------------------------------------
SIGNAL Oldstata: STD_LOGIC_VECTOR(1 DOWNTO 0);
SIGNAL Temp0: STD_LOGIC;
SIGNAL Temp1: STD_LOGIC;
SIGNAL Temp2: STD_LOGIC;
--------------------------------------------------------------
BEGIN
PROCESS
BEGIN
WAIT UNTIL Clk = '1';
IF MeasIn = Stata0 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
ELSIF MeasIn = Stata1 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
ELSIF MeasIn = Stata2 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
ELSIF MeasIn = Stata3 THEN
Oldstata <= MeasIn;
Temp0 <= MeasIn(0) XOR MeasIn(1);
Temp1 <= Oldstata(0) XOR Oldstata(1);
Temp2 <= Temp0 XOR Temp1;
IF Temp2 = '1' THEN
Count <= '1';
ELSIF Temp2 = '0' THEN
Count <= '0';
END IF;
END IF;
END PROCESS;
END Rt1;
已退回5积分