0

SO用户,

我正在尝试以 5Hz 的频率(每秒 5 个样本)对我的电阻式湿度传感器进行采样。我正在使用 ADC 读取输出。现在,有人告诉我,您可以以任何频率运行 ADC,但您需要使用 5hz 时钟来启动转换并从 ADC 读取值。

我这样做的方式是通过以 5hz 运行并有一个标志来启动转换的过程,在时钟的上升沿将“start_convert”说为“1”。

PROCESS (CLK_5HZ)       
BEGIN
    IF (CLK_5HZ'EVENT AND CLK_5HZ = '1') THEN
        START_CONVERT <= '1';
    END IF;
END PROCESS;

然后我有一个 ADC 的状态机;

PROCESS (CURR_STATE, INTR)
                BEGIN

                CASE CURR_STATE IS

                        WHEN STARTUP =>
                            WR <= '0';
                            READ_DATA <= '0';
                            IF (START_CONVERT = '1') THEN
                                NEXT_STATE <= CONVERT;
                            ELSE
                                NEXT_STATE <= STARTUP;
                            END IF;

                        WHEN CONVERT =>
                            IF (INTR = '0' AND STREAM = '1') THEN
                                NEXT_STATE <= WAIT500;
                            ELSIF (INTR = '0' AND STREAM = '0') THEN
                                NEXT_STATE <= READ1;
                            ELSE
                                NEXT_STATE <= CONVERT;
                            END IF;
                            WR <= '1';
                            READ_DATA <= '0';

                        WHEN WAIT10 =>
                            IF (COUNTER_WAIT = 10) THEN
                                NEXT_STATE <= READ1;
                            ELSE
                                NEXT_STATE <= WAIT10;
                            END IF;
                            COUNTER_WAIT <= COUNTER_WAIT + 1;

                        WHEN READ1 =>
                            NEXT_STATE <= CONVERT;
                            WR <= '1';
                            READ_DATA <= '1';

                        WHEN OTHERS =>
                            NEXT_STATE <= STARTUP;
                END CASE;
                END PROCESS;

然后我在 5hz 使用另一个进程来检测 READ_DATA 是否为 1,以便我从 ADC 读取值。

PROCESS (CLK_5HZ, RST)
    BEGIN
    IF (RST = '1') THEN
    Y <= (OTHERS => '0');
    ELSIF (CLK_5HZ'EVENT AND CLK_5HZ = '1') THEN
        IF (READ_DATA = '1') THEN
        Y <= DATA_IN (0) & DATA_IN (1) &
         DATA_IN (2) & DATA_IN (3) &
         DATA_IN (4) & DATA_IN (5) &
         DATA_IN (6) & DATA_IN (7);
    END IF;
   END IF;
END PROCESS;

谁能告诉我这是否是正确的方法?

编辑:我正在使用 Spartan-3 板连接 ADC (ADC0804)。

4

1 回答 1

3

当不知道您要连接的设备的具体情况时,很难给出具体的建议。

但是,关于您的代码的一些一般性评论:

  • 您的异步过程(PROCESS (CURR_STATE, INTR))在合成它时会生成很多锁存器,因为您不是在所有情况下都设置所有信号。WR并且READ_DATA例如没有设置在您的WAIT10状态。这很可能会导致严重的时间问题,所以纠正这是你绝对想做的事情。

  • WAIT10同一进程中的状态将为您提供一个组合循环,因为它在COUNTER_WAIT更新时运行。由于该状态也会更新COUNTER_WAIT,理论上它会继续运行,但实际上大多数合成器只会给你一个错误(我认为)。您需要将增量移动到同步/时钟过程,这也可以让您控制每个周期需要多长时间。

  • Your 5 Hz processes seem to run on a separate clock (CLK_5HZ). I presume that the rest of your system is running at a faster clock? This essentially gives you two (or more) clock domains, that will need special interface logic for interfacing them with each other. A much, much better solution is to run everything on the same (fast) clock, and control slower processes using clock enables. Everything is thus inherently synchronized, and shouldn't give you any nasty timing surprises.

于 2012-10-15T09:54:40.660 回答