首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MyHDL:无法将Signal.intbv.max转换为VHDL语言

MyHDL:无法将Signal.intbv.max转换为VHDL语言
EN

Stack Overflow用户
提问于 2017-06-28 14:14:15
回答 2查看 71关注 0票数 2

我是新接触MyHDL和MyHDL的,所以我从把旧的VHDL项目转换成python开始。这个项目是一个vga计时器,可以接受任何宽度,高度和频率(考虑到他们实际上与显示器工作)。由于以下语句,它无法成功转换为VHDL或Verilog:

代码语言:javascript
复制
h_count.val.max  # line 30
v_count.val.max  # line 33

我可以很好地打印它们的值,这样它们肯定会计算成整数,但是如果我用它们的文字值替换它们,那么它就可以正确地转换。我在myhdl问题跟踪器中找不到任何关于这个问题的东西,但我不想因为一个新手的错误而添加一个错误的问题。有没有合适的方式来使用Signal.val.max,或者我应该避免使用它?下面是完整的代码:

代码语言:javascript
复制
from myhdl import Signal, intbv, always_comb, always, toVHDL


def vga_timer(clk, x, y, h_sync, v_sync, vidon, width=800, height=600, frequency=72,
          left_buffer=0, right_buffer=0, top_buffer=0, bottom_buffer=0):
    # load vga constants by resolution
    resolution = (width, height, frequency)
    supported_resolutions = {(640, 480, 60): (16, 96, 48, 10, 2, 33, 0),
                         (800, 600, 60): (40, 128, 88, 1, 4, 23, 1),
                         (800, 600, 72): (56, 120, 64, 37, 6, 23, 1),
                         (1024, 768, 60): (24, 136, 160, 3, 6, 29, 0),
                         (1280, 720, 60): (72, 80, 216, 3, 5, 22, 1),
                         (1920, 1080, 60): (88, 44, 148, 4, 5, 36, 1)}
    assert resolution in supported_resolutions, "%ix%i @ %ifps not a supported resolution" % (width, height, frequency)
    screen_constants = supported_resolutions.get(resolution)

    # h for horizontal variables and signals, v for vertical constants and signals
    h_front_porch, h_sync_width, h_back_porch, v_front_porch, v_sync_width, v_back_porch, polarity = screen_constants

    h_count = Signal(intbv(0, 0, width + h_front_porch + h_sync_width + h_back_porch))
    v_count = Signal(intbv(0, 0, height + v_front_porch + v_sync_width + v_back_porch))

    print(h_count.val.max)
    print(v_count.val.max)

    @always(clk.posedge)
    def counters():
        h_count.next = h_count + 1
        v_count.next = v_count
        if h_count == 1040 - 1:  # h_count.val.max - 1:
            h_count.next = 0
            v_count.next = v_count + 1
            if v_count == 666 - 1:  # v_count.val.max - 1:
                v_count.next = 0

    # determines h_sync and v_sync
    @always_comb
    def sync_pulses():
        h_sync_left = width - left_buffer + h_front_porch
        h_sync_right = h_sync_left + h_sync_width
        h_sync.next = polarity
        if h_sync_left <= h_count and h_count < h_sync_right:
             h_sync.next = not polarity

        v_sync_left = height - top_buffer + v_front_porch
        v_sync_right = v_sync_left + v_sync_width
        v_sync.next = polarity
        if v_sync_left <= v_count and v_count < v_sync_right:
            v_sync.next = not polarity

    @always_comb
    def blanking():
        vidon.next = 0
        if h_count < width - left_buffer - right_buffer and v_count < height - top_buffer - bottom_buffer:
            vidon.next = 1

    @always_comb
    def x_y_adjust():
        # x and y are only used when vidon = 1. during this time x = h_count and y = v_count
        x.next = h_count[len(x.val):]
        y.next = v_count[len(y.val):]

    return counters, sync_pulses, blanking, x_y_adjust

width = 800
height = 600
frequency = 72

clk = Signal(bool(0))
x = Signal(intbv(0)[(width-1).bit_length():])
y = Signal(intbv(0)[(height-1).bit_length():])
h_sync = Signal(bool(0))
v_sync = Signal(bool(0))
vidon = Signal(bool(0))

vga_timer_inst = toVHDL(vga_timer, clk, x, y, h_sync, v_sync, vidon, width, height, frequency)

任何关于我的代码的建议也是受欢迎的。

EN

回答 2

Stack Overflow用户

发布于 2018-04-05 15:39:17

你现在可能已经发现了这一点,但是如果你想要可转换的代码,你不能使用信号质量(最小,最大,位数等)。在组合或顺序块中。不过,您可以在这些块之外的常量赋值中使用它们。因此,如果您使用这些语句而不是print语句:h_counter_max = h_count.val.max - 1 v_counter_max = v_count.val.max - 1,则可以在测试中的第30和33行使用h_counter_maxv_counter_max

票数 0
EN

Stack Overflow用户

发布于 2018-12-08 04:12:58

可以在最新版本中使用minmax属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44794900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档