AHDL dff 重置为其默认值

AHDL dff resets to it default value

我正在 AHDL 上做变频时钟。算法是:一个计数器(触发器)从 0 计数到 x,当它到达 x 时 - 我们有脉冲。我有另一个用于存储 X 的触发器。我还有两个输入 plusminus 用于更改频率(增加或减少 X 值)。

我有以下代码:

constant maximum = 9;
constant minimum = 1;
constant default = 5;
subdesign generator(
    plus, minus, clk: input;
    pulse, level[3..0], curr_val[3..0]: output;
)

variable
    level[3..0]: dff;
    curr_val[3..0]: dff;

begin
    defaults
        level[].d = default; % load 5 as default X value %
    end defaults;

    level[].clk = clk;
    curr_val[].clk = clk;

    pulse = (curr_val[] == level[]); % if main counter reached X - send one pulsation %

    % main counter %    
    if curr_val[] < level[] then
        curr_val[] = curr_val[] + 1;
    elsif curr_val[] == level[] then
        curr_val[] = 0;
    end if;

    % buttons %
    if plus then
        if (level[].q > minimum) then % if X == maximum ignore button %
            level[].d = level[].q - 1;
        end if;
    end if;

    if minus then
        if (level[].q < maximum) then
            level[].d = level[].q + 1;
        end if;
    end if;
end;

问题是 - 在我更改 X (level[]) 值时打勾后 - 它会恢复到默认值。我错过了什么吗?

由于标记错误,语法高亮显示错误。 % text %是评论。

找到问题了。 如果未设置值,defaults 块每次都有效。所以,如果你想存储相同的值,你应该每次都设置它。