Fellow SO用戶,VHDL - 設置傳感器的採樣率
我試圖以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)。
那麼,你必須提供更多關於你試圖連接的設備的數據。 代碼對我來說似乎還行,但不知道你要與哪個設備進行交互,不可能給你一個很好的答案。 – FarhadA