0

我正在为野马的连续尾灯编写代码,但我正在使用 Llights 和 Rlights 获得闩锁。按照我的逻辑应该没有问题。

----------------------------------------------------------------------------------
-- Company:        Pony incorporated
-- Engineer:       Pony
-- 
-- Create Date:    17:41:27 10/23/2013 
-- Design Name: 
-- Module Name:    Mustang_FSM - Behavioral 
-- Project Name: 
-- Target Devices: Spartan 6 (Nexys 3 Digilent board)
-- Tool versions:  ISE Webpack v14.6
-- Description:    Using a Moore FSM, define the sequential tail
--                 lights found on a Ford Mustang. Look at the
--                 following video:
--                 https://www.youtube.com/watch?v=KVFA-HuikfY
-- Dependencies:   None
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: The realization of the Moore FSM is based
--                      on the template described by your teacher
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Mustang_FSM is
    Port ( Lturn     : in   STD_LOGIC;
           Rturn     : in   STD_LOGIC;
           Hazard    : in   STD_LOGIC;
           Rst       : in   STD_LOGIC;
              Break     : in   STD_LOGIC;
           Clk100MHz : in   STD_LOGIC;
           Llights   : out  STD_LOGIC_VECTOR (2 downto 0);
           Rlights   : out  STD_LOGIC_VECTOR (0 to 2));
end Mustang_FSM;

architecture Behavioral of Mustang_FSM is
  -- Definition of embedded signals and constants
  -- Constants used for frequency division
  constant Fosc    : integer := 100000000;   --Frecuencia del oscilador de tabletas NEXYS 3
  constant Fdiv    : integer := 4;           --Frecuencia deseada del divisor
  constant CtaMax  : integer := Fosc / Fdiv; --Cuenta maxima a la que hay que llegar
  -- Signal used by the frequency division process
  signal Cont      : integer range 0 to CtaMax;
  signal Clk_En    : STD_LOGIC;

  -- State definition for the FSM
  -- Binary encoding (default) will be used 
  -- Equivalent of enumeration types in programming languages  
   type state_values is (ST0,ST1,ST2,ST3,ST4,ST5,ST6,ST7, ST8);
   signal pres_state, next_state: state_values;

  -- One hot state coding
  -- ONE HOT ENCODED state machine: Sreg0
--  subtype Sreg0_type is std_logic_vector(7 downto 0);
--  constant ST0: Sreg0_type := "00000001";
--  constant ST1: Sreg0_type := "00000010";
--  constant ST2: Sreg0_type := "00000100";
--  constant ST3: Sreg0_type := "00001000";
--  constant ST4: Sreg0_type := "00010000";
--  constant ST5: Sreg0_type := "00100000";
--  constant ST6: Sreg0_type := "01000000";
--  constant ST7: Sreg0_type := "10000000";
--  signal pres_state, next_state: Sreg0_type;

  -- Used to concatenate Lturn, Rturn and Hazard for easier
  -- handling
  signal LRH       : STD_LOGIC_VECTOR (3 downto 0);

begin
  -- Frequency divider to obtain a 2Hz signal from
  -- the 100 MHz board oscillator
  FreqDiv: process (Rst, Clk100MHz)
  begin
    if Rst = '1' then
       Cont <= 0;
     elsif (rising_edge(Clk100MHz)) then
       if Cont = CtaMax - 1 then
        Cont      <= 0;
        Clk_En    <= '1';
      else        
         Cont      <= Cont + 1;
          Clk_En    <= '0';
        end if;
    end if;
  end process FreqDiv;

  -- The FSM definition begins next

  -- "Current State Register" (StateReg) description
  StateReg: process (Clk100MHz,Clk_En,Rst)
  begin
    if (Rst = '1') then 
      pres_state <= ST0;
    elsif (rising_edge(Clk100MHz) and Clk_En = '1') then
      pres_state <= next_state;
    end if;
  end process StateReg;

  -- "Next State Logic" (FSM) description
  LRH <= Break & Lturn & Rturn & Hazard;
  FSM: process (pres_state, LRH)
  begin
    case pres_state is

      when ST0 => 
        case LRH is
          when "0000"   => next_state <= ST0; -- All off
          when "0110"   => next_state <= ST0; -- All off
          when "0100"   => next_state <= ST2; -- Left Turn
          when "0010"   => next_state <= ST5; -- Right Turn
          when "1000"   => next_state <= ST8; -- Break

          when others  => next_state <= ST1; -- Hazard
        end case;

      when ST1         => next_state <= ST0;
      when ST2         => next_state <= ST3;
      when ST3         => next_state <= ST4;
      when ST4         => next_state <= ST0;
      when ST5         => next_state <= ST6;
      when ST6         => next_state <= ST7;    
      when ST7         => next_state <= ST0;

        when ST8 =>
            case LRH is 
                when "1000" => next_state <= ST8;
                when others  => next_state <= ST0;
        end case;



      -- Include when others to avoid latches  
      when others      => next_state <= ST0;
    end case;
  end process FSM;

  -- "Output Logic" (Outputs) description
  Outputs: process (pres_state)
  begin
    case pres_state is

      when ST0 => Llights <= "000"; Rlights <= "000";
      when ST1 => Llights <= "111"; Rlights <= "111";   
      when ST2 => Llights <= "001"; Rlights <= "000";
      when ST3 => Llights <= "011"; Rlights <= "000";
      when ST4 => Llights <= "111"; Rlights <= "000";
      when ST5 => Llights <= "000"; Rlights <= "001";
      when ST6 => Llights <= "000"; Rlights <= "011";
      when ST7 => Llights <= "000"; Rlights <= "111";   
      when ST8 => Llights <= "111"; Rlights <= "111";
      when others => null;
   end case;
  end process Outputs;

