【问题标题】:Synthesis and Simulation Independent Clock Divider综合和仿真独立时钟分频器
【发布时间】:2012-10-21 14:19:01
【问题描述】:

我是 VHDL 新手,正在做家庭作业。

我有一个使用泛型的非常简单的时钟分频器。 (这是一个计数器/分隔符。)

-- the actual divider will be 2.1e6 or so (25Mhz down to 15hz)
run_divider : clk_divider
--pragma synthesis off
    generic map(clkmax => 4) -- simulation
--pragma synthesis on
    generic map(clkmax => 50000) -- synthesis
      port map( clk_in => mclk,
                reset => rst,
                clk_out => divider_out );

我在上面的编译指示中部分使用了Equivalent of #ifdef in VHDL for simulation/synthesis separation?。但是,这仅适用于综合,但在模拟中是语法错误。

除了使用外部工具(建议的另一个答案是 M4、C 预处理器)之外,还有没有更好的方法来为合成和模拟分别编写代码?当我在综合和仿真之间切换时,我不想再担心这些常量。

How to convert 24MHz and 12MHz clock to 8MHz clock using VHDL? 的回答告诉我计数器/除法器不是最佳解决方案,但它对我的作业来说足够简单 :-)

我的完整分隔符代码在这里: https://github.com/linuxlizard/vhdl/blob/master/divider.vhdl

谢谢!

【问题讨论】:

    标签: vhdl


    【解决方案1】:

    正如 simon 所说,您可以使用带有 generate 的标志 - 如果您将此代码放入某个实用程序包中,则可以在整个设计中使用它。或者如果它是一次性的,只需将其添加到本地架构中:

    constant in_simulation : boolean := false
    --synthesis translate_off
                                        or true
    --synthesis translate_on
    ;
    

    一个可能有用的替代方法是:

    constant in_simulation : integer  := 0
    --synthesis translate_off
                                        + 1
    --synthesis translate_on
    ;
    
    constant in_synthesis : integer  := 1
    --synthesis translate_off
                                        - 1
    --synthesis translate_on
    ;
    

    根据您的情况,可以使用以下方法:

    constant clkmax_coefficient : integer := 4*in_simulation + 50000*in_synthesis;
    
    run_divider : clk_divider
        generic map(clkmax => clkmax_coefficient)
    ...
    

    【讨论】:

    • 所有很棒的有用的答案!谢谢!
    【解决方案2】:

    您可以在包中将generate 语句与boolean 标志结合使用。

    g_simulation : if SIMULATION_FLAG generate
        run_divider : clk_divider
        generic map(clkmax => 4) -- simulation
        port map(clk_in => mclk,
            reset => rst,
            clk_out => divider_out);
    end generate g_simulation;
    
    g_synthesis : if not SIMULATION_FLAG generate
        run_divider : clk_divider
        generic map(clkmax => 50000) -- synthesis
        port map(clk_in => mclk,
            reset => rst,
            clk_out => divider_out);
    end generate g_synthesis;
    

    您可以编写一个简单的模拟/综合脚本,在编译源代码之前设置SIMULATION_FLAG(或者如果您不需要经常手动更改它)。

    【讨论】:

      【解决方案3】:

      模拟器给你一个语法错误是正确的,因为你在代码中有两个通用语句。

      最简单的方法是在设计中将 50000 设为默认值,然后将代码修改为:

          -- the actual divider will be 2.1e6 or so (25Mhz down to 15hz)
      run_divider : clk_divider
      --pragma synthesis off
          generic map(clkmax => 4) -- simulation
      --pragma synthesis on
            port map( clk_in => mclk,
                      reset => rst,
                      clk_out => divider_out );
      

      这样,对于模拟,您将clkmax 设置为 4,对于综合,它将设置为默认值 50000。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-17
        • 2016-09-25
        • 2021-08-15
        • 2012-10-22
        相关资源
        最近更新 更多