我在这个模拟中缺少什么?

时间:2016-01-01 15:23:52

标签: vhdl modelsim

我正在尝试为键盘驱动程序编写VHDL代码,因为我需要读取11位向量中的8位,这里要清楚的是读取输入信号的过程(有信号CLK和数据) 。

KEYBOARD_SYNC : process(CLK,SYSRESET)
        begin 
            if (CLK'event and CLK='1') then 
                KEYBOARD_CLK_VECTOR <=   KEYBOARD_CLK_VECTOR( 6 downto 0 ) & KEYBOARD_CLK;
                    RECEIVING_FLAG <='0';
                    if ( KEYBOARD_CLK_VECTOR = x"F0" ) then  -- Falling edge 
                        KEYBOARD_DATA_VECTOR <= KEYBOARD_DATA_VECTOR( 9 downto 0 ) & KEYBOARD_DATA;-- shifting 
                        BIT_COUNTER <= BIT_COUNTER + 1 ; 

                    end if; 

                    if( BIT_COUNTER = 11 ) then 
                        RECEIVING_FLAG <='1';
                        TEMP_WORD <= KEYBOARD_DATA_VECTOR( 8 downto 1 );
                        BIT_COUNTER <=0 ;
                        KEYBOARD_DATA_VECTOR <= (others =>'1');
                    end if ;

            end if ; 
end process KEYBOARD_SYNC; 

 PROCESSING  : process ( CLK ,SYSRESET ) 
        begin 
            if ( CLK'event and CLK ='1') then 
                if ( RECEIVING_FLAG = '1') then 
                    ACTUAL_WORD <= TEMP_WORD; 
                end if ;
            end if ;
end process PROCESSING;

为了运行模拟,我写了一个应该发送0xF0的测试平台,这个值应该保存在ACTUAL_WORD中,这里应该是测试平台的一部分:

-- Timing variables 
constant CLK_PERIOD: time := 10 ns;
constant KEYBOARD_CLK_PERIOD: time := 80 us;

...................................................



    KEYBOARD_PROCESS : process 
    BEGIN 


        -- BREAK Code 
            KEYBOARD_CLK <= '1';
            KEYBOARD_DATA <= '0';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            --Start  Bit  always 0 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';                
            KEYBOARD_DATA <= '1';           -- Sending a break code 0xF0 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 0  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 1  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 2  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 3  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_DATA<= '0';
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 4  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 5  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 6  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- 7  Bit 
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_DATA<= '1';
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- Parity Bit           
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '0';            -- Stop Bit  always 1   
        wait for (KEYBOARD_CLK_PERIOD/2);
            KEYBOARD_CLK <= '1';
        wait for (KEYBOARD_CLK_PERIOD/2);
end process KEYBOARD_PROCESS;

结果是: rotated (点击)

问题在于我一直在阅读0xE1而不是0xF0其他一切正常工作,我无法弄清楚为什么我错过了这一点。

1 个答案:

答案 0 :(得分:3)

读取0xF0的周期性模式为0xE1看起来像1位移位,这可能是由同时生成时钟(KEYBOARD_CLK)和数据(KEYBOARD_DATA)的测试平台引起的时间。

在硬件设计中,输出数据是由时钟产生的,因此在时钟的上升沿和新数据之间至少会有一个增量周期延迟,但当前的测试平台设计会产生时钟和数据。同时:

KEYBOARD_CLK <= '1';
KEYBOARD_DATA <= '0';

其波形看起来很熟悉,但信号流实际上缺少时钟和数据之间的增量周期延迟,因此数据比波形预期提前一个周期准备就绪,导致1位移位。然而,在当前的波形图中没有示出,这可能是令人费解的部分。 ModelSim可以显示缺少delta周期,但这不是默认值。

在测试平台设计中遵循通用设计方法通常是个好主意,以便保持单一的通用设计实践,这使得阅读代码和波形更容易。

因此,在测试平台中,制作一个生成时钟的过程,然后根据时钟进行生成数据的过程,就像硬件设计一样。这可以这样做:

CLK_PROCESS : process 
BEGIN 
  KEYBOARD_CLK <= '1';
  wait for (KEYBOARD_CLK_PERIOD/2);
  KEYBOARD_CLK <= '1';
  wait for (KEYBOARD_CLK_PERIOD/2);
end process;

DATA_PROCESS : process
BEGIN
  KEYBOARD_DATA <= '0';
  for i in 1 to 5 loop  -- Number of cycles with same data
      wait until rising_edge(KEYBOARD_CLK);
  end loop;
  ...
  KEYBOARD_DATA <= '1';
  for i in 1 to 5 loop  -- Number of cycles with same data
      wait until rising_edge(KEYBOARD_CLK);
  end loop;
  ...
end process;

根据所需的测试模式调整重复数据的循环。