end Behavioral;

警告说明:

警告:Xst:737 - 找到信号的 3 位锁存器。不完整的 case 或 if 语句可能会生成锁存器。我们不建议在 FPGA/CPLD 设计中使用锁存器,因为它们可能会导致时序问题。

警告:Xst:737 - 找到信号的 3 位锁存器。不完整的 case 或 if 语句可能会生成锁存器。我们不建议在 FPGA/CPLD 设计中使用锁存器,因为它们可能会导致时序问题。

谢谢您的帮助。:D

4

2 回答 2

3

而不是这个:

  Outputs: process (pres_state)
  begin
    case pres_state is
      when ST0 => Llights <= "000"; Rlights <= "000";
      when ST1 => Llights <= "111"; Rlights <= "111";   
      when ST2 => Llights <= "001"; Rlights <= "000";
      when ST3 => Llights <= "011"; Rlights <= "000";
      when ST4 => Llights <= "111"; Rlights <= "000";
      when ST5 => Llights <= "000"; Rlights <= "001";
      when ST6 => Llights <= "000"; Rlights <= "011";
      when ST7 => Llights <= "000"; Rlights <= "111";   
      when ST8 => Llights <= "111"; Rlights <= "111";
      when others => null;
   end case;
  end process Outputs;

做这个:

  Outputs: process (pres_state)
  begin
    case pres_state is
      when ST0 => Llights <= "000"; Rlights <= "000";
      when ST1 => Llights <= "111"; Rlights <= "111";   
      when ST2 => Llights <= "001"; Rlights <= "000";
      when ST3 => Llights <= "011"; Rlights <= "000";
      when ST4 => Llights <= "111"; Rlights <= "000";
      when ST5 => Llights <= "000"; Rlights <= "001";
      when ST6 => Llights <= "000"; Rlights <= "011";
      when ST7 => Llights <= "000"; Rlights <= "111";   
      when ST8 => Llights <= "111"; Rlights <= "111";
      when others => Llights <= "000"; Rlights <= "000";
   end case;
  end process Outputs;

您的编译器问您的问题是:“Llights当 pres_state 为 时的值是ST9多少?” 我知道 ST9 不存在,但编译器不在乎。这很烦人。

于 2013-11-01T19:32:07.710 回答
1

不要在组合过程中使用 case 语句。如果您在输出过程中添加时钟,它将起作用。或者,您可以使用 VHDL SELECT 信号分配。组合过程中的 case 语句正在生成锁存器。

你可以这样解决它:(这将增加 1 个时钟周期延迟)

Outputs: process (Clk100MHz)
begin
  if (rising_edge(Clk100MHz) then

  case pres_state is

  when ST0 => Llights <= "000"; Rlights <= "000";
  when ST1 => Llights <= "111"; Rlights <= "111";   
  when ST2 => Llights <= "001"; Rlights <= "000";
  when ST3 => Llights <= "011"; Rlights <= "000";
  when ST4 => Llights <= "111"; Rlights <= "000";
  when ST5 => Llights <= "000"; Rlights <= "001";
  when ST6 => Llights <= "000"; Rlights <= "011";
  when ST7 => Llights <= "000"; Rlights <= "111";   
  when ST8 => Llights <= "111"; Rlights <= "111";
  when others => null;
 end case;
 end if;

结束过程输出;

你也可以这样做:

Llights <= "000" when pres_state = ST0 else
           "111" when pres_state = ST1 else
           etc etc

或者您可以使用 VHDL 选择信号分配。

于 2013-11-01T19:28:33.087 回答