2013-07-04 3 views
0

SPI를 통해 LTC2426 DAC와의 통신을 시도 했으므로 missrebly에 실패했습니다. 지금 나는 도움을 구하고있다. 누군가 내 코드가 작동하지 않는 이유를 말해 줄 수 있습니까? CSDAC가 올바르게 작동하고 SCLK가 생성되고 32 비트가 전송되지만 여전히 타이밍을 망칠 수 있습니다. 누군가가 제가 코드를 수정하도록 도와 주신다면 매우 감사 할 것입니다.vhdl에서 SPI 버스를 구현하려고 시도했습니다.

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

entity DAC is 
    port 
     (
      CLK : in STD_LOGIC;   
      SCLK : out STD_LOGIC; 
      MOSI : out STD_LOGIC; 
      CSDAC : out STD_LOGIC := '1'   
     ); 
end DAC; 

architecture Behavioral of DAC is 
Signal Counter : Integer range 0 to 32 := 0; 
Signal CurrentBit : Integer range 0 to 32 := 0; 
Signal DataSent : STD_LOGIC := '1'; 
Constant Data : STD_LOGIC_VECTOR(31 downto 0) := X"0030FFF0"; 
Signal Slope : STD_LOGIC := '0'; 
begin 
Prescaler : process(CLK) 
begin 
    if rising_edge(CLK) then 
     if Counter = 5 then 
      Slope <= not(Slope); 
      Counter <= 0; 
     else 
      Counter <= Counter + 1; 
     end if; 
    end if; 
end process; 
SCLK <= SLOPE; 
WriteDac : process(CLK) 
begin 
    if rising_edge(CLK) then 
     if DataSent = '1' then 
      if CurrentBit <= 31 then 
       CSDAC <= '0'; 
       MOSI <= Data(CurrentBit); 
       CurrentBit <= CurrentBit +1; 
      else 
       CSDAC <= '1';  
       DataSent <= '0';     
      end if; 
     end if; 
    end if; 
end process; 
end Behavioral; 

편집 : NEW CODE

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.STD_LOGIC_ARITH.ALL; 
use IEEE.STD_LOGIC_UNSIGNED.ALL; 

entity DAC is 
    port 
     (
      CLK : in STD_LOGIC;   
      SCLK : out STD_LOGIC; 
      MOSI : out STD_LOGIC; 
      DEBUG : out STD_LOGIC := '1'; 
      CSDAC : out STD_LOGIC := '1'   
     ); 
end DAC; 

architecture Behavioral of DAC is 
Signal Counter : Integer range 0 to 6 := 0; 
Signal Counter2 : Integer range 0 to 33 := 0; 
Signal CurrentBit : Integer range 0 to 33 := 0; 
Signal Fixed : STD_LOGIC := '0'; 
Signal DataSent : STD_LOGIC := '0'; 
Constant Data : STD_LOGIC_VECTOR(31 downto 0) := X"0FFF0C00"; 
Signal Slope_last : STD_LOGIC := '0'; 
Signal Slope : STD_LOGIC := '0'; 
Signal MSS : STD_LOGIC := '0'; 
begin 

WriteDac : process(CLK) 
begin 
    if rising_edge(CLK) then 
     if Counter = 5 then 
      Slope_last <= Slope; 
      Slope <= not(Slope); 
      if Slope_last = '1' and Slope = '0' then 
       if Fixed = '1' then 
        if DataSent = '0' then 
         if CurrentBit <= 31 then 
          CSDAC <= '0'; 
          DEBUG <= '0'; 
          MOSI <= Data(CurrentBit); 
          CurrentBit <= CurrentBit +1; 
         else 
          MOSI <= '0'; 
          CSDAC <= '1'; 
          DEBUG <= '1'; 
          DataSent <= '1'; 
         end if; 
        end if; 
       else 
        if Counter2 <= 31 then 
         CSDAC <= '1'; 
         DEBUG <= '1'; 
         Counter2 <= Counter2 + 1; 
         MSS <= not(MSS); 
         MOSI <= MSS; 
        else 
         Fixed <= '1'; 
         MOSI <= '0'; 
        end if; 
       end if; 
      end if; 
     else 
      Counter <= Counter + 1; 
     end if; 
    end if; 
end process; 
SCLK <= SLOPE; 

end Behavioral; 

내가 SCLK가 회복 비트의 몇 가지를 보낼 때 때문에이 MOSI을 펄싱하고 있습니다. 첫 번째 SCLK는 약 1.4 mhz에서 작동합니다. 모스를 펄스하면 4.167MHZ로 복구됩니다. 1.4mhz가되면 1.5mhz가 될 수 있으므로 너무 좋지 않습니다.

답변

0

두 번째 프로세스가 SCLK (또는 슬로프) i.s.o에 민감해야합니다. CLK? SPI 모듈의 몇 가지 예를 보려면 opencores.org을 확인할 수 있습니다. Verilog로 작성된 경우에도, 어떻게하면 일을 할 수있는 좋은 예가 될 수 있습니다.

+0

@baldyHDL이 더 좋은 답변입니다. 하나의 프로세스에 코드를 추가하는 것이 좋습니다. FSM을 구축하는 것도 생각할 수 있습니다. 약간의 과장이 현재의 필요하지만, 솔루션은 항상 좀 더 복잡한 시간이 지나면 :-) – vermaete

0

SCK 관련 비트 카운터 (CurrentBit)를 업데이트해야합니다. 예 :

... 
WriteDac : process(CLK) 
begin 
    if rising_edge(CLK) then 
     slope_last<=slope; 

     if slope_last='1' and slope='0' then -- e.g. falling edge! 
      if DataSent = '1' then 
... 
+0

내 코드를 기반으로 귀하의 recomendation 내 로직 분석기는 SPI 버스를 디코딩하지만 lt2624 여전히 나던 작동합니다. 내 새 코드는 몇 분 안에 올 것입니다 – user150374

+0

시뮬레이터를 사용합니까? 예 : Lite 시뮬레이터가 포함 된 Xilinx WebPack (무료)을 사용하십시오. 시뮬레이션을 통해 명백한 오류를 찾을 수 있습니다. 예 : 새 코드 "if counter = 5 then"행 다음에 "Counter"를 0으로 재설정해야합니다. – baldyHDL

+0

보드를 직접 프로그래밍하고 logic8 논리 분석기를 연결하십시오. – user150374