salut á tous.
j'ai un devoir donc je devrai regulariser la distance grace á un moteur Pas-á-Pas.
pour cela je dispose d'un Laser qui me mesure la distance (0 - 255).
SVP comment pouvoir gerer le moteur en tenant compte aussi de la reponse que je recois du laser.
voici ce que j'ai fais
Code:library IEEE; use IEEE.STD_LOGIC_1164.ALL; --use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; use ieee.numeric_std.all; entity step_motor is port (SW1:in STD_LOGIC; --Reset-Signal CW_CCW: in STD_LOGIC; --sens clk5: in STD_LOGIC; --clock Enaeble: in STD_LOGIC; --permition manner: inout STD_LOGIC_VECTOR (1 downto 0); --Erregungsmodus -Wahlschalter Resultat : in STD_LOGIC_VECTOR (7 downto 0); --8 bit ce que je recois du laser Phase: out STD_LOGIC_VECTOR (3 downto 0)); --pour les sorties du moteur end step_motor; architecture stepmotor_arch of step_motor is signal angle: integer range 255 downto 0; -- signal count: integer range 0 to 7; -- signal cntInc: integer range -2 to 2; -- signal cc : integer range 0 to 3; signal cntIni: integer range -1 to 0; -- signal angleDnCount: integer range 255 downto 0; --angle signal angleDnCntDec: integer range 2 downto 1; begin process(clk5,SW1) begin If SW1='0' then manner<="00"; elsif(clk5'event and clk5 ='1')then manner <= manner + 1; End If; end process; process(CW_CCW, manner, angle)--, Enaeble) begin --if Enaeble='1' then angle <= to_integer(unsigned(Resultat)); --Get the input for PID from the 8_bit_Data in integer form cc <= to_integer(unsigned(manner)); if Enaeble = '1' then if CW_CCW='0' then case cc is when 1 => -- 1 --count<=0; cntIni<=0; cntInc<=2; angleDnCntDec<=2;--"10"; when 2 => -- 2 --count<=7; cntIni<=-1; cntInc<=2; angleDnCntDec<=2;--"10"; when 3 => -- 1 --count<=0; cntIni<=0; cntInc<=1; angleDnCntDec<=1;--"01"; when 0 => --manner="00" autodetect if (angle rem 2) =1 then -- 2- --count<=7; cntIni<=-1; cntInc<=2; angleDnCntDec<=2;--"10"; else -- 1- --count<=0; cntIni<=0; cntInc<=2; angleDnCntDec<=2;--"10"; end if; --angle end case; --manner else -- if CW_CCW='1' case cc is when 1 => -- 1-Phase Anregung --count<=0; cntIni<=0; cntInc<=-2; angleDnCntDec<=2;--"10"; when 2 => -- 2-Phase Anregung --count<=7; cntIni<=-1; cntInc<=-2; angleDnCntDec<=2;--"10"; when 3 => -- 1-2Phase Anregung --count<=0; cntIni<=0; cntInc<=-1; angleDnCntDec<=1;--"01"; when 0 => --manner="00" autodetect if (angle rem 2) = 1 then -- 2-Phase Anregung cntIni<=-1; cntInc<=-2; angleDnCntDec<=2;--"10"; else -- 1 Phase Anregung cntIni<=0; cntInc<=-2; angleDnCntDec<=2;--"10"; end if; --angle end case; --manner end if; -- else CW_CCW=0 end if; -- Enaeble end process; counting_reset: process(SW1,Enaeble, angle, clk5) begin if SW1='0' then count<=0; angleDnCount<=0; elsif clk5'event and clk5='1' then if Enaeble='0' then count<=0+ cntIni; angleDnCount<= angle; else count <= count+cntInc; if angleDnCount > angleDnCntDec then angleDnCount <= angleDnCount-angleDnCntDec; else angleDnCount <= 0; end if; end if; end if; end process; Phase <="0000" when angleDnCount=0 else "0001" when count=0 else "0011" when count=1 else "0010" when count=2 else "0110" when count=3 else "0100" when count=4 else "1100" when count=5 else "1000" when count=6 else "1001"; -- when count>=7; end stepmotor_arch;
-----