Академический Документы
Профессиональный Документы
Культура Документы
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY bidir IS
PORT(
w,r,en: in STD_LOGIC:='0';
END bidir;
begin
p1:process(en,r,w)
begin
w1<=w;
r1<='Z';
elselsif(en='1') then
w1<='Z';
r1<=r;
end elsif;
end process;
END maxpld;
library ieee;
use ieee.std_logic_1164.all;
entity Test_Bidir is
generic (width : natural := 0); -- Width of buffer
end Test_Bidir;
begin -- RTL
end RTL;
(OR)
library ieee;
use ieee.std_logic_1164.all;
library ieee;
use ieee.std_logic_1164.all;
entity clkdcd1 is
port (Data_w : in std_logic; -- input data
end clkdcd1;
begin -- RTL
end RTL;
(OR)
library ieee;
use ieee.std_logic_1164.all;
entity clkdcd1 is
end clkdcd1;
------------------------------------------------------------------
begin -- RTL
-----------------------------------------------------------------
p1:process(clk,reset)
variable cnt:integer;
begin
elsif(reset='0') then
clk_sig0<='0';
cnt:=0;
elsif(cnt=20000000)then
clk_sig0<= not(clk_sig0);
data_rw_cnt<=not data_rw_cnt;
cnt:=0;
else
cnt:= cnt + 1;
end elsif;
end elsif;
clk_sig_out<=clk_sig0;
end process;
------------------------------------------------------------
---------------------------------------------------------------
end RTL;
Design Example 5.17: Develop a digital system in FPGA to measure the wind speed
and its direction using a cup-anemometer and a direction finding van respectively. Assume
that the vane consists of eight reed switches. Measure and log those data, once in every
second, in the registers.
Solution:
A JK FF is used to hold the pulse coming from anemometer and to reset it after reading the
pulse. Every polling of the anemometer actually, a clock pulse to the JK-FF and its output (Q)
goes high for all the rising edge of the clock pulse. The level hold and reset controller
continuously monitors the voltage changes at ‘Q’ and increments the value of 5-digit counter
at the rising edge of the ‘Q’. After one milli second, it resets the JK FF by sending a low
signal to the ‘clr’ pin.
The LED glows every time when anemometer sends a signal to the FPGA. A one second
clock counter is designed to trigger the counter controller unit once in every second which
keeps the counter in counting mode, shifting mode or reset mode. The clock manager
generates the control and trigger signal at 5kHz rate in order to synchronize the measurement.
The counter value (000000010000)2 for a given second, is equal to 16 in radix 10. The reed
switch of anemometer polls for four times per cycle, hence the angular velocity s(t) of the
anemometer is given by counter value/4. The VHDL code is as below:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ws_se is
Port ( ws_data_in,clk,ws_reg_reset : in STD_LOGIC:='0';
w_dir: in std_logic_vector(7 downto 0):="00000000";
ws_ff_reset: out std_logic:='0';
ws_out : out STD_LOGIC_vector(13 downto 0):="00000000000000");
end ws_se;
architecture Behavioral of ws_se is
signal ws_reg:std_logic_vector(13 downto 0):="00000000000000";
signal w_dir_reg:std_logic_vector(7 downto 0):="00000000";
signal ws_clk_sig:std_logic:='0';
begin
p0:process(clk)
variable ws_cnt1:integer:=0;
begin
if rising_edge(clk) then
if(ws_cnt1=400)then
ws_clk_sig<= not(ws_clk_sig);
ws_cnt1:=1;
else
ws_cnt1:= ws_cnt1 + 1;
end if;
end if;
end process;
p1:process(ws_clk_sig,ws_data_in,ws_reg_reset,w_dir)
variable ws_cnt2: integer:=0;
begin
if (ws_reg_reset='1') then
ws_reg<="00000000000000";
ws_cnt2:=0;
ws_ff_reset<='1';
elsif (rising_edge(ws_clk_sig))then
if(ws_cnt2=0) then
ws_ff_reset<='1';
ws_cnt2:=ws_cnt2+1;
elsif(ws_cnt2=1) then
if (ws_data_in ='0') then
ws_ff_reset<='1';
ws_cnt2:=ws_cnt2;
else ws_cnt2:=ws_cnt2+1;
end if;
elsif(ws_cnt2=3) then
ws_reg<=ws_reg+ 1;
ws_ff_reset<='1';
ws_cnt2:=ws_cnt2+1;
elsif(ws_cnt2=20) then
ws_ff_reset<='0';
ws_cnt2:=ws_cnt2+1;
elsif(ws_cnt2=50) then
ws_ff_reset<='1';
ws_cnt2:=0;
else
ws_cnt2:=ws_cnt2+1;
w_dir_reg<=w_dir;
end if;
end if;
end process;
ws_out<=ws_reg;
end Behavioral